Merge pull request #1019 from splinterofchaos/globpath

vim-patch:7.4.279
This commit is contained in:
Justin M. Keyes
2014-08-18 00:27:07 -04:00
7 changed files with 94 additions and 111 deletions

View File

@@ -6408,7 +6408,7 @@ static struct fst {
{"getwinposy", 0, 0, f_getwinposy},
{"getwinvar", 2, 3, f_getwinvar},
{"glob", 1, 3, f_glob},
{"globpath", 2, 3, f_globpath},
{"globpath", 2, 4, f_globpath},
{"has", 1, 1, f_has},
{"has_key", 2, 2, f_has_key},
{"haslocaldir", 0, 0, f_haslocaldir},
@@ -9605,27 +9605,50 @@ static void f_glob(typval_T *argvars, typval_T *rettv)
rettv->vval.v_string = NULL;
}
/*
* "globpath()" function
*/
/// "globpath()" function
static void f_globpath(typval_T *argvars, typval_T *rettv)
{
int flags = 0;
char_u buf1[NUMBUFLEN];
char_u *file = get_tv_string_buf_chk(&argvars[1], buf1);
int error = FALSE;
int flags = 0; // Flags for globpath.
int error = false;
/* When the optional second argument is non-zero, don't remove matches
* for 'wildignore' and don't put matches for 'suffixes' at the end. */
if (argvars[2].v_type != VAR_UNKNOWN
&& get_tv_number_chk(&argvars[2], &error))
flags |= WILD_KEEP_ALL;
// Return a string, or a list if the optional third argument is non-zero.
rettv->v_type = VAR_STRING;
if (file == NULL || error)
if (argvars[2].v_type != VAR_UNKNOWN) {
// When the optional second argument is non-zero, don't remove matches
// for 'wildignore' and don't put matches for 'suffixes' at the end.
if (get_tv_number_chk(&argvars[2], &error)) {
flags |= WILD_KEEP_ALL;
}
if (argvars[3].v_type != VAR_UNKNOWN
&& get_tv_number_chk(&argvars[3], &error)) {
rettv->v_type = VAR_LIST;
rettv->vval.v_list = NULL;
}
}
char_u buf1[NUMBUFLEN];
char_u *file = get_tv_string_buf_chk(&argvars[1], buf1);
if (file != NULL && !error) {
garray_T ga;
ga_init(&ga, (int)sizeof(char_u *), 10);
globpath(get_tv_string(&argvars[0]), file, &ga, flags);
if (rettv->v_type == VAR_STRING) {
rettv->vval.v_string = ga_concat_strings_sep(&ga, "\n");
} else {
rettv_list_alloc(rettv);
for (int i = 0; i < ga.ga_len; i++) {
list_append_string(rettv->vval.v_list,
((char_u **)(ga.ga_data))[i], -1);
}
}
ga_clear_strings(&ga);
} else {
rettv->vval.v_string = NULL;
else
rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), file,
flags);
}
}
/*