shithub: neatroff

Download patch

ref: 905b0fded9406edfce210f2b9990a12ab964944e
parent: cf343033b3077b6976585bff25c5a110dc445b49
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Sep 19 07:26:34 EDT 2014

cp: remove c_ni from strings not pushed via in_push()

In order to prevent the interpretation of escaped backslashes,
cp.c replaces the first backslash of \\ with c_ni.  This is
necessary for ren.c escape sequences like \\D.  However, when
a string is processed directly and not read from ren.c, like
the arguments of built-in requests, c_ni characters should be
removed.  Reported by Carsten Kunze <carsten.kunze@arcor.de>.

--- a/cp.c
+++ b/cp.c
@@ -9,18 +9,27 @@
 static int cp_reqln;		/* a request line; replace \{ with an space */
 static int cp_reqdep;		/* the block depth of current request line */
 
-static void cparg(char *d, int len)
+/* just like cp_next(), but remove c_ni characters */
+static int cp_noninext(void)
 {
 	int c = cp_next();
+	while (c == c_ni)
+		c = cp_next();
+	return c;
+}
+
+static void cparg(char *d, int len)
+{
+	int c = cp_noninext();
 	int i = 0;
 	if (c == '(') {
-		d[i++] = cp_next();
-		d[i++] = cp_next();
+		d[i++] = cp_noninext();
+		d[i++] = cp_noninext();
 	} else if (!n_cp && c == '[') {
-		c = cp_next();
+		c = cp_noninext();
 		while (i < NMLEN - 1 && c >= 0 && c != ']') {
 			d[i++] = c;
-			c = cp_next();
+			c = cp_noninext();
 		}
 	} else {
 		d[i++] = c;
@@ -39,7 +48,7 @@
 static void cp_num(void)
 {
 	int id;
-	int c = cp_next();
+	int c = cp_noninext();
 	if (c != '-' && c != '+')
 		cp_back(c);
 	id = regid();
@@ -104,7 +113,7 @@
 {
 	char arg[ILNLEN];
 	char *s;
-	quotednext(arg, cp_next, cp_back);
+	quotednext(arg, cp_noninext, cp_back);
 	s = arg;
 	while (*s && *s != ' ')
 		s++;
@@ -122,7 +131,7 @@
 	char *r, *s = arg;
 	char *s1, *s2;
 	int n;
-	quotednext(arg, cp_next, cp_back);
+	quotednext(arg, cp_noninext, cp_back);
 	n = eval_up(&s, '\0');
 	if (charread(&s, delim) < 0)
 		return;
--- a/tr.c
+++ b/tr.c
@@ -112,11 +112,13 @@
 {
 	int c = cp_next();
 	int n = n_cp ? 2 : NMLEN - 1;
-	while (c == ' ' || c == '\t')
+	while (c == ' ' || c == '\t' || c == c_ni)
 		c = cp_next();
 	while (c >= 0 && c != ' ' && c != '\t' && c != '\n' && --n >= 0) {
 		*s++ = c;
-		c = cp_next();
+		do {
+			c = cp_next();
+		} while (n && c == c_ni);
 	}
 	if (c >= 0)
 		cp_back(c);
@@ -182,6 +184,8 @@
 	char cs[GNLEN], cs2[GNLEN];
 	int c;
 	while ((c = next()) >= 0) {
+		if (c == c_ni)
+			continue;
 		back(c);
 		if (c == '\n')
 			return 1;
@@ -703,7 +707,8 @@
 	if (c == '"')
 		c = cp_next();
 	while (c > 0 && c != '\n') {
-		sbuf_add(sbuf, c);
+		if (c != c_ni)
+			sbuf_add(sbuf, c);
 		c = cp_next();
 	}
 	sbuf_add(sbuf, 0);
@@ -783,7 +788,8 @@
 		while (c == ' ' || c == '\t')
 			c = cp_next();
 		while (c >= 0 && c != '\n' && c != ' ' && c != '\t') {
-			sbuf_add(sbuf, c);
+			if (c != c_ni)
+				sbuf_add(sbuf, c);
 			c = cp_next();
 		}
 		if (sbuf_len(sbuf) > idx[n])
@@ -844,7 +850,8 @@
 	while (c == ' ')
 		c = cp_next();
 	while (c >= 0 && c != '\n') {
-		sbuf_add(sbuf, c);
+		if (c != c_ni)
+			sbuf_add(sbuf, c);
 		c = cp_next();
 	}
 	cp_copymode(0);