]> git.cameronkatri.com Git - mandoc.git/blobdiff - html.c
Using putchar for single-character prints (noted by Joerg Sonnenberger).
[mandoc.git] / html.c
diff --git a/html.c b/html.c
index 7ed94c9a94ceff3d8767d7ca1a547100844cc441..47171298685a4e8dd3d5cdf567f3f709d45a0b19 100644 (file)
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/*     $Id: html.c,v 1.76 2009/11/01 07:44:32 kristaps Exp $ */
+/*     $Id: html.c,v 1.78 2009/11/01 15:34:15 kristaps Exp $ */
 /*
  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -316,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("&lt;");
+               } else if ('\0' == *p)
                        break;
-               case ('>'):
+
+               if ('<' == *p)
+                       printf("&lt;");
+               else if ('>' == *p)
                        printf("&gt;");
-                       break;
-               case ('&'):
+               else if ('&' == *p)
                        printf("&amp;");
-                       break;
-               default:
-                       putchar(*p);
-                       break;
-               }
        }
 }
 
@@ -361,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)
@@ -391,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;
 }
@@ -437,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;