shithub: neatroff

Download patch

ref: af5f4e16da8242be88bd1cfdd241ec54264e737c
parent: d2f835e905fcbe8fba2d08b80eca0a360be677fa
author: Ali Gholami Rudi <[email protected]>
date: Fri Aug 2 18:59:20 EDT 2013

cp: allow \$[] and more than 9 arguments

--- a/cp.c
+++ b/cp.c
@@ -6,28 +6,32 @@
 static int cp_sblk[NIES];	/* skip \} escape at this depth, if set */
 static int cp_widreq = 1;	/* inline \w requests */
 
-static int regid(void)
+static void cparg(char *d)
 {
-	char key[NMLEN];
+	int c = cp_next();
 	int i = 0;
-	int c1;
-	int c2 = 0;
-	c1 = cp_next();
-	if (c1 == '(') {
-		c1 = cp_next();
-		c2 = cp_next();
-	} else if (!n_cp && c1 == '[') {
-		c1 = cp_next();
-		while (i < NMLEN - 1 && c1 >= 0 && c1 != ']') {
-			key[i++] = c1;
-			c1 = cp_next();
+	if (c == '(') {
+		d[i++] = cp_next();
+		d[i++] = cp_next();
+	} else if (!n_cp && c == '[') {
+		c = cp_next();
+		while (i < NMLEN - 1 && c >= 0 && c != ']') {
+			d[i++] = c;
+			c = cp_next();
 		}
-		key[i] = '\0';
-		return map(key);
+	} else {
+		d[i++] = c;
 	}
-	return REG(c1, c2);
+	d[i] = '\0';
 }
 
+static int regid(void)
+{
+	char regname[NMLEN];
+	cparg(regname);
+	return map(regname);
+}
+
 static void cp_num(void)
 {
 	int id;
@@ -55,11 +59,13 @@
 
 static void cp_arg(void)
 {
-	int c;
+	char argname[NMLEN];
 	char *arg = NULL;
-	c = cp_next();
-	if (c >= '1' && c <= '9')
-		arg = in_arg(c - '0');
+	int argnum;
+	cparg(argname);
+	argnum = atoi(argname);
+	if (argnum > 0 && argnum < NARGS + 1)
+		arg = in_arg(argnum);
 	if (arg)
 		in_push(arg, NULL);
 }
--- a/roff.h
+++ b/roff.h
@@ -19,7 +19,7 @@
 #define ILNLEN		1000	/* line limit of input files */
 #define LNLEN		4000	/* line buffer length (ren.c/out.c) */
 #define NWORDS		256	/* number of words in line buffer */
-#define NARGS		9	/* number of macro arguments */
+#define NARGS		16	/* number of macro arguments */
 #define NPREV		16	/* environment stack depth */
 #define NTRAPS		1024	/* number of traps per page */
 #define NIES		128	/* number of nested .ie commands */