#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/file_search.h"
#include "nvim/fileio.h"
#include "nvim/globals.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/option.h"
#include "nvim/os/fs_defs.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/strings.h"
#include "nvim/tag.h"
#include "nvim/vim.h"
#include "nvim/window.h"
Data Structures | |
struct | ff_stack |
struct | ff_visited |
struct | ff_visited_list_hdr |
struct | ff_search_ctx_T |
Macros | |
#define | FF_MAX_STAR_STAR_EXPAND ((char_u)30) |
Typedefs | |
typedef struct ff_stack | ff_stack_T |
typedef struct ff_visited | ff_visited_T |
typedef struct ff_visited_list_hdr | ff_visited_list_hdr_T |
typedef struct ff_search_ctx_T | ff_search_ctx_T |
Functions | |
void * | vim_findfile_init (char_u *path, char_u *filename, char_u *stopdirs, int level, int free_visited, int find_what, void *search_ctx_arg, int tagfile, char_u *rel_fname) |
char_u * | vim_findfile_stopdir (char_u *buf) |
void | vim_findfile_cleanup (void *ctx) |
Clean up the given search context. Can handle a NULL pointer. More... | |
char_u * | vim_findfile (void *search_ctx_arg) |
void | vim_findfile_free_visited (void *search_ctx_arg) |
char_u * | find_file_in_path (char_u *ptr, size_t len, int options, int first, char_u *rel_fname) |
char_u * | find_directory_in_path (char_u *ptr, size_t len, int options, char_u *rel_fname) |
char_u * | find_file_in_path_option (char_u *ptr, size_t len, int options, int first, char_u *path_option, int find_what, char_u *rel_fname, char_u *suffixes) |
void | do_autocmd_dirchanged (char *new_dir, CdScope scope, CdCause cause, bool pre) |
int | vim_chdirfile (char_u *fname, CdCause cause) |
int | vim_chdir (char_u *new_dir) |
Change directory to "new_dir". Search 'cdpath' for relative directory names. More... | |
#define FF_MAX_STAR_STAR_EXPAND ((char_u)30) |
typedef struct ff_search_ctx_T ff_search_ctx_T |
typedef struct ff_stack ff_stack_T |
typedef struct ff_visited_list_hdr ff_visited_list_hdr_T |
typedef struct ff_visited ff_visited_T |
Find the directory name "ptr[len]" in the path.
options: FNAME_MESS give error message when not found FNAME_UNESC unescape backslashes
Uses NameBuff[]!
ptr | file name |
len | length of file name |
rel_fname | file name searching relative to |
Find the file name "ptr[len]" in the path. Also finds directory names.
On the first call set the parameter 'first' to TRUE to initialize the search. For repeating calls to FALSE.
Repeating calls will return other files called 'ptr[len]' from the path.
Only on the first call 'ptr' and 'len' are used. For repeating calls they don't need valid values.
If nothing found on the first call the option FNAME_MESS will issue the message: 'Can't find file "<file>" in path' On repeating calls: 'No more file "<file>" found in path'
options: FNAME_MESS give error message when not found
Uses NameBuff[]!
ptr | file name |
len | length of file name |
first | use count'th matching file name |
rel_fname | file name searching relative to |
char_u* find_file_in_path_option | ( | char_u * | ptr, |
size_t | len, | ||
int | options, | ||
int | first, | ||
char_u * | path_option, | ||
int | find_what, | ||
char_u * | rel_fname, | ||
char_u * | suffixes | ||
) |
ptr | file name |
len | length of file name |
first | use count'th matching file name |
path_option | p_path or p_cdpath |
find_what | FINDFILE_FILE, _DIR or _BOTH |
rel_fname | file name we are looking relative to. |
suffixes | list of suffixes, 'suffixesadd' option |
int vim_chdir | ( | char_u * | new_dir | ) |
Change directory to "new_dir". Search 'cdpath' for relative directory names.
Change to a file's directory. Caller must call shorten_fnames()!
Find a file in a search context. The search context was created with vim_findfile_init() above.
To get all matching files call this function until you get NULL.
If the passed search_context is NULL, NULL is returned.
The search algorithm is depth first. To change this replace the stack with a list (don't forget to leave partly searched directories on the top of the list).
Clean up the given search context. Can handle a NULL pointer.
Free the list of lists of visited files and directories Can handle it if the passed search_context is NULL;
void* vim_findfile_init | ( | char_u * | path, |
char_u * | filename, | ||
char_u * | stopdirs, | ||
int | level, | ||
int | free_visited, | ||
int | find_what, | ||
void * | search_ctx_arg, | ||
int | tagfile, | ||
char_u * | rel_fname | ||
) |
Initialization routine for vim_findfile().
Returns the newly allocated search context or NULL if an error occurred.
Don't forget to clean up by calling vim_findfile_cleanup() if you are done with the search context.
Find the file 'filename' in the directory 'path'. The parameter 'path' may contain wildcards. If so only search 'level' directories deep. The parameter 'level' is the absolute maximum and is not related to restricts given to the '**' wildcard. If 'level' is 100 and you use '**200' vim_findfile() will stop after 100 levels.
'filename' cannot contain wildcards! It is used as-is, no backslashes to escape special characters.
If 'stopdirs' is not NULL and nothing is found downward, the search is restarted on the next higher directory level. This is repeated until the start-directory of a search is contained in 'stopdirs'. 'stopdirs' has the format ";*<dirname>*\(;<dirname>\)*;\=$".
If the 'path' is relative, the starting dir for the search is either VIM's current dir or if the path starts with "./" the current files dir. If the 'path' is absolute, the starting dir is that part of the path before the first wildcard.
Upward search is only done on the starting dir.
If 'free_visited' is TRUE the list of already visited files/directories is cleared. Set this to FALSE if you just want to search from another directory, but want to be sure that no directory from a previous search is searched again. This is useful if you search for a file at different places. The list of visited files/dirs can also be cleared with the function vim_findfile_free_visited().
Set the parameter 'find_what' to FINDFILE_DIR if you want to search for directories only, FINDFILE_FILE for files only, FINDFILE_BOTH for both.
A search context returned by a previous call to vim_findfile_init() can be passed in the parameter "search_ctx_arg". This context is reused and reinitialized with the new parameters. The list of already visited directories from this context is only deleted if the parameter "free_visited" is true. Be aware that the passed "search_ctx_arg" is freed if the reinitialization fails.
If you don't have a search context from a previous call "search_ctx_arg" must be NULL.
This function silently ignores a few errors, vim_findfile() will have limited functionality then.
tagfile | expanding names of tags files |
rel_fname | file name to use for "." |