diff options
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c index 0d7685031b..17a9d0fe7e 100644 --- a/src/path.c +++ b/src/path.c @@ -1903,3 +1903,112 @@ void shorten_filenames(char_u **fnames, int count) } #endif +/* + * Invoke expand_wildcards() for one pattern. + * Expand items like "%:h" before the expansion. + * Returns OK or FAIL. + */ +int +expand_wildcards_eval ( + char_u **pat, /* pointer to input pattern */ + int *num_file, /* resulting number of files */ + char_u ***file, /* array of resulting files */ + int flags /* EW_DIR, etc. */ +) +{ + int ret = FAIL; + char_u *eval_pat = NULL; + char_u *exp_pat = *pat; + char_u *ignored_msg; + int usedlen; + + if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<') { + ++emsg_off; + eval_pat = eval_vars(exp_pat, exp_pat, &usedlen, + NULL, &ignored_msg, NULL); + --emsg_off; + if (eval_pat != NULL) + exp_pat = concat_str(eval_pat, exp_pat + usedlen); + } + + if (exp_pat != NULL) + ret = expand_wildcards(1, &exp_pat, num_file, file, flags); + + if (eval_pat != NULL) { + vim_free(exp_pat); + vim_free(eval_pat); + } + + return ret; +} + +/* + * Expand wildcards. Calls gen_expand_wildcards() and removes files matching + * 'wildignore'. + * Returns OK or FAIL. When FAIL then "num_file" won't be set. + */ +int +expand_wildcards ( + int num_pat, /* number of input patterns */ + char_u **pat, /* array of input patterns */ + int *num_file, /* resulting number of files */ + char_u ***file, /* array of resulting files */ + int flags /* EW_DIR, etc. */ +) +{ + int retval; + int i, j; + char_u *p; + int non_suf_match; /* number without matching suffix */ + + retval = gen_expand_wildcards(num_pat, pat, num_file, file, flags); + + /* When keeping all matches, return here */ + if ((flags & EW_KEEPALL) || retval == FAIL) + return retval; + + /* + * Remove names that match 'wildignore'. + */ + if (*p_wig) { + char_u *ffname; + + /* check all files in (*file)[] */ + for (i = 0; i < *num_file; ++i) { + ffname = FullName_save((*file)[i], FALSE); + if (ffname == NULL) /* out of memory */ + break; + if (match_file_list(p_wig, (*file)[i], ffname)) { + /* remove this matching file from the list */ + vim_free((*file)[i]); + for (j = i; j + 1 < *num_file; ++j) + (*file)[j] = (*file)[j + 1]; + --*num_file; + --i; + } + vim_free(ffname); + } + } + + /* + * Move the names where 'suffixes' match to the end. + */ + if (*num_file > 1) { + non_suf_match = 0; + for (i = 0; i < *num_file; ++i) { + if (!match_suffix((*file)[i])) { + /* + * Move the name without matching suffix to the front + * of the list. + */ + p = (*file)[i]; + for (j = i; j > non_suf_match; --j) + (*file)[j] = (*file)[j - 1]; + (*file)[non_suf_match++] = p; + } + } + } + + return retval; +} + |