[dev] [sbase] [PATCH] cut: clean up file loop

From: Truls Becken <truls.becken_AT_gmail.com>
Date: Wed, 17 Dec 2014 21:14:14 +0100

---
 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
_AT_@ -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;
-- 
1.8.3.1
Received on Wed Dec 17 2014 - 21:14:14 CET

This archive was generated by hypermail 2.3.0 : Wed Dec 17 2014 - 21:24:07 CET