diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-09-18 20:39:36 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-09-18 20:39:36 -0700 |
commit | 16e15867f94241f357b39dc7aa84788af87fd698 (patch) | |
tree | 6e038fd4aba3c55102644db84b423619026e27fc | |
parent | e219764e7fff79f53c25ef9d7d9c3bb94c5a2fee (diff) | |
download | man-16e15867f94241f357b39dc7aa84788af87fd698.tar.gz man-16e15867f94241f357b39dc7aa84788af87fd698.tar.bz2 man-16e15867f94241f357b39dc7aa84788af87fd698.zip |
Fix double evaluation in .SH, .SS and .M2SS.
The add_index function's interface changes so that it returns
the result of scan_troff. The caller can use that instead of
doing a redundant scan_troff which causes trouble when the
text contains side effects like incrementing counters.
-rw-r--r-- | man2html/man2html.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/man2html/man2html.c b/man2html/man2html.c index 7a7ef56..8a09b8c 100644 --- a/man2html/man2html.c +++ b/man2html/man2html.c @@ -1560,10 +1560,10 @@ manidx_need(int m) { } } -static void -add_to_index(int level, char *item) +static char * +add_to_index(int level, char *item, char **result) { - char *c = NULL; + char *c = NULL, *out; label[3]++; if (label[3]>'Z') { @@ -1585,11 +1585,15 @@ add_to_index(int level, char *item) } } - scan_troff(item, 1, &c); + out = scan_troff(item, 1, &c); manidx_need(100 + strlen(c)); sprintf(manidx+mip, "<DT><A HREF=\"#%s\">%s</A><DD>\n", label, c); - if (c) free(c); + if (result) + *result = c; + else + free(c); while (manidx[mip]) mip++; + return out; } static char * @@ -2208,14 +2212,16 @@ scan_request(char *c) { out_html("</PRE>"); } trans_char(c,'"', '\a'); - add_to_index(mode, c); + h = NULL; + c = add_to_index(mode, c, &h); out_html("<A NAME=\""); out_html(label); /* for mosaic users */ if (mode) out_html("\"> </A>\n<H3>"); else out_html("\"> </A>\n<H2>"); mandoc_synopsis = (strncmp(c, "SYNOPSIS", 8) == 0); - c = (mandoc_command ? scan_troff_mandoc : scan_troff)(c,1,NULL); + out_html(h); + free(h); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); curpos=0; @@ -2232,17 +2238,13 @@ scan_request(char *c) { out_html(change_to_font(0)); out_html(change_to_size(0)); (void) scan_expression(wordlist[0], &i); - add_to_index(i, wordlist[2]); if (mandoc_command) scan_troff_mandoc(wordlist[1],1,&h); else scan_troff(wordlist[1],1,&h); wordlist[1] = h; h = NULL; - if (mandoc_command) - scan_troff_mandoc(wordlist[2],1,&h); - else - scan_troff(wordlist[2],1,&h); + (void) add_to_index(i, wordlist[2], &h); wordlist[2] = h; out_html("<A NAME=\""); out_html(label); |