shithub: neatroff

Download patch

ref: ed5ff0386952cfeee3467f4d6a7ec50641a6e61f
parent: 905b0fded9406edfce210f2b9990a12ab964944e
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Sep 19 08:32:56 EDT 2014

cp: replace \{ and \} with a space

In normal mode, \{ and \} are always replaced with a space.

--- a/cp.c
+++ b/cp.c
@@ -5,8 +5,7 @@
 #include "roff.h"
 
 static int cp_blkdep;		/* input block depth (text in \{ and \}) */
-static int cp_cpmode;		/* disable the interpretation \w and \E */
-static int cp_reqln;		/* a request line; replace \{ with an space */
+static int cp_cpmode;		/* disable the interpretation of \w and \E */
 static int cp_reqdep;		/* the block depth of current request line */
 
 /* just like cp_next(), but remove c_ni characters */
@@ -178,19 +177,18 @@
 			in_back('');
 			return c_ni;
 		}
+		/* replace \{ and \} with a space if not in copy mode */
 		if (c == '}' && !cp_cpmode) {
 			cp_blkdep--;
-			return cp_raw();
+			return ' ';
 		}
 		if (c == '{' && !cp_cpmode) {
 			cp_blkdep++;
-			return cp_reqln ? ' ' : cp_raw();
+			return ' ';
 		}
 		in_back(c);
 		return c_ec;
 	}
-	if (c == '\n')
-		cp_reqln = 0;
 	return c;
 }
 
@@ -246,7 +244,7 @@
 		int c = cp_next();
 		while ((c == ' ' || c == '\t'))
 			c = cp_next();
-		/* push back if the space is not inserted because of cp_reqln */
+		/* push back if the space is not inserted due to \{ and \} */
 		if (c != ' ' && c != '\t')
 			cp_back(c);
 	}
@@ -257,9 +255,8 @@
 	cp_cpmode = mode;
 }
 
-/* beginning of a request line; replace \{ with a space until an EOL */
-void cp_reqline(void)
+/* beginning of a request; save current cp_blkdep */
+void cp_reqbeg(void)
 {
-	cp_reqln = 1;
 	cp_reqdep = cp_blkdep;
 }
--- a/roff.h
+++ b/roff.h
@@ -202,7 +202,7 @@
 int in_lnum(void);		/* current line number */
 
 void cp_blk(int skip);		/* skip or read the next line or block */
-void cp_reqline(void);		/* beginning of a request line */
+void cp_reqbeg(void);		/* beginning of a request line */
 void cp_copymode(int mode);	/* do not interpret \w and \E */
 #define cp_back		in_back	/* cp.c is stateless */
 int tr_nextreq(void);		/* read the next troff request */
--- a/tr.c
+++ b/tr.c
@@ -211,6 +211,7 @@
 	sbuf_init(&s2);
 	read_until(&s1, delim, next, back);
 	read_until(&s2, delim, next, back);
+	cp_reqbeg();
 	ret = !strcmp(sbuf_buf(&s1), sbuf_buf(&s2));
 	sbuf_done(&s1);
 	sbuf_done(&s2);
@@ -982,7 +983,7 @@
 	args[0] = cmd;
 	cmd[0] = c;
 	req = NULL;
-	cp_reqline();
+	cp_reqbeg();
 	read_regname(cmd + 1);
 	sbuf_init(&sbuf);
 	req = str_dget(map(cmd + 1));