shithub: neatroff

Download patch

ref: 8fdaed8335f3396503838e7403de464f7ebf7211
parent: 685ad77a9f419ef025f9a67b2593b571f4a971bd
author: Ali Gholami Rudi <[email protected]>
date: Wed Jul 24 12:08:11 EDT 2013

ren: add .ab

--- a/ren.c
+++ b/ren.c
@@ -30,6 +30,7 @@
 static int ren_unbuf[8];	/* ren_back() buffer */
 static int ren_un;
 static int ren_fillreq;		/* \p request */
+static int ren_aborted;		/* .ab executed */
 
 static int bp_first = 1;	/* prior to the first page */
 static int bp_next = 1;		/* next page number */
@@ -492,6 +493,12 @@
 	n_m = m;
 }
 
+void tr_ab(char **args)
+{
+	fprintf(stderr, "%s\n", args[1]);
+	ren_aborted = 1;
+}
+
 static void escarg_ren(char *d, int cmd, int (*next)(void), void (*back)(int))
 {
 	char delim[GNLEN];
@@ -813,7 +820,7 @@
 }
 
 /* read characters from in.c and pass rendered lines to out.c */
-void render(void)
+int render(void)
 {
 	struct wb *wb = &ren_wb;
 	int fillreq;
@@ -824,6 +831,8 @@
 	ren_first();			/* transition to the first page */
 	c = ren_next();
 	while (1) {
+		if (ren_aborted)
+			return 1;
 		if (c < 0) {
 			if (bp_final >= 2)
 				break;
@@ -875,6 +884,7 @@
 		ren_page(bp_next, 1);
 	ren_br(1);
 	wb_done(wb);
+	return 0;
 }
 
 /* trap handling */
--- a/roff.c
+++ b/roff.c
@@ -18,14 +18,6 @@
 	n_kn = 0;
 }
 
-static void compile(void)
-{
-	out("s%d\n", n_s);
-	out("f%d\n", n_f);
-	render();
-	out("V%d\n", n_p);
-}
-
 void errmsg(char *fmt, ...)
 {
 	va_list ap;
@@ -38,6 +30,7 @@
 {
 	int i;
 	char path[PATHLEN];
+	int ret;
 	dev_open(TROFFROOT "/font/devutf");
 	env_init();
 	tr_init();
@@ -57,8 +50,11 @@
 	for (; i < argc; i++)
 		in_queue(!strcmp("-", argv[i]) ? NULL : argv[i]);
 	str_set(REG('.', 'P'), TROFFROOT);
-	compile();
+	out("s%d\n", n_s);
+	out("f%d\n", n_f);
+	ret = render();
+	out("V%d\n", n_p);
 	env_done();
 	dev_close();
-	return 0;
+	return ret;
 }
--- a/roff.h
+++ b/roff.h
@@ -55,10 +55,6 @@
 int eval_up(char **s, int unit);
 int eval_re(char *s, int orig, int unit);
 
-/* mapping register, macro and environment names to numbers */
-int map(char *s);
-char *map_name(int id);
-
 /* string registers */
 void str_set(int id, char *s);
 void str_dset(int id, void *d);
@@ -242,13 +238,10 @@
 void adj_nonl(struct adj *adj);
 
 /* rendering */
-void render(void);				/* the main loop */
+int render(void);				/* the main loop */
 void ren_char(struct wb *wb, int (*next)(void), void (*back)(int));
 int ren_wid(int (*next)(void), void (*back)(int));
 void ren_tl(int (*next)(void), void (*back)(int));
-void out_line(char *s);				/* output rendered line */
-int out_readc(char **s, char *d);		/* read request or glyph */
-void out(char *s, ...);				/* output troff cmd */
 void ren_hline(struct wb *wb, char *arg);	/* horizontal line */
 void ren_vline(struct wb *wb, char *arg);	/* vertical line */
 void ren_bracket(struct wb *wb, char *arg);	/* \b */
@@ -255,7 +248,13 @@
 void ren_over(struct wb *wb, char *arg);	/* \o */
 void ren_draw(struct wb *wb, char *arg);	/* \D */
 
+/* out.c */
+void out_line(char *s);				/* output rendered line */
+int out_readc(char **s, char *d);		/* read request or glyph */
+void out(char *s, ...);				/* output troff cmd */
+
 /* troff commands */
+void tr_ab(char **args);
 void tr_bp(char **args);
 void tr_br(char **args);
 void tr_ce(char **args);
@@ -303,10 +302,13 @@
 #define TR_DIVEND	"\07>"	/* diversion ends */
 #define TR_EJECT	"\07P"	/* page eject */
 
-/* register mapping */
+/* mapping register, macro and environment names to numbers */
 #define NREGS		(1 << 16)
 #define NREGS2		(NREGS * 2)
 #define REG(c1, c2)	((c1) * 256 + (c2))
+
+int map(char *s);
+char *map_name(int id);
 
 /* colors */
 #define CLR_R(c)		(((c) >> 16) & 0xff)
--- a/tr.c
+++ b/tr.c
@@ -605,6 +605,7 @@
 	{TR_DIVBEG, tr_divbeg},
 	{TR_DIVEND, tr_divend},
 	{TR_EJECT, tr_eject},
+	{"ab", tr_ab, mkargs_eol},
 	{"ad", tr_ad},
 	{"af", tr_af},
 	{"am", tr_de, mkargs_reg1},