resolve some code duplication; no functional change
authorschwarze <schwarze@openbsd.org>
Sat, 20 Dec 2014 00:19:54 +0000 (00:19 +0000)
committerschwarze <schwarze@openbsd.org>
Sat, 20 Dec 2014 00:19:54 +0000 (00:19 +0000)
usr.bin/mandoc/html.c

index a420293..69f907f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: html.c,v 1.53 2014/12/02 10:07:17 schwarze Exp $ */
+/*     $OpenBSD: html.c,v 1.54 2014/12/20 00:19:54 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -119,7 +119,7 @@ static      const char      *const roffscales[SCALE_MAX] = {
 };
 
 static void     bufncat(struct html *, const char *, size_t);
-static void     print_ctag(struct html *, enum htmltag);
+static void     print_ctag(struct html *, struct tag *);
 static int      print_escape(char);
 static int      print_encode(struct html *, const char *, int);
 static void     print_metaf(struct html *, enum mandoc_esc);
@@ -509,14 +509,26 @@ print_otag(struct html *h, enum htmltag tag,
 }
 
 static void
-print_ctag(struct html *h, enum htmltag tag)
+print_ctag(struct html *h, struct tag *tag)
 {
 
-       printf("</%s>", htmltags[tag].name);
-       if (HTML_CLRLINE & htmltags[tag].flags) {
+       /*
+        * Remember to close out and nullify the current
+        * meta-font and table, if applicable.
+        */
+       if (tag == h->metaf)
+               h->metaf = NULL;
+       if (tag == h->tblt)
+               h->tblt = NULL;
+
+       printf("</%s>", htmltags[tag->tag].name);
+       if (HTML_CLRLINE & htmltags[tag->tag].flags) {
                h->flags |= HTML_NOSPACE;
                putchar('\n');
        }
+
+       h->tags.head = tag->next;
+       free(tag);
 }
 
 void
@@ -578,17 +590,7 @@ print_tagq(struct html *h, const struct tag *until)
        struct tag      *tag;
 
        while ((tag = h->tags.head) != NULL) {
-               /*
-                * Remember to close out and nullify the current
-                * meta-font and table, if applicable.
-                */
-               if (tag == h->metaf)
-                       h->metaf = NULL;
-               if (tag == h->tblt)
-                       h->tblt = NULL;
-               print_ctag(h, tag->tag);
-               h->tags.head = tag->next;
-               free(tag);
+               print_ctag(h, tag);
                if (until && tag == until)
                        return;
        }
@@ -602,17 +604,7 @@ print_stagq(struct html *h, const struct tag *suntil)
        while ((tag = h->tags.head) != NULL) {
                if (suntil && tag == suntil)
                        return;
-               /*
-                * Remember to close out and nullify the current
-                * meta-font and table, if applicable.
-                */
-               if (tag == h->metaf)
-                       h->metaf = NULL;
-               if (tag == h->tblt)
-                       h->tblt = NULL;
-               print_ctag(h, tag->tag);
-               h->tags.head = tag->next;
-               free(tag);
+               print_ctag(h, tag);
        }
 }