I had been wondering for a while whether the use of random addresses
[sgt/agedu] / html.c
diff --git a/html.c b/html.c
index 5ca85e0..4390668 100644 (file)
--- a/html.c
+++ b/html.c
@@ -237,6 +237,7 @@ static void end_colour_bar(struct html *ctx)
 struct vector {
     int want_href;
     char *name;
+    int literal; /* should the name be formatted in fixed-pitch? */
     unsigned long index;
     unsigned long long sizes[MAXCOLOUR+1];
 };
@@ -264,7 +265,7 @@ int vec_compare(const void *av, const void *bv)
 }
 
 static struct vector *make_vector(struct html *ctx, char *path,
-                                 int want_href, char *name)
+                                 int want_href, char *name, int literal)
 {
     unsigned long xi1, xi2;
     struct vector *vec = snew(struct vector);
@@ -272,6 +273,7 @@ static struct vector *make_vector(struct html *ctx, char *path,
 
     vec->want_href = want_href;
     vec->name = name ? dupstr(name) : NULL;
+    vec->literal = literal;
 
     get_indices(ctx->t, path, &xi1, &xi2);
 
@@ -360,13 +362,29 @@ static void write_report_line(struct html *ctx, struct vector *vec)
            htprintf(ctx, "<a href=\"%s\">", ctx->href);
            doing_href = 1;
        }
+       if (vec->literal)
+           htprintf(ctx, "<code>");
        htescape(ctx, vec->name, strlen(vec->name), 1);
+       if (vec->literal)
+           htprintf(ctx, "</code>");
        if (doing_href)
            htprintf(ctx, "</a>");
     }
     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 +460,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, "./");
@@ -524,7 +542,7 @@ char *html_query(const void *t, unsigned long index,
     vecsize = 64;
     vecs = snewn(vecsize, struct vector *);
     nvecs = 1;
-    vecs[0] = make_vector(ctx, path, 0, NULL);
+    vecs[0] = make_vector(ctx, path, 0, NULL, 0);
     print_heading(ctx, "Overall");
     write_report_line(ctx, vecs[0]);
 
@@ -552,7 +570,7 @@ char *html_query(const void *t, unsigned long index,
            vecs = sresize(vecs, vecsize, struct vector *);
        }
        assert(strlen(path2) > pathlen);
-       vecs[nvecs] = make_vector(ctx, path2, 1, path2 + subdirpos);
+       vecs[nvecs] = make_vector(ctx, path2, 1, path2 + subdirpos, 1);
        for (i = 0; i <= MAXCOLOUR; i++)
            vecs[0]->sizes[i] -= vecs[nvecs]->sizes[i];
        nvecs++;