shithub: neatroff

Download patch

ref: 37292b45bd9935671eacae7ef3d4286f764182c8
parent: 7c5f650fdfbb739ca71414c6701136b8882cb01b
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sun Apr 14 14:05:33 EDT 2013

tr: add .po and handle requests that save their previous value

--- a/reg.c
+++ b/reg.c
@@ -28,9 +28,12 @@
 	REG('.', 'u'),
 	REG('.', 'v'),
 	REG(0, 'f'),
+	REG(0, 'i'),
+	REG(0, 'l'),
 	REG(0, 'n'),
 	REG(0, 's'),
 	REG(0, 't'),
+	REG(0, 'v'),
 };
 
 /* return the address of a number register */
--- a/ren.c
+++ b/ren.c
@@ -264,10 +264,11 @@
 
 void tr_in(char **args)
 {
+	int in = args[1] ? eval(args[1], n_i, 'm') : n_i0;
 	if (args[0][0] == '.')
 		ren_br(1);
-	if (args[1])
-		n_i = eval(args[1], n_i, 'm');
+	n_i0 = n_i;
+	n_i = in;
 }
 
 void tr_ti(char **args)
--- a/tr.c
+++ b/tr.c
@@ -16,14 +16,16 @@
 
 static void tr_ll(char **args)
 {
-	if (args[1])
-		n_l = eval(args[1], n_l, 'm');
+	int ll = args[1] ? eval(args[1], n_l, 'm') : n_l0;
+	n_l0 = n_l;
+	n_l = ll;
 }
 
 static void tr_vs(char **args)
 {
-	if (args[1])
-		n_v = eval(args[1], n_v, 'p');
+	int vs = args[1] ? eval(args[1], n_v, 'p') : n_v0;
+	n_v0 = n_v;
+	n_v = vs;
 }
 
 static void tr_pl(char **args)
@@ -79,6 +81,13 @@
 	str_rn(REG(args[1][0], args[1][1]), REG(args[2][0], args[2][1]));
 }
 
+static void tr_po(char **args)
+{
+	int po = args[1] ? eval(args[1], n_o, 'm') : n_o0;
+	n_o0 = n_o;
+	n_o = po;
+}
+
 static char *arg_regname(char *s, int len);
 
 static void tr_de(char **args)
@@ -453,6 +462,7 @@
 	{"nf", tr_nf},
 	{"nr", tr_nr, mkargs_reg1},
 	{"pl", tr_pl},
+	{"po", tr_po},
 	{"ps", tr_ps},
 	{"rm", tr_rm},
 	{"rn", tr_rn},
--- a/xroff.h
+++ b/xroff.h
@@ -190,10 +190,14 @@
 #define n_nl		(*nreg(REG('n', 'l')))
 #define n_pg		(*nreg(REG('%', '\0')))	/* % */
 #define n_lb		(*nreg(REG(0, 'b')))	/* input line beg */
-#define n_f0		(*nreg(REG(0, 'f')))	/* last font */
+#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_na		(*nreg(REG(0, 'n')))	/* .na mode */
-#define n_s0		(*nreg(REG(0, 's')))	/* last size */
+#define n_o0		(*nreg(REG(0, 'o')))	/* last .o */
+#define n_s0		(*nreg(REG(0, 's')))	/* last .s */
 #define n_ti		(*nreg(REG(0, 't')))	/* temp indent */
+#define n_v0		(*nreg(REG(0, 'v')))	/* last .v */
 
 /* functions for implementing read-only registers */
 int f_nexttrap(void);	/* .t */