diff options
-rw-r--r-- | src/buffer.c | 2 | ||||
-rw-r--r-- | src/ex_cmds.c | 4 | ||||
-rw-r--r-- | src/ex_cmds2.c | 4 | ||||
-rw-r--r-- | src/if_cscope.c | 2 | ||||
-rw-r--r-- | src/main.c | 12 | ||||
-rw-r--r-- | src/memline.c | 2 | ||||
-rw-r--r-- | src/path.c | 65 | ||||
-rw-r--r-- | src/path.h | 4 | ||||
-rw-r--r-- | src/search.c | 2 | ||||
-rw-r--r-- | src/spell.c | 12 | ||||
-rw-r--r-- | src/tag.c | 4 | ||||
-rw-r--r-- | test/unit/path.moon | 22 |
12 files changed, 50 insertions, 85 deletions
diff --git a/src/buffer.c b/src/buffer.c index c181d1d7c5..83b1928dd2 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -3738,7 +3738,7 @@ do_arg_all ( for (i = 0; i < opened_len; ++i) { if (i < alist->al_ga.ga_len && (AARGLIST(alist)[i].ae_fnum == buf->b_fnum - || fullpathcmp(alist_name(&AARGLIST(alist)[i]), + || path_full_compare(alist_name(&AARGLIST(alist)[i]), buf->b_ffname, TRUE) & FPC_SAME)) { int weight = 1; diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 65c71cdcb2..e8eb458f70 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -5213,7 +5213,7 @@ void fix_help_buffer(void) copy_option_part(&p, NameBuff, MAXPATHL, ","); mustfree = FALSE; rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); - if (fullpathcmp(rt, NameBuff, FALSE) != FPC_SAME) { + if (path_full_compare(rt, NameBuff, FALSE) != FPC_SAME) { int fcount; char_u **fnames; FILE *fd; @@ -5522,7 +5522,7 @@ helptags_one ( * add the "help-tags" tag. */ ga_init(&ga, (int)sizeof(char_u *), 100); - if (add_help_tags || fullpathcmp((char_u *)"$VIMRUNTIME/doc", + if (add_help_tags || path_full_compare((char_u *)"$VIMRUNTIME/doc", dir, FALSE) == FPC_SAME) { if (ga_grow(&ga, 1) == FAIL) got_int = TRUE; diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 5b7e32fcce..00f993168a 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -1691,7 +1691,7 @@ static int editing_arg_idx(win_T *win) || (win->w_buffer->b_fnum != WARGLIST(win)[win->w_arg_idx].ae_fnum && (win->w_buffer->b_ffname == NULL - || !(fullpathcmp( + || !(path_full_compare( alist_name(&WARGLIST(win)[win->w_arg_idx]), win->w_buffer->b_ffname, TRUE) & FPC_SAME)))); } @@ -1712,7 +1712,7 @@ void check_arg_idx(win_T *win) && win->w_arg_idx < GARGCOUNT && (win->w_buffer->b_fnum == GARGLIST[GARGCOUNT - 1].ae_fnum || (win->w_buffer->b_ffname != NULL - && (fullpathcmp(alist_name(&GARGLIST[GARGCOUNT - 1]), + && (path_full_compare(alist_name(&GARGLIST[GARGCOUNT - 1]), win->w_buffer->b_ffname, TRUE) & FPC_SAME)))) arg_had_last = TRUE; } else { diff --git a/src/if_cscope.c b/src/if_cscope.c index 884fb002ff..bcbd8da40d 100644 --- a/src/if_cscope.c +++ b/src/if_cscope.c @@ -1303,7 +1303,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags, struct stat && csinfo[j].st_dev == sb->st_dev && csinfo[j].st_ino == sb->st_ino #else /* compare pathnames first */ - && ((fullpathcmp(csinfo[j].fname, fname, FALSE) & FPC_SAME) + && ((path_full_compare(csinfo[j].fname, fname, FALSE) & FPC_SAME) /* if not Windows 9x, test index file attributes too */ || (!mch_windows95() && csinfo[j].nVolume == bhfi.dwVolumeSerialNumber diff --git a/src/main.c b/src/main.c index 0b1f650827..ccabd43d38 100644 --- a/src/main.c +++ b/src/main.c @@ -2048,18 +2048,18 @@ static void source_startup_scripts(mparm_T *parmp) secure = p_secure; i = FAIL; - if (fullpathcmp((char_u *)USR_VIMRC_FILE, + if (path_full_compare((char_u *)USR_VIMRC_FILE, (char_u *)VIMRC_FILE, FALSE) != FPC_SAME #ifdef USR_VIMRC_FILE2 - && fullpathcmp((char_u *)USR_VIMRC_FILE2, + && path_full_compare((char_u *)USR_VIMRC_FILE2, (char_u *)VIMRC_FILE, FALSE) != FPC_SAME #endif #ifdef USR_VIMRC_FILE3 - && fullpathcmp((char_u *)USR_VIMRC_FILE3, + && path_full_compare((char_u *)USR_VIMRC_FILE3, (char_u *)VIMRC_FILE, FALSE) != FPC_SAME #endif #ifdef SYS_VIMRC_FILE - && fullpathcmp((char_u *)SYS_VIMRC_FILE, + && path_full_compare((char_u *)SYS_VIMRC_FILE, (char_u *)VIMRC_FILE, FALSE) != FPC_SAME #endif ) @@ -2073,10 +2073,10 @@ static void source_startup_scripts(mparm_T *parmp) else secure = 0; #endif - if ( fullpathcmp((char_u *)USR_EXRC_FILE, + if ( path_full_compare((char_u *)USR_EXRC_FILE, (char_u *)EXRC_FILE, FALSE) != FPC_SAME #ifdef USR_EXRC_FILE2 - && fullpathcmp((char_u *)USR_EXRC_FILE2, + && path_full_compare((char_u *)USR_EXRC_FILE2, (char_u *)EXRC_FILE, FALSE) != FPC_SAME #endif ) diff --git a/src/memline.c b/src/memline.c index 6b948f606f..c9ab5e3920 100644 --- a/src/memline.c +++ b/src/memline.c @@ -1646,7 +1646,7 @@ recover_names ( if (curbuf->b_ml.ml_mfp != NULL && (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) { for (i = 0; i < num_files; ++i) - if (fullpathcmp(p, files[i], TRUE) & FPC_SAME) { + if (path_full_compare(p, files[i], TRUE) & FPC_SAME) { /* Remove the name from files[i]. Move further entries * down. When the array becomes empty free it here, since * FreeWild() won't be called below. */ diff --git a/src/path.c b/src/path.c index 1b22a1e656..e5680d5073 100644 --- a/src/path.c +++ b/src/path.c @@ -29,71 +29,36 @@ #define URL_SLASH 1 /* path_is_url() has found "://" */ #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */ -FileComparison fullpathcmp ( - char_u *s1, - char_u *s2, - int checkname -) +FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname) { -#ifdef UNIX + assert(s1 && s2); char_u exp1[MAXPATHL]; char_u full1[MAXPATHL]; char_u full2[MAXPATHL]; - struct stat st1, st2; + uv_stat_t st1, st2; int r1, r2; expand_env(s1, exp1, MAXPATHL); - r1 = mch_stat((char *)exp1, &st1); - r2 = mch_stat((char *)s2, &st2); - if (r1 != 0 && r2 != 0) { - /* if mch_stat() doesn't work, may compare the names */ + r1 = os_stat(exp1, &st1); + r2 = os_stat(s2, &st2); + if (r1 != OK && r2 != OK) { + // If os_stat() doesn't work, may compare the names. if (checkname) { - if (fnamecmp(exp1, s2) == 0) - return FPC_SAMEX; - r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE); - r2 = vim_FullName(s2, full2, MAXPATHL, FALSE); - if (r1 == OK && r2 == OK && fnamecmp(full1, full2) == 0) + vim_FullName(exp1, full1, MAXPATHL, FALSE); + vim_FullName(s2, full2, MAXPATHL, FALSE); + if (fnamecmp(full1, full2) == 0) { return FPC_SAMEX; + } } return FPC_NOTX; } - if (r1 != 0 || r2 != 0) + if (r1 != OK || r2 != OK) { return FPC_DIFFX; - if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) + } + if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) { return FPC_SAME; - return FPC_DIFF; -#else - char_u *exp1; /* expanded s1 */ - char_u *full1; /* full path of s1 */ - char_u *full2; /* full path of s2 */ - int retval = FPC_DIFF; - int r1, r2; - - /* allocate one buffer to store three paths (alloc()/free() is slow!) */ - if ((exp1 = alloc(MAXPATHL * 3)) != NULL) { - full1 = exp1 + MAXPATHL; - full2 = full1 + MAXPATHL; - - expand_env(s1, exp1, MAXPATHL); - r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE); - r2 = vim_FullName(s2, full2, MAXPATHL, FALSE); - - /* If vim_FullName() fails, the file probably doesn't exist. */ - if (r1 != OK && r2 != OK) { - if (checkname && fnamecmp(exp1, s2) == 0) - retval = FPC_SAMEX; - else - retval = FPC_NOTX; - } else if (r1 != OK || r2 != OK) - retval = FPC_DIFFX; - else if (fnamecmp(full1, full2)) - retval = FPC_DIFF; - else - retval = FPC_SAME; - vim_free(exp1); } - return retval; -#endif + return FPC_DIFF; } /* diff --git a/src/path.h b/src/path.h index 5802128db5..e4acfa62b2 100644 --- a/src/path.h +++ b/src/path.h @@ -1,7 +1,7 @@ #ifndef NEOVIM_PATH_H #define NEOVIM_PATH_H -/// Return value for the comparison of two files. Also @see fullpathcmp. +/// Return value for the comparison of two files. Also @see path_full_compare. typedef enum file_comparison { FPC_SAME = 1, ///< Both exist and are the same file. FPC_DIFF = 2, ///< Both exist and are different files. @@ -17,7 +17,7 @@ typedef enum file_comparison { /// @param s2 Second file name. /// @param checkname When both files don't exist, only compare their names. /// @return Enum of type FileComparison. @see FileComparison. -FileComparison fullpathcmp(char_u *s1, char_u *s2, int checkname); +FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname); int vim_ispathsep(int c); int vim_ispathsep_nocolon(int c); diff --git a/src/search.c b/src/search.c index da159e4cde..25b809bd39 100644 --- a/src/search.c +++ b/src/search.c @@ -4094,7 +4094,7 @@ find_pattern_in_path ( i = old_files; if (i == max_path_depth) break; - if (fullpathcmp(new_fname, files[i].name, TRUE) & FPC_SAME) { + if (path_full_compare(new_fname, files[i].name, TRUE) & FPC_SAME) { if (type != CHECK_PATH && action == ACTION_SHOW_ALL && files[i].matched) { msg_putchar('\n'); /* cursor below last one */ diff --git a/src/spell.c b/src/spell.c index 52a85171eb..99258b4f88 100644 --- a/src/spell.c +++ b/src/spell.c @@ -3887,7 +3887,7 @@ char_u *did_set_spelllang(win_T *wp) /* Check if we loaded this language before. */ for (slang = first_lang; slang != NULL; slang = slang->sl_next) - if (fullpathcmp(lang, slang->sl_fname, FALSE) == FPC_SAME) + if (path_full_compare(lang, slang->sl_fname, FALSE) == FPC_SAME) break; } else { filename = FALSE; @@ -3932,7 +3932,7 @@ char_u *did_set_spelllang(win_T *wp) * Loop over the languages, there can be several files for "lang". */ for (slang = first_lang; slang != NULL; slang = slang->sl_next) - if (filename ? fullpathcmp(lang, slang->sl_fname, FALSE) == FPC_SAME + if (filename ? path_full_compare(lang, slang->sl_fname, FALSE) == FPC_SAME : STRICMP(lang, slang->sl_name) == 0) { region_mask = REGION_ALL; if (!filename && region != NULL) { @@ -3988,7 +3988,7 @@ char_u *did_set_spelllang(win_T *wp) /* If it was already found above then skip it. */ for (c = 0; c < ga.ga_len; ++c) { p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; - if (p != NULL && fullpathcmp(spf_name, p, FALSE) == FPC_SAME) + if (p != NULL && path_full_compare(spf_name, p, FALSE) == FPC_SAME) break; } if (c < ga.ga_len) @@ -3997,7 +3997,7 @@ char_u *did_set_spelllang(win_T *wp) /* Check if it was loaded already. */ for (slang = first_lang; slang != NULL; slang = slang->sl_next) - if (fullpathcmp(spf_name, slang->sl_fname, FALSE) == FPC_SAME) + if (path_full_compare(spf_name, slang->sl_fname, FALSE) == FPC_SAME) break; if (slang == NULL) { /* Not loaded, try loading it now. The language name includes the @@ -4334,7 +4334,7 @@ spell_reload_one ( int didit = FALSE; for (slang = first_lang; slang != NULL; slang = slang->sl_next) { - if (fullpathcmp(fname, slang->sl_fname, FALSE) == FPC_SAME) { + if (path_full_compare(fname, slang->sl_fname, FALSE) == FPC_SAME) { slang_clear(slang); if (spell_load_file(fname, NULL, slang, FALSE) == NULL) /* reloading failed, clear the language */ @@ -7679,7 +7679,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) * It might have been done already by spell_reload_one(). */ for (slang = first_lang; slang != NULL; slang = slang->sl_next) - if (fullpathcmp(wfname, slang->sl_fname, FALSE) == FPC_SAME) + if (path_full_compare(wfname, slang->sl_fname, FALSE) == FPC_SAME) break; if (slang == NULL) { spell_message(spin, (char_u *)_("Reading back spell file...")); @@ -2723,7 +2723,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand) /* * Check if we have a tag for the buffer with name "buf_ffname". - * This is a bit slow, because of the full path compare in fullpathcmp(). + * This is a bit slow, because of the full path compare in path_full_compare(). * Return TRUE if tag for file "fname" if tag file "tag_fname" is for current * file. */ @@ -2740,7 +2740,7 @@ static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname, } fullname = expand_tag_fname(fname, tag_fname, TRUE); if (fullname != NULL) { - retval = (fullpathcmp(fullname, buf_ffname, TRUE) & FPC_SAME); + retval = (path_full_compare(fullname, buf_ffname, TRUE) & FPC_SAME); vim_free(fullname); } *fname_end = c; diff --git a/test/unit/path.moon b/test/unit/path.moon index 90142a8cbb..b989283c1d 100644 --- a/test/unit/path.moon +++ b/test/unit/path.moon @@ -6,19 +6,19 @@ ffi.cdef [[ typedef enum file_comparison { FPC_SAME = 1, FPC_DIFF = 2, FPC_NOTX = 4, FPC_DIFFX = 6, FPC_SAMEX = 7 } FileComparison; -FileComparison fullpathcmp(char_u *s1, char_u *s2, int checkname); +FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname); ]] -- import constants parsed by ffi {:FPC_SAME, :FPC_DIFF, :FPC_NOTX, :FPC_DIFFX, :FPC_SAMEX} = path describe 'path function', -> - describe 'fullpathcmp', -> + describe 'path_full_compare', -> - fullpathcmp = (s1, s2, cn) -> + path_full_compare = (s1, s2, cn) -> s1 = to_cstr s1 s2 = to_cstr s2 - path.fullpathcmp s1, s2, cn or 0 + path.path_full_compare s1, s2, cn or 0 f1 = 'f1.o' f2 = 'f2.o' @@ -33,19 +33,19 @@ describe 'path function', -> os.remove f2 it 'returns FPC_SAME when passed the same file', -> - eq FPC_SAME, (fullpathcmp f1, f1) + eq FPC_SAME, (path_full_compare f1, f1) it 'returns FPC_SAMEX when files that dont exist and have same name', -> - eq FPC_SAMEX, (fullpathcmp 'null.txt', 'null.txt', true) + eq FPC_SAMEX, (path_full_compare 'null.txt', 'null.txt', true) it 'returns FPC_NOTX when files that dont exist', -> - eq FPC_NOTX, (fullpathcmp 'null.txt', 'null.txt') + eq FPC_NOTX, (path_full_compare 'null.txt', 'null.txt') it 'returns FPC_DIFF when passed different files', -> - eq FPC_DIFF, (fullpathcmp f1, f2) - eq FPC_DIFF, (fullpathcmp f2, f1) + eq FPC_DIFF, (path_full_compare f1, f2) + eq FPC_DIFF, (path_full_compare f2, f1) it 'returns FPC_DIFFX if only one does not exist', -> - eq FPC_DIFFX, (fullpathcmp f1, 'null.txt') - eq FPC_DIFFX, (fullpathcmp 'null.txt', f1) + eq FPC_DIFFX, (path_full_compare f1, 'null.txt') + eq FPC_DIFFX, (path_full_compare 'null.txt', f1) |