shithub: neatroff

Download patch

ref: 5d3333450b2456279531d67e9ca11ce08446da9a
parent: c0958e44843f678a014c3ede1b5f4d857fa10784
author: Ali Gholami Rudi <[email protected]>
date: Sun Nov 19 18:35:23 EST 2017

cp: invoking built-in requests like \*[nr reg 10]

--- a/cp.c
+++ b/cp.c
@@ -66,17 +66,17 @@
 static void cp_str(void)
 {
 	char reg[NMLEN];
-	char *args[NARGS + 1] = {NULL};
+	char *args[NARGS + 2] = {reg};
+	char *buf = NULL;
 	if (cparg(reg, sizeof(reg))) {
-		char *buf = tr_args(args, ']', cp_noninext, cp_back);
+		buf = tr_args(args + 1, ']', cp_noninext, cp_back);
 		cp_noninext();
-		if (str_get(map(reg)))
-			in_push(str_get(map(reg)), args);
-		free(buf);
-	} else {
-		if (str_get(map(reg)))
-			in_push(str_get(map(reg)), NULL);
 	}
+	if (str_get(map(reg)))
+		in_push(str_get(map(reg)), buf ? args + 1 : NULL);
+	else if (!n_cp)
+		tr_req(map(reg), args);
+	free(buf);
 }
 
 /* interpolate \g(xy */
--- a/roff.h
+++ b/roff.h
@@ -202,6 +202,7 @@
 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 */
+void tr_req(int reg, char **args);	/* execute a built-in troff request */
 
 /* variable length string buffer */
 struct sbuf {
--- a/tr.c
+++ b/tr.c
@@ -1132,6 +1132,14 @@
 	return out;
 }
 
+/* execute a built-in request */
+void tr_req(int reg, char **args)
+{
+	struct cmd *req = str_dget(reg);
+	if (req)
+		req->f(args);
+}
+
 /* read the next troff request; return zero if a request was executed. */
 int tr_nextreq(void)
 {