diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-08-30 23:29:44 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-08-30 23:29:44 -0600 |
commit | 442d4e54c30b8e193e3f6e4d32b43e96815bccd7 (patch) | |
tree | b52e341e7db3d2428d8762a7ecf9b58dd84ff6c4 /src/nvim/os | |
parent | 8436383af96dc7afa3596fc22c012d68e76f47f8 (diff) | |
parent | f4274d0f62625683486d3912dcd6e8e45877c6a4 (diff) | |
download | rneovim-442d4e54c30b8e193e3f6e4d32b43e96815bccd7.tar.gz rneovim-442d4e54c30b8e193e3f6e4d32b43e96815bccd7.tar.bz2 rneovim-442d4e54c30b8e193e3f6e4d32b43e96815bccd7.zip |
Merge remote-tracking branch 'upstream/master' into usermarks
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/env.c | 79 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 37 | ||||
-rw-r--r-- | src/nvim/os/input.c | 4 | ||||
-rw-r--r-- | src/nvim/os/pty_conpty_win.h | 3 | ||||
-rw-r--r-- | src/nvim/os/shell.c | 23 | ||||
-rw-r--r-- | src/nvim/os/signal.c | 2 |
6 files changed, 80 insertions, 68 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index eaa56ffe63..c940c86675 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -8,9 +8,8 @@ #include "nvim/ascii.h" #include "nvim/charset.h" +#include "nvim/cmdexpand.h" #include "nvim/eval.h" -#include "nvim/ex_getln.h" -#include "nvim/fileio.h" #include "nvim/macros.h" #include "nvim/map.h" #include "nvim/memory.h" @@ -554,9 +553,9 @@ char_u *expand_env_save_opt(char_u *src, bool one) /// @param src Input string e.g. "$HOME/vim.hlp" /// @param dst[out] Where to put the result /// @param dstlen Maximum length of the result -void expand_env(char_u *src, char_u *dst, int dstlen) +void expand_env(char *src, char *dst, int dstlen) { - expand_env_esc(src, dst, dstlen, false, false, NULL); + expand_env_esc((char_u *)src, (char_u *)dst, dstlen, false, false, NULL); } /// Expand environment variable with path name and escaping. @@ -580,18 +579,18 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo int prefix_len = (prefix == NULL) ? 0 : (int)STRLEN(prefix); - char_u *src = (char_u *)skipwhite((char *)srcp); + char *src = skipwhite((char *)srcp); dstlen--; // leave one char space for "\," while (*src && dstlen > 0) { // Skip over `=expr`. if (src[0] == '`' && src[1] == '=') { - var = src; + var = (char_u *)src; src += 2; - (void)skip_expr((char **)&src); + (void)skip_expr(&src); if (*src == '`') { src++; } - size_t len = (size_t)(src - var); + size_t len = (size_t)(src - (char *)var); if (len > (size_t)dstlen) { len = (size_t)dstlen; } @@ -608,7 +607,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo // The variable name is copied into dst temporarily, because it may // be a string in read-only memory and a NUL needs to be appended. if (*src != '~') { // environment var - tail = src + 1; + tail = (char_u *)src + 1; var = dst; int c = dstlen - 1; @@ -646,11 +645,11 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo || vim_ispathsep(src[1]) || vim_strchr(" ,\t\n", src[1]) != NULL) { var = (char_u *)homedir; - tail = src + 1; + tail = (char_u *)src + 1; } else { // user directory #if defined(UNIX) // Copy ~user to dst[], so we can put a NUL after it. - tail = src; + tail = (char_u *)src; var = dst; int c = dstlen - 1; while (c-- > 0 @@ -723,7 +722,7 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo tail++; } dst += c; - src = tail; + src = (char *)tail; copy_char = false; } if (mustfree) { @@ -737,17 +736,17 @@ void expand_env_esc(char_u *restrict srcp, char_u *restrict dst, int dstlen, boo // ":edit foo ~ foo". at_start = false; if (src[0] == '\\' && src[1] != NUL) { - *dst++ = *src++; + *dst++ = (char_u)(*src++); dstlen--; } else if ((src[0] == ' ' || src[0] == ',') && !one) { at_start = true; } if (dstlen > 0) { - *dst++ = *src++; + *dst++ = (char_u)(*src++); dstlen--; if (prefix != NULL - && src - prefix_len >= srcp + && src - prefix_len >= (char *)srcp && STRNCMP(src - prefix_len, prefix, prefix_len) == 0) { at_start = true; } @@ -766,12 +765,12 @@ static char *vim_version_dir(const char *vimdir) return NULL; } char *p = concat_fnames(vimdir, VIM_VERSION_NODOT, true); - if (os_isdir((char_u *)p)) { + if (os_isdir(p)) { return p; } xfree(p); p = concat_fnames(vimdir, RUNTIME_DIRNAME, true); - if (os_isdir((char_u *)p)) { + if (os_isdir(p)) { return p; } xfree(p); @@ -938,8 +937,8 @@ char *vim_getenv(const char *name) // - the directory name from 'helpfile' (unless it contains '$') // - the executable name from argv[0] if (vim_path == NULL) { - if (p_hf != NULL && vim_strchr((char *)p_hf, '$') == NULL) { - vim_path = (char *)p_hf; + if (p_hf != NULL && vim_strchr(p_hf, '$') == NULL) { + vim_path = p_hf; } char exe_name[MAXPATHL]; @@ -958,7 +957,7 @@ char *vim_getenv(const char *name) char *vim_path_end = path_tail(vim_path); // remove "doc/" from 'helpfile', if present - if (vim_path == (char *)p_hf) { + if (vim_path == p_hf) { vim_path_end = remove_tail(vim_path, vim_path_end, "doc"); } @@ -977,7 +976,7 @@ char *vim_getenv(const char *name) assert(vim_path_end >= vim_path); vim_path = xstrndup(vim_path, (size_t)(vim_path_end - vim_path)); - if (!os_isdir((char_u *)vim_path)) { + if (!os_isdir(vim_path)) { xfree(vim_path); vim_path = NULL; } @@ -1069,9 +1068,8 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si must_free = true; size_t usedlen = 0; size_t flen = strlen(homedir_env_mod); - char_u *fbuf = NULL; - (void)modify_fname(":p", false, &usedlen, - &homedir_env_mod, (char **)&fbuf, &flen); + char *fbuf = NULL; + (void)modify_fname(":p", false, &usedlen, &homedir_env_mod, &fbuf, &flen); flen = strlen(homedir_env_mod); assert(homedir_env_mod != homedir_env); if (vim_ispathsep(homedir_env_mod[flen - 1])) { @@ -1158,15 +1156,12 @@ char *home_replace_save(buf_T *buf, const char *src) /// Function given to ExpandGeneric() to obtain an environment variable name. char *get_env_name(expand_T *xp, int idx) { -#define ENVNAMELEN 100 - // this static buffer is needed to avoid a memory leak in ExpandGeneric - static char_u name[ENVNAMELEN]; assert(idx >= 0); char *envname = os_getenvname_at_index((size_t)idx); if (envname) { - STRLCPY(name, envname, ENVNAMELEN); + STRLCPY(xp->xp_buf, envname, EXPAND_BUF_LEN); xfree(envname); - return (char *)name; + return xp->xp_buf; } return NULL; } @@ -1231,3 +1226,29 @@ bool os_shell_is_cmdexe(const char *sh) } return striequal("cmd.exe", path_tail(sh)); } + +/// Removes environment variable "name" and take care of side effects. +void vim_unsetenv_ext(const char *var) +{ + os_unsetenv(var); + + // "homedir" is not cleared, keep using the old value until $HOME is set. + if (STRICMP(var, "VIM") == 0) { + didset_vim = false; + } else if (STRICMP(var, "VIMRUNTIME") == 0) { + didset_vimruntime = false; + } +} + +/// Set environment variable "name" and take care of side effects. +void vim_setenv_ext(const char *name, const char *val) +{ + os_setenv(name, val, 1); + if (STRICMP(name, "HOME") == 0) { + init_homedir(); + } else if (didset_vim && STRICMP(name, "VIM") == 0) { + didset_vim = false; + } else if (didset_vimruntime && STRICMP(name, "VIMRUNTIME") == 0) { + didset_vimruntime = false; + } +} diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 901a1bc5a6..c0d5616666 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -129,10 +129,10 @@ bool os_isrealdir(const char *name) /// Check if the given path exists and is a directory. /// /// @return `true` if `name` is a directory. -bool os_isdir(const char_u *name) +bool os_isdir(const char *name) FUNC_ATTR_NONNULL_ALL { - int32_t mode = os_getperm((const char *)name); + int32_t mode = os_getperm(name); if (mode < 0) { return false; } @@ -144,25 +144,6 @@ bool os_isdir(const char_u *name) return true; } -/// Check if the given path is a directory and is executable. -/// Gives the same results as `os_isdir()` on Windows. -/// -/// @return `true` if `name` is a directory and executable. -bool os_isdir_executable(const char *name) - FUNC_ATTR_NONNULL_ALL -{ - int32_t mode = os_getperm(name); - if (mode < 0) { - return false; - } - -#ifdef WIN32 - return (S_ISDIR(mode)); -#else - return (S_ISDIR(mode) && (S_IXUSR & mode)); -#endif -} - /// Check what `name` is: /// @return NODE_NORMAL: file or directory (or doesn't exist) /// NODE_WRITABLE: writable device, socket, fifo, etc. @@ -339,7 +320,7 @@ static bool is_executable_ext(const char *name, char **abspath) const char *ext_end = ext; size_t ext_len = - copy_option_part((char_u **)&ext_end, (char_u *)buf_end, + copy_option_part(&ext_end, (char_u *)buf_end, sizeof(os_buf) - (size_t)(buf_end - os_buf), ENV_SEPSTR); if (ext_len != 0) { bool in_pathext = nameext_len == ext_len @@ -884,7 +865,7 @@ int os_file_is_writable(const char *name) int r; RUN_UV_FS_FUNC(r, uv_fs_access, name, W_OK, NULL); if (r == 0) { - return os_isdir((char_u *)name) ? 2 : 1; + return os_isdir(name) ? 2 : 1; } return 0; } @@ -930,11 +911,11 @@ int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_di // We're done when it's "/" or "c:/". const size_t dirlen = strlen(dir); char *const curdir = xmemdupz(dir, dirlen); - char *const past_head = (char *)get_past_head((char_u *)curdir); + char *const past_head = get_past_head(curdir); char *e = curdir + dirlen; const char *const real_end = e; const char past_head_save = *past_head; - while (!os_isdir((char_u *)curdir)) { + while (!os_isdir(curdir)) { e = path_tail_with_sep(curdir); if (e <= past_head) { *past_head = NUL; @@ -1051,7 +1032,7 @@ int os_remove(const char *path) bool os_fileinfo(const char *path, FileInfo *file_info) FUNC_ATTR_NONNULL_ARG(2) { - memset(file_info, 0, sizeof(*file_info)); + CLEAR_POINTER(file_info); return os_stat(path, &(file_info->stat)) == kLibuvSuccess; } @@ -1063,7 +1044,7 @@ bool os_fileinfo(const char *path, FileInfo *file_info) bool os_fileinfo_link(const char *path, FileInfo *file_info) FUNC_ATTR_NONNULL_ARG(2) { - memset(file_info, 0, sizeof(*file_info)); + CLEAR_POINTER(file_info); if (path == NULL) { return false; } @@ -1087,7 +1068,7 @@ bool os_fileinfo_fd(int file_descriptor, FileInfo *file_info) FUNC_ATTR_NONNULL_ALL { uv_fs_t request; - memset(file_info, 0, sizeof(*file_info)); + CLEAR_POINTER(file_info); fs_loop_lock(); bool ok = uv_fs_fstat(&fs_loop, &request, diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index c47a891c18..bfe6d59dc6 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -8,10 +8,9 @@ #include "nvim/api/private/defs.h" #include "nvim/ascii.h" +#include "nvim/autocmd.h" #include "nvim/event/loop.h" #include "nvim/event/rstream.h" -#include "nvim/ex_cmds2.h" -#include "nvim/fileio.h" #include "nvim/getchar.h" #include "nvim/keycodes.h" #include "nvim/main.h" @@ -19,6 +18,7 @@ #include "nvim/memory.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/os/input.h" +#include "nvim/profile.h" #include "nvim/screen.h" #include "nvim/state.h" #include "nvim/ui.h" diff --git a/src/nvim/os/pty_conpty_win.h b/src/nvim/os/pty_conpty_win.h index c243db4fa5..15e7c3da0c 100644 --- a/src/nvim/os/pty_conpty_win.h +++ b/src/nvim/os/pty_conpty_win.h @@ -1,6 +1,9 @@ #ifndef NVIM_OS_PTY_CONPTY_WIN_H #define NVIM_OS_PTY_CONPTY_WIN_H +#include "nvim/lib/kvec.h" +#include "nvim/os/input.h" + #ifndef HPCON # define HPCON VOID * #endif diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 8f2018c1f4..461a79c37b 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -25,6 +25,7 @@ #include "nvim/os/shell.h" #include "nvim/os/signal.h" #include "nvim/path.h" +#include "nvim/profile.h" #include "nvim/screen.h" #include "nvim/strings.h" #include "nvim/tag.h" @@ -54,7 +55,7 @@ static void save_patterns(int num_pat, char **pat, int *num_file, char ***file) char_u *s = vim_strsave((char_u *)pat[i]); // Be compatible with expand_filename(): halve the number of // backslashes. - backslash_halve(s); + backslash_halve((char *)s); (*file)[i] = (char *)s; } *num_file = num_pat; @@ -73,7 +74,7 @@ static bool have_wildcard(int num, char **file) static bool have_dollars(int num, char **file) { for (int i = 0; i < num; i++) { - if (vim_strchr((char *)file[i], '$') != NULL) { + if (vim_strchr(file[i], '$') != NULL) { return true; } } @@ -248,10 +249,16 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } STRCAT(command, ">"); } else { - if (flags & EW_NOTFOUND) { - STRCPY(command, "set nonomatch; "); - } else { - STRCPY(command, "unset nonomatch; "); + STRCPY(command, ""); + if (shell_style == STYLE_GLOB) { + // Assume the nonomatch option is valid only for csh like shells, + // otherwise, this may set the positional parameters for the shell, + // e.g. "$*". + if (flags & EW_NOTFOUND) { + STRCAT(command, "set nonomatch; "); + } else { + STRCAT(command, "unset nonomatch; "); + } } if (shell_style == STYLE_GLOB) { STRCAT(command, "glob >"); @@ -501,7 +508,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in } // check if this entry should be included - dir = (os_isdir((char_u *)(*file)[i])); + dir = (os_isdir((*file)[i])); if ((dir && !(flags & EW_DIR)) || (!dir && !(flags & EW_FILE))) { continue; } @@ -904,7 +911,7 @@ static int do_os_system(char **argv, const char *input, size_t len, char **outpu out_data_ring(NULL, SIZE_MAX); } if (forward_output) { - // caller should decide if wait_return is invoked + // caller should decide if wait_return() is invoked no_wait_return++; msg_end(); no_wait_return--; diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 581f025a0f..e592570966 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -9,10 +9,10 @@ #endif #include "nvim/ascii.h" +#include "nvim/autocmd.h" #include "nvim/eval.h" #include "nvim/event/loop.h" #include "nvim/event/signal.h" -#include "nvim/fileio.h" #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/main.h" |