=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.72 retrieving revision 1.81 diff -u -p -r1.72 -r1.81 --- mandoc/html.c 2009/10/30 18:43:24 1.72 +++ mandoc/html.c 2009/11/05 10:16:01 1.81 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.72 2009/10/30 18:43:24 kristaps Exp $ */ +/* $Id: html.c,v 1.81 2009/11/05 10:16:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -18,9 +18,8 @@ #include #include -#include -#include #include +#include #include #include #include @@ -102,7 +101,7 @@ html_alloc(char *outopts) h = calloc(1, sizeof(struct html)); if (NULL == h) { - fprintf(stderr, "memory exhausted\n"); + perror(NULL); exit(EXIT_FAILURE); } @@ -190,15 +189,13 @@ static void print_spec(struct html *h, const char *p, int len) { const char *rhs; - int i; size_t sz; rhs = chars_a2ascii(h->symtab, p, (size_t)len, &sz); if (NULL == rhs) return; - for (i = 0; i < (int)sz; i++) - putchar(rhs[i]); + fwrite(rhs, 1, sz, stdout); } @@ -206,15 +203,13 @@ static void print_res(struct html *h, const char *p, int len) { const char *rhs; - int i; size_t sz; rhs = chars_a2res(h->symtab, p, (size_t)len, &sz); if (NULL == rhs) return; - for (i = 0; i < (int)sz; i++) - putchar(rhs[i]); + fwrite(rhs, 1, sz, stdout); } @@ -275,21 +270,19 @@ print_escape(struct html *h, const char **p) return; } - switch (*wp) { - case ('B'): - /* TODO */ - break; - case ('I'): - /* TODO */ - break; - case ('P'): - /* FALLTHROUGH */ - case ('R'): - /* TODO */ - break; - default: - break; - } + /* + * These aren't supported, as they're symmetry-breaking + * constructs that don't play well with hierarchical + * mark-up. Consider: + * + * \fBHello. + * .PP + * World. + * + * The style started before "Hello" wouldn't be able to + * propogate into the next `PP' because we'd exit the + * current paragraph's scope. + */ *p = wp; return; @@ -321,26 +314,27 @@ print_escape(struct html *h, const char **p) static void print_encode(struct html *h, const char *p) { + size_t sz; for (; *p; p++) { + sz = strcspn(p, "\\<>&"); + + fwrite(p, 1, sz, stdout); + p += /* LINTED */ + sz; + if ('\\' == *p) { print_escape(h, &p); continue; - } - switch (*p) { - case ('<'): - printf("<"); + } else if ('\0' == *p) break; - case ('>'): + + if ('<' == *p) + printf("<"); + else if ('>' == *p) printf(">"); - break; - case ('&'): + else if ('&' == *p) printf("&"); - break; - default: - putchar(*p); - break; - } } } @@ -355,7 +349,7 @@ print_otag(struct html *h, enum htmltag tag, if ( ! (HTML_NOSTACK & htmltags[tag].flags)) { t = malloc(sizeof(struct tag)); if (NULL == t) { - fprintf(stderr, "memory exhausted\n"); + perror(NULL); exit(EXIT_FAILURE); } t->tag = tag; @@ -366,16 +360,16 @@ print_otag(struct html *h, enum htmltag tag, if ( ! (HTML_NOSPACE & h->flags)) if ( ! (HTML_CLRLINE & htmltags[tag].flags)) - printf(" "); + putchar(' '); printf("<%s", htmltags[tag].name); for (i = 0; i < sz; i++) { printf(" %s=\"", htmlattrs[p[i].key]); assert(p->val); print_encode(h, p[i].val); - printf("\""); + putchar('\"'); } - printf(">"); + putchar('>'); h->flags |= HTML_NOSPACE; if (HTML_CLRLINE & htmltags[tag].flags) @@ -396,7 +390,7 @@ print_ctag(struct html *h, enum htmltag tag) if (HTML_CLRLINE & htmltags[tag].flags) { h->flags |= HTML_NOSPACE; h->flags |= HTML_NEWLINE; - printf("\n"); + putchar('\n'); } else h->flags &= ~HTML_NEWLINE; } @@ -442,7 +436,7 @@ print_text(struct html *h, const char *p) } if ( ! (h->flags & HTML_NOSPACE)) - printf(" "); + putchar(' '); h->flags &= ~HTML_NOSPACE; h->flags &= ~HTML_NEWLINE; @@ -673,7 +667,7 @@ html_idcat(char *dst, const char *src, int sz) sz--; for ( ; *src != '\0' && sz > 1; src++) { - ssz = snprintf(dst, sz, "%.2x", *src); + ssz = snprintf(dst, (size_t)sz, "%.2x", *src); sz -= ssz; dst += ssz; }