summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-07-14 14:34:21 -0400
committerJakob Kaivo <jkk@ung.org>2020-07-14 14:34:21 -0400
commitea8d0dfcd29f9f014bbd7f8c1065d8d949b89658 (patch)
treee4b532479122dd2c23383001c8694446c2d01dae
parent5998db47316af2c9cd7dbe6f9d62420de1726d6d (diff)
only test for blank line compression once
-rw-r--r--more.c12
1 files 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) {