From ea8d0dfcd29f9f014bbd7f8c1065d8d949b89658 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 14 Jul 2020 14:34:21 -0400 Subject: only test for blank line compression once --- more.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/more.c b/more.c index 1517c34..c7d1d32 100644 --- a/more.c +++ b/more.c @@ -381,7 +381,7 @@ static void compress_loop(FILE *f) } } -static int more_cat(const char *path, int compressempty) +static int more_cat(const char *path, void (*loop)(FILE *)) { FILE *f = stdin; if (path != NULL && strcmp(path, "-") != 0) { @@ -392,11 +392,7 @@ static int more_cat(const char *path, int compressempty) } } - if (compressempty) { - compress_loop(f); - } else { - cat_loop(f); - } + loop(f); if (f != stdin) { fclose(f); @@ -460,13 +456,15 @@ int main(int argc, char *argv[]) if (!isatty(STDOUT_FILENO)) { int ret = 0; + void (*loop)(FILE*) = compressempty ? compress_loop : cat_loop; do { - ret |= more_cat(argv[optind++], compressempty); + ret |= more_cat(argv[optind++], loop); } while (optind < argc); return ret; } openrawtty(); + global.lines--; if (optind >= argc) { -- cgit v1.2.1