shithub: neatroff

Download patch

ref: 593fe1b1846b79ddfcb46e47ec7cf613115b20bb
parent: 9521c10a1a8fcbe1bbfedb531f276038c0598a51
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Nov 13 04:14:34 EST 2014

ren: allow arbitrary page number characters in .tl

--- a/ren.c
+++ b/ren.c
@@ -849,9 +849,10 @@
 void ren_tl(int (*next)(void), void (*back)(int))
 {
 	struct wb wb, wb2;
-	char src[4] = {c_pc};
-	char *dst = num_str(map("%"));
+	char *pgnum;
 	char delim[GNLEN];
+	ren_first();
+	pgnum = num_str(map("%"));
 	wb_init(&wb);
 	wb_init(&wb2);
 	charnext(delim, next, back);
@@ -858,13 +859,13 @@
 	if (!strcmp("\n", delim))
 		back('\n');
 	/* the left-adjusted string */
-	ren_untilmap(&wb2, next, back, delim, src, dst);
+	ren_untilmap(&wb2, next, back, delim, c_pc, pgnum);
 	wb_cpy(&wb, &wb2, 0);
 	/* the centered string */
-	ren_untilmap(&wb2, next, back, delim, src, dst);
+	ren_untilmap(&wb2, next, back, delim, c_pc, pgnum);
 	wb_cpy(&wb, &wb2, (n_lt - wb_wid(&wb2)) / 2);
 	/* the right-adjusted string */
-	ren_untilmap(&wb2, next, back, delim, src, dst);
+	ren_untilmap(&wb2, next, back, delim, c_pc, pgnum);
 	wb_cpy(&wb, &wb2, n_lt - wb_wid(&wb2));
 	/* flushing the line */
 	ren_line(wb_buf(&wb), wb_wid(&wb), AD_L, 0,
--- a/roff.h
+++ b/roff.h
@@ -69,7 +69,7 @@
 extern int c_ec;	/* escape character (\) */
 extern int c_cc;	/* basic control character (.) */
 extern int c_c2;	/* no-break control character (') */
-extern int c_pc;	/* page number character */
+extern char c_pc[];	/* page number character (%) */
 #define c_ni	4	/* non-interpreted copy-mode escape */
 #define c_hc	env_hc()/* hyphenation character */
 #define c_mc	env_mc()/* margin character (.mc) */
--- a/tr.c
+++ b/tr.c
@@ -6,10 +6,10 @@
 #include "roff.h"
 
 static int tr_nl = 1;		/* just read a newline */
-int c_pc = '%';			/* page number character */
-int c_ec = '\\';
-int c_cc = '.';
-int c_c2 = '\'';
+char c_pc[GNLEN] = "%";		/* page number character */
+int c_ec = '\\';		/* escape character */
+int c_cc = '.';			/* control character */
+int c_c2 = '\'';		/* no-break control character */
 
 /* skip everything until the end of line */
 static void jmp_eol(void)
@@ -356,7 +356,9 @@
 
 static void tr_pc(char **args)
 {
-	c_pc = args[1] ? args[1][0] : -1;
+	char *s = args[1];
+	if (!s || charread(&s, c_pc) < 0)
+		strcpy(c_pc, "");
 }
 
 static void tr_tl(char **args)