Data Structures | Macros | Typedefs | Functions
file_search.c File Reference
#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/misc1.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

voidvim_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_uvim_findfile_stopdir (char_u *buf)
 
void vim_findfile_cleanup (void *ctx)
 
char_uvim_findfile (void *search_ctx_arg)
 
void vim_findfile_free_visited (void *search_ctx_arg)
 
char_ufind_file_in_path (char_u *ptr, size_t len, int options, int first, char_u *rel_fname)
 
char_ufind_directory_in_path (char_u *ptr, size_t len, int options, char_u *rel_fname)
 
char_ufind_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)
 
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...
 

Macro Definition Documentation

◆ FF_MAX_STAR_STAR_EXPAND

#define FF_MAX_STAR_STAR_EXPAND   ((char_u)30)

Typedef Documentation

◆ ff_search_ctx_T

◆ ff_stack_T

typedef struct ff_stack ff_stack_T

◆ ff_visited_list_hdr_T

◆ ff_visited_T

typedef struct ff_visited ff_visited_T

Function Documentation

◆ do_autocmd_dirchanged()

void do_autocmd_dirchanged ( char *  new_dir,
CdScope  scope,
CdCause  cause 
)

◆ find_directory_in_path()

char_u* find_directory_in_path ( char_u ptr,
size_t  len,
int  options,
char_u rel_fname 
)

Find the directory name "ptr[len]" in the path.

options: FNAME_MESS give error message when not found FNAME_UNESC unescape backslashes

Uses NameBuff[]!

Parameters
ptrfile name
lenlength of file name
rel_fnamefile name searching relative to
Returns
an allocated string for the file name. NULL for error.

◆ find_file_in_path()

char_u* find_file_in_path ( char_u ptr,
size_t  len,
int  options,
int  first,
char_u rel_fname 
)

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[]!

Parameters
ptrfile name
lenlength of file name
firstuse count'th matching file name
rel_fnamefile name searching relative to
Returns
an allocated string for the file name. NULL for error.

◆ find_file_in_path_option()

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 
)
Parameters
ptrfile name
lenlength of file name
firstuse count'th matching file name
path_optionp_path or p_cdpath
find_whatFINDFILE_FILE, _DIR or _BOTH
rel_fnamefile name we are looking relative to.
suffixeslist of suffixes, 'suffixesadd' option

◆ vim_chdir()

int vim_chdir ( char_u new_dir)

Change directory to "new_dir". Search 'cdpath' for relative directory names.

◆ vim_chdirfile()

int vim_chdirfile ( char_u fname,
CdCause  cause 
)

Change to a file's directory. Caller must call shorten_fnames()!

Returns
OK or FAIL

◆ vim_findfile()

char_u* vim_findfile ( void search_ctx_arg)

◆ vim_findfile_cleanup()

void vim_findfile_cleanup ( void ctx)

◆ vim_findfile_free_visited()

void vim_findfile_free_visited ( void search_ctx_arg)

◆ vim_findfile_init()

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.

Parameters
tagfileexpanding names of tags files
rel_fnamefile name to use for "."

◆ vim_findfile_stopdir()

char_u* vim_findfile_stopdir ( char_u buf)