From 75f16e09b7cdc6f7323bc095c4401c9e5baae065 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 14 Jul 2020 12:20:06 -0400 Subject: carry newline compression between files --- more.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/more.c b/more.c index a27f740..d546b9b 100644 --- a/more.c +++ b/more.c @@ -375,14 +375,18 @@ static void cat_loop(FILE *f) static void compress_loop(FILE *f) { + static int nl = 0; int c = 0; - int nl = 0; + while ((c = fgetc(f)) != EOF) { if (c == '\n') { - if (nl) { + if (nl == 2) { continue; + } else if (nl == 1) { + nl = 2; + } else { + nl = 1; } - nl = 1; } else { nl = 0; } -- cgit v1.2.1