aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/file_search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/file_search.c')
-rw-r--r--src/nvim/file_search.c54
1 files changed, 24 insertions, 30 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 460cd48fc5..ed4848b402 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -51,10 +51,13 @@
#include "nvim/ascii_defs.h"
#include "nvim/autocmd.h"
+#include "nvim/autocmd_defs.h"
+#include "nvim/buffer_defs.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
#include "nvim/file_search.h"
-#include "nvim/gettext.h"
+#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
#include "nvim/macros_defs.h"
#include "nvim/mbyte.h"
@@ -63,8 +66,10 @@
#include "nvim/option.h"
#include "nvim/option_vars.h"
#include "nvim/os/fs.h"
+#include "nvim/os/fs_defs.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
+#include "nvim/os/os_defs.h"
#include "nvim/path.h"
#include "nvim/strings.h"
#include "nvim/vim_defs.h"
@@ -156,7 +161,7 @@ typedef struct ff_visited_list_hdr {
// ffsc_stopdirs_v: array of stop directories for upward search
// ffsc_find_what: FINDFILE_BOTH, FINDFILE_DIR or FINDFILE_FILE
// ffsc_tagfile: searching for tags file, don't use 'suffixesadd'
-typedef struct ff_search_ctx_T {
+typedef struct {
ff_stack_T *ffsc_stack_ptr;
ff_visited_list_hdr_T *ffsc_visited_list;
ff_visited_list_hdr_T *ffsc_dir_visited_list;
@@ -237,7 +242,6 @@ static const char e_path_too_long_for_completion[]
void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, int free_visited,
int find_what, void *search_ctx_arg, int tagfile, char *rel_fname)
{
- char *wc_part;
ff_stack_T *sptr;
ff_search_ctx_T *search_ctx;
@@ -308,7 +312,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
goto error_return;
}
path += 2;
- } else // NOLINT(readability/braces)
+ } else
#endif
if (os_dirname(ff_expand_buffer, MAXPATHL) == FAIL) {
goto error_return;
@@ -372,7 +376,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
// split into:
// -fix path
// -wildcard_stuff (might be NULL)
- wc_part = vim_strchr(path, '*');
+ char *wc_part = vim_strchr(path, '*');
if (wc_part != NULL) {
int64_t llevel;
int len;
@@ -548,24 +552,22 @@ void vim_findfile_cleanup(void *ctx)
/// NULL if nothing found.
char *vim_findfile(void *search_ctx_arg)
{
- char *file_path;
char *rest_of_wildcards;
char *path_end = NULL;
ff_stack_T *stackp = NULL;
size_t len;
char *p;
char *suf;
- ff_search_ctx_T *search_ctx;
if (search_ctx_arg == NULL) {
return NULL;
}
- search_ctx = (ff_search_ctx_T *)search_ctx_arg;
+ ff_search_ctx_T *search_ctx = (ff_search_ctx_T *)search_ctx_arg;
// filepath is used as buffer for various actions and as the storage to
// return a found filename.
- file_path = xmalloc(MAXPATHL);
+ char *file_path = xmalloc(MAXPATHL);
// store the end of the start dir -- needed for upward search
if (search_ctx->ffsc_start_dir != NULL) {
@@ -882,7 +884,7 @@ char *vim_findfile(void *search_ctx_arg)
// is the last starting directory in the stop list?
if (ff_path_in_stoplist(search_ctx->ffsc_start_dir,
(int)(path_end - search_ctx->ffsc_start_dir),
- search_ctx->ffsc_stopdirs_v) == true) {
+ search_ctx->ffsc_stopdirs_v)) {
break;
}
@@ -928,13 +930,11 @@ fail:
/// Can handle it if the passed search_context is NULL;
void vim_findfile_free_visited(void *search_ctx_arg)
{
- ff_search_ctx_T *search_ctx;
-
if (search_ctx_arg == NULL) {
return;
}
- search_ctx = (ff_search_ctx_T *)search_ctx_arg;
+ ff_search_ctx_T *search_ctx = (ff_search_ctx_T *)search_ctx_arg;
vim_findfile_free_visited_list(&search_ctx->ffsc_visited_lists_list);
vim_findfile_free_visited_list(&search_ctx->ffsc_dir_visited_lists_list);
}
@@ -1156,9 +1156,7 @@ static void ff_push(ff_search_ctx_T *search_ctx, ff_stack_T *stack_ptr)
/// @return NULL if stack is empty.
static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx)
{
- ff_stack_T *sptr;
-
- sptr = search_ctx->ffsc_stack_ptr;
+ ff_stack_T *sptr = search_ctx->ffsc_stack_ptr;
if (search_ctx->ffsc_stack_ptr != NULL) {
search_ctx->ffsc_stack_ptr = search_ctx->ffsc_stack_ptr->ffs_prev;
}
@@ -1221,10 +1219,8 @@ static void ff_clear(ff_search_ctx_T *search_ctx)
/// check if the given path is in the stopdirs
///
/// @return true if yes else false
-static int ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v)
+static bool ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v)
{
- int i = 0;
-
// eat up trailing path separators, except the first
while (path_len > 1 && vim_ispathsep(path[path_len - 1])) {
path_len--;
@@ -1235,7 +1231,7 @@ static int ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v)
return true;
}
- for (i = 0; stopdirs_v[i] != NULL; i++) {
+ for (int i = 0; stopdirs_v[i] != NULL; i++) {
if ((int)strlen(stopdirs_v[i]) > path_len) {
// match for parent directory. So '/home' also matches
// '/home/rks'. Check for PATHSEP in stopdirs_v[i], else
@@ -1338,11 +1334,9 @@ char *find_file_in_path_option(char *ptr, size_t len, int options, int first, ch
{
ff_search_ctx_T **search_ctx = (ff_search_ctx_T **)search_ctx_arg;
static char *dir;
- static int did_findfile_init = false;
- char save_char;
+ static bool did_findfile_init = false;
char *file_name = NULL;
char *buf = NULL;
- int rel_to_curdir;
if (rel_fname != NULL && path_with_url(rel_fname)) {
// Do not attempt to search "relative" to a URL. #6009
@@ -1355,7 +1349,7 @@ char *find_file_in_path_option(char *ptr, size_t len, int options, int first, ch
}
// copy file name into NameBuff, expanding environment variables
- save_char = ptr[len];
+ char save_char = ptr[len];
ptr[len] = NUL;
expand_env_esc(ptr, NameBuff, MAXPATHL, false, true, NULL);
ptr[len] = save_char;
@@ -1372,12 +1366,12 @@ char *find_file_in_path_option(char *ptr, size_t len, int options, int first, ch
}
}
- rel_to_curdir = ((*file_to_find)[0] == '.'
- && ((*file_to_find)[1] == NUL
- || vim_ispathsep((*file_to_find)[1])
- || ((*file_to_find)[1] == '.'
- && ((*file_to_find)[2] == NUL
- || vim_ispathsep((*file_to_find)[2])))));
+ bool rel_to_curdir = ((*file_to_find)[0] == '.'
+ && ((*file_to_find)[1] == NUL
+ || vim_ispathsep((*file_to_find)[1])
+ || ((*file_to_find)[1] == '.'
+ && ((*file_to_find)[2] == NUL
+ || vim_ispathsep((*file_to_find)[2])))));
if (vim_isAbsName(*file_to_find)
// "..", "../path", "." and "./path": don't use the path_option
|| rel_to_curdir