Reposition r8253's change to avoid redundant index lookups.
[sgt/agedu] / html.c
diff --git a/html.c b/html.c
index be13590..7633dec 100644 (file)
--- a/html.c
+++ b/html.c
 #include <limits.h>
 #include <time.h>
 
+#include "agedu.h"
 #include "html.h"
 #include "malloc.h"
 #include "trie.h"
 #include "index.h"
 
-#define lenof(x) ( sizeof((x)) / sizeof(*(x)) )
-
 #define MAXCOLOUR 511
 
-extern char pathsep;
-
 struct html {
     char *buf;
     size_t buflen, bufsize;
@@ -428,7 +425,7 @@ char *html_query(const void *t, unsigned long index,
      */
     htprintf(ctx, "<head>\n");
     trie_getpath(t, index, path);
-    htprintf(ctx, "<title>agedu: ");
+    htprintf(ctx, "<title>%s: ", PNAME);
     htescape(ctx, path, strlen(path), 0);
     htprintf(ctx, "</title>\n");
     htprintf(ctx, "</head>\n");
@@ -446,7 +443,7 @@ char *html_query(const void *t, unsigned long index,
      */
     htprintf(ctx, "<p align=center>\n<code>");
     q = path;
-    for (p = strchr(path, pathsep); p; p = strchr(p, pathsep)) {
+    for (p = strchr(path, pathsep); p && p[1]; p = strchr(p, pathsep)) {
        int doing_href = 0;
        char c, *zp;
 
@@ -466,6 +463,8 @@ char *html_query(const void *t, unsigned long index,
        trie_getpath(t, index2, path2);
        if (!strcmp(path, path2) && cfg->format) {
            snprintf(href, hreflen, cfg->format, index2);
+           if (!*href)                /* special case that we understand */
+               strcpy(href, "./");
            htprintf(ctx, "<a href=\"%s\">", href);
            doing_href = 1;
        }