forked from aniani/vim
patch 9.0.0270: some values of 'path' and 'tags' invalid in the tiny version
Problem: Some values of 'path' and 'tags' do not work in the tiny version. Solution: Graduate the +path_extra feature.
This commit is contained in:
113
src/findfile.c
113
src/findfile.c
@@ -67,9 +67,7 @@ typedef struct ff_stack
|
||||
// the fix part (no wildcards) and the part containing the wildcards
|
||||
// of the search path
|
||||
char_u *ffs_fix_path;
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
char_u *ffs_wc_path;
|
||||
#endif
|
||||
|
||||
// files/dirs found in the above directory, matched by the first wildcard
|
||||
// of wc_part
|
||||
@@ -97,11 +95,10 @@ typedef struct ff_visited
|
||||
{
|
||||
struct ff_visited *ffv_next;
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
// Visited directories are different if the wildcard string are
|
||||
// different. So we have to save it.
|
||||
char_u *ffv_wc_path;
|
||||
#endif
|
||||
|
||||
// for unix use inode etc for comparison (needed because of links), else
|
||||
// use filename.
|
||||
#ifdef UNIX
|
||||
@@ -173,21 +170,15 @@ typedef struct ff_search_ctx_T
|
||||
char_u *ffsc_file_to_search;
|
||||
char_u *ffsc_start_dir;
|
||||
char_u *ffsc_fix_path;
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
char_u *ffsc_wc_path;
|
||||
int ffsc_level;
|
||||
char_u **ffsc_stopdirs_v;
|
||||
#endif
|
||||
int ffsc_find_what;
|
||||
int ffsc_tagfile;
|
||||
} ff_search_ctx_T;
|
||||
|
||||
// locally needed functions
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
static int ff_check_visited(ff_visited_T **, char_u *, char_u *);
|
||||
#else
|
||||
static int ff_check_visited(ff_visited_T **, char_u *);
|
||||
#endif
|
||||
static void vim_findfile_free_visited(void *search_ctx_arg);
|
||||
static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp);
|
||||
static void ff_free_visited_list(ff_visited_T *vl);
|
||||
@@ -197,14 +188,8 @@ static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr);
|
||||
static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx);
|
||||
static void ff_clear(ff_search_ctx_T *search_ctx);
|
||||
static void ff_free_stack_element(ff_stack_T *stack_ptr);
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
static ff_stack_T *ff_create_stack_element(char_u *, char_u *, int, int);
|
||||
#else
|
||||
static ff_stack_T *ff_create_stack_element(char_u *, int, int);
|
||||
#endif
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
static int ff_path_in_stoplist(char_u *, int, char_u **);
|
||||
#endif
|
||||
|
||||
static char_u *ff_expand_buffer = NULL; // used for expanding filenames
|
||||
|
||||
@@ -306,9 +291,7 @@ vim_findfile_init(
|
||||
int tagfile, // expanding names of tags files
|
||||
char_u *rel_fname) // file name to use for "."
|
||||
{
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
char_u *wc_part;
|
||||
#endif
|
||||
ff_stack_T *sptr;
|
||||
ff_search_ctx_T *search_ctx;
|
||||
|
||||
@@ -409,7 +392,6 @@ vim_findfile_init(
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
/*
|
||||
* If stopdirs are given, split them into an array of pointers.
|
||||
* If this fails (mem allocation), there is no upward search at all or a
|
||||
@@ -464,9 +446,7 @@ vim_findfile_init(
|
||||
search_ctx->ffsc_stopdirs_v[dircount-1] = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
search_ctx->ffsc_level = level;
|
||||
|
||||
/*
|
||||
@@ -531,7 +511,6 @@ vim_findfile_init(
|
||||
goto error_return;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
search_ctx->ffsc_fix_path = vim_strsave(path);
|
||||
|
||||
if (search_ctx->ffsc_start_dir == NULL)
|
||||
@@ -565,7 +544,6 @@ vim_findfile_init(
|
||||
STRCAT(ff_expand_buffer, search_ctx->ffsc_fix_path);
|
||||
add_pathsep(ff_expand_buffer);
|
||||
}
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
else
|
||||
{
|
||||
char_u *p = gettail(search_ctx->ffsc_fix_path);
|
||||
@@ -612,15 +590,11 @@ vim_findfile_init(
|
||||
search_ctx->ffsc_wc_path = temp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
vim_free(buf);
|
||||
}
|
||||
|
||||
sptr = ff_create_stack_element(ff_expand_buffer,
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
search_ctx->ffsc_wc_path,
|
||||
#endif
|
||||
level, 0);
|
||||
search_ctx->ffsc_wc_path, level, 0);
|
||||
|
||||
if (sptr == NULL)
|
||||
goto error_return;
|
||||
@@ -643,7 +617,6 @@ error_return:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(FEAT_PATH_EXTRA) || defined(PROTO)
|
||||
/*
|
||||
* Get the stopdir string. Check that ';' is not escaped.
|
||||
*/
|
||||
@@ -672,7 +645,6 @@ vim_findfile_stopdir(char_u *buf)
|
||||
r_ptr = NULL;
|
||||
return r_ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Clean up the given search context. Can handle a NULL pointer.
|
||||
@@ -704,10 +676,8 @@ vim_findfile_cleanup(void *ctx)
|
||||
vim_findfile(void *search_ctx_arg)
|
||||
{
|
||||
char_u *file_path;
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
char_u *rest_of_wildcards;
|
||||
char_u *path_end = NULL;
|
||||
#endif
|
||||
ff_stack_T *stackp;
|
||||
int len;
|
||||
int i;
|
||||
@@ -727,18 +697,14 @@ vim_findfile(void *search_ctx_arg)
|
||||
if ((file_path = alloc(MAXPATHL)) == NULL)
|
||||
return NULL;
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
// store the end of the start dir -- needed for upward search
|
||||
if (search_ctx->ffsc_start_dir != NULL)
|
||||
path_end = &search_ctx->ffsc_start_dir[
|
||||
STRLEN(search_ctx->ffsc_start_dir)];
|
||||
#endif
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
// upward search loop
|
||||
for (;;)
|
||||
{
|
||||
#endif
|
||||
// downward search loop
|
||||
for (;;)
|
||||
{
|
||||
@@ -774,11 +740,7 @@ vim_findfile(void *search_ctx_arg)
|
||||
if (stackp->ffs_filearray == NULL
|
||||
&& ff_check_visited(&search_ctx->ffsc_dir_visited_list
|
||||
->ffvl_visited_list,
|
||||
stackp->ffs_fix_path
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
, stackp->ffs_wc_path
|
||||
#endif
|
||||
) == FAIL)
|
||||
stackp->ffs_fix_path, stackp->ffs_wc_path) == FAIL)
|
||||
{
|
||||
#ifdef FF_VERBOSE
|
||||
if (p_verbose >= 5)
|
||||
@@ -859,7 +821,6 @@ vim_findfile(void *search_ctx_arg)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
rest_of_wildcards = stackp->ffs_wc_path;
|
||||
if (*rest_of_wildcards != NUL)
|
||||
{
|
||||
@@ -919,7 +880,6 @@ vim_findfile(void *search_ctx_arg)
|
||||
if (vim_ispathsep(*rest_of_wildcards))
|
||||
rest_of_wildcards++;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Expand wildcards like "*" and "$VAR".
|
||||
@@ -947,18 +907,14 @@ vim_findfile(void *search_ctx_arg)
|
||||
stackp->ffs_filearray_cur = 0;
|
||||
stackp->ffs_stage = 0;
|
||||
}
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
else
|
||||
rest_of_wildcards = &stackp->ffs_wc_path[
|
||||
STRLEN(stackp->ffs_wc_path)];
|
||||
#endif
|
||||
|
||||
if (stackp->ffs_stage == 0)
|
||||
{
|
||||
// this is the first time we work on this directory
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
if (*rest_of_wildcards == NUL)
|
||||
#endif
|
||||
{
|
||||
/*
|
||||
* We don't have further wildcards to expand, so we have to
|
||||
@@ -1008,23 +964,17 @@ vim_findfile(void *search_ctx_arg)
|
||||
== mch_isdir(file_path)))))
|
||||
#ifndef FF_VERBOSE
|
||||
&& (ff_check_visited(
|
||||
&search_ctx->ffsc_visited_list->ffvl_visited_list,
|
||||
file_path
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
, (char_u *)""
|
||||
#endif
|
||||
) == OK)
|
||||
&search_ctx->ffsc_visited_list
|
||||
->ffvl_visited_list,
|
||||
file_path, (char_u *)"") == OK)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#ifdef FF_VERBOSE
|
||||
if (ff_check_visited(
|
||||
&search_ctx->ffsc_visited_list->ffvl_visited_list,
|
||||
file_path
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
, (char_u *)""
|
||||
#endif
|
||||
) == FAIL)
|
||||
&search_ctx->ffsc_visited_list
|
||||
->ffvl_visited_list,
|
||||
file_path, (char_u *)"") == FAIL)
|
||||
{
|
||||
if (p_verbose >= 5)
|
||||
{
|
||||
@@ -1074,7 +1024,6 @@ vim_findfile(void *search_ctx_arg)
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
else
|
||||
{
|
||||
/*
|
||||
@@ -1094,12 +1043,10 @@ vim_findfile(void *search_ctx_arg)
|
||||
stackp->ffs_level - 1, 0));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
stackp->ffs_filearray_cur = 0;
|
||||
stackp->ffs_stage = 1;
|
||||
}
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
/*
|
||||
* if wildcards contains '**' we have to descent till we reach the
|
||||
* leaves of the directory tree.
|
||||
@@ -1119,14 +1066,12 @@ vim_findfile(void *search_ctx_arg)
|
||||
stackp->ffs_wc_path, stackp->ffs_level - 1, 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// we are done with the current directory
|
||||
ff_free_stack_element(stackp);
|
||||
|
||||
}
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
// If we reached this, we didn't find anything downwards.
|
||||
// Let's check if we should do an upward search.
|
||||
if (search_ctx->ffsc_start_dir
|
||||
@@ -1173,7 +1118,6 @@ vim_findfile(void *search_ctx_arg)
|
||||
else
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
fail:
|
||||
vim_free(file_path);
|
||||
@@ -1222,9 +1166,7 @@ ff_free_visited_list(ff_visited_T *vl)
|
||||
while (vl != NULL)
|
||||
{
|
||||
vp = vl->ffv_next;
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
vim_free(vl->ffv_wc_path);
|
||||
#endif
|
||||
vim_free(vl);
|
||||
vl = vp;
|
||||
}
|
||||
@@ -1298,7 +1240,6 @@ ff_get_visited_list(
|
||||
return retptr;
|
||||
}
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
/*
|
||||
* check if two wildcard paths are equal. Returns TRUE or FALSE.
|
||||
* They are equal if:
|
||||
@@ -1339,7 +1280,6 @@ ff_wc_equal(char_u *s1, char_u *s2)
|
||||
}
|
||||
return s1[i] == s2[j];
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* maintains the list of already visited files and dirs
|
||||
@@ -1353,11 +1293,8 @@ ff_wc_equal(char_u *s1, char_u *s2)
|
||||
static int
|
||||
ff_check_visited(
|
||||
ff_visited_T **visited_list,
|
||||
char_u *fname
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
, char_u *wc_path
|
||||
#endif
|
||||
)
|
||||
char_u *fname,
|
||||
char_u *wc_path)
|
||||
{
|
||||
ff_visited_T *vp;
|
||||
#ifdef UNIX
|
||||
@@ -1397,10 +1334,8 @@ ff_check_visited(
|
||||
fnamecmp(vp->ffv_fname, ff_expand_buffer) == 0
|
||||
)
|
||||
{
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
// are the wildcard parts equal
|
||||
if (ff_wc_equal(vp->ffv_wc_path, wc_path) == TRUE)
|
||||
#endif
|
||||
// already visited
|
||||
return FAIL;
|
||||
}
|
||||
@@ -1429,12 +1364,10 @@ ff_check_visited(
|
||||
#ifdef UNIX
|
||||
}
|
||||
#endif
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
if (wc_path != NULL)
|
||||
vp->ffv_wc_path = vim_strsave(wc_path);
|
||||
else
|
||||
vp->ffv_wc_path = NULL;
|
||||
#endif
|
||||
|
||||
vp->ffv_next = *visited_list;
|
||||
*visited_list = vp;
|
||||
@@ -1449,9 +1382,7 @@ ff_check_visited(
|
||||
static ff_stack_T *
|
||||
ff_create_stack_element(
|
||||
char_u *fix_part,
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
char_u *wc_part,
|
||||
#endif
|
||||
int level,
|
||||
int star_star_empty)
|
||||
{
|
||||
@@ -1474,17 +1405,11 @@ ff_create_stack_element(
|
||||
fix_part = (char_u *)"";
|
||||
new->ffs_fix_path = vim_strsave(fix_part);
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
if (wc_part == NULL)
|
||||
wc_part = (char_u *)"";
|
||||
new->ffs_wc_path = vim_strsave(wc_part);
|
||||
#endif
|
||||
|
||||
if (new->ffs_fix_path == NULL
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
|| new->ffs_wc_path == NULL
|
||||
#endif
|
||||
)
|
||||
if (new->ffs_fix_path == NULL || new->ffs_wc_path == NULL)
|
||||
{
|
||||
ff_free_stack_element(new);
|
||||
new = NULL;
|
||||
@@ -1532,9 +1457,7 @@ ff_free_stack_element(ff_stack_T *stack_ptr)
|
||||
{
|
||||
// vim_free handles possible NULL pointers
|
||||
vim_free(stack_ptr->ffs_fix_path);
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
vim_free(stack_ptr->ffs_wc_path);
|
||||
#endif
|
||||
|
||||
if (stack_ptr->ffs_filearray != NULL)
|
||||
FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray);
|
||||
@@ -1557,11 +1480,8 @@ ff_clear(ff_search_ctx_T *search_ctx)
|
||||
vim_free(search_ctx->ffsc_file_to_search);
|
||||
vim_free(search_ctx->ffsc_start_dir);
|
||||
vim_free(search_ctx->ffsc_fix_path);
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
vim_free(search_ctx->ffsc_wc_path);
|
||||
#endif
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
if (search_ctx->ffsc_stopdirs_v != NULL)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -1574,19 +1494,15 @@ ff_clear(ff_search_ctx_T *search_ctx)
|
||||
vim_free(search_ctx->ffsc_stopdirs_v);
|
||||
}
|
||||
search_ctx->ffsc_stopdirs_v = NULL;
|
||||
#endif
|
||||
|
||||
// reset everything
|
||||
search_ctx->ffsc_file_to_search = NULL;
|
||||
search_ctx->ffsc_start_dir = NULL;
|
||||
search_ctx->ffsc_fix_path = NULL;
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
search_ctx->ffsc_wc_path = NULL;
|
||||
search_ctx->ffsc_level = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef FEAT_PATH_EXTRA
|
||||
/*
|
||||
* check if the given path is in the stopdirs
|
||||
* returns TRUE if yes else FALSE
|
||||
@@ -1623,7 +1539,6 @@ ff_path_in_stoplist(char_u *path, int path_len, char_u **stopdirs_v)
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Find the file name "ptr[len]" in the path. Also finds directory names.
|
||||
@@ -1873,12 +1788,8 @@ find_file_in_path_option(
|
||||
buf[0] = 0;
|
||||
copy_option_part(&dir, buf, MAXPATHL, " ,");
|
||||
|
||||
# ifdef FEAT_PATH_EXTRA
|
||||
// get the stopdir string
|
||||
r_ptr = vim_findfile_stopdir(buf);
|
||||
# else
|
||||
r_ptr = NULL;
|
||||
# endif
|
||||
fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find,
|
||||
r_ptr, 100, FALSE, find_what,
|
||||
fdip_search_ctx, FALSE, rel_fname);
|
||||
|
Reference in New Issue
Block a user