mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.1.1927: code for dealing with script files is spread out
Problem: Code for dealing with script files is spread out. Solution: Move the code to scriptfile.c. (Yegappan Lakshmanan, closes #4861)
This commit is contained in:
156
src/cmdexpand.c
156
src/cmdexpand.c
@@ -19,8 +19,6 @@ static void set_expand_context(expand_T *xp);
|
||||
static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int);
|
||||
static int expand_showtail(expand_T *xp);
|
||||
static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg);
|
||||
static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]);
|
||||
static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file);
|
||||
#if defined(FEAT_EVAL)
|
||||
static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file);
|
||||
static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file);
|
||||
@@ -2564,160 +2562,6 @@ ExpandUserList(
|
||||
}
|
||||
# endif
|
||||
|
||||
/*
|
||||
* Expand color scheme, compiler or filetype names.
|
||||
* Search from 'runtimepath':
|
||||
* 'runtimepath'/{dirnames}/{pat}.vim
|
||||
* When "flags" has DIP_START: search also from 'start' of 'packpath':
|
||||
* 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
|
||||
* When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
|
||||
* 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
|
||||
* "dirnames" is an array with one or more directory names.
|
||||
*/
|
||||
static int
|
||||
ExpandRTDir(
|
||||
char_u *pat,
|
||||
int flags,
|
||||
int *num_file,
|
||||
char_u ***file,
|
||||
char *dirnames[])
|
||||
{
|
||||
char_u *s;
|
||||
char_u *e;
|
||||
char_u *match;
|
||||
garray_T ga;
|
||||
int i;
|
||||
int pat_len;
|
||||
|
||||
*num_file = 0;
|
||||
*file = NULL;
|
||||
pat_len = (int)STRLEN(pat);
|
||||
ga_init2(&ga, (int)sizeof(char *), 10);
|
||||
|
||||
for (i = 0; dirnames[i] != NULL; ++i)
|
||||
{
|
||||
s = alloc(STRLEN(dirnames[i]) + pat_len + 7);
|
||||
if (s == NULL)
|
||||
{
|
||||
ga_clear_strings(&ga);
|
||||
return FAIL;
|
||||
}
|
||||
sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat);
|
||||
globpath(p_rtp, s, &ga, 0);
|
||||
vim_free(s);
|
||||
}
|
||||
|
||||
if (flags & DIP_START) {
|
||||
for (i = 0; dirnames[i] != NULL; ++i)
|
||||
{
|
||||
s = alloc(STRLEN(dirnames[i]) + pat_len + 22);
|
||||
if (s == NULL)
|
||||
{
|
||||
ga_clear_strings(&ga);
|
||||
return FAIL;
|
||||
}
|
||||
sprintf((char *)s, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat);
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
vim_free(s);
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DIP_OPT) {
|
||||
for (i = 0; dirnames[i] != NULL; ++i)
|
||||
{
|
||||
s = alloc(STRLEN(dirnames[i]) + pat_len + 20);
|
||||
if (s == NULL)
|
||||
{
|
||||
ga_clear_strings(&ga);
|
||||
return FAIL;
|
||||
}
|
||||
sprintf((char *)s, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat);
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
vim_free(s);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ga.ga_len; ++i)
|
||||
{
|
||||
match = ((char_u **)ga.ga_data)[i];
|
||||
s = match;
|
||||
e = s + STRLEN(s);
|
||||
if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0)
|
||||
{
|
||||
e -= 4;
|
||||
for (s = e; s > match; MB_PTR_BACK(match, s))
|
||||
if (s < match || vim_ispathsep(*s))
|
||||
break;
|
||||
++s;
|
||||
*e = NUL;
|
||||
mch_memmove(match, s, e - s + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (ga.ga_len == 0)
|
||||
return FAIL;
|
||||
|
||||
// Sort and remove duplicates which can happen when specifying multiple
|
||||
// directories in dirnames.
|
||||
remove_duplicates(&ga);
|
||||
|
||||
*file = ga.ga_data;
|
||||
*num_file = ga.ga_len;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand loadplugin names:
|
||||
* 'packpath'/pack/ * /opt/{pat}
|
||||
*/
|
||||
static int
|
||||
ExpandPackAddDir(
|
||||
char_u *pat,
|
||||
int *num_file,
|
||||
char_u ***file)
|
||||
{
|
||||
char_u *s;
|
||||
char_u *e;
|
||||
char_u *match;
|
||||
garray_T ga;
|
||||
int i;
|
||||
int pat_len;
|
||||
|
||||
*num_file = 0;
|
||||
*file = NULL;
|
||||
pat_len = (int)STRLEN(pat);
|
||||
ga_init2(&ga, (int)sizeof(char *), 10);
|
||||
|
||||
s = alloc(pat_len + 26);
|
||||
if (s == NULL)
|
||||
{
|
||||
ga_clear_strings(&ga);
|
||||
return FAIL;
|
||||
}
|
||||
sprintf((char *)s, "pack/*/opt/%s*", pat);
|
||||
globpath(p_pp, s, &ga, 0);
|
||||
vim_free(s);
|
||||
|
||||
for (i = 0; i < ga.ga_len; ++i)
|
||||
{
|
||||
match = ((char_u **)ga.ga_data)[i];
|
||||
s = gettail(match);
|
||||
e = s + STRLEN(s);
|
||||
mch_memmove(match, s, e - s + 1);
|
||||
}
|
||||
|
||||
if (ga.ga_len == 0)
|
||||
return FAIL;
|
||||
|
||||
// Sort and remove duplicates which can happen when specifying multiple
|
||||
// directories in dirnames.
|
||||
remove_duplicates(&ga);
|
||||
|
||||
*file = ga.ga_data;
|
||||
*num_file = ga.ga_len;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand "file" for all comma-separated directories in "path".
|
||||
* Adds the matches to "ga". Caller must init "ga".
|
||||
|
Reference in New Issue
Block a user