shithub: neatroff

Download patch

ref: 05a16d44cffef2f7d906f50532fd56c9e0726585
parent: 08b6db376a3ed78a46af972ca853256160dddbab
author: Ali Gholami Rudi <ali@rudi.ir>
date: Tue Apr 16 07:17:11 EDT 2013

ren: add .pn

The transition to the first page is included also.

--- a/ren.c
+++ b/ren.c
@@ -23,7 +23,8 @@
 
 static int ren_backed = -1;	/* pushed back character */
 
-static int bp_next;		/* next page number */
+static int bp_first = 1;	/* prior to the first page */
+static int bp_next = 1;		/* next page number */
 static int bp_force;		/* execute the traps until the next page */
 
 static int ren_next(void)
@@ -103,20 +104,37 @@
 	ren_div--;
 }
 
+static void ren_page(int pg)
+{
+	n_nl = 0;
+	n_d = 0;
+	n_pg = pg;
+	bp_next = n_pg + 1;
+	OUT("p%d\n", pg);
+	OUT("V%d\n", 0);
+}
+
+static void ren_first(void)
+{
+	if (bp_first) {
+		ren_page(bp_next);
+		bp_first = 0;
+	}
+}
+
 static void ren_sp(int n)
 {
 	char cmd[32];
+	ren_first();
 	if (!n && ren_div && !n_u)
 		return;
 	n_d += n ? n : n_v;
 	if (cdiv) {
 		sbuf_putnl(&cdiv->sbuf);
-		sprintf(cmd, ".sp %du\n", n ? n : n_v);
+		sprintf(cmd, "'sp %du\n", n ? n : n_v);
 		sbuf_append(&cdiv->sbuf, cmd);
 	} else {
 		n_nl = n_d;
-		if (n_nl <= n_p)
-			OUT("v%d\n", n ? n : n_v);
 	}
 }
 
@@ -205,6 +223,7 @@
 {
 	char out[LNLEN];
 	int adj_b, w;
+	ren_first();
 	if (!adj_empty(cadj, n_u)) {
 		adj_b = n_u && !n_na && n_j == AD_B;
 		w = adj_fill(cadj, !force && adj_b, !force && n_u, out);
@@ -225,16 +244,6 @@
 	down(args[1] ? eval(args[1], 0, 'v') : n_v);
 }
 
-void ren_page(int pg)
-{
-	n_nl = -1;
-	n_d = 0;
-	n_pg = pg;
-	bp_next = n_pg + 1;
-	OUT("p%d\n", pg);
-	OUT("V%d\n", 0);
-}
-
 void tr_ne(char **args)
 {
 	int n = args[1] ? eval(args[1], 0, 'v') : n_v;
@@ -247,14 +256,20 @@
 	if (!cdiv) {
 		bp_force = 1;
 		if (args[1])
-			bp_next = eval(args[1], n_pg, '\0');
+			bp_next = eval(args[1], n_pg, 0);
 		push_ne(args[0][0] == '.');
 	}
 }
 
+void tr_pn(char **args)
+{
+	if (args[1])
+		bp_next = eval(args[1], n_pg, 0);
+}
+
 static void ren_ps(char *s)
 {
-	int ps = !s || !*s || !strcmp("0", s) ? n_s0 : eval(s, n_s, '\0');
+	int ps = !s || !*s || !strcmp("0", s) ? n_s0 : eval(s, n_s, 0);
 	n_s0 = n_s;
 	n_s = ps;
 }
@@ -456,7 +471,7 @@
 void render(void)
 {
 	int c;
-	ren_br(1);
+	n_nl = -1;
 	c = ren_next();
 	while (c >= 0) {
 		if (c == ' ' || c == '\n') {
--- a/tr.c
+++ b/tr.c
@@ -474,6 +474,7 @@
 	{"nf", tr_nf},
 	{"nr", tr_nr, mkargs_reg1},
 	{"pl", tr_pl},
+	{"pn", tr_pn},
 	{"po", tr_po},
 	{"ps", tr_ps},
 	{"rm", tr_rm},
--- a/xroff.c
+++ b/xroff.c
@@ -20,7 +20,6 @@
 {
 	OUT("s%d\n", n_s);
 	OUT("f%d\n", n_f);
-	ren_page(1);
 	render();
 	OUT("V%d\n", n_p);
 }
--- a/xroff.h
+++ b/xroff.h
@@ -111,7 +111,6 @@
 /* rendering */
 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 out_draw(char *s, char *cc);
 
 /* troff commands */
@@ -130,6 +129,7 @@
 void tr_ll(char **args);
 void tr_ne(char **args);
 void tr_nf(char **args);
+void tr_pn(char **args);
 void tr_ps(char **args);
 void tr_sp(char **args);
 void tr_ti(char **args);