=================================================================== RCS file: /cvs/mandoc/html.c,v retrieving revision 1.74 retrieving revision 1.77 diff -u -p -r1.74 -r1.77 --- mandoc/html.c 2009/10/30 18:53:08 1.74 +++ mandoc/html.c 2009/11/01 08:15:20 1.77 @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.74 2009/10/30 18:53:08 kristaps Exp $ */ +/* $Id: html.c,v 1.77 2009/11/01 08:15:20 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 += 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;