From 06994e0e21eb5545aef7c2234f5d1a271865366e Mon Sep 17 00:00:00 2001 From: George Zhao Date: Wed, 17 Jan 2018 19:35:57 +0800 Subject: Fix warning about conversion on mingw64 --- src/nvim/path.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 51adcfb135..09cede8805 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -332,7 +332,7 @@ int path_fnamencmp(const char *const fname1, const char *const fname2, && (p_fic ? (c1 != c2 && CH_FOLD(c1) != CH_FOLD(c2)) : c1 != c2)) { break; } - len -= MB_PTR2LEN((const char_u *)p1); + len -= (size_t)MB_PTR2LEN((const char_u *)p1); p1 += MB_PTR2LEN((const char_u *)p1); p2 += MB_PTR2LEN((const char_u *)p2); } @@ -1691,7 +1691,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force) if (strlen(fname) > (len - 1)) { xstrlcpy(buf, fname, len); // truncate #ifdef WIN32 - slash_adjust(buf); + slash_adjust((char_u *)buf); #endif return FAIL; } @@ -1706,7 +1706,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force) xstrlcpy(buf, fname, len); // something failed; use the filename } #ifdef WIN32 - slash_adjust(buf); + slash_adjust((char_u *)buf); #endif return rv; } @@ -1741,7 +1741,7 @@ char *fix_fname(const char *fname) path_fix_case((char_u *)fname); // set correct case for file name # endif - return fname; + return (char *)fname; #endif } -- cgit From 909c967f35c3d38be6d98d7dba6cfd087a6542f4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 11 Jan 2018 11:35:07 -0500 Subject: win: detect / and \ as root path separator --- src/nvim/path.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 09cede8805..d18d9ecace 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2202,7 +2202,11 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, // expand it if forced or not an absolute path if (force || !path_is_absolute_path(fname)) { - if ((p = vim_strrchr(fname, PATHSEP)) != NULL) { + p = vim_strrchr(fname, "/") +#ifdef WIN32 + if (p == NULL) p = vim_strrchr(fname, "\\") +#endif + if (p != NULL) { // relative to root if (p == fname) { // only one path component -- cgit From e39be42c0998d8048354961cd7a0864111c01e0b Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 11 Jan 2018 11:56:29 -0500 Subject: fixup: compile-time errors --- src/nvim/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index d18d9ecace..8e4f72be68 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2202,9 +2202,9 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, // expand it if forced or not an absolute path if (force || !path_is_absolute_path(fname)) { - p = vim_strrchr(fname, "/") + p = vim_strrchr(fname, PATHSEP); #ifdef WIN32 - if (p == NULL) p = vim_strrchr(fname, "\\") + if (p == NULL) p = vim_strrchr(fname, '/'); #endif if (p != NULL) { // relative to root -- cgit From ec5af91b90a6e1d7b8e6f789c3d435316391a4c6 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 11 Jan 2018 16:27:10 -0500 Subject: win: explicitly specify pathsep --- src/nvim/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 8e4f72be68..d8f5163ed0 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2202,9 +2202,9 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, // expand it if forced or not an absolute path if (force || !path_is_absolute_path(fname)) { - p = vim_strrchr(fname, PATHSEP); + p = vim_strrchr(fname, '/'); #ifdef WIN32 - if (p == NULL) p = vim_strrchr(fname, '/'); + if (p == NULL) p = vim_strrchr(fname, '\\'); #endif if (p != NULL) { // relative to root -- cgit From 273c7cfa2a01430411ce4c58c354e42337c6e6a7 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 11 Jan 2018 17:35:36 -0500 Subject: fixup: lint errors --- src/nvim/path.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index d8f5163ed0..21ac064c30 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2204,7 +2204,9 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, if (force || !path_is_absolute_path(fname)) { p = vim_strrchr(fname, '/'); #ifdef WIN32 - if (p == NULL) p = vim_strrchr(fname, '\\'); + if (p == NULL) { + p = vim_strrchr(fname, '\\'); + } #endif if (p != NULL) { // relative to root -- cgit From 998a16c926623a667ecb0228f4a6cd8ba1e90201 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 24 Mar 2018 11:21:20 +0100 Subject: refactor/rename: path_is_absolute() --- src/nvim/path.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 21ac064c30..63aeaf5f92 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -452,10 +452,10 @@ char *FullName_save(const char *fname, bool force) /// Saves the absolute path. /// @param name An absolute or relative path. /// @return The absolute path of `name`. -char_u *save_absolute_path(const char_u *name) +char_u *save_abs_path(const char_u *name) FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { - if (!path_is_absolute_path(name)) { + if (!path_is_absolute(name)) { return (char_u *)FullName_save((char *)name, true); } return vim_strsave((char_u *) name); @@ -814,7 +814,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap) STRCPY(buf, curdir); // relative to current directory } else if (path_with_url((char *)buf)) { continue; // URL can't be used here - } else if (!path_is_absolute_path(buf)) { + } else if (!path_is_absolute(buf)) { // Expand relative path to their full path equivalent size_t len = STRLEN(curdir); if (len + STRLEN(buf) + 3 > MAXPATHL) { @@ -949,19 +949,17 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) } } - if (path_is_absolute_path(path)) { - /* - * Last resort: shorten relative to curdir if possible. - * 'possible' means: - * 1. It is under the current directory. - * 2. The result is actually shorter than the original. - * - * Before curdir After - * /foo/bar/file.txt /foo/bar ./file.txt - * c:\foo\bar\file.txt c:\foo\bar .\file.txt - * /file.txt / /file.txt - * c:\file.txt c:\ .\file.txt - */ + if (path_is_absolute(path)) { + // Last resort: shorten relative to curdir if possible. + // 'possible' means: + // 1. It is under the current directory. + // 2. The result is actually shorter than the original. + // + // Before curdir After + // /foo/bar/file.txt /foo/bar ./file.txt + // c:\foo\bar\file.txt c:\foo\bar .\file.txt + // /file.txt / /file.txt + // c:\file.txt c:\ .\file.txt short_name = path_shorten_fname(path, curdir); if (short_name != NULL && short_name > path + 1 ) { @@ -1221,7 +1219,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, */ if (path_has_exp_wildcard(p)) { if ((flags & EW_PATH) - && !path_is_absolute_path(p) + && !path_is_absolute(p) && !(p[0] == '.' && (vim_ispathsep(p[1]) || (p[1] == '.' && vim_ispathsep(p[2])))) @@ -1667,7 +1665,7 @@ int path_with_url(const char *fname) */ bool vim_isAbsName(char_u *name) { - return path_with_url((char *)name) != 0 || path_is_absolute_path(name); + return path_with_url((char *)name) != 0 || path_is_absolute(name); } /// Save absolute file name to "buf[len]". @@ -2201,7 +2199,7 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, char *end_of_path = (char *) fname; // expand it if forced or not an absolute path - if (force || !path_is_absolute_path(fname)) { + if (force || !path_is_absolute(fname)) { p = vim_strrchr(fname, '/'); #ifdef WIN32 if (p == NULL) { @@ -2234,10 +2232,10 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, return append_path((char *)buf, end_of_path, len); } -/// Check if the given file is absolute. +/// Check if file `fname` is a full (absolute) path. /// /// @return `TRUE` if "fname" is absolute. -int path_is_absolute_path(const char_u *fname) +int path_is_absolute(const char_u *fname) { #ifdef WIN32 // A name like "d:/foo" and "//server/share" is absolute @@ -2262,7 +2260,7 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize) { char *path = getenv("PATH"); - if (path == NULL || path_is_absolute_path((char_u *)argv0)) { + if (path == NULL || path_is_absolute((char_u *)argv0)) { xstrlcpy(buf, argv0, bufsize); } else if (argv0[0] == '.' || strchr(argv0, PATHSEP)) { // Relative to CWD. -- cgit From 7ae41442088a4b1b1cd324b683defd87998ba75c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 24 Mar 2018 13:56:55 +0100 Subject: refactor/rename: path_try_shorten_fname() --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 63aeaf5f92..a1f9b2a0cc 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1908,7 +1908,7 @@ int pathcmp(const char *p, const char *q, int maxlen) /// - Pointer into `full_path` if shortened. /// - `full_path` unchanged if no shorter name is possible. /// - NULL if `full_path` is NULL. -char_u *path_shorten_fname_if_possible(char_u *full_path) +char_u *path_try_shorten_fname(char_u *full_path) { char_u *dirname = xmalloc(MAXPATHL); char_u *p = full_path; -- cgit From 0ecf7e3a2d3bf4c8062ebf1d462a16d716a37352 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 24 Mar 2018 14:01:39 +0100 Subject: refactor/rename: path_to_absolute() --- src/nvim/path.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index a1f9b2a0cc..168d835a66 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1699,7 +1699,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force) return OK; } - int rv = path_get_absolute_path((char_u *)fname, (char_u *)buf, len, force); + int rv = path_to_absolute((char_u *)fname, (char_u *)buf, len, force); if (rv == FAIL) { xstrlcpy(buf, fname, len); // something failed; use the filename } @@ -2189,8 +2189,8 @@ int append_path(char *path, const char *to_append, size_t max_len) /// @param force also expand when "fname" is already absolute. /// /// @return FAIL for failure, OK for success. -static int path_get_absolute_path(const char_u *fname, char_u *buf, - size_t len, int force) +static int path_to_absolute(const char_u *fname, char_u *buf, size_t len, + int force) { char_u *p; *buf = NUL; -- cgit