From e1890e3e829665a54f04284f4e23bd0fd37de06b Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 20 May 2015 18:18:33 +0300 Subject: [PATCH] Fix slash collapsing in etags on MS-Windows * lib-src/etags.c (canonicalize_filename) [DOS_NT]: Separate the MS-Windows code from the Posix code, and support collapsing both forward- and back-slashes on MS-Windows. Fixes a regression found by the test suite. --- lib-src/etags.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib-src/etags.c b/lib-src/etags.c index 7bacbd3e619..0a308c1984f 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -6484,7 +6484,6 @@ static void canonicalize_filename (register char *fn) { register char* cp; - char sep = '/'; #ifdef DOS_NT /* Canonicalize drive letter case. */ @@ -6492,19 +6491,33 @@ canonicalize_filename (register char *fn) if (fn[0] != '\0' && fn[1] == ':' && ISUPPER (fn[0])) fn[0] = lowcase (fn[0]); - sep = '\\'; -#endif + /* Collapse multiple forward- and back-slashes into a single forward + slash. */ + for (cp = fn; *cp != '\0'; cp++, fn++) + if (*cp == '/' || *cp == '\\') + { + *fn = '/'; + while (cp[1] == '/' || cp[1] == '\\') + cp++; + } + else + *fn = *cp; + +#else /* !DOS_NT */ - /* Collapse multiple separators into a single slash. */ + /* Collapse multiple slashes into a single slash. */ for (cp = fn; *cp != '\0'; cp++, fn++) - if (*cp == sep) + if (*cp == '/') { *fn = '/'; - while (cp[1] == sep) + while (cp[1] == '/') cp++; } else *fn = *cp; + +#endif /* !DOS_NT */ + *fn = '\0'; } -- 2.39.2