From b71246fa13d1bf81bb7dce4dee4c6b40dcd0f120 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 28 Mar 2021 11:54:45 -0700 Subject: Fix bug handling escape code at end of a line. When scan_troff expands an escape, it calls FLUSHIBP, which nukes all previous context. If the escape is subsequently followed by a newline, it looks like the newline at the start of a line, which is consumed. There is a subtlety there that we also want to preserve a newline after an escape in preformatted mode. This fix addresses at least two issues in the TXR Man page. One is that occurrences of the \*(TL and \*(TX at the ends of lines are causing run-on output: the expansion gets glued to the word which follows in the next line. The other issue is that in some code exmaple blocks, lines ending in a backslash (encoded as the \e escape) are being joined. --- man2html/man2html.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/man2html/man2html.c b/man2html/man2html.c index eed6be2..f400ed8 100644 --- a/man2html/man2html.c +++ b/man2html/man2html.c @@ -2984,6 +2984,7 @@ scan_troff(char *c, int san, char **result) { /* san : stop at newline */ char *exbuffer; int exbuffpos, exbuffmax, exscaninbuff, exnewline_for_fun; int usenbsp = 0; + int escnl = 0; /* prevent eating newline after escape at end-of-line */ exbuffer = buffer; exbuffpos = buffpos; @@ -3008,8 +3009,12 @@ scan_troff(char *c, int san, char **result) { /* san : stop at newline */ while (*h && (!san || newline_for_fun || *h != '\n')) { if (*h == escapesym) { h++; + if ((ibp > 0 && !isspace(intbuff[ibp-1])) || !fillout) + escnl = 1; FLUSHIBP; h = scan_escape(h); + if (*h != '\n') + escnl = 0; } else if (*h == '\b') { intbuff[ibp++]=*h++; if (ibp>480) { FLUSHIBP; } @@ -3086,7 +3091,7 @@ scan_troff(char *c, int san, char **result) { /* san : stop at newline */ contained_tab=0; curpos=0; usenbsp=0; - if (ibp > 0 && !isspace(intbuff[ibp-1])) + if ((ibp > 0 && !isspace(intbuff[ibp-1])) || escnl) intbuff[ibp++]='\n'; break; case '\t': -- cgit v1.2.3