[hackers] [lchat][PATCH] filter/indent: properly reset textwidth on newlines

From: Ivo Cicchese <tizero_AT_autistici.org>
Date: Wed, 19 Nov 2025 17:26:43 +0100

---
 Makefile        | 2 +-
 filter/indent.c | 7 +++----
 2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index bb41165..be708ad 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -31,7 +31,7 @@ lchat.o: lchat.c
 
 filter: filter/indent
 filter/indent: filter/indent.c util.o util.h
-	$(CC) $(CFLAGS) -o $_AT_ filter/indent.c util.o
+	$(CC) $(CFLAGS) -D_BSD_SOURCE -o $_AT_ filter/indent.c util.o
 
 sl_test.o: sl_test.c slackline.h
 	$(CC) $(CFLAGS) -Wno-sign-compare -c -o $_AT_ sl_test.c
diff --git a/filter/indent.c b/filter/indent.c
index c9be0e9..9360281 100644
--- a/filter/indent.c
+++ b/filter/indent.c
_AT_@ -68,11 +68,10 @@ main(void)
 		/* print indented text */
 		while ((word = strsep(&next, " ")) != NULL) {
 			tw -= strlen(word) + 1;
-			if (tw < 0 && !first) {
+			if (tw < 0 && !first)
 				fputs("\n                  ", stdout);
-				tw = cols - pw;
-				first = true;
-			}
+			if (tw < 0)
+				tw = cols - pw - strlen(word);
 
 			fputc(' ', stdout);
 			fputs(word, stdout);
-- 
2.51.2
Received on Wed Nov 19 2025 - 17:26:43 CET

This archive was generated by hypermail 2.3.0 : Wed Nov 19 2025 - 17:36:36 CET