* html.c: implementation of html.h.
*/
-#include <assert.h>
-#include <stddef.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <time.h>
-
+#include "agedu.h"
#include "html.h"
-#include "malloc.h"
+#include "alloc.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;
{
va_list ap2;
int size, size2;
+ char testbuf[2];
va_copy(ap2, ap);
- size = vsnprintf(NULL, 0, fmt, ap2);
+ /*
+ * Some C libraries (Solaris, I'm looking at you) don't like
+ * an output buffer size of zero in vsnprintf, but will return
+ * sensible values given any non-zero buffer size. Hence, we
+ * use testbuf to gauge the length of the string.
+ */
+ size = vsnprintf(testbuf, 1, fmt, ap2);
va_end(ap2);
if (ctx->buflen + size >= ctx->bufsize) {
*/
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");
*/
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;
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;
}