aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c2
-rw-r--r--src/eval.c2
-rw-r--r--src/ex_docmd.c2
-rw-r--r--src/file_search.c2
-rw-r--r--src/fileio.c2
-rw-r--r--src/mark.c2
-rw-r--r--src/path.c59
-rw-r--r--src/path.h22
-rw-r--r--src/quickfix.c2
9 files changed, 48 insertions, 47 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 8f856e9dc6..8723e31be3 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -4255,7 +4255,7 @@ int read_viminfo_bufferlist(vir_T *virp, int writing)
/* Expand "~/" in the file name at "line + 1" to a full path.
* Then try shortening it by comparing with the current directory */
expand_env(xline, NameBuff, MAXPATHL);
- sfname = shorten_fname1(NameBuff);
+ sfname = path_shorten_fname_if_possible(NameBuff);
buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED);
if (buf != NULL) { /* just in case... */
diff --git a/src/eval.c b/src/eval.c
index c59b335a6a..f183ba852c 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -19553,7 +19553,7 @@ repeat:
if (p != NULL) {
if (c == '.') {
os_dirname(dirname, MAXPATHL);
- s = shorten_fname(p, dirname);
+ s = path_shorten_fname(p, dirname);
if (s != NULL) {
*fnamep = s;
if (pbuf != NULL) {
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index c0ff3c853c..ff1ebeb2f5 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -7965,7 +7965,7 @@ eval_vars (
"E495: no autocommand file name to substitute for \"<afile>\"");
return NULL;
}
- result = shorten_fname1(result);
+ result = path_shorten_fname_if_possible(result);
break;
case SPEC_ABUF: /* buffer number for autocommand */
diff --git a/src/file_search.c b/src/file_search.c
index 57ff7ad3f4..1bcb9fa519 100644
--- a/src/file_search.c
+++ b/src/file_search.c
@@ -869,7 +869,7 @@ char_u *vim_findfile(void *search_ctx_arg)
simplify_filename(file_path);
if (os_dirname(ff_expand_buffer, MAXPATHL)
== OK) {
- p = shorten_fname(file_path,
+ p = path_shorten_fname(file_path,
ff_expand_buffer);
if (p != NULL)
STRMOVE(file_path, p);
diff --git a/src/fileio.c b/src/fileio.c
index e1542cf1f1..48172eca03 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4654,7 +4654,7 @@ void shorten_fnames(int force)
|| path_is_absolute_path(buf->b_sfname))) {
vim_free(buf->b_sfname);
buf->b_sfname = NULL;
- p = shorten_fname(buf->b_ffname, dirname);
+ p = path_shorten_fname(buf->b_ffname, dirname);
if (p != NULL) {
buf->b_sfname = vim_strsave(p);
buf->b_fname = buf->b_sfname;
diff --git a/src/mark.c b/src/mark.c
index d5dd868167..bd37f93eb1 100644
--- a/src/mark.c
+++ b/src/mark.c
@@ -482,7 +482,7 @@ static void fname2fnum(xfmark_T *fm)
/* Try to shorten the file name. */
os_dirname(IObuff, IOSIZE);
- p = shorten_fname(NameBuff, IObuff);
+ p = path_shorten_fname(NameBuff, IObuff);
/* buflist_new() will call fmarks_check_names() */
(void)buflist_new(NameBuff, p, (linenr_T)1, 0);
diff --git a/src/path.c b/src/path.c
index ccc673b1ab..6e736f1daa 100644
--- a/src/path.c
+++ b/src/path.c
@@ -796,7 +796,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
* /file.txt / /file.txt
* c:\file.txt c:\ .\file.txt
*/
- short_name = shorten_fname(path, curdir);
+ short_name = path_shorten_fname(path, curdir);
if (short_name != NULL && short_name > path + 1
) {
STRCPY(path, ".");
@@ -817,7 +817,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
/* If the {filename} is not unique, change it to ./{filename}.
* Else reduce it to {filename} */
- short_name = shorten_fname(path, curdir);
+ short_name = path_shorten_fname(path, curdir);
if (short_name == NULL)
short_name = path;
if (is_unique(short_name, gap, i)) {
@@ -1708,54 +1708,37 @@ int flags; /* EW_* flags */
}
#endif
-#if defined(FEAT_VIMINFO) || defined(FEAT_BROWSE) || \
- defined(FEAT_QUICKFIX) || defined(FEAT_AUTOCMD) || defined(PROTO)
-/*
- * Try to find a shortname by comparing the fullname with the current
- * directory.
- * Returns "full_path" or pointer into "full_path" if shortened.
- */
-char_u *shorten_fname1(char_u *full_path)
+char_u *path_shorten_fname_if_possible(char_u *full_path)
{
- char_u *dirname;
- char_u *p = full_path;
+ char_u *dirname = xmalloc(MAXPATHL);
+ char_u *p = full_path;
- dirname = alloc(MAXPATHL);
if (os_dirname(dirname, MAXPATHL) == OK) {
- p = shorten_fname(full_path, dirname);
- if (p == NULL || *p == NUL)
+ p = path_shorten_fname(full_path, dirname);
+ if (p == NULL || *p == NUL) {
p = full_path;
+ }
}
vim_free(dirname);
return p;
}
-#endif
-/*
- * Try to find a shortname by comparing the fullname with the current
- * directory.
- * Returns NULL if not shorter name possible, pointer into "full_path"
- * otherwise.
- */
-char_u *shorten_fname(char_u *full_path, char_u *dir_name)
+char_u *path_shorten_fname(char_u *full_path, char_u *dir_name)
{
- int len;
- char_u *p;
+ if (full_path == NULL) {
+ return NULL;
+ }
+
+ assert(dir_name != NULL);
+ size_t len = strlen((char *)dir_name);
+ char_u *p = full_path + len;
- if (full_path == NULL)
+ if (fnamencmp(dir_name, full_path, len) != 0
+ || !vim_ispathsep(*p)) {
return NULL;
- len = (int)STRLEN(dir_name);
- if (fnamencmp(dir_name, full_path, len) == 0) {
- p = full_path + len;
- {
- if (vim_ispathsep(*p))
- ++p;
- else
- p = NULL;
- }
- } else
- p = NULL;
- return p;
+ }
+
+ return p + 1;
}
/*
diff --git a/src/path.h b/src/path.h
index 7ef4296278..51503c3bdd 100644
--- a/src/path.h
+++ b/src/path.h
@@ -83,8 +83,26 @@ int after_pathsep(char_u *b, char_u *p);
int same_directory(char_u *f1, char_u *f2);
int pathcmp(const char *p, const char *q, int maxlen);
int mch_expandpath(garray_T *gap, char_u *path, int flags);
-char_u *shorten_fname1(char_u *full_path);
-char_u *shorten_fname(char_u *full_path, char_u *dir_name);
+
+/// Try to find a shortname by comparing the fullname with the current
+/// directory.
+///
+/// @param full_path The full path of the file.
+/// @return
+/// - 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);
+
+/// Try to find a shortname by comparing the fullname with `dir_name`.
+///
+/// @param full_path The full path of the file.
+/// @param dir_name The directory to shorten relative to.
+/// @return
+/// - Pointer into `full_path` if shortened.
+/// - NULL if no shorter name is possible.
+char_u *path_shorten_fname(char_u *full_path, char_u *dir_name);
+
int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file,
int flags);
int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u *
diff --git a/src/quickfix.c b/src/quickfix.c
index cfbe07ac87..c98b43fff6 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -2859,7 +2859,7 @@ void ex_vimgrep(exarg_T *eap)
seconds = (time_t)0;
for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) {
- fname = shorten_fname1(fnames[fi]);
+ fname = path_shorten_fname_if_possible(fnames[fi]);
if (time(NULL) > seconds) {
/* Display the file name every second or so, show the user we are
* working on it. */