shithub: neatroff

Download patch

ref: 0b94c7c529bf0baf7685990596e2cd58f354e11a
parent: 293bea16104281fe65719b462177dc29dd092db0
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Sep 26 07:26:42 EDT 2014

tr: read transparent output escape sequence in tr.c

--- a/ren.c
+++ b/ren.c
@@ -110,6 +110,14 @@
 	ren_div--;
 }
 
+void tr_transparent(char **args)
+{
+	if (cdiv)
+		sbuf_printf(&cdiv->sbuf, "%s\n", args[1]);
+	else
+		out("%s\n", args[1]);
+}
+
 static int trap_reg(int pos);
 static int trap_pos(int pos);
 static void trap_exec(int reg);
@@ -160,6 +168,7 @@
 }
 
 static int render_rec(int level);
+
 static void trap_exec(int reg)
 {
 	char cmd[16];
@@ -253,14 +262,6 @@
 	}
 }
 
-static void ren_transparent(char *s)
-{
-	if (cdiv)
-		sbuf_printf(&cdiv->sbuf, "%s\n", s);
-	else
-		out("%s\n", s);
-}
-
 static int zwid(void)
 {
 	struct glyph *g = dev_glyph("0", n_f);
@@ -703,8 +704,7 @@
 static void ren_put(struct wb *wb, char *c, int (*next)(void), void (*back)(int))
 {
 	char arg[ILNLEN];
-	char *s;
-	int w, n;
+	int w;
 	if (c[0] == ' ' || c[0] == '\n') {
 		wb_put(wb, c);
 		return;
@@ -724,20 +724,7 @@
 			wb_hmov(wb, w - wb_wid(wb));
 			return;
 		}
-		if (c[1] == '!') {
-			if (ren_nl && next == ren_next) {
-				s = arg;
-				n = next();
-				while (n >= 0 && n != '\n') {
-					*s++ = n;
-					n = next();
-				}
-				*s = '\0';
-				ren_transparent(arg);
-			}
-			return;
-		}
-		if (strchr(" bCcDdefHhkLlmNoprSsuvXxZz0^|{}&/,", c[1])) {
+		if (strchr(" bCcDdefHhkLlmNoprSsuvXxZz0^|!{}&/,", c[1])) {
 			arg[0] = '\0';
 			if (strchr(ESC_P, c[1]))
 				unquotednext(arg, c[1], next, back);
--- a/roff.h
+++ b/roff.h
@@ -373,6 +373,7 @@
 void tr_ti(char **args);
 void tr_wh(char **args);
 void tr_popren(char **args);
+void tr_transparent(char **args);
 
 void tr_init(void);
 int tr_readargs(char **args, struct sbuf *sbuf,
--- a/tr.c
+++ b/tr.c
@@ -977,6 +977,20 @@
 	if (!tr_nl)
 		return 1;
 	c = cp_next();
+	if (c == c_ec) {
+		int c2 = cp_next();
+		if (c2 == '!') {
+			args[0] = "\\!";
+			sbuf_init(&sbuf);
+			cp_copymode(1);
+			mkargs_eol(args + 1, &sbuf);
+			cp_copymode(0);
+			tr_transparent(args);
+			sbuf_done(&sbuf);
+			return 0;
+		}
+		cp_back(c2);
+	}
 	if (c < 0 || (c != c_cc && c != c_c2)) {
 		cp_back(c);
 		return 1;