stdpaths: Export get_xdg function (renamed) and use it for runtimepath

This commit is contained in:
ZyX
2015-10-17 14:45:53 +03:00
parent afb0f2f9b1
commit be91bc1e1a
4 changed files with 21 additions and 15 deletions

View File

@@ -332,11 +332,11 @@ static char *strcpy_comma_escaped(char *dest, const char *src, const size_t len)
static void set_runtimepath_default(void) static void set_runtimepath_default(void)
{ {
size_t rtp_size = 0; size_t rtp_size = 0;
char *const data_home = vim_getenv("XDG_DATA_HOME"); char *const data_home = stdpaths_get_xdg_var(kXDGDataHome);
char *const config_home = vim_getenv("XDG_CONFIG_HOME"); char *const config_home = stdpaths_get_xdg_var(kXDGConfigHome);
char *const vimruntime = vim_getenv("VIMRUNTIME"); char *const vimruntime = vim_getenv("VIMRUNTIME");
char *const data_dirs = vim_getenv("XDG_DATA_DIRS"); char *const data_dirs = stdpaths_get_xdg_var(kXDGDataDirs);
char *const config_dirs = vim_getenv("XDG_CONFIG_DIRS"); char *const config_dirs = stdpaths_get_xdg_var(kXDGConfigDirs);
#define NVIM_SIZE (sizeof("/nvim") - 1) #define NVIM_SIZE (sizeof("/nvim") - 1)
#define SITE_SIZE (sizeof("/site") - 1) #define SITE_SIZE (sizeof("/site") - 1)
#define AFTER_SIZE (sizeof("/after") - 1) #define AFTER_SIZE (sizeof("/after") - 1)

View File

@@ -5,6 +5,7 @@
#include <uv.h> #include <uv.h>
#include "nvim/os/fs_defs.h" #include "nvim/os/fs_defs.h"
#include "nvim/os/stdpaths_defs.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS

View File

@@ -1,18 +1,10 @@
#include <stdbool.h> #include <stdbool.h>
#include "nvim/os/stdpaths_defs.h"
#include "nvim/os/os.h" #include "nvim/os/os.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/memory.h" #include "nvim/memory.h"
typedef enum {
kXDGConfigHome,
kXDGDataHome,
kXDGCacheHome,
kXDGRuntimeDir,
kXDGConfigDirs,
kXDGDataDirs,
} XDGVarType;
static const char *xdg_env_vars[] = { static const char *xdg_env_vars[] = {
[kXDGConfigHome] = "XDG_CONFIG_HOME", [kXDGConfigHome] = "XDG_CONFIG_HOME",
[kXDGDataHome] = "XDG_DATA_HOME", [kXDGDataHome] = "XDG_DATA_HOME",
@@ -45,7 +37,7 @@ static const char *const xdg_defaults[] = {
}; };
#endif #endif
static char *get_xdg(const XDGVarType idx) char *stdpaths_get_xdg_var(const XDGVarType idx)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_WARN_UNUSED_RESULT
{ {
const char *const env = xdg_env_vars[idx]; 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) static char *get_xdg_home(const XDGVarType idx)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_WARN_UNUSED_RESULT
{ {
char *dir = get_xdg(idx); char *dir = stdpaths_get_xdg_var(idx);
if (dir) { if (dir) {
dir = concat_fnames(dir, "nvim", true); dir = concat_fnames(dir, "nvim", true);
} }

View File

@@ -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