aboutsummaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2014-03-31 16:42:14 +0200
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-01 08:08:08 -0300
commit7ec4d478eb619e298cb0715d9ffb068d077df098 (patch)
treefc3e7edbc6b26407332d06c51b6aa3da17fc7460 /src/path.c
parent35e737e63c5c57a0ec0b52f86a81cbf94fd32bcd (diff)
downloadrneovim-7ec4d478eb619e298cb0715d9ffb068d077df098.tar.gz
rneovim-7ec4d478eb619e298cb0715d9ffb068d077df098.tar.bz2
rneovim-7ec4d478eb619e298cb0715d9ffb068d077df098.zip
Move match_suffix from misc1.c
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c
index 17a9d0fe7e..acdd216c06 100644
--- a/src/path.c
+++ b/src/path.c
@@ -4,6 +4,7 @@
#include "path.h"
#include "charset.h"
#include "eval.h"
+#include "ex_docmd.h"
#include "ex_getln.h"
#include "fileio.h"
#include "file_search.h"
@@ -2012,3 +2013,35 @@ expand_wildcards (
return retval;
}
+/*
+ * Return TRUE if "fname" matches with an entry in 'suffixes'.
+ */
+int match_suffix(char_u *fname)
+{
+ int fnamelen, setsuflen;
+ char_u *setsuf;
+#define MAXSUFLEN 30 /* maximum length of a file suffix */
+ char_u suf_buf[MAXSUFLEN];
+
+ fnamelen = (int)STRLEN(fname);
+ setsuflen = 0;
+ for (setsuf = p_su; *setsuf; ) {
+ setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,");
+ if (setsuflen == 0) {
+ char_u *tail = gettail(fname);
+
+ /* empty entry: match name without a '.' */
+ if (vim_strchr(tail, '.') == NULL) {
+ setsuflen = 1;
+ break;
+ }
+ } else {
+ if (fnamelen >= setsuflen
+ && fnamencmp(suf_buf, fname + fnamelen - setsuflen,
+ (size_t)setsuflen) == 0)
+ break;
+ setsuflen = 0;
+ }
+ }
+ return setsuflen != 0;
+}