From dfbf19b9a96474b8c1bacac85e43605e5691ceb2 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 17 May 2021 03:16:39 -0700 Subject: Reduce spurious blank lines in output. The escape-at-end-of-line fixes have the side effect of adding some 20,000 blank lines to the HTML output for the TXR man page. The reason is that the logic is applied even within macro expansions which have internal escapes. we introduce a recursion depth variable which is incremented for each call to scan_request. The escnl flag is only set at recursion depth 0, unless we are in no-fill mode. The exception for no-fill mode is because there are a few cases where macro-expansion produces nofill mode output, like the .mets macro in the TXR man page. --- man2html/man2html.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'man2html/man2html.c') diff --git a/man2html/man2html.c b/man2html/man2html.c index 6c8799d..d190fd1 100644 --- a/man2html/man2html.c +++ b/man2html/man2html.c @@ -48,6 +48,7 @@ int still_dd=0; int tabstops[20] = { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96 }; int maxtstop=12; int curpos=0; +int recdepth=0; /* request recursion depth */ static char *scan_troff(char *c, int san, char **result); static char *scan_troff_raw(char *c, int san, char **result); @@ -1659,6 +1660,8 @@ scan_request(char *c) { if (c[0] == '\n') return c+1; + recdepth++; + j = strcspn(c, " \n\t"); j += strspn(c + j, " \t"); @@ -3008,6 +3011,9 @@ scan_request(char *c) { if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; } + + --recdepth; + return c; } @@ -3051,9 +3057,12 @@ do_scan_troff(char *c, int san, int htmlesc, char **result) { /* san : stop at n FLUSHIBP; h = scan_escape(h); outbuffer[obp] = 0; - if (*h == '\n' && - ((obp > 0 && !isspace(outbuffer[obp-1])) || !fillout)) - escnl = 1; + if (*h == '\n') { + if (recdepth == 0 && ((obp > 0 && !isspace(outbuffer[obp-1])))) + escnl = 1; + else if (!fillout) + escnl = 1; + } } else if (*h == '\b') { intbuff[ibp++]=*h++; if (ibp>480) { FLUSHIBP; } -- cgit v1.2.3