shithub: neatroff

Download patch

ref: 7936220f7971f2a34be3a215750626f5e82f2353
parent: dc80a8d4a5fdba90f8962a732be7f5a3b3601b51
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Apr 24 06:08:24 EDT 2014

adj: access n_ll and n_i directly

--- a/adj.c
+++ b/adj.c
@@ -4,7 +4,7 @@
 #include <string.h>
 #include "roff.h"
 
-#define ADJ_LLEN(a)	MAX(0, (a)->ll - ((a)->lt >= 0 ? (a)->lt : (a)->li))
+#define ADJ_LLEN(a)	MAX(0, (a)->ll - (a)->li)
 
 struct adj {
 	struct wb wbs[NWORDS];	/* words in buf */
@@ -14,33 +14,16 @@
 	int swid;		/* current space width */
 	int gap;		/* space before the next word */
 	int nls;		/* newlines before the next word */
-	int l, i, t;		/* current .l, .i and ti */
-	int ll, li, lt;		/* current line's .l, .i and ti */
+	int li, ll;		/* current line indentation and length */
 	int filled;		/* filled all words in the last adj_fill() */
 };
 
-void adj_ll(struct adj *adj, int ll)
-{
-	adj->l = ll;
-}
-
-void adj_ti(struct adj *adj, int ti)
-{
-	adj->t = ti;
-}
-
-void adj_in(struct adj *adj, int in)
-{
-	adj->i = in;
-}
-
 /* .ll, .in and .ti are delayed until the partial line is output */
 static void adj_confupdate(struct adj *adj)
 {
-	adj->ll = adj->l;
-	adj->li = adj->i;
-	adj->lt = adj->t;
-	adj->t = -1;
+	adj->ll = n_l;
+	adj->li = n_ti > 0 ? n_ti : n_i;
+	n_ti = 0;
 }
 
 /* does the adjustment buffer need to be flushed without filling? */
@@ -151,7 +134,7 @@
 
 /* fill and copy a line into s */
 int adj_fill(struct adj *a, int ad_b, int fill, int hyph, struct sbuf *s,
-		int *ll, int *in, int *ti, int *els_neg, int *els_pos)
+		int *li, int *ll, int *els_neg, int *els_pos)
 {
 	int adj_div, adj_rem;
 	int w = 0;
@@ -158,8 +141,7 @@
 	int i, n;
 	int llen = ADJ_LLEN(a);
 	*ll = a->ll;
-	*in = a->li;
-	*ti = a->lt;
+	*li = a->li;
 	if (!fill || adj_fullnf(a)) {
 		a->filled = 0;
 		a->nls--;
--- a/reg.c
+++ b/reg.c
@@ -37,7 +37,7 @@
 	".it", ".itn", ".mc", ".mcn",
 	".ce", ".f0", ".hy", ".i0", ".l0",
 	".L0", ".m0", ".n0", ".s0", ".ss",
-	".lt", ".lt0", ".v0",
+	".ti", ".lt", ".lt0", ".v0",
 };
 
 /* return the address of a number register */
@@ -200,8 +200,6 @@
 		n_nS = 1;
 		strcpy(env->hc, "\\%");
 		strcpy(env->lc, ".");
-		adj_ll(env->adj, n_l);
-		adj_in(env->adj, n_i);
 		for (i = 0; i < NTABS; i++)
 			env->tabs[i] = i * SC_IN / 2;
 	}
--- a/ren.c
+++ b/ren.c
@@ -216,9 +216,9 @@
 }
 
 /* line adjustment */
-static int ren_ljust(struct sbuf *spre, int w, int ad, int ll, int li, int lt)
+static int ren_ljust(struct sbuf *spre, int w, int ad, int li, int ll)
 {
-	int ljust = lt >= 0 ? lt : li;
+	int ljust = li;
 	int llen = ll - ljust;
 	n_n = w;
 	if (ad == AD_C)
@@ -309,7 +309,7 @@
 
 /* process a line and print it with ren_out() */
 static int ren_line(char *line, int w, int ad, int body,
-		int ll, int li, int lt, int els_neg, int els_pos)
+		int li, int ll, int els_neg, int els_pos)
 {
 	char cmd[16];
 	struct sbuf sbeg, send;
@@ -325,7 +325,7 @@
 		ren_sp(0, 0);
 		if (line[0] && n_nm && body)
 			ren_lnum(&sbeg);
-		ljust = ren_ljust(&sbeg, w, ad, ll, li, lt);
+		ljust = ren_ljust(&sbeg, w, ad, li, ll);
 		if (line[0] && body && n_mc)
 			ren_mc(&send, w, ljust);
 		ren_out(sbuf_buf(&sbeg), line, sbuf_buf(&send));
@@ -353,7 +353,7 @@
 static int ren_bradj(struct adj *adj, int fill, int ad)
 {
 	struct sbuf sbuf;
-	int ll, li, lt, els_neg, els_pos;
+	int ll, li, els_neg, els_pos;
 	int w, hyph, ret;
 	ren_first();
 	if (adj_empty(adj, fill))
@@ -363,9 +363,8 @@
 	if ((n_hy & HY_LAST) && ren_lastline())
 		hyph = 0;	/* disable hyphenation final lines */
 	w = adj_fill(adj, ad == AD_B, fill, hyph, &sbuf,
-			&ll, &li, &lt, &els_neg, &els_pos);
-	ret = ren_line(sbuf_buf(&sbuf), w, ad, 1,
-			ll, li, lt, els_neg, els_pos);
+			&li, &ll, &els_neg, &els_pos);
+	ret = ren_line(sbuf_buf(&sbuf), w, ad, 1, li, ll, els_neg, els_pos);
 	sbuf_done(&sbuf);
 	return ret;
 }
@@ -513,7 +512,6 @@
 	int ll = args[1] ? eval_re(args[1], n_l, 'm') : n_l0;
 	n_l0 = n_l;
 	n_l = MAX(0, ll);
-	adj_ll(cadj, n_l);
 }
 
 void tr_in(char **args)
@@ -523,8 +521,7 @@
 		ren_br(1);
 	n_i0 = n_i;
 	n_i = MAX(0, in);
-	adj_in(cadj, n_i);
-	adj_ti(cadj, -1);
+	n_ti = 0;
 }
 
 void tr_ti(char **args)
@@ -532,7 +529,7 @@
 	if (args[0][0] == c_cc)
 		ren_br(1);
 	if (args[1])
-		adj_ti(cadj, eval_re(args[1], n_i, 'm'));
+		n_ti = eval_re(args[1], n_i, 'm');
 }
 
 static void ren_ft(char *s)
@@ -849,7 +846,7 @@
 	wb_cpy(&wb, &wb2, n_lt - wb_wid(&wb2));
 	/* flushing the line */
 	ren_line(sbuf_buf(&wb.sbuf), wb_wid(&wb), AD_L, 0,
-			n_lt, 0, 0, wb.els_neg, wb.els_pos);
+			0, n_lt, wb.els_neg, wb.els_pos);
 	wb_done(&wb2);
 	wb_done(&wb);
 }
--- a/roff.h
+++ b/roff.h
@@ -298,14 +298,11 @@
 struct adj *adj_alloc(void);
 void adj_free(struct adj *adj);
 int adj_fill(struct adj *adj, int ad_b, int fill, int hyph, struct sbuf *dst,
-		int *ll, int *in, int *ti, int *els_neg, int *els_pos);
+		int *li, int *ll, int *els_neg, int *els_pos);
 int adj_full(struct adj *adj, int fill);
 int adj_empty(struct adj *adj, int fill);
 int adj_wid(struct adj *adj);
 void adj_swid(struct adj *adj, int swid);
-void adj_ll(struct adj *adj, int ll);
-void adj_in(struct adj *adj, int in);
-void adj_ti(struct adj *adj, int ti);
 void adj_wb(struct adj *adj, struct wb *wb);
 void adj_nl(struct adj *adj);
 void adj_sp(struct adj *adj);
@@ -448,6 +445,7 @@
 #define n_lg		(*nreg(map(".lg")))	/* .lg mode */
 #define n_hy		(*nreg(map(".hy")))	/* .hy mode */
 #define n_i0		(*nreg(map(".i0")))	/* last .i */
+#define n_ti		(*nreg(map(".ti")))	/* pending .ti */
 #define n_kn		(*nreg(map(".kern")))	/* .kn mode */
 #define n_l0		(*nreg(map(".l0")))	/* last .l */
 #define n_L0		(*nreg(map(".L0")))	/* last .L */