cut: clean up file loop

This commit is contained in:
Truls Becken 2014-12-17 21:14:14 +01:00 committed by sin
parent f08d798f77
commit 2433bb78cb

16
cut.c
View File

@ -162,20 +162,18 @@ main(int argc, char *argv[])
if (!mode) if (!mode)
usage(); usage();
if (!argc)
if (!argc) {
cut(stdin); cut(stdin);
else { } else for (; argc--; argv++) {
for (; argc--; argv++) { if (!strcmp(*argv, "-")) {
if (strcmp(*argv, "-")) cut(stdin);
fp = fopen(*argv, "r"); } else {
else if (!(fp = fopen(*argv, "r"))) {
fp = stdin;
if (!fp) {
weprintf("fopen %s:", *argv); weprintf("fopen %s:", *argv);
continue; continue;
} }
cut(fp); cut(fp);
if (fp != stdin)
fclose(fp); fclose(fp);
} }
} }