/* TODO: make some #ifdef for this *//*--------[ file searching ]-------------------------------------------------*//* * File searching functions for 'path', 'tags' and 'cdpath' options. * External visible functions: * vim_findfile_init() creates/initialises the search context * vim_findfile_free_visited() free list of visited files/dirs of search * context * vim_findfile() find a file in the search context * vim_findfile_cleanup() cleanup/free search context created by * vim_findfile_init() * * All static functions and variables start with 'ff_' * * In general it works like this: * First you create yourself a search context by calling vim_findfile_init(). * It is possible to give a search context from a previous call to * vim_findfile_init(), so it can be reused. After this you call vim_findfile() * until you are satisfied with the result or it returns NULL. On every call it * returns the next file which matches the conditions given to * vim_findfile_init(). If it doesn't find a next file it returns NULL. * * It is possible to call vim_findfile_init() again to reinitialise your search * with some new parameters. Don't forget to pass your old search context to * it, so it can reuse it and especially reuse the list of already visited * directories. If you want to delete the list of already visited directories * simply call vim_findfile_free_visited(). * * When you are done call vim_findfile_cleanup() to free the search context. * * The function vim_findfile_init() has a long comment, which describes the * needed parameters. * * * * ATTENTION: * ========== * Also we use an allocated search context here, this functions are NOT * thread-safe!!!!! * * To minimize parameter passing (or because I'm to lazy), only the * external visible functions get a search context as a parameter. This is * then assigned to a static global, which is used throughout the local * functions. */#include <assert.h>#include <string.h>#include <stdbool.h>#include <stdint.h>#include <inttypes.h>#include <limits.h>#include"nvim/vim.h"#include"nvim/ascii.h"#include"nvim/file_search.h"#include"nvim/charset.h"#include"nvim/fileio.h"#include"nvim/memory.h"#include"nvim/message.h"#include"nvim/misc1.h"#include"nvim/misc2.h"#include"nvim/os_unix.h"#include"nvim/path.h"#include"nvim/strings.h"#include"nvim/tag.h"#include"nvim/window.h"#include"nvim/os/os.h"#include"nvim/os/input.h"#include"nvim/os/fs_defs.h"static char_u *ff_expand_buffer = NULL;/* used for expanding filenames *//* * type for the directory search stack */typedefstruct ff_stack {struct ff_stack *ffs_prev;/* the fix part (no wildcards) and the part containing the wildcards * of the search path */
char_u *ffs_fix_path;
char_u *ffs_wc_path;/* files/dirs found in the above directory, matched by the first wildcard * of wc_part */
char_u **ffs_filearray;int ffs_filearray_size;
char_u ffs_filearray_cur;/* needed for partly handled dirs *//* to store status of partly handled directories * 0: we work on this directory for the first time * 1: this directory was partly searched in an earlier step */int ffs_stage;/* How deep are we in the directory tree? * Counts backward from value of level parameter to vim_findfile_init */int ffs_level;/* Did we already expand '**' to an empty string? */int ffs_star_star_empty;} ff_stack_T;/* * type for already visited directories or files. */typedefstruct ff_visited