shithub: neatroff

Download patch

ref: f6e18c39070cc5c9d51d5aec71539eda66efcdf7
parent: 9e1124cb460b1bdfc52c18b299fe0a7d56c5270a
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sun Nov 25 14:45:56 EST 2012

tr: remove the superfluous argc argument of macros

--- a/reg.c
+++ b/reg.c
@@ -20,10 +20,10 @@
 	return o;
 }
 
-void tr_nr(int argc, char **args)
+void tr_nr(char **args)
 {
 	int id;
-	if (argc < 3)
+	if (!args[2])
 		return;
 	id = REG(args[1][0], args[1][1]);
 	nreg[id] = tr_int(args[2], nreg[id], 'u');
--- a/ren.c
+++ b/ren.c
@@ -91,15 +91,15 @@
 	words[0].blanks = 0;
 }
 
-void tr_br(int argc, char **args)
+void tr_br(char **args)
 {
 	req_br = 1;
 }
 
-void tr_sp(int argc, char **args)
+void tr_sp(char **args)
 {
-	tr_br(0, NULL);
-	if (argc > 1)
+	tr_br(NULL);
+	if (args[1])
 		req_sp = tr_int(args[1], 0, 'v');
 }
 
@@ -110,9 +110,9 @@
 	n_s = ps;
 }
 
-void tr_ps(int argc, char **args)
+void tr_ps(char **args)
 {
-	if (argc >= 2)
+	if (args[1])
 		ren_ps(args[1]);
 }
 
@@ -125,17 +125,17 @@
 	}
 }
 
-void tr_ft(int argc, char **args)
+void tr_ft(char **args)
 {
-	if (argc > 1)
+	if (args[1])
 		ren_ft(args[1]);
 }
 
-void tr_fp(int argc, char **args)
+void tr_fp(char **args)
 {
-	if (argc < 3)
+	if (!args[2])
 		return;
-	if (dev_mnt(atoi(args[1]), args[2], argc > 3 ? args[3] : args[2]) < 0)
+	if (dev_mnt(atoi(args[1]), args[2], args[3] ? args[3] : args[2]) < 0)
 		errmsg("troff: failed to mount %s\n", args[2]);
 }
 
@@ -200,7 +200,7 @@
 	int r_s = n_s;
 	int r_f = n_f;
 	int esc = 0;
-	tr_br(0, NULL);
+	tr_br(NULL);
 	while (nextchar(c) > 0) {
 		g = NULL;
 		if (!word && (wid > n_l || req_br))
--- a/tr.c
+++ b/tr.c
@@ -72,21 +72,21 @@
 	return rel ? orig + n : n;
 }
 
-static void tr_ll(int argc, char **args)
+static void tr_ll(char **args)
 {
-	if (argc >= 2)
+	if (args[1])
 		n_l = tr_int(args[1], n_l, 'm');
 }
 
-static void tr_vs(int argc, char **args)
+static void tr_vs(char **args)
 {
-	if (argc >= 2)
+	if (args[1])
 		n_v = tr_int(args[1], n_v, 'p');
 }
 
-static void tr_ds(int argc, char **args)
+static void tr_ds(char **args)
 {
-	if (argc < 3)
+	if (!args[2])
 		return;
 	str_set(REG(args[1][0], args[1][1]), args[2]);
 }
@@ -93,7 +93,7 @@
 
 static char *arg_regname(char *s, int len);
 
-static void tr_de(int argc, char **args)
+static void tr_de(char **args)
 {
 	struct sbuf sbuf;
 	char buf[4];
@@ -100,9 +100,9 @@
 	int end[4] = {'.'};
 	int c;
 	int i;
-	if (argc <= 1)
+	if (!args[1])
 		return;
-	if (argc > 2 && args[2]) {
+	if (args[2]) {
 		end[0] = args[2][0];
 		end[1] = args[2][1];
 	}
@@ -129,13 +129,13 @@
 	sbuf_done(&sbuf);
 }
 
-static void tr_in(int argc, char **args)
+static void tr_in(char **args)
 {
-	if (argc >= 2)
+	if (args[1])
 		n_i = tr_int(args[1], n_i, 'm');
 }
 
-static void tr_na(int argc, char **args)
+static void tr_na(char **args)
 {
 	n_ad = 0;
 }
@@ -212,13 +212,13 @@
 }
 
 /* read macro arguments */
-static int mkargs(char **args, int maxargs, char *buf, int len)
+static int mkargs(char **args, char *buf, int len)
 {
 	char *s = buf;
 	char *e = buf + len - 1;
 	int c;
 	int n = 0;
-	while (n < maxargs) {
+	while (n < NARGS) {
 		c = cp_next();
 		if (c < 0 || c == '\n')
 			return n;
@@ -231,7 +231,7 @@
 }
 
 /* read arguments for .ds */
-static int mkargs_ds(char **args, int maxargs, char *buf, int len)
+static int mkargs_ds(char **args, char *buf, int len)
 {
 	char *s = buf;
 	char *e = buf + len - 1;
@@ -247,19 +247,19 @@
 }
 
 /* read arguments for commands .nr that expect a register name */
-static int mkargs_reg1(char **args, int maxargs, char *buf, int len)
+static int mkargs_reg1(char **args, char *buf, int len)
 {
 	char *s = buf;
 	char *e = buf + len - 1;
 	args[0] = s;
 	s = arg_regname(s, e - s);
-	return mkargs(args + 1, maxargs - 1, s, e - s) + 1;
+	return mkargs(args + 1, s, e - s) + 1;
 }
 
 static struct cmd {
 	char *id;
-	void (*f)(int argc, char **args);
-	int (*args)(char **args, int maxargs, char *buf, int len);
+	void (*f)(char **args);
+	int (*args)(char **args, char *buf, int len);
 } cmds[] = {
 	{"br", tr_br},
 	{"de", tr_de, mkargs_reg1},
@@ -279,7 +279,7 @@
 {
 	int c = cp_next();
 	int nl = c == '\n';
-	char *args[NARGS + 1] = {NULL};
+	char *args[NARGS + 3] = {NULL};
 	char cmd[RLEN];
 	char buf[LNLEN];
 	struct cmd *req = NULL;
@@ -295,12 +295,12 @@
 				req = &cmds[i];
 		if (req) {
 			if (req->args)
-				argc = req->args(args + 1, NARGS, buf, sizeof(buf));
+				argc = req->args(args + 1, buf, sizeof(buf));
 			else
-				argc = mkargs(args + 1, NARGS, buf, sizeof(buf));
-			req->f(argc + 1, args);
+				argc = mkargs(args + 1, buf, sizeof(buf));
+			req->f(args);
 		} else {
-			argc = mkargs(args + 1, NARGS, buf, sizeof(buf));
+			argc = mkargs(args + 1, buf, sizeof(buf));
 			if (str_get(REG(cmd[1], cmd[2])))
 				in_push(str_get(REG(cmd[1], cmd[2])), args + 1);
 		}
--- a/xroff.h
+++ b/xroff.h
@@ -96,12 +96,12 @@
 void output(char *s);	/* output the given rendered line */
 
 /* troff commands */
-void tr_br(int argc, char **args);
-void tr_sp(int argc, char **args);
-void tr_nr(int argc, char **args);
-void tr_ps(int argc, char **args);
-void tr_ft(int argc, char **args);
-void tr_fp(int argc, char **args);
+void tr_br(char **args);
+void tr_sp(char **args);
+void tr_nr(char **args);
+void tr_ps(char **args);
+void tr_ft(char **args);
+void tr_fp(char **args);
 
 /* helpers */
 void errmsg(char *msg, ...);