shithub: neatroff

Download patch

ref: b6234f3e32fd4698cf2f872e446ec8a95ffc9275
parent: fa4cd6d591046509be035f978c703f3652984656
author: Ali Gholami Rudi <[email protected]>
date: Thu Nov 1 18:32:17 EDT 2018

fmt: ignore hyphenation marks at the end of the words

Reported and tested by aksr <[email protected]>.

--- a/fmt.c
+++ b/fmt.c
@@ -296,24 +296,31 @@
 	char *s = word;
 	char *d = NULL;
 	int c, n = 0;
+	int lastchar = 0;
 	while ((c = escread(&s, &d)) > 0)
 		;
 	if (c < 0 || !strcmp(c_hc, d))
 		return -1;
 	while ((c = escread(&s, &d)) >= 0 && n < NHYPHSWORD) {
-		if (!c && !strcmp(c_hc, d)) {
-			hyins[n] = 1;
-			hyidx[n++] = s - word;
+		if (!c) {
+			if (!strcmp(c_hc, d)) {
+				hyins[n] = 1;
+				hyidx[n++] = s - word;
+			}
+			if (c_hydash(d)) {
+				hyins[n] = 0;
+				hyidx[n++] = s - word;
+			}
+			if (!strcmp(c_nb, d)) {
+				hygap[n] = 1;
+				hyidx[n++] = s - word;
+			}
+			lastchar = s - word;
 		}
-		if (!c && c_hydash(d)) {
-			hyins[n] = 0;
-			hyidx[n++] = s - word;
-		}
-		if (!c && !strcmp(c_nb, d)) {
-			hygap[n] = 1;
-			hyidx[n++] = s - word;
-		}
 	}
+	/* cannot break the end of a word */
+	while (n > 0 && hyidx[n - 1] == lastchar)
+		n--;
 	return n;
 }