=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.74 retrieving revision 1.79 diff -u -p -r1.74 -r1.79 --- mandoc/html.c 2009/10/30 18:53:08 1.74 +++ mandoc/html.c 2009/11/01 15:34:44 1.79 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.74 2009/10/30 18:53:08 kristaps Exp $ */ +/* $Id: html.c,v 1.79 2009/11/01 15:34:44 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -18,8 +18,8 @@ #include #include -#include #include +#include #include #include #include @@ -101,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); } @@ -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); } @@ -320,26 +316,26 @@ 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 += (int)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; - } } } @@ -354,7 +350,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; @@ -365,16 +361,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 +391,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 +437,7 @@ print_text(struct html *h, const char *p) } if ( ! (h->flags & HTML_NOSPACE)) - printf(" "); + putchar(' '); h->flags &= ~HTML_NOSPACE; h->flags &= ~HTML_NEWLINE;