From 2433bb78cb896bcaec61616830a3f71c2458a282 Mon Sep 17 00:00:00 2001 From: Truls Becken Date: Wed, 17 Dec 2014 21:14:14 +0100 Subject: [PATCH] cut: clean up file loop --- cut.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cut.c b/cut.c index aca0083..99ec4ce 100644 --- a/cut.c +++ b/cut.c @@ -162,21 +162,19 @@ main(int argc, char *argv[]) if (!mode) usage(); - if (!argc) + + if (!argc) { cut(stdin); - else { - for (; argc--; argv++) { - if (strcmp(*argv, "-")) - fp = fopen(*argv, "r"); - else - fp = stdin; - if (!fp) { + } else for (; argc--; argv++) { + if (!strcmp(*argv, "-")) { + cut(stdin); + } else { + if (!(fp = fopen(*argv, "r"))) { weprintf("fopen %s:", *argv); continue; } cut(fp); - if (fp != stdin) - fclose(fp); + fclose(fp); } } return 0;