diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-11-22 11:02:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 11:02:24 +0100 |
commit | cd386b2c72eaacd9acac27380ee34db1accad9cb (patch) | |
tree | 15f906032e4091204450ed197da3ad97ddcb5049 /src/nvim/file_search.c | |
parent | 5eb5f4948826e9d47685ea9e257409cc3e693614 (diff) | |
parent | 40f3f75867bf03abfd90e0389a38197a00d37af1 (diff) | |
download | rneovim-cd386b2c72eaacd9acac27380ee34db1accad9cb.tar.gz rneovim-cd386b2c72eaacd9acac27380ee34db1accad9cb.tar.bz2 rneovim-cd386b2c72eaacd9acac27380ee34db1accad9cb.zip |
Merge pull request #20151 from dundargoc/refactor/char_u/13
refactor: replace char_u with char 13: remove `STRLEN` part 3
Diffstat (limited to 'src/nvim/file_search.c')
-rw-r--r-- | src/nvim/file_search.c | 112 |
1 files changed, 55 insertions, 57 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 1d891799a5..36d58923b0 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -82,8 +82,8 @@ typedef struct ff_stack { // 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; + char *ffs_fix_path; + char *ffs_wc_path; // files/dirs found in the above directory, matched by the first wildcard // of wc_part @@ -511,7 +511,7 @@ char_u *vim_findfile_stopdir(char_u *buf) while (*r_ptr != NUL && *r_ptr != ';') { if (r_ptr[0] == '\\' && r_ptr[1] == ';') { // Overwrite the escape char, - // use STRLEN(r_ptr) to move the trailing '\0'. + // use strlen(r_ptr) to move the trailing '\0'. STRMOVE(r_ptr, r_ptr + 1); r_ptr++; } @@ -553,12 +553,12 @@ void vim_findfile_cleanup(void *ctx) /// NULL if nothing found. char_u *vim_findfile(void *search_ctx_arg) { - char_u *file_path; - char_u *rest_of_wildcards; + char *file_path; + char *rest_of_wildcards; char_u *path_end = NULL; ff_stack_T *stackp = NULL; size_t len; - char_u *p; + char *p; char *suf; ff_search_ctx_T *search_ctx; @@ -612,7 +612,7 @@ char_u *vim_findfile(void *search_ctx_arg) // first time (hence stackp->ff_filearray == NULL) if (stackp->ffs_filearray == NULL && ff_check_visited(&search_ctx->ffsc_dir_visited_list->ffvl_visited_list, - (char *)stackp->ffs_fix_path, (char *)stackp->ffs_wc_path) == FAIL) { + stackp->ffs_fix_path, stackp->ffs_wc_path) == FAIL) { #ifdef FF_VERBOSE if (p_verbose >= 5) { verbose_enter_scroll(); @@ -650,37 +650,37 @@ char_u *vim_findfile(void *search_ctx_arg) char *dirptrs[2]; // we use filepath to build the path expand_wildcards() should expand. - dirptrs[0] = (char *)file_path; + dirptrs[0] = file_path; dirptrs[1] = NULL; // if we have a start dir copy it in - if (!vim_isAbsName(stackp->ffs_fix_path) + if (!vim_isAbsName((char_u *)stackp->ffs_fix_path) && search_ctx->ffsc_start_dir) { if (strlen(search_ctx->ffsc_start_dir) + 1 >= MAXPATHL) { ff_free_stack_element(stackp); goto fail; } STRCPY(file_path, search_ctx->ffsc_start_dir); - if (!add_pathsep((char *)file_path)) { + if (!add_pathsep(file_path)) { ff_free_stack_element(stackp); goto fail; } } // append the fix part of the search path - if (STRLEN(file_path) + STRLEN(stackp->ffs_fix_path) + 1 >= MAXPATHL) { + if (strlen(file_path) + strlen(stackp->ffs_fix_path) + 1 >= MAXPATHL) { ff_free_stack_element(stackp); goto fail; } STRCAT(file_path, stackp->ffs_fix_path); - if (!add_pathsep((char *)file_path)) { + if (!add_pathsep(file_path)) { ff_free_stack_element(stackp); goto fail; } rest_of_wildcards = stackp->ffs_wc_path; if (*rest_of_wildcards != NUL) { - len = STRLEN(file_path); + len = strlen(file_path); if (STRNCMP(rest_of_wildcards, "**", 2) == 0) { // pointer to the restrict byte // The restrict byte is not a character! @@ -705,7 +705,7 @@ char_u *vim_findfile(void *search_ctx_arg) if (stackp->ffs_star_star_empty == 0) { // if not done before, expand '**' to empty stackp->ffs_star_star_empty = 1; - dirptrs[1] = (char *)stackp->ffs_fix_path; + dirptrs[1] = stackp->ffs_fix_path; } } @@ -748,7 +748,7 @@ char_u *vim_findfile(void *search_ctx_arg) stackp->ffs_filearray_cur = 0; stackp->ffs_stage = 0; } else { - rest_of_wildcards = &stackp->ffs_wc_path[STRLEN(stackp->ffs_wc_path)]; + rest_of_wildcards = &stackp->ffs_wc_path[strlen(stackp->ffs_wc_path)]; } if (stackp->ffs_stage == 0) { @@ -768,7 +768,7 @@ char_u *vim_findfile(void *search_ctx_arg) goto fail; } STRCPY(file_path, stackp->ffs_filearray[i]); - if (!add_pathsep((char *)file_path)) { + if (!add_pathsep(file_path)) { ff_free_stack_element(stackp); goto fail; } @@ -776,7 +776,7 @@ char_u *vim_findfile(void *search_ctx_arg) // Try without extra suffix and then with suffixes // from 'suffixesadd'. - len = STRLEN(file_path); + len = strlen(file_path); if (search_ctx->ffsc_tagfile) { suf = ""; } else { @@ -784,14 +784,14 @@ char_u *vim_findfile(void *search_ctx_arg) } for (;;) { // if file exists and we didn't already find it - if ((path_with_url((char *)file_path) - || (os_path_exists((char *)file_path) + if ((path_with_url(file_path) + || (os_path_exists(file_path) && (search_ctx->ffsc_find_what == FINDFILE_BOTH || ((search_ctx->ffsc_find_what == FINDFILE_DIR) - == os_isdir((char *)file_path))))) + == os_isdir(file_path))))) #ifndef FF_VERBOSE && (ff_check_visited(&search_ctx->ffsc_visited_list->ffvl_visited_list, - (char *)file_path, "") == OK) + file_path, "") == OK) #endif ) { #ifdef FF_VERBOSE @@ -812,12 +812,11 @@ char_u *vim_findfile(void *search_ctx_arg) stackp->ffs_filearray_cur = i + 1; ff_push(search_ctx, stackp); - if (!path_with_url((char *)file_path)) { - simplify_filename(file_path); + if (!path_with_url(file_path)) { + simplify_filename((char_u *)file_path); } - if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) - == OK) { - p = (char_u *)path_shorten_fname((char *)file_path, ff_expand_buffer); + if (os_dirname((char_u *)ff_expand_buffer, MAXPATHL) == OK) { + p = path_shorten_fname(file_path, ff_expand_buffer); if (p != NULL) { STRMOVE(file_path, p); } @@ -830,7 +829,7 @@ char_u *vim_findfile(void *search_ctx_arg) verbose_leave_scroll(); } #endif - return file_path; + return (char_u *)file_path; } // Not found or found already, try next suffix. @@ -838,7 +837,7 @@ char_u *vim_findfile(void *search_ctx_arg) break; } assert(MAXPATHL >= len); - copy_option_part(&suf, (char *)file_path + len, MAXPATHL - len, ","); + copy_option_part(&suf, file_path + len, MAXPATHL - len, ","); } } } else { @@ -849,7 +848,7 @@ char_u *vim_findfile(void *search_ctx_arg) } ff_push(search_ctx, ff_create_stack_element(stackp->ffs_filearray[i], - (char *)rest_of_wildcards, + rest_of_wildcards, stackp->ffs_level - 1, 0)); } } @@ -863,7 +862,7 @@ char_u *vim_findfile(void *search_ctx_arg) for (int i = stackp->ffs_filearray_cur; i < stackp->ffs_filearray_size; i++) { if (path_fnamecmp(stackp->ffs_filearray[i], - (char *)stackp->ffs_fix_path) == 0) { + stackp->ffs_fix_path) == 0) { continue; // don't repush same directory } if (!os_isdir(stackp->ffs_filearray[i])) { @@ -871,7 +870,7 @@ char_u *vim_findfile(void *search_ctx_arg) } ff_push(search_ctx, ff_create_stack_element(stackp->ffs_filearray[i], - (char *)stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); + stackp->ffs_wc_path, stackp->ffs_level - 1, 1)); } } @@ -911,13 +910,13 @@ char_u *vim_findfile(void *search_ctx_arg) goto fail; } STRCPY(file_path, search_ctx->ffsc_start_dir); - if (!add_pathsep((char *)file_path)) { + if (!add_pathsep(file_path)) { goto fail; } STRCAT(file_path, search_ctx->ffsc_fix_path); // create a new stack entry - sptr = ff_create_stack_element((char *)file_path, + sptr = ff_create_stack_element(file_path, search_ctx->ffsc_wc_path, search_ctx->ffsc_level, 0); ff_push(search_ctx, sptr); } else { @@ -1136,12 +1135,12 @@ static ff_stack_T *ff_create_stack_element(char *fix_part, char *wc_part, int le if (fix_part == NULL) { fix_part = ""; } - new->ffs_fix_path = (char_u *)xstrdup(fix_part); + new->ffs_fix_path = xstrdup(fix_part); if (wc_part == NULL) { wc_part = ""; } - new->ffs_wc_path = (char_u *)xstrdup(wc_part); + new->ffs_wc_path = xstrdup(wc_part); return new; } @@ -1242,7 +1241,7 @@ static int ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v) } for (i = 0; stopdirs_v[i] != NULL; i++) { - if ((int)STRLEN(stopdirs_v[i]) > path_len) { + 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 // '/home/r' would also match '/home/rks' @@ -1288,11 +1287,11 @@ static int ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v) /// @return an allocated string for the file name. NULL for error. char_u *find_file_in_path(char_u *ptr, size_t len, int options, int first, char_u *rel_fname) { - return find_file_in_path_option(ptr, len, options, first, - (*curbuf->b_p_path == NUL - ? p_path - : (char_u *)curbuf->b_p_path), - FINDFILE_BOTH, rel_fname, (char_u *)curbuf->b_p_sua); + return (char_u *)find_file_in_path_option((char *)ptr, len, options, first, + (*curbuf->b_p_path == NUL + ? (char *)p_path + : curbuf->b_p_path), + FINDFILE_BOTH, (char *)rel_fname, curbuf->b_p_sua); } static char *ff_file_to_find = NULL; @@ -1323,8 +1322,8 @@ void free_findfile(void) /// @return an allocated string for the file name. NULL for error. char_u *find_directory_in_path(char_u *ptr, size_t len, int options, char_u *rel_fname) { - return find_file_in_path_option(ptr, len, options, true, p_cdpath, - FINDFILE_DIR, rel_fname, (char_u *)""); + return (char_u *)find_file_in_path_option((char *)ptr, len, options, true, (char *)p_cdpath, + FINDFILE_DIR, (char *)rel_fname, ""); } /// @param ptr file name @@ -1334,13 +1333,12 @@ char_u *find_directory_in_path(char_u *ptr, size_t len, int options, char_u *rel /// @param find_what FINDFILE_FILE, _DIR or _BOTH /// @param rel_fname file name we are looking relative to. /// @param suffixes list of suffixes, 'suffixesadd' 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) +char *find_file_in_path_option(char *ptr, size_t len, int options, int first, char *path_option, + int find_what, char *rel_fname, char *suffixes) { static char *dir; static int did_findfile_init = false; - char_u save_char; + char save_char; char *file_name = NULL; char *buf = NULL; int rel_to_curdir; @@ -1358,16 +1356,16 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first // copy file name into NameBuff, expanding environment variables save_char = ptr[len]; ptr[len] = NUL; - expand_env_esc(ptr, (char_u *)NameBuff, MAXPATHL, false, true, NULL); + expand_env_esc(ptr, NameBuff, MAXPATHL, false, true, NULL); ptr[len] = save_char; xfree(ff_file_to_find); ff_file_to_find = xstrdup(NameBuff); if (options & FNAME_UNESC) { // Change all "\ " to " ". - for (ptr = (char_u *)ff_file_to_find; *ptr != NUL; ptr++) { + for (ptr = ff_file_to_find; *ptr != NUL; ptr++) { if (ptr[0] == '\\' && ptr[1] == ' ') { - memmove(ptr, ptr + 1, STRLEN(ptr)); + memmove(ptr, ptr + 1, strlen(ptr)); } } } @@ -1406,7 +1404,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first && rel_to_curdir && (options & FNAME_REL) && rel_fname != NULL - && STRLEN(rel_fname) + l < MAXPATHL) { + && strlen(rel_fname) + l < MAXPATHL) { STRCPY(NameBuff, rel_fname); STRCPY(path_tail((char *)NameBuff), ff_file_to_find); l = strlen(NameBuff); @@ -1416,7 +1414,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first } // When the file doesn't exist, try adding parts of 'suffixesadd'. - buf = (char *)suffixes; + buf = suffixes; for (;;) { if ((os_path_exists(NameBuff) && (find_what == FINDFILE_BOTH @@ -1440,7 +1438,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first if (first == true) { // vim_findfile_free_visited can handle a possible NULL pointer vim_findfile_free_visited(fdip_search_ctx); - dir = (char *)path_option; + dir = path_option; did_findfile_init = false; } @@ -1472,7 +1470,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first r_ptr = vim_findfile_stopdir((char_u *)buf); fdip_search_ctx = vim_findfile_init(buf, ff_file_to_find, (char *)r_ptr, 100, false, find_what, - fdip_search_ctx, false, (char *)rel_fname); + fdip_search_ctx, false, rel_fname); if (fdip_search_ctx != NULL) { did_findfile_init = true; } @@ -1501,7 +1499,7 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first } theend: - return (char_u *)file_name; + return file_name; } void do_autocmd_dirchanged(char *new_dir, CdScope scope, CdCause cause, bool pre) @@ -1608,9 +1606,9 @@ int vim_chdirfile(char *fname, CdCause cause) } /// Change directory to "new_dir". Search 'cdpath' for relative directory names. -int vim_chdir(char_u *new_dir) +int vim_chdir(char *new_dir) { - char *dir_name = (char *)find_directory_in_path(new_dir, STRLEN(new_dir), + char *dir_name = (char *)find_directory_in_path((char_u *)new_dir, strlen(new_dir), FNAME_MESS, (char_u *)curbuf->b_ffname); if (dir_name == NULL) { return -1; |