Remove two-iteration loop from expand_filename

This commit is contained in:
Pavel Platto
2014-04-28 16:32:47 +03:00
committed by Thiago de Arruda
parent 1a946ad05f
commit 97f02bb609

View File

@@ -3605,7 +3605,6 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
char_u *repl; char_u *repl;
int srclen; int srclen;
char_u *p; char_u *p;
int n;
int escaped; int escaped;
/* Skip a regexp pattern for ":vimgrep[add] pat file..." */ /* Skip a regexp pattern for ":vimgrep[add] pat file..." */
@@ -3718,81 +3717,77 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
* Don't do this with ":r !command" or ":w !command". * Don't do this with ":r !command" or ":w !command".
*/ */
if ((eap->argt & NOSPC) && !eap->usefilter) { if ((eap->argt & NOSPC) && !eap->usefilter) {
/* // Replace environment variables.
* May do this twice: if (has_wildcards) {
* 1. Replace environment variables. /*
* 2. Replace any other wildcards, remove backslashes. * May expand environment variables. This
*/ * can be done much faster with expand_env() than with
for (n = 1; n <= 2; ++n) { * something else (e.g., calling a shell).
if (n == 2) { * After expanding environment variables, check again
#ifdef UNIX * if there are still wildcards present.
/* */
* Only for Unix we check for more than one file name. if (vim_strchr(eap->arg, '$') != NULL
* For other systems spaces are considered to be part || vim_strchr(eap->arg, '~') != NULL) {
* of the file name. expand_env_esc(eap->arg, NameBuff, MAXPATHL,
* Only check here if there is no wildcard, otherwise TRUE, TRUE, NULL);
* ExpandOne() will check for errors. This allows has_wildcards = mch_has_wildcard(NameBuff);
* ":e `ls ve*.c`" on Unix. p = NameBuff;
*/ } else
if (!has_wildcards) p = NULL;
for (p = eap->arg; *p; ++p) { if (p != NULL) {
/* skip escaped characters */ (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg),
if (p[1] && (*p == '\\' || *p == Ctrl_V)) p, cmdlinep);
++p;
else if (vim_iswhite(*p)) {
*errormsgp = (char_u *)_("E172: Only one file name allowed");
return FAIL;
}
}
#endif
/*
* Halve the number of backslashes (this is Vi compatible).
* For Unix, when wildcards are expanded, this is
* done by ExpandOne() below.
*/
#if defined(UNIX)
if (!has_wildcards)
#endif
backslash_halve(eap->arg);
} }
}
if (has_wildcards) { // Replace any other wildcards, remove backslashes.
if (n == 1) { #ifdef UNIX
/* /*
* First loop: May expand environment variables. This * Only for Unix we check for more than one file name.
* can be done much faster with expand_env() than with * For other systems spaces are considered to be part
* something else (e.g., calling a shell). * of the file name.
* After expanding environment variables, check again * Only check here if there is no wildcard, otherwise
* if there are still wildcards present. * ExpandOne() will check for errors. This allows
*/ * ":e `ls ve*.c`" on Unix.
if (vim_strchr(eap->arg, '$') != NULL */
|| vim_strchr(eap->arg, '~') != NULL) { if (!has_wildcards)
expand_env_esc(eap->arg, NameBuff, MAXPATHL, for (p = eap->arg; *p; ++p) {
TRUE, TRUE, NULL); /* skip escaped characters */
has_wildcards = mch_has_wildcard(NameBuff); if (p[1] && (*p == '\\' || *p == Ctrl_V))
p = NameBuff; ++p;
} else else if (vim_iswhite(*p)) {
p = NULL; *errormsgp = (char_u *)_("E172: Only one file name allowed");
} else { /* n == 2 */ return FAIL;
expand_T xpc; }
int options = WILD_LIST_NOTFOUND|WILD_ADD_SLASH; }
#endif
ExpandInit(&xpc); /*
xpc.xp_context = EXPAND_FILES; * Halve the number of backslashes (this is Vi compatible).
if (p_wic) * For Unix, when wildcards are expanded, this is
options += WILD_ICASE; * done by ExpandOne() below.
p = ExpandOne(&xpc, eap->arg, NULL, */
options, WILD_EXPAND_FREE); #ifdef UNIX
if (p == NULL) if (!has_wildcards)
return FAIL; #endif
} backslash_halve(eap->arg);
if (p != NULL) {
(void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), if (has_wildcards) {
p, cmdlinep); expand_T xpc;
if (n == 2) /* p came from ExpandOne() */ int options = WILD_LIST_NOTFOUND|WILD_ADD_SLASH;
vim_free(p);
} ExpandInit(&xpc);
xpc.xp_context = EXPAND_FILES;
if (p_wic)
options += WILD_ICASE;
p = ExpandOne(&xpc, eap->arg, NULL,
options, WILD_EXPAND_FREE);
if (p == NULL)
return FAIL;
if (p != NULL) {
(void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg),
p, cmdlinep);
vim_free(p);
} }
} }
} }