diff options
author | John Schmidt <john.schmidt.h@gmail.com> | 2014-03-31 01:08:01 +0200 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-01 08:08:07 -0300 |
commit | d31e5988959c116db7130799f692750f08ae8d9b (patch) | |
tree | 675849997e85d07f7451e3d1013b6b4478b13c0f | |
parent | 7464b07c225629b3969cfdcd135f4ac1fa0b7a0b (diff) | |
download | rneovim-d31e5988959c116db7130799f692750f08ae8d9b.tar.gz rneovim-d31e5988959c116db7130799f692750f08ae8d9b.tar.bz2 rneovim-d31e5988959c116db7130799f692750f08ae8d9b.zip |
Move shorten_fname{,1,s} and shorten_filenames from fileio.c
-rw-r--r-- | src/fileio.c | 123 | ||||
-rw-r--r-- | src/fileio.h | 4 | ||||
-rw-r--r-- | src/path.c | 126 | ||||
-rw-r--r-- | src/path.h | 4 |
4 files changed, 130 insertions, 127 deletions
diff --git a/src/fileio.c b/src/fileio.c index 876f8cc4fd..45ba8986d8 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4702,129 +4702,6 @@ static int make_bom(char_u *buf, char_u *name) return (int)(p - buf); } -#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 *dirname; - char_u *p = full_path; - - dirname = alloc(MAXPATHL); - if (dirname == NULL) - return full_path; - if (os_dirname(dirname, MAXPATHL) == OK) { - p = 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) -{ - int len; - char_u *p; - - if (full_path == NULL) - 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; -} - -/* - * Shorten filenames for all buffers. - * When "force" is TRUE: Use full path from now on for files currently being - * edited, both for file name and swap file name. Try to shorten the file - * names a bit, if safe to do so. - * When "force" is FALSE: Only try to shorten absolute file names. - * For buffers that have buftype "nofile" or "scratch": never change the file - * name. - */ -void shorten_fnames(int force) -{ - char_u dirname[MAXPATHL]; - buf_T *buf; - char_u *p; - - os_dirname(dirname, MAXPATHL); - for (buf = firstbuf; buf != NULL; buf = buf->b_next) { - if (buf->b_fname != NULL - && !bt_nofile(buf) - && !path_with_url(buf->b_fname) - && (force - || buf->b_sfname == NULL - || os_is_absolute_path(buf->b_sfname))) { - vim_free(buf->b_sfname); - buf->b_sfname = NULL; - p = shorten_fname(buf->b_ffname, dirname); - if (p != NULL) { - buf->b_sfname = vim_strsave(p); - buf->b_fname = buf->b_sfname; - } - if (p == NULL || buf->b_fname == NULL) - buf->b_fname = buf->b_ffname; - } - - /* Always make the swap file name a full path, a "nofile" buffer may - * also have a swap file. */ - mf_fullname(buf->b_ml.ml_mfp); - } - status_redraw_all(); - redraw_tabline = TRUE; -} - -#if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \ - || defined(FEAT_GUI_MSWIN) \ - || defined(FEAT_GUI_MAC) \ - || defined(PROTO) -/* - * Shorten all filenames in "fnames[count]" by current directory. - */ -void shorten_filenames(char_u **fnames, int count) -{ - int i; - char_u dirname[MAXPATHL]; - char_u *p; - - if (fnames == NULL || count < 1) - return; - os_dirname(dirname, sizeof(dirname)); - for (i = 0; i < count; ++i) { - if ((p = shorten_fname(fnames[i], dirname)) != NULL) { - /* shorten_fname() returns pointer in given "fnames[i]". If free - * "fnames[i]" first, "p" becomes invalid. So we need to copy - * "p" first then free fnames[i]. */ - p = vim_strsave(p); - vim_free(fnames[i]); - fnames[i] = p; - } - } -} -#endif - /* * add extension to file name - change path/fo.o.h to path/fo.o.h.ext or * fo_o_h.ext for MSDOS or when shortname option set. diff --git a/src/fileio.h b/src/fileio.h index 86bf1614bd..ba776f0dba 100644 --- a/src/fileio.h +++ b/src/fileio.h @@ -33,10 +33,6 @@ int buf_write(buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, int filtering); void msg_add_fname(buf_T *buf, char_u *fname); void msg_add_lines(int insert_space, long lnum, off_t nchars); -char_u *shorten_fname1(char_u *full_path); -char_u *shorten_fname(char_u *full_path, char_u *dir_name); -void shorten_fnames(int force); -void shorten_filenames(char_u **fnames, int count); char_u *modname(char_u *fname, char_u *ext, int prepend_dot); char_u *buf_modname(int shortname, char_u *fname, char_u *ext, int prepend_dot); diff --git a/src/path.c b/src/path.c index 99a4cec6cf..0d7685031b 100644 --- a/src/path.c +++ b/src/path.c @@ -8,6 +8,7 @@ #include "fileio.h" #include "file_search.h" #include "garray.h" +#include "memfile.h" #include "memline.h" #include "message.h" #include "misc1.h" @@ -16,7 +17,9 @@ #include "os/os.h" #include "os/shell.h" #include "os_unix.h" +#include "quickfix.h" #include "regexp.h" +#include "screen.h" #include "tag.h" #include "types.h" #include "ui.h" @@ -1777,3 +1780,126 @@ 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 *dirname; + char_u *p = full_path; + + dirname = alloc(MAXPATHL); + if (dirname == NULL) + return full_path; + if (os_dirname(dirname, MAXPATHL) == OK) { + p = 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) +{ + int len; + char_u *p; + + if (full_path == NULL) + 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; +} + +/* + * Shorten filenames for all buffers. + * When "force" is TRUE: Use full path from now on for files currently being + * edited, both for file name and swap file name. Try to shorten the file + * names a bit, if safe to do so. + * When "force" is FALSE: Only try to shorten absolute file names. + * For buffers that have buftype "nofile" or "scratch": never change the file + * name. + */ +void shorten_fnames(int force) +{ + char_u dirname[MAXPATHL]; + buf_T *buf; + char_u *p; + + os_dirname(dirname, MAXPATHL); + for (buf = firstbuf; buf != NULL; buf = buf->b_next) { + if (buf->b_fname != NULL + && !bt_nofile(buf) + && !path_with_url(buf->b_fname) + && (force + || buf->b_sfname == NULL + || os_is_absolute_path(buf->b_sfname))) { + vim_free(buf->b_sfname); + buf->b_sfname = NULL; + p = shorten_fname(buf->b_ffname, dirname); + if (p != NULL) { + buf->b_sfname = vim_strsave(p); + buf->b_fname = buf->b_sfname; + } + if (p == NULL || buf->b_fname == NULL) + buf->b_fname = buf->b_ffname; + } + + /* Always make the swap file name a full path, a "nofile" buffer may + * also have a swap file. */ + mf_fullname(buf->b_ml.ml_mfp); + } + status_redraw_all(); + redraw_tabline = TRUE; +} + +#if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \ + || defined(FEAT_GUI_MSWIN) \ + || defined(FEAT_GUI_MAC) \ + || defined(PROTO) +/* + * Shorten all filenames in "fnames[count]" by current directory. + */ +void shorten_filenames(char_u **fnames, int count) +{ + int i; + char_u dirname[MAXPATHL]; + char_u *p; + + if (fnames == NULL || count < 1) + return; + os_dirname(dirname, sizeof(dirname)); + for (i = 0; i < count; ++i) { + if ((p = shorten_fname(fnames[i], dirname)) != NULL) { + /* shorten_fname() returns pointer in given "fnames[i]". If free + * "fnames[i]" first, "p" becomes invalid. So we need to copy + * "p" first then free fnames[i]. */ + p = vim_strsave(p); + vim_free(fnames[i]); + fnames[i] = p; + } + } +} +#endif + diff --git a/src/path.h b/src/path.h index c65367289c..8304741d2b 100644 --- a/src/path.h +++ b/src/path.h @@ -35,4 +35,8 @@ 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); +void shorten_fnames(int force); +void shorten_filenames(char_u **fnames, int count); #endif |