From c2dd07448ff1b2922e8ea14f909a9cbde481e5fc Mon Sep 17 00:00:00 2001 From: Keerthan Jaic Date: Tue, 4 Aug 2015 21:41:38 -0400 Subject: option,main: Partial support of XDG base directory specification - Add functions that are able to query XDG. - Replace defaults for - &runtimepath. Does not follow #78. - &viewdir. - &undodir. - &directory. - &backupdir. Does not follow #78. - vimrc location. - Remove user vimrc file line from :version message. --- src/nvim/os/os.h | 1 + src/nvim/os/stdpaths.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ src/nvim/os/unix_defs.h | 29 -------------- src/nvim/os/win_defs.h | 1 - 4 files changed, 101 insertions(+), 30 deletions(-) create mode 100644 src/nvim/os/stdpaths.c (limited to 'src/nvim/os') diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index 69bd1ff4fd..198f9ae897 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -12,6 +12,7 @@ # include "os/mem.h.generated.h" # include "os/env.h.generated.h" # include "os/users.h.generated.h" +# include "os/stdpaths.h.generated.h" #endif #endif // NVIM_OS_OS_H diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c new file mode 100644 index 0000000000..230e760d7d --- /dev/null +++ b/src/nvim/os/stdpaths.c @@ -0,0 +1,100 @@ +#include "nvim/os/os.h" +#include "nvim/strings.h" +#include "nvim/path.h" +#include "nvim/garray.h" + +typedef enum { + kXDGConfigHome, + kXDGDataHome, + kXDGCacheHome, + kXDGRuntimeDir, + kXDGConfigDirs, + kXDGDataDirs, +} XDGDirType; + +static const char *xdg_env_vars[] = { + [kXDGConfigHome] = "XDG_CONFIG_HOME", + [kXDGDataHome] = "XDG_DATA_HOME", + [kXDGCacheHome] = "XDG_CACHE_HOME", + [kXDGRuntimeDir] = "XDG_RUNTIME_DIR", + [kXDGConfigDirs] = "XDG_CONFIG_DIRS", + [kXDGDataDirs] = "XDG_DATA_DIRS", +}; + +static const char *const xdg_defaults[] = { + // Windows, Apple stuff are just shims right now +#ifdef WIN32 + // Windows +#elif APPLE + // Apple (this includes iOS, which we might need to handle differently) + [kXDGConfigHome] = "~/Library/Preferences", + [kXDGDataHome] = "~/Library/Application Support", + [kXDGCacheHome] = "~/Library/Caches", + [kXDGRuntimeDir] = "~/Library/Application Support", + [kXDGConfigDirs] = "/Library/Application Support", + [kXDGDataDirs] = "/Library/Application Support", +#else + // Linux, BSD, CYGWIN + [kXDGConfigHome] = "~/.config", + [kXDGDataHome] = "~/.local/share", + [kXDGCacheHome] = "~/.cache", + [kXDGRuntimeDir] = "", + [kXDGConfigDirs] = "/etc/xdg/", + [kXDGDataDirs] = "/usr/local/share/:/usr/share/", +}; +#endif + +static const char *get_xdg(XDGDirType idx) +{ + const char *env = xdg_env_vars[idx]; + const char *fallback = xdg_defaults[idx]; + + const char *ret = os_getenv(env); + if (!ret && fallback) { + ret = (const char *)expand_env_save((char_u *)fallback); + } + + return ret; +} + +static const char *get_xdg_home(XDGDirType idx) +{ + const char *dir = get_xdg(idx); + if (dir) { + dir = (const char *)concat_fnames(dir, "nvim", true); + } + return dir; +} + +static void create_dir(const char *dir, int mode, const char *suffix) +{ + char *failed; + if (!os_mkdir_recurse(dir, mode, &failed)) { + // TODO: Create a folder in $TMPDIR instead + DLOG("Create dir failed"); + } +} + +const char *get_user_conf_dir(void) +{ + return get_xdg_home(kXDGConfigHome); +} + +const char *get_from_user_conf(const char * fname) +{ + return (const char *)concat_fnames(get_user_conf_dir(), fname, true); +} + +const char *get_user_data_dir(void) +{ + return get_xdg_home(kXDGDataHome); +} + +const char *get_from_user_data(const char * fname) +{ + const char *dir = (const char *)concat_fnames(get_user_data_dir(), fname, true); + if (!os_isdir((char_u *)dir)) { + create_dir(dir, 0755, fname); + } + return dir; +} diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 949973bf40..83c6752ff7 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -31,12 +31,6 @@ #ifndef USR_EXRC_FILE # define USR_EXRC_FILE "~/.exrc" #endif -#ifndef USR_VIMRC_FILE -# define USR_VIMRC_FILE "~/.nvimrc" -#endif -#ifndef USR_VIMRC_FILE2 -# define USR_VIMRC_FILE2 "~/.nvim/nvimrc" -#endif #ifndef EXRC_FILE # define EXRC_FILE ".exrc" #endif @@ -47,27 +41,4 @@ # define SHADA_FILE "~/.nvim/shada/main.shada" #endif -// Default for 'backupdir'. -#ifndef DFLT_BDIR -# define DFLT_BDIR ".,~/tmp,~/" -#endif - -// Default for 'directory'. -#ifndef DFLT_DIR -# define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" -#endif - -// Default for 'viewdir'. -#ifndef DFLT_VDIR -# define DFLT_VDIR "~/.nvim/view" -#endif - -#ifdef RUNTIME_GLOBAL -# define DFLT_RUNTIMEPATH "~/.nvim," RUNTIME_GLOBAL ",$VIMRUNTIME," \ - RUNTIME_GLOBAL "/after,~/.nvim/after" -#else -# define DFLT_RUNTIMEPATH \ - "~/.nvim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.nvim/after" -#endif - #endif // NVIM_OS_UNIX_DEFS_H diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index b7ec50a109..62889a7d2f 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -8,7 +8,6 @@ // Defines needed to fix the build on Windows: // - USR_EXRC_FILE -// - USR_VIMRC_FILE // - SHADA_FILE // - DFLT_DIR // - DFLT_BDIR -- cgit From 674629be0c8bc02d79d263b1b795ab125e1341e0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Aug 2015 01:51:19 +0300 Subject: os/env: Add functions that can iterate over colon-separated variables --- src/nvim/os/env.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 7be8a868bd..bdf406af5e 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -415,6 +415,74 @@ static char *remove_tail(char *p, char *pend, char *name) return pend; } +/// Iterate over colon-separated list +/// +/// @note Environment variables must not be modified during iteration. +/// +/// @param[in] val Value of the environment variable to iterate over. +/// @param[in] iter Pointer used for iteration. Must be NULL on first +/// iteration. +/// @param[out] dir Location where pointer to the start of the current +/// directory name should be saved. May be set to NULL. +/// @param[out] len Location where current directory length should be saved. +/// +/// @return Next iter argument value or NULL when iteration should stop. +const void *vim_colon_env_iter(const char *const val, + const void *const iter, + const char **const dir, + size_t *const len) + FUNC_ATTR_NONNULL_ARG(1,3,4) FUNC_ATTR_WARN_UNUSED_RESULT +{ + const char *varval = (const char *) iter; + if (varval == NULL) { + varval = val; + } + *dir = varval; + const char *const dirend = strchr(varval, ':'); + if (dirend == NULL) { + *len = strlen(varval); + return NULL; + } else { + *len = (size_t) (dirend - varval); + return dirend + 1; + } +} + +/// Iterate over colon-separated list in reverse order +/// +/// @note Environment variables must not be modified during iteration. +/// +/// @param[in] val Value of the environment variable to iterate over. +/// @param[in] iter Pointer used for iteration. Must be NULL on first +/// iteration. +/// @param[out] dir Location where pointer to the start of the current +/// directory name should be saved. May be set to NULL. +/// @param[out] len Location where current directory length should be saved. +/// +/// @return Next iter argument value or NULL when iteration should stop. +const void *vim_colon_env_iter_rev(const char *const val, + const void *const iter, + const char **const dir, + size_t *const len) + FUNC_ATTR_NONNULL_ARG(1,3,4) FUNC_ATTR_WARN_UNUSED_RESULT +{ + const char *varend = (const char *) iter; + if (varend == NULL) { + varend = val + strlen(val) - 1; + } + const size_t varlen = (size_t) (varend - val) + 1; + const char *const colon = xmemrchr(val, ':', varlen); + if (colon == NULL) { + *len = varlen; + *dir = val; + return NULL; + } else { + *dir = colon + 1; + *len = (size_t) (varend - colon); + return colon - 1; + } +} + /// Vim's version of getenv(). /// Special handling of $HOME, $VIM and $VIMRUNTIME, allowing the user to /// override the vim runtime directory at runtime. Also does ACP to 'enc' -- cgit From 76e2788d87f8474055536efbbc4827ddf290bc89 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 1 Aug 2015 03:04:28 +0300 Subject: option: Use different default value for &runtimepath --- src/nvim/os/win_defs.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 62889a7d2f..427e6a8481 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -12,7 +12,6 @@ // - DFLT_DIR // - DFLT_BDIR // - DFLT_VDIR -// - DFLT_RUNTIMEPATH // - EXRC_FILE // - VIMRC_FILE // - SYNTAX_FNAME -- cgit From 1db5a807b203634de608f68e76387fcf0a7857d7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 14:17:16 +0300 Subject: stdpaths: Fix some issues, specifically - Remove/add includes - Do not pretend that returns are const - Add function attributes - Allocate memory always in get_xdg --- src/nvim/os/stdpaths.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 230e760d7d..e8cfba8b3a 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -1,7 +1,8 @@ +#include + #include "nvim/os/os.h" -#include "nvim/strings.h" #include "nvim/path.h" -#include "nvim/garray.h" +#include "nvim/memory.h" typedef enum { kXDGConfigHome, @@ -44,29 +45,35 @@ static const char *const xdg_defaults[] = { }; #endif -static const char *get_xdg(XDGDirType idx) +static char *get_xdg(const XDGDirType idx) + FUNC_ATTR_WARN_UNUSED_RESULT { - const char *env = xdg_env_vars[idx]; - const char *fallback = xdg_defaults[idx]; + const char *const env = xdg_env_vars[idx]; + const char *const fallback = xdg_defaults[idx]; - const char *ret = os_getenv(env); - if (!ret && fallback) { - ret = (const char *)expand_env_save((char_u *)fallback); + const char *const env_val = os_getenv(env); + char *ret = NULL; + if (env_val != NULL) { + ret = xstrdup(env_val); + } else if (fallback) { + ret = (char *) expand_env_save((char_u *)fallback); } return ret; } -static const char *get_xdg_home(XDGDirType idx) +static char *get_xdg_home(XDGDirType idx) + FUNC_ATTR_WARN_UNUSED_RESULT { - const char *dir = get_xdg(idx); + char *dir = get_xdg(idx); if (dir) { - dir = (const char *)concat_fnames(dir, "nvim", true); + dir = concat_fnames(dir, "nvim", true); } return dir; } static void create_dir(const char *dir, int mode, const char *suffix) + FUNC_ATTR_NONNULL_ALL { char *failed; if (!os_mkdir_recurse(dir, mode, &failed)) { @@ -75,24 +82,28 @@ static void create_dir(const char *dir, int mode, const char *suffix) } } -const char *get_user_conf_dir(void) +char *get_user_conf_dir(void) + FUNC_ATTR_WARN_UNUSED_RESULT { return get_xdg_home(kXDGConfigHome); } -const char *get_from_user_conf(const char * fname) +char *get_from_user_conf(const char *fname) + FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return (const char *)concat_fnames(get_user_conf_dir(), fname, true); + return concat_fnames(get_user_conf_dir(), fname, true); } -const char *get_user_data_dir(void) +char *get_user_data_dir(void) + FUNC_ATTR_WARN_UNUSED_RESULT { return get_xdg_home(kXDGDataHome); } -const char *get_from_user_data(const char * fname) +char *get_from_user_data(const char *fname) + FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - const char *dir = (const char *)concat_fnames(get_user_data_dir(), fname, true); + char *dir = concat_fnames(get_user_data_dir(), fname, true); if (!os_isdir((char_u *)dir)) { create_dir(dir, 0755, fname); } -- cgit From 120ec8c2eab21dc44baa0c4814cb004fd3db6e54 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 14:37:13 +0300 Subject: stdpaths: Remove useless functions get_user_*_dir --- src/nvim/os/stdpaths.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index e8cfba8b3a..0380c9ea37 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -11,7 +11,7 @@ typedef enum { kXDGRuntimeDir, kXDGConfigDirs, kXDGDataDirs, -} XDGDirType; +} XDGVarType; static const char *xdg_env_vars[] = { [kXDGConfigHome] = "XDG_CONFIG_HOME", @@ -45,7 +45,7 @@ static const char *const xdg_defaults[] = { }; #endif -static char *get_xdg(const XDGDirType idx) +static char *get_xdg(const XDGVarType idx) FUNC_ATTR_WARN_UNUSED_RESULT { const char *const env = xdg_env_vars[idx]; @@ -62,7 +62,7 @@ static char *get_xdg(const XDGDirType idx) return ret; } -static char *get_xdg_home(XDGDirType idx) +static char *get_xdg_home(const XDGVarType idx) FUNC_ATTR_WARN_UNUSED_RESULT { char *dir = get_xdg(idx); @@ -82,28 +82,16 @@ static void create_dir(const char *dir, int mode, const char *suffix) } } -char *get_user_conf_dir(void) - FUNC_ATTR_WARN_UNUSED_RESULT -{ - return get_xdg_home(kXDGConfigHome); -} - char *get_from_user_conf(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return concat_fnames(get_user_conf_dir(), fname, true); -} - -char *get_user_data_dir(void) - FUNC_ATTR_WARN_UNUSED_RESULT -{ - return get_xdg_home(kXDGDataHome); + return concat_fnames(get_xdg_home(kXDGConfigHome), fname, true); } char *get_from_user_data(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - char *dir = concat_fnames(get_user_data_dir(), fname, true); + char *dir = concat_fnames(get_xdg_home(kXDGDataHome), fname, true); if (!os_isdir((char_u *)dir)) { create_dir(dir, 0755, fname); } -- cgit From afb0f2f9b14f0ebcb5c53a47338a6a4359019e38 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 14:40:27 +0300 Subject: stdpaths: Rename export functions so that they have common prefix --- src/nvim/os/stdpaths.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 0380c9ea37..b8ce400276 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -82,13 +82,13 @@ static void create_dir(const char *dir, int mode, const char *suffix) } } -char *get_from_user_conf(const char *fname) +char *stdpaths_user_conf_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { return concat_fnames(get_xdg_home(kXDGConfigHome), fname, true); } -char *get_from_user_data(const char *fname) +char *stdpaths_user_data_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { char *dir = concat_fnames(get_xdg_home(kXDGDataHome), fname, true); -- cgit From be91bc1e1a110da938201eab9b43736e64a7392e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 14:45:53 +0300 Subject: stdpaths: Export get_xdg function (renamed) and use it for runtimepath --- src/nvim/os/os.h | 1 + src/nvim/os/stdpaths.c | 14 +++----------- src/nvim/os/stdpaths_defs.h | 13 +++++++++++++ 3 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/nvim/os/stdpaths_defs.h (limited to 'src/nvim/os') diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index 198f9ae897..3e89e5a94a 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -5,6 +5,7 @@ #include #include "nvim/os/fs_defs.h" +#include "nvim/os/stdpaths_defs.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index b8ce400276..86daa7257a 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -1,18 +1,10 @@ #include +#include "nvim/os/stdpaths_defs.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/memory.h" -typedef enum { - kXDGConfigHome, - kXDGDataHome, - kXDGCacheHome, - kXDGRuntimeDir, - kXDGConfigDirs, - kXDGDataDirs, -} XDGVarType; - static const char *xdg_env_vars[] = { [kXDGConfigHome] = "XDG_CONFIG_HOME", [kXDGDataHome] = "XDG_DATA_HOME", @@ -45,7 +37,7 @@ static const char *const xdg_defaults[] = { }; #endif -static char *get_xdg(const XDGVarType idx) +char *stdpaths_get_xdg_var(const XDGVarType idx) FUNC_ATTR_WARN_UNUSED_RESULT { const char *const env = xdg_env_vars[idx]; @@ -65,7 +57,7 @@ static char *get_xdg(const XDGVarType idx) static char *get_xdg_home(const XDGVarType idx) FUNC_ATTR_WARN_UNUSED_RESULT { - char *dir = get_xdg(idx); + char *dir = stdpaths_get_xdg_var(idx); if (dir) { dir = concat_fnames(dir, "nvim", true); } diff --git a/src/nvim/os/stdpaths_defs.h b/src/nvim/os/stdpaths_defs.h new file mode 100644 index 0000000000..3b882cd582 --- /dev/null +++ b/src/nvim/os/stdpaths_defs.h @@ -0,0 +1,13 @@ +#ifndef NVIM_OS_STDPATHS_DEFS_H +#define NVIM_OS_STDPATHS_DEFS_H + +typedef enum { + kXDGConfigHome, + kXDGDataHome, + kXDGCacheHome, + kXDGRuntimeDir, + kXDGConfigDirs, + kXDGDataDirs, +} XDGVarType; + +#endif // NVIM_OS_STDPATHS_DEFS_H -- cgit From 502a20a8feb80e7e12eb34231975257b915e3115 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 15:32:11 +0300 Subject: stdpaths,main: Remove all remaining memory leaks --- src/nvim/os/stdpaths.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 86daa7257a..9d93f25a7e 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -59,7 +59,7 @@ static char *get_xdg_home(const XDGVarType idx) { char *dir = stdpaths_get_xdg_var(idx); if (dir) { - dir = concat_fnames(dir, "nvim", true); + dir = concat_fnames_realloc(dir, "nvim", true); } return dir; } @@ -77,13 +77,13 @@ static void create_dir(const char *dir, int mode, const char *suffix) char *stdpaths_user_conf_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return concat_fnames(get_xdg_home(kXDGConfigHome), fname, true); + return concat_fnames_realloc(get_xdg_home(kXDGConfigHome), fname, true); } char *stdpaths_user_data_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - char *dir = concat_fnames(get_xdg_home(kXDGDataHome), fname, true); + char *dir = concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true); if (!os_isdir((char_u *)dir)) { create_dir(dir, 0755, fname); } -- cgit From 2e750973e936a04d9effea88f78f03a5a07ab282 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 15:41:05 +0300 Subject: shada: Move shada file to a new location --- src/nvim/os/unix_defs.h | 3 --- src/nvim/os/win_defs.h | 1 - 2 files changed, 4 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 83c6752ff7..82a434cdf1 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -37,8 +37,5 @@ #ifndef VIMRC_FILE # define VIMRC_FILE ".nvimrc" #endif -#ifndef SHADA_FILE -# define SHADA_FILE "~/.nvim/shada/main.shada" -#endif #endif // NVIM_OS_UNIX_DEFS_H diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 427e6a8481..585def7dd0 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -8,7 +8,6 @@ // Defines needed to fix the build on Windows: // - USR_EXRC_FILE -// - SHADA_FILE // - DFLT_DIR // - DFLT_BDIR // - DFLT_VDIR -- cgit From a06a8bad6080e605c25124446c7441cee8911234 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 15:48:38 +0300 Subject: stdpaths: Give proper error message in case directory creation failed --- src/nvim/os/stdpaths.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 9d93f25a7e..e242cd3d69 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -64,13 +64,15 @@ static char *get_xdg_home(const XDGVarType idx) return dir; } -static void create_dir(const char *dir, int mode, const char *suffix) +static void create_dir(const char *dir, int mode) FUNC_ATTR_NONNULL_ALL { char *failed; - if (!os_mkdir_recurse(dir, mode, &failed)) { - // TODO: Create a folder in $TMPDIR instead - DLOG("Create dir failed"); + int err; + if ((err = os_mkdir_recurse(dir, mode, &failed)) != 0) { + EMSG3(_("E920: Failed to create data directory %s: %s"), failed, + os_strerror(-err)); + xfree(failed); } } @@ -85,7 +87,7 @@ char *stdpaths_user_data_subpath(const char *fname) { char *dir = concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true); if (!os_isdir((char_u *)dir)) { - create_dir(dir, 0755, fname); + create_dir(dir, 0755); } return dir; } -- cgit From a1b0f4073deb7f50e1b7137174bcb9914c97078f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 15:51:31 +0300 Subject: stdpaths: Do NOT create data directories This is none of option.c business to create *possibly unneeded* **default** directories **before** user specified where he actually wants to place the files. --- src/nvim/os/stdpaths.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index e242cd3d69..167a53c985 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -64,18 +64,6 @@ static char *get_xdg_home(const XDGVarType idx) return dir; } -static void create_dir(const char *dir, int mode) - FUNC_ATTR_NONNULL_ALL -{ - char *failed; - int err; - if ((err = os_mkdir_recurse(dir, mode, &failed)) != 0) { - EMSG3(_("E920: Failed to create data directory %s: %s"), failed, - os_strerror(-err)); - xfree(failed); - } -} - char *stdpaths_user_conf_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { @@ -85,9 +73,5 @@ char *stdpaths_user_conf_subpath(const char *fname) char *stdpaths_user_data_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - char *dir = concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true); - if (!os_isdir((char_u *)dir)) { - create_dir(dir, 0755); - } - return dir; + return concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true); } -- cgit From 89a10b3e7cadc5d088217380de7ed1af70ed8b31 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 19:41:03 +0300 Subject: main,os/env: Fix lint errors --- src/nvim/os/env.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index bdf406af5e..bf6db97fcf 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -431,7 +431,7 @@ const void *vim_colon_env_iter(const char *const val, const void *const iter, const char **const dir, size_t *const len) - FUNC_ATTR_NONNULL_ARG(1,3,4) FUNC_ATTR_WARN_UNUSED_RESULT + FUNC_ATTR_NONNULL_ARG(1, 3, 4) FUNC_ATTR_WARN_UNUSED_RESULT { const char *varval = (const char *) iter; if (varval == NULL) { @@ -464,7 +464,7 @@ const void *vim_colon_env_iter_rev(const char *const val, const void *const iter, const char **const dir, size_t *const len) - FUNC_ATTR_NONNULL_ARG(1,3,4) FUNC_ATTR_WARN_UNUSED_RESULT + FUNC_ATTR_NONNULL_ARG(1, 3, 4) FUNC_ATTR_WARN_UNUSED_RESULT { const char *varend = (const char *) iter; if (varend == NULL) { -- cgit From aadaa1fed4d471fc2e286b0ffa151c006482389e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 21:30:52 +0300 Subject: stdpaths: Add documentation --- src/nvim/os/stdpaths.c | 24 ++++++++++++++++++++++++ src/nvim/os/stdpaths_defs.h | 13 +++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 167a53c985..0ed7aec2a6 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -5,6 +5,7 @@ #include "nvim/path.h" #include "nvim/memory.h" +/// Names of the environment variables, mapped to XDGVarType values static const char *xdg_env_vars[] = { [kXDGConfigHome] = "XDG_CONFIG_HOME", [kXDGDataHome] = "XDG_DATA_HOME", @@ -14,6 +15,9 @@ static const char *xdg_env_vars[] = { [kXDGDataDirs] = "XDG_DATA_DIRS", }; +/// Defaults for XDGVarType values +/// +/// Used in case environment variables contain nothing. Need to be expanded. static const char *const xdg_defaults[] = { // Windows, Apple stuff are just shims right now #ifdef WIN32 @@ -37,6 +41,11 @@ static const char *const xdg_defaults[] = { }; #endif +/// Return XDG variable value +/// +/// @param[in] idx XDG variable to use. +/// +/// @return [allocated] variable value. char *stdpaths_get_xdg_var(const XDGVarType idx) FUNC_ATTR_WARN_UNUSED_RESULT { @@ -54,6 +63,11 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) return ret; } +/// Return nvim-specific XDG directory subpath +/// +/// @param[in] idx XDG directory to use. +/// +/// @return [allocated] `{xdg_directory}/nvim` static char *get_xdg_home(const XDGVarType idx) FUNC_ATTR_WARN_UNUSED_RESULT { @@ -64,12 +78,22 @@ static char *get_xdg_home(const XDGVarType idx) return dir; } +/// Return subpath of $XDG_CONFIG_HOME +/// +/// @param[in] fname New component of the path. +/// +/// @return [allocated] `$XDG_CONFIG_HOME/nvim/{fname}` char *stdpaths_user_conf_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { return concat_fnames_realloc(get_xdg_home(kXDGConfigHome), fname, true); } +/// Return subpath of $XDG_DATA_HOME +/// +/// @param[in] fname New component of the path. +/// +/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}` char *stdpaths_user_data_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { diff --git a/src/nvim/os/stdpaths_defs.h b/src/nvim/os/stdpaths_defs.h index 3b882cd582..1433e0bc62 100644 --- a/src/nvim/os/stdpaths_defs.h +++ b/src/nvim/os/stdpaths_defs.h @@ -1,13 +1,14 @@ #ifndef NVIM_OS_STDPATHS_DEFS_H #define NVIM_OS_STDPATHS_DEFS_H +/// List of possible XDG variables typedef enum { - kXDGConfigHome, - kXDGDataHome, - kXDGCacheHome, - kXDGRuntimeDir, - kXDGConfigDirs, - kXDGDataDirs, + kXDGConfigHome, ///< XDG_CONFIG_HOME + kXDGDataHome, ///< XDG_DATA_HOME + kXDGCacheHome, ///< XDG_CACHE_HOME + kXDGRuntimeDir, ///< XDG_RUNTIME_DIR + kXDGConfigDirs, ///< XDG_CONFIG_DIRS + kXDGDataDirs, ///< XDG_DATA_DIRS } XDGVarType; #endif // NVIM_OS_STDPATHS_DEFS_H -- cgit From a82a059921f36fb580026ef4cc31f64c110d07b7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 21:46:30 +0300 Subject: option: Add `//` to the end of default `&directory` --- src/nvim/os/stdpaths.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 0ed7aec2a6..d4bff65312 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -92,10 +92,19 @@ char *stdpaths_user_conf_subpath(const char *fname) /// Return subpath of $XDG_DATA_HOME /// /// @param[in] fname New component of the path. +/// @param[in] trailing_pathseps Amount of trailing path separators to add. /// /// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}` -char *stdpaths_user_data_subpath(const char *fname) +char *stdpaths_user_data_subpath(const char *fname, + const size_t trailing_pathseps) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL { - return concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true); + char *ret = concat_fnames_realloc(get_xdg_home(kXDGDataHome), fname, true); + if (trailing_pathseps) { + const size_t len = strlen(ret); + ret = xrealloc(ret, len + trailing_pathseps + 1); + memset(ret + len, PATHSEP, trailing_pathseps); + ret[len + trailing_pathseps] = NUL; + } + return ret; } -- cgit From afcc842881d2569c11da26a75057062ba4f124e7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 21:53:16 +0300 Subject: main,version: Remove USR_EXRC_FILE* --- src/nvim/os/unix_defs.h | 3 --- src/nvim/os/win_defs.h | 1 - 2 files changed, 4 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 82a434cdf1..e1c3060999 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -28,9 +28,6 @@ #ifndef SYNTAX_FNAME # define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim" #endif -#ifndef USR_EXRC_FILE -# define USR_EXRC_FILE "~/.exrc" -#endif #ifndef EXRC_FILE # define EXRC_FILE ".exrc" #endif diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 585def7dd0..d614582250 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -7,7 +7,6 @@ #define TEMP_FILE_PATH_MAXLEN _MAX_PATH // Defines needed to fix the build on Windows: -// - USR_EXRC_FILE // - DFLT_DIR // - DFLT_BDIR // - DFLT_VDIR -- cgit From fee3c320484f8444b6b078bdff6777a7aac31c89 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 21:56:27 +0300 Subject: stdpaths: Remove Apple defaults, use \*nix ones instead --- src/nvim/os/stdpaths.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index d4bff65312..520836b983 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -22,24 +22,16 @@ static const char *const xdg_defaults[] = { // Windows, Apple stuff are just shims right now #ifdef WIN32 // Windows -#elif APPLE - // Apple (this includes iOS, which we might need to handle differently) - [kXDGConfigHome] = "~/Library/Preferences", - [kXDGDataHome] = "~/Library/Application Support", - [kXDGCacheHome] = "~/Library/Caches", - [kXDGRuntimeDir] = "~/Library/Application Support", - [kXDGConfigDirs] = "/Library/Application Support", - [kXDGDataDirs] = "/Library/Application Support", #else - // Linux, BSD, CYGWIN + // Linux, BSD, CYGWIN, Apple [kXDGConfigHome] = "~/.config", [kXDGDataHome] = "~/.local/share", [kXDGCacheHome] = "~/.cache", [kXDGRuntimeDir] = "", [kXDGConfigDirs] = "/etc/xdg/", [kXDGDataDirs] = "/usr/local/share/:/usr/share/", -}; #endif +}; /// Return XDG variable value /// -- cgit From d2e07c8307af8a1ab37e68746a8ba600ee372948 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 17 Oct 2015 23:18:04 +0300 Subject: stdpaths: Add missing include --- src/nvim/os/stdpaths.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 520836b983..6e5e37ec08 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -4,6 +4,7 @@ #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/memory.h" +#include "nvim/ascii.h" /// Names of the environment variables, mapped to XDGVarType values static const char *xdg_env_vars[] = { -- cgit From 181c377697b8d4ef8234d3881466837ebae43f69 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 18 Oct 2015 00:24:23 +0300 Subject: stdpaths: Add Windows-specific directories --- src/nvim/os/stdpaths.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 6e5e37ec08..ef20fe0883 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -23,6 +23,12 @@ static const char *const xdg_defaults[] = { // Windows, Apple stuff are just shims right now #ifdef WIN32 // Windows + [kXDGConfigHome] = "$LOCALAPPDATA\\nvim\\config", + [kXDGDataHome] = "$LOCALAPPDATA\\nvim\\data", + [kXDGCacheHome] = "$LOCALAPPDATA\\nvim\\cache", + [kXDGRuntimeDir] = "", + [kXDGConfigDirs] = NULL, + [kXDGDataDirs] = NULL, #else // Linux, BSD, CYGWIN, Apple [kXDGConfigHome] = "~/.config", -- cgit From 198ba323b89fbfb5ea254ec7595a5c58ba7d2aa4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 18 Oct 2015 00:35:30 +0300 Subject: stdpaths: Remove outdated comment --- src/nvim/os/stdpaths.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index ef20fe0883..ce374828f9 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -20,7 +20,6 @@ static const char *xdg_env_vars[] = { /// /// Used in case environment variables contain nothing. Need to be expanded. static const char *const xdg_defaults[] = { - // Windows, Apple stuff are just shims right now #ifdef WIN32 // Windows [kXDGConfigHome] = "$LOCALAPPDATA\\nvim\\config", -- cgit From fefcc01cc1da9540767a2c0b14ebb532a51dd412 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 19 Oct 2015 15:25:49 +0300 Subject: os/fs: Allow os_mkdir_recurse directory name to end with /// --- src/nvim/os/fs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 522e49950c..05f0f53c63 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -366,11 +366,17 @@ int os_mkdir_recurse(const char *const dir, int32_t mode, } while (e != real_end) { if (e > past_head) { - *e = '/'; + *e = PATHSEP; } else { *past_head = past_head_save; } - e += strlen(e); + const size_t component_len = strlen(e); + e += component_len; + if (e == real_end + && memcnt(e - component_len, PATHSEP, component_len) == component_len) { + // Path ends with something like "////". Ignore this. + break; + } int ret; if ((ret = os_mkdir(curdir, mode)) != 0) { *failed_dir = curdir; -- cgit From 157af47202c41b3d987d45be3542e74456f06470 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 23 Oct 2015 17:45:59 +0300 Subject: os/unix_defs: Rename default system vimrc file to sysinit.vim This way all standard Vim file paths have .vim extension. VIMRC_FILE constant used for &exrc option was not touched. --- src/nvim/os/unix_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index e1c3060999..b1511d4b56 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -20,7 +20,7 @@ // Unix system-dependent file names #ifndef SYS_VIMRC_FILE -# define SYS_VIMRC_FILE "$VIM/nvimrc" +# define SYS_VIMRC_FILE "$VIM/sysinit.vim" #endif #ifndef DFLT_HELPFILE # define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt" -- cgit