shithub: neatroff

Download patch

ref: a34728b41ee63da09f2314ae44cb01580135c512
parent: 338f7e3154e7c527d356dbcf2e6db48d2452444a
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Apr 13 15:15:59 EDT 2013

reg: add \n(.z

--- a/reg.c
+++ b/reg.c
@@ -39,13 +39,25 @@
 	return &nregs[id];
 }
 
+static void reg_name(char *s, int id)
+{
+	s[0] = (id >> 8) & 0xff;
+	s[1] = id & 0xff;
+	s[3] = '\0';
+}
+
 /* the contents of a number register (returns a static buffer) */
 char *num_get(int id)
 {
 	static char numbuf[128];
+	numbuf[0] = '\0';
 	switch (id) {
 	case REG('.', 't'):
-		sprintf(numbuf, "%d", trap_next());
+		sprintf(numbuf, "%d", f_nexttrap());
+		break;
+	case REG('.', 'z'):
+		if (f_divreg() >= 0)
+			reg_name(numbuf, f_divreg());
 		break;
 	default:
 		sprintf(numbuf, "%d", *nreg(id));
--- a/ren.c
+++ b/ren.c
@@ -83,6 +83,11 @@
 	}
 }
 
+int f_divreg(void)
+{
+	return cdiv ? cdiv->reg : -1;
+}
+
 void tr_divbeg(char **args)
 {
 	odiv_beg();
@@ -525,7 +530,7 @@
 	return ret >= 0 ? treg[ret] : -1;
 }
 
-int trap_next(void)
+int f_nexttrap(void)
 {
 	int pos = trap_pos(n_d);
 	if (cdiv)
--- a/xroff.h
+++ b/xroff.h
@@ -105,9 +105,7 @@
 void render(void);	/* read from in.c and print the output */
 void output(char *s);	/* output the given rendered line */
 void ren_page(int pg);
-int trap_next(void);
 
-
 /* troff commands */
 void tr_bp(char **args);
 void tr_br(char **args);
@@ -186,3 +184,7 @@
 #define n_pg		(*nreg(REG('%', '\0')))	/* % */
 #define n_f0		(*nreg(REG(0, 'f')))	/* last font */
 #define n_s0		(*nreg(REG(0, 's')))	/* last size */
+
+/* functions for implementing read-only registers */
+int f_nexttrap(void);
+int f_divreg(void);