aboutsummaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2014-03-31 00:43:55 +0200
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-01 08:08:07 -0300
commit703490359118ecb2f66d3529b57771fd3dcff5b7 (patch)
tree3b4a65ec6b841fd5cd2f7d5bea0dff12156e8a84 /src/path.c
parent2a6df95fb533fd451b9b13ec15ae8c1437e048ca (diff)
downloadrneovim-703490359118ecb2f66d3529b57771fd3dcff5b7.tar.gz
rneovim-703490359118ecb2f66d3529b57771fd3dcff5b7.tar.bz2
rneovim-703490359118ecb2f66d3529b57771fd3dcff5b7.zip
Move pathcmp from misc2.c
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c
index bfd21b426c..eaa4b87a02 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1694,3 +1694,70 @@ int same_directory(char_u *f1, char_u *f2)
&& pathcmp((char *)ffname, (char *)f2, (int)(t1 - ffname)) == 0;
}
+#if !defined(NO_EXPANDPATH) || defined(PROTO)
+/*
+ * Compare path "p[]" to "q[]".
+ * If "maxlen" >= 0 compare "p[maxlen]" to "q[maxlen]"
+ * Return value like strcmp(p, q), but consider path separators.
+ */
+int pathcmp(const char *p, const char *q, int maxlen)
+{
+ int i;
+ int c1, c2;
+ const char *s = NULL;
+
+ for (i = 0; maxlen < 0 || i < maxlen; i += MB_PTR2LEN((char_u *)p + i)) {
+ c1 = PTR2CHAR((char_u *)p + i);
+ c2 = PTR2CHAR((char_u *)q + i);
+
+ /* End of "p": check if "q" also ends or just has a slash. */
+ if (c1 == NUL) {
+ if (c2 == NUL) /* full match */
+ return 0;
+ s = q;
+ break;
+ }
+
+ /* End of "q": check if "p" just has a slash. */
+ if (c2 == NUL) {
+ s = p;
+ break;
+ }
+
+ if ((p_fic ? MB_TOUPPER(c1) != MB_TOUPPER(c2) : c1 != c2)
+#ifdef BACKSLASH_IN_FILENAME
+ /* consider '/' and '\\' to be equal */
+ && !((c1 == '/' && c2 == '\\')
+ || (c1 == '\\' && c2 == '/'))
+#endif
+ ) {
+ if (vim_ispathsep(c1))
+ return -1;
+ if (vim_ispathsep(c2))
+ return 1;
+ return p_fic ? MB_TOUPPER(c1) - MB_TOUPPER(c2)
+ : c1 - c2; /* no match */
+ }
+ }
+ if (s == NULL) /* "i" ran into "maxlen" */
+ return 0;
+
+ c1 = PTR2CHAR((char_u *)s + i);
+ c2 = PTR2CHAR((char_u *)s + i + MB_PTR2LEN((char_u *)s + i));
+ /* ignore a trailing slash, but not "//" or ":/" */
+ if (c2 == NUL
+ && i > 0
+ && !after_pathsep((char_u *)s, (char_u *)s + i)
+#ifdef BACKSLASH_IN_FILENAME
+ && (c1 == '/' || c1 == '\\')
+#else
+ && c1 == '/'
+#endif
+ )
+ return 0; /* match with trailing slash */
+ if (s == q)
+ return -1; /* no match */
+ return 1;
+}
+#endif
+