commit 0837556c21869b36dba23d19c0e882a82be56106
parent 0c43215d0b1981d1689105122da02b7e994e250a
Author: Ivo Cicchese <tizero@autistici.org>
Date: Thu, 20 Nov 2025 17:00:34 +0100
filter/indent: properly reset textwidth on newlines
Diffstat:
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
@@ -31,7 +31,7 @@ lchat.o: lchat.c
filter: filter/indent
filter/indent: filter/indent.c util.o util.h
- $(CC) $(CFLAGS) -o $@ filter/indent.c util.o
+ $(CC) $(CFLAGS) -D_BSD_SOURCE -o $@ filter/indent.c util.o
sl_test.o: sl_test.c slackline.h
$(CC) $(CFLAGS) -Wno-sign-compare -c -o $@ sl_test.c
diff --git a/filter/indent.c b/filter/indent.c
@@ -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);