=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.75 retrieving revision 1.81 diff -u -p -r1.75 -r1.81 --- mandoc/html.c 2009/10/31 06:10:57 1.75 +++ mandoc/html.c 2009/11/05 10:16:01 1.81 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.75 2009/10/31 06:10:57 kristaps Exp $ */ +/* $Id: html.c,v 1.81 2009/11/05 10:16:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -18,8 +18,8 @@ #include #include -#include #include +#include #include #include #include @@ -189,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); } @@ -205,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); } @@ -274,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; @@ -320,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; - } } } @@ -365,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) @@ -395,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; } @@ -441,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;