Handle another fiddly special case in HTML back-link generation.
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 15 Nov 2008 09:04:21 +0000 (09:04 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 15 Nov 2008 09:04:21 +0000 (09:04 +0000)
This enables agedu -w to deal sensibly with scans generated on
Windows and starting in a drive's root directory such as "c:\".

git-svn-id: svn://svn.tartarus.org/sgt/agedu@8297 cda61777-01e9-0310-a592-d414129be87e

html.c

diff --git a/html.c b/html.c
index 5ca85e0..d6d6ad1 100644 (file)
--- a/html.c
+++ b/html.c
@@ -367,6 +367,18 @@ static void write_report_line(struct html *ctx, struct vector *vec)
     htprintf(ctx, "</td>\n</tr>\n");
 }
 
+int strcmptrailingpathsep(const char *a, const char *b)
+{
+    while (*a == *b && *a)
+       a++, b++;
+
+    if ((*a == pathsep && !a[1] && !*b) ||
+       (*b == pathsep && !b[1] && !*a))
+       return 0;
+
+    return (int)(unsigned char)*a - (int)(unsigned char)*b;
+}
+
 char *html_query(const void *t, unsigned long index,
                 const struct html_config *cfg)
 {
@@ -442,7 +454,7 @@ char *html_query(const void *t, unsigned long index,
        *zp = '\0';
        index2 = trie_before(t, path);
        trie_getpath(t, index2, path2);
-       if (!strcmp(path, path2) && cfg->format) {
+       if (!strcmptrailingpathsep(path, path2) && cfg->format) {
            snprintf(href, hreflen, cfg->format, index2);
            if (!*href)                /* special case that we understand */
                strcpy(href, "./");