shithub: neatroff

Download patch

ref: 27e85f150fa856a46ccba345d1e77849a279d26f
parent: 9b5448d2cc4b03f27285fd047b0fed9a596fac29
author: Ali Gholami Rudi <[email protected]>
date: Thu Jun 23 10:14:21 EDT 2016

fmt: shrink spaces in the last line of a paragraph

--- a/fmt.c
+++ b/fmt.c
@@ -176,17 +176,18 @@
 	return l;
 }
 
-static int fmt_extractline(struct fmt *f, int beg, int end, int llen)
+/* extract words from beg to end; shrink or stretch spaces if needed */
+static int fmt_extractline(struct fmt *f, int beg, int end, int str)
 {
 	int fmt_div, fmt_rem;
-	int w, i, nspc;
+	int w, i, nspc, llen;
 	struct line *l;
 	if (!(l = fmt_mkline(f)))
 		return 1;
+	llen = FMT_LLEN(f);
 	w = fmt_wordslen(f, beg, end);
 	nspc = fmt_spaces(f, beg, end);
-	/* stretch if (spread & 1) and shrink if (spread & 2) */
-	if (nspc && llen) {
+	if (nspc && FMT_ADJ(f) && (llen < w || str)) {
 		fmt_div = (llen - w) / nspc;
 		fmt_rem = (llen - w) % nspc;
 		if (fmt_rem < 0) {
@@ -553,7 +554,7 @@
 	if (beg > 0)
 		ret += fmt_break(f, beg);
 	f->words[beg].gap = 0;
-	if (fmt_extractline(f, beg, end, FMT_ADJ(f) ? FMT_LLEN(f) : 0))
+	if (fmt_extractline(f, beg, end, 1))
 		return ret;
 	if (beg > 0)
 		fmt_confupdate(f);