Commit 35e737e6 authored by John Schmidt's avatar John Schmidt Committed by Thiago de Arruda

Move expand_wildcards{,_eval} from misc1.c

parent d31e5988
......@@ -3485,115 +3485,6 @@ void fast_breakcheck(void)
}
}
/*
* 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;
}
/*
* Return TRUE if "fname" matches with an entry in 'suffixes'.
*/
......
......@@ -67,11 +67,6 @@ void prepare_to_exit(void);
void preserve_exit(void);
void line_breakcheck(void);
void fast_breakcheck(void);
int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file,
int flags);
int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u *
**file,
int flags);
int match_suffix(char_u *fname);
char_u *get_cmd_output(char_u *cmd, char_u *infile, int flags);
void FreeWild(int count, char_u **files);
......
......@@ -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;
}
......@@ -39,4 +39,9 @@ char_u *shorten_fname1(char_u *full_path);
char_u *shorten_fname(char_u *full_path, char_u *dir_name);
void shorten_fnames(int force);
void shorten_filenames(char_u **fnames, int count);
int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file,
int flags);
int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u *
**file,
int flags);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment