shithub: neatroff

Download patch

ref: acf6476228825e442f68bd4b36f4dcede001eab0
parent: 80b1a9452d88359232e2b2d361cdb48f8dd39546
author: Ali Gholami Rudi <ali@rudi.ir>
date: Thu Jul 25 18:40:44 EDT 2013

adj: end of sentence space when newline follows .!?

--- a/adj.c
+++ b/adj.c
@@ -214,6 +214,11 @@
 	wb_cat(&adj->wbs[i], wb);
 }
 
+static int adj_eos(struct adj *adj)
+{
+	return adj->nwords && wb_eos(&adj->wbs[adj->nwords - 1]);
+}
+
 /* insert wb into the adjustment buffer */
 void adj_wb(struct adj *adj, struct wb *wb)
 {
@@ -222,7 +227,7 @@
 	if (!adj->nwords)	/* apply the new .l and .i */
 		adj_confupdate(adj);
 	if (adj->nls && !adj->gap && adj->nwords >= 1)
-		adj->gap = adj->swid;
+		adj->gap = adj_eos(adj) ? adj->swid * 2 : adj->swid;
 	adj_word(adj, wb);
 	adj->nls = 0;
 	adj->gap = 0;
--- a/roff.h
+++ b/roff.h
@@ -190,6 +190,7 @@
 	char prev_c[GNLEN];	/* previous character added via wb_put() */
 	int prev_h;		/* wb->h after wb_put() calls */
 	int prev_l;		/* sbuf_len(&wb->sbuf) after wb_put() calls */
+	int eos;		/* nonzero if wb ends a sentence (.?!) */
 };
 
 void wb_init(struct wb *wb);
@@ -212,6 +213,7 @@
 int wb_hyph(struct wb *wb, int w, struct wb *w1, struct wb *w2, int flg);
 int wb_wid(struct wb *wb);
 int wb_empty(struct wb *wb);
+int wb_eos(struct wb *wb);
 void wb_wconf(struct wb *wb, int *ct, int *st, int *sb);
 int wb_lig(struct wb *wb, char *c);
 int wb_kern(struct wb *wb, char *c);
--- a/wb.c
+++ b/wb.c
@@ -112,6 +112,10 @@
 		wb->prev_h = wb->h;
 		wb->h += charwid(R_F(wb), R_S(wb), g ? g->wid : SC_DW);
 		wb->ct |= g ? g->type : 0;
+		if (c[1])
+			wb->eos = 0;
+		else if (strchr("'\")]*", c[0]) == NULL)
+			wb->eos = strchr(".?!", c[0]) != NULL;
 		wb_stsb(wb);
 	}
 }
@@ -268,6 +272,11 @@
 int wb_empty(struct wb *wb)
 {
 	return sbuf_empty(&wb->sbuf);
+}
+
+int wb_eos(struct wb *wb)
+{
+	return wb->eos;
 }
 
 void wb_wconf(struct wb *wb, int *ct, int *st, int *sb)