mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Un-mch mch_has_(exp_)wildcard().
Merge mch_has_wildcard() and mch_has_exp_wildcar() with their upstream equivalents for Windows and replace the "mch_" suffix with "path_".
This commit is contained in:
parent
99869989c8
commit
3f74067565
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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] == '.'
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user