aboutsummaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
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;
+}