* 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.
canonicalize_filename (register char *fn)
{
register char* cp;
- char sep = '/';
#ifdef DOS_NT
/* Canonicalize drive letter case. */
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';
}