shithub: neatroff

Download patch

ref: d4a6c339e2825fa9bd57b0c8588096aa623c3bdd
parent: 05a16d44cffef2f7d906f50532fd56c9e0726585
author: Ali Gholami Rudi <[email protected]>
date: Tue Apr 16 08:14:25 EDT 2013

ren: add .mk and .rt

--- a/reg.c
+++ b/reg.c
@@ -76,10 +76,14 @@
 	return numbuf;
 }
 
-void num_set(int id, int val, int inc)
+void num_set(int id, int val)
 {
 	*nreg(id) = val;
-	nregs_inc[id] = inc;
+}
+
+void num_inc(int id, int val)
+{
+	nregs_inc[id] = val;
 }
 
 void num_del(int id)
--- a/ren.c
+++ b/ren.c
@@ -12,6 +12,7 @@
 	int reg;		/* diversion register */
 	int dl;			/* diversion width */
 	int prev_d;		/* previous \(.d value */
+	int prev_mk;		/* previous .mk internal register */
 	int tpos;		/* diversion trap position */
 	int treg;		/* diversion trap register */
 };
@@ -61,6 +62,7 @@
 		sbuf_init(&cdiv->sbuf);
 		cdiv->reg = REG(args[1][0], args[1][1]);
 		cdiv->prev_d = n_d;
+		cdiv->prev_mk = n_mk;
 		cdiv->treg = -1;
 		if (args[0][2] == 'a' && str_get(cdiv->reg))	/* .da */
 			sbuf_append(&cdiv->sbuf, str_get(cdiv->reg));
@@ -76,6 +78,7 @@
 		n_dl = cdiv->dl;
 		n_dn = n_d;
 		n_d = cdiv->prev_d;
+		n_mk = cdiv->prev_mk;
 		cdiv = cdiv > divs ? cdiv - 1 : NULL;
 		ren_f = 0;
 		ren_s = 0;
@@ -242,6 +245,21 @@
 	if (args[0][0] == '.')
 		ren_br(1);
 	down(args[1] ? eval(args[1], 0, 'v') : n_v);
+}
+
+void tr_mk(char **args)
+{
+	if (args[1])
+		num_set(REG(args[1][0], args[1][1]), n_d);
+	else
+		n_mk = n_d;
+}
+
+void tr_rt(char **args)
+{
+	int n = args[1] ? eval(args[1], n_d, 'v') : n_mk;
+	if (n >= 0 && n < n_d)
+		ren_sp(n - n_d);
 }
 
 void tr_ne(char **args)
--- a/tr.c
+++ b/tr.c
@@ -33,8 +33,8 @@
 	if (!args[2])
 		return;
 	id = REG(args[1][0], args[1][1]);
-	num_set(id, eval(args[2], num_get(id, 0), 'u'),
-			args[3] ? eval(args[3], 0, 'u') : 0);
+	num_set(id, eval(args[2], num_get(id, 0), 'u'));
+	num_inc(id, args[3] ? eval(args[3], 0, 'u') : 0);
 }
 
 static void tr_rr(char **args)
@@ -469,6 +469,7 @@
 	{"ig", tr_ig},
 	{"in", tr_in},
 	{"ll", tr_ll},
+	{"mk", tr_mk},
 	{"na", tr_na},
 	{"ne", tr_ne},
 	{"nf", tr_nf},
@@ -480,6 +481,7 @@
 	{"rm", tr_rm},
 	{"rn", tr_rn},
 	{"rr", tr_rr},
+	{"rt", tr_rt},
 	{"so", tr_so},
 	{"sp", tr_sp},
 	{"ti", tr_ti},
--- a/xroff.h
+++ b/xroff.h
@@ -26,7 +26,8 @@
 
 /* number registers */
 int num_get(int id, int inc);
-void num_set(int id, int val, int inc);
+void num_set(int id, int val);
+void num_inc(int id, int val);
 void num_del(int id);
 char *num_str(int id);
 int *nreg(int id);
@@ -127,10 +128,12 @@
 void tr_ft(char **args);
 void tr_in(char **args);
 void tr_ll(char **args);
+void tr_mk(char **args);
 void tr_ne(char **args);
 void tr_nf(char **args);
 void tr_pn(char **args);
 void tr_ps(char **args);
+void tr_rt(char **args);
 void tr_sp(char **args);
 void tr_ti(char **args);
 void tr_wh(char **args);
@@ -202,6 +205,7 @@
 #define n_f0		(*nreg(REG(0, 'f')))	/* last .f */
 #define n_i0		(*nreg(REG(0, 'i')))	/* last .i */
 #define n_l0		(*nreg(REG(0, 'l')))	/* last .l */
+#define n_mk		(*nreg(REG(0, 'm')))	/* .mk internal register */
 #define n_na		(*nreg(REG(0, 'n')))	/* .na mode */
 #define n_o0		(*nreg(REG(0, 'o')))	/* last .o */
 #define n_s0		(*nreg(REG(0, 's')))	/* last .s */