commit 71154d42aa8909854d3f292dcfc49da5c915a207
parent 5cf4544f2cd03a56ad7cf660062cc2e3a8c56461
Author: Michael Forney <mforney@mforney.org>
Date: Thu, 20 Feb 2020 21:39:28 -0800
sed: Simplify next_file slightly
Diffstat:
M | sed.c | | | 21 | +++++++++------------ |
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/sed.c b/sed.c
@@ -1119,23 +1119,20 @@ next_file(void)
clearerr(file);
else if (file)
fshut(file, "<file>");
- file = NULL;
-
- do {
- if (!*files) {
- if (first) /* given no files, default to stdin */
- file = stdin;
- /* else we've used all our files, leave file = NULL */
- } else if (!strcmp(*files, "-")) {
+ /* given no files, default to stdin */
+ file = first && !*files ? stdin : NULL;
+ first = 0;
+
+ while (!file && *files) {
+ if (!strcmp(*files, "-")) {
file = stdin;
- files++;
- } else if (!(file = fopen(*files++, "r"))) {
+ } else if (!(file = fopen(*files, "r"))) {
/* warn this file didn't open, but move on to next */
weprintf("fopen:");
ret = 1;
}
- } while (!file && *files);
- first = 0;
+ files++;
+ }
return !file;
}