diff options
| author | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:17:51 -0500 | 
|---|---|---|
| committer | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:17:51 -0500 | 
| commit | ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f (patch) | |
| tree | 92de2079e80f5f289dd87a54af123cb7d90c3058 /src/nvim/path.c | |
| parent | 78bc52ea5397c092d01cd08296fe1dc85d998329 (diff) | |
| parent | ef4feab0e75be19c5f41d70a001db980b72090f5 (diff) | |
| download | rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.tar.gz rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.tar.bz2 rneovim-ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f.zip  | |
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'src/nvim/path.c')
| -rw-r--r-- | src/nvim/path.c | 66 | 
1 files changed, 35 insertions, 31 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 51adcfb135..168d835a66 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);    } @@ -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]". @@ -1691,7 +1689,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;    } @@ -1701,12 +1699,12 @@ 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    }  #ifdef WIN32 -  slash_adjust(buf); +  slash_adjust((char_u *)buf);  #endif    return rv;  } @@ -1741,7 +1739,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  } @@ -1910,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; @@ -2191,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; @@ -2201,8 +2199,14 @@ 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 ((p = vim_strrchr(fname, PATHSEP)) != NULL) { +  if (force || !path_is_absolute(fname)) { +    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 @@ -2228,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 @@ -2256,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.  | 
