summaryrefslogtreecommitdiffstats
path: root/man2html/man2html.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-03-28 11:54:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-03-28 11:54:45 -0700
commitb71246fa13d1bf81bb7dce4dee4c6b40dcd0f120 (patch)
treeae5810e2f51ed9e0c0282a0787ff6443956298cd /man2html/man2html.c
parentf684e2326a56b2e8d648f99113460de602e65691 (diff)
downloadman-b71246fa13d1bf81bb7dce4dee4c6b40dcd0f120.tar.gz
man-b71246fa13d1bf81bb7dce4dee4c6b40dcd0f120.tar.bz2
man-b71246fa13d1bf81bb7dce4dee4c6b40dcd0f120.zip
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.
Diffstat (limited to 'man2html/man2html.c')
-rw-r--r--man2html/man2html.c7
1 files changed, 6 insertions, 1 deletions
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':