diff options
author | Pavel Platto <hinidu@gmail.com> | 2014-04-28 16:32:47 +0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-02 15:37:43 -0300 |
commit | 97f02bb609b18bba8c71bc5208e4a782d99b950c (patch) | |
tree | 691e353e325e17d091e598215951f74562862be4 /src | |
parent | 1a946ad05f73a2eb56679627df0fb3f299cef7de (diff) | |
download | rneovim-97f02bb609b18bba8c71bc5208e4a782d99b950c.tar.gz rneovim-97f02bb609b18bba8c71bc5208e4a782d99b950c.tar.bz2 rneovim-97f02bb609b18bba8c71bc5208e4a782d99b950c.zip |
Remove two-iteration loop from expand_filename
Diffstat (limited to 'src')
-rw-r--r-- | src/ex_docmd.c | 137 |
1 files changed, 66 insertions, 71 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c index a7735e2af2..83b9a08fef 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -3605,7 +3605,6 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) char_u *repl; int srclen; char_u *p; - int n; int escaped; /* 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". */ if ((eap->argt & NOSPC) && !eap->usefilter) { + // Replace environment variables. + if (has_wildcards) { + /* + * May expand environment variables. This + * can be done much faster with expand_env() than with + * something else (e.g., calling a shell). + * After expanding environment variables, check again + * if there are still wildcards present. + */ + if (vim_strchr(eap->arg, '$') != NULL + || vim_strchr(eap->arg, '~') != NULL) { + expand_env_esc(eap->arg, NameBuff, MAXPATHL, + TRUE, TRUE, NULL); + has_wildcards = mch_has_wildcard(NameBuff); + p = NameBuff; + } else + p = NULL; + if (p != NULL) { + (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), + p, cmdlinep); + } + } + + // Replace any other wildcards, remove backslashes. +#ifdef UNIX /* - * May do this twice: - * 1. Replace environment variables. - * 2. Replace any other wildcards, remove backslashes. + * Only for Unix we check for more than one file name. + * For other systems spaces are considered to be part + * of the file name. + * Only check here if there is no wildcard, otherwise + * ExpandOne() will check for errors. This allows + * ":e `ls ve*.c`" on Unix. */ - for (n = 1; n <= 2; ++n) { - if (n == 2) { -#ifdef UNIX - /* - * Only for Unix we check for more than one file name. - * For other systems spaces are considered to be part - * of the file name. - * Only check here if there is no wildcard, otherwise - * ExpandOne() will check for errors. This allows - * ":e `ls ve*.c`" on Unix. - */ - if (!has_wildcards) - for (p = eap->arg; *p; ++p) { - /* skip escaped characters */ - if (p[1] && (*p == '\\' || *p == Ctrl_V)) - ++p; - else if (vim_iswhite(*p)) { - *errormsgp = (char_u *)_("E172: Only one file name allowed"); - return FAIL; - } - } + if (!has_wildcards) + for (p = eap->arg; *p; ++p) { + /* skip escaped characters */ + if (p[1] && (*p == '\\' || *p == Ctrl_V)) + ++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) + /* + * Halve the number of backslashes (this is Vi compatible). + * For Unix, when wildcards are expanded, this is + * done by ExpandOne() below. + */ +#ifdef UNIX + if (!has_wildcards) #endif - backslash_halve(eap->arg); - } - - if (has_wildcards) { - if (n == 1) { - /* - * First loop: May expand environment variables. This - * can be done much faster with expand_env() than with - * something else (e.g., calling a shell). - * After expanding environment variables, check again - * if there are still wildcards present. - */ - if (vim_strchr(eap->arg, '$') != NULL - || vim_strchr(eap->arg, '~') != NULL) { - expand_env_esc(eap->arg, NameBuff, MAXPATHL, - TRUE, TRUE, NULL); - has_wildcards = mch_has_wildcard(NameBuff); - p = NameBuff; - } else - p = NULL; - } else { /* n == 2 */ - expand_T xpc; - int options = WILD_LIST_NOTFOUND|WILD_ADD_SLASH; - - 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); - if (n == 2) /* p came from ExpandOne() */ - vim_free(p); - } + backslash_halve(eap->arg); + + if (has_wildcards) { + expand_T xpc; + int options = WILD_LIST_NOTFOUND|WILD_ADD_SLASH; + + 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); } } } |