diff options
-rw-r--r-- | src/nvim/charset.c | 5 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 4 | ||||
-rw-r--r-- | src/nvim/os_unix.c | 37 | ||||
-rw-r--r-- | src/nvim/path.c | 56 | ||||
-rw-r--r-- | src/nvim/tag.c | 2 |
5 files changed, 61 insertions, 43 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 5e11e202a3..4633bacb78 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -24,6 +24,7 @@ #include "nvim/move.h" #include "nvim/os_unix.h" #include "nvim/strings.h" +#include "nvim/path.h" #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -871,7 +872,7 @@ int vim_isfilec(int c) /// return TRUE if 'c' is a valid file-name character or a wildcard character /// Assume characters above 0x100 are valid (multi-byte). -/// Explicitly interpret ']' as a wildcard character as mch_has_wildcard("]") +/// Explicitly interpret ']' as a wildcard character as path_has_wildcard("]") /// returns false. /// /// @param c @@ -882,7 +883,7 @@ int vim_isfilec_or_wc(int c) char_u buf[2]; buf[0] = (char_u)c; buf[1] = NUL; - return vim_isfilec(c) || c == ']' || mch_has_wildcard(buf); + return vim_isfilec(c) || c == ']' || path_has_wildcard(buf); } /// return TRUE if 'c' is a printable character diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 776ed844e9..db4f3a54f1 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -3432,7 +3432,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) * the file name contains a wildcard it should not cause expanding. * (it will be expanded anyway if there is a wildcard before replacing). */ - has_wildcards = mch_has_wildcard(p); + has_wildcards = path_has_wildcard(p); while (*p != NUL) { /* Skip over `=expr`, wildcards in it are not expanded. */ if (p[0] == '`' && p[1] == '=') { @@ -3543,7 +3543,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) || vim_strchr(eap->arg, '~') != NULL) { expand_env_esc(eap->arg, NameBuff, MAXPATHL, TRUE, TRUE, NULL); - has_wildcards = mch_has_wildcard(NameBuff); + has_wildcards = path_has_wildcard(NameBuff); p = NameBuff; } else p = NULL; diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 8e4569033a..82a43499b4 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -719,47 +719,12 @@ static void save_patterns(int num_pat, char_u **pat, int *num_file, *num_file = num_pat; } -/* - * Return TRUE if the string "p" contains a wildcard that mch_expandpath() can - * expand. - */ -int mch_has_exp_wildcard(char_u *p) -{ - for (; *p; mb_ptr_adv(p)) { - if (*p == '\\' && p[1] != NUL) - ++p; - else if (vim_strchr((char_u *) - "*?[{'" - , *p) != NULL) - return TRUE; - } - return FALSE; -} - -/* - * Return TRUE if the string "p" contains a wildcard. - * Don't recognize '~' at the end as a wildcard. - */ -int mch_has_wildcard(char_u *p) -{ - for (; *p; mb_ptr_adv(p)) { - if (*p == '\\' && p[1] != NUL) - ++p; - else if (vim_strchr((char_u *) - "*?[{`'$" - , *p) != NULL - || (*p == '~' && p[1] != NUL)) - return TRUE; - } - return FALSE; -} - static int have_wildcard(int num, char_u **file) { int i; for (i = 0; i < num; i++) - if (mch_has_wildcard(file[i])) + if (path_has_wildcard(file[i])) return 1; return 0; } diff --git a/src/nvim/path.c b/src/nvim/path.c index 346be9108d..3c0adcfae8 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -400,6 +400,32 @@ char_u *save_absolute_path(const char_u *name) return vim_strsave((char_u *) name); } +/// Checks if a path has a wildcard character including '~', unless at the end. +/// @param p The path to expand. +/// @returns Unix: True if it contains one of "?[{`'$". +/// @returns Windows: True if it contains one of "*?$[". +bool path_has_wildcard(const char_u *p) + FUNC_ATTR_NONNULL_ALL +{ + for (; *p; mb_ptr_adv(p)) { +#if defined(UNIX) + if (p[0] == '\\' && p[1] != NUL) { + p++; + continue; + } + + const char *wildcards = "*?[{`'$"; +#else + // Windows: + const char *wildcards = "?*$[`"; +#endif + if (vim_strchr((char_u *)wildcards, *p) != NULL + || (p[0] == '~' && p[1] != NUL)) { + return true; + } + } + return false; +} #if defined(UNIX) /* @@ -410,6 +436,32 @@ static int pstrcmp(const void *a, const void *b) { return pathcmp(*(char **)a, *(char **)b, -1); } +#endif + +/// Checks if a path has a character expandpath can expand. +/// @param p The path to expand. +/// @returns Unix: True if it contains one of *?[{. +/// @returns Windows: True if it contains one of *?[. +bool path_has_exp_wildcard(const char_u *p) + FUNC_ATTR_NONNULL_ALL +{ + for (; *p != NUL; mb_ptr_adv(p)) { +#if defined(UNIX) + if (p[0] == '\\' && p[1] != NUL) { + p++; + continue; + } + + const char *wildcards = "*?[{"; +#else + const char *wildcards = "*?["; // Windows. +#endif + if (vim_strchr((char_u *) wildcards, *p) != NULL) { + return true; + } + } + return false; +} /* * Recursively expand one path component into all matching files and/or @@ -566,7 +618,7 @@ unix_expandpath ( } STRCPY(buf + len, path_end); - if (mch_has_exp_wildcard(path_end)) { /* handle more wildcards */ + if (path_has_exp_wildcard(path_end)) { // handle more wildcards /* need to expand another component of the path */ /* remove backslashes for the remaining components only */ (void)unix_expandpath(gap, buf, len + 1, flags, FALSE); @@ -1078,7 +1130,7 @@ gen_expand_wildcards ( * If there are no wildcards: Add the file name if it exists or * when EW_NOTFOUND is given. */ - if (mch_has_exp_wildcard(p)) { + if (path_has_exp_wildcard(p)) { if ((flags & EW_PATH) && !path_is_absolute_path(p) && !(p[0] == '.' diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 361afb7e07..1f6b42d9cf 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2587,7 +2587,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand) /* * Expand file name (for environment variables) when needed. */ - if (expand && mch_has_wildcard(fname)) { + if (expand && path_has_wildcard(fname)) { ExpandInit(&xpc); xpc.xp_context = EXPAND_FILES; expanded_fname = ExpandOne(&xpc, fname, NULL, |