Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: condense code for parsing command lin...
details: https://anonhg.NetBSD.org/src/rev/9b09b06396e0
branches: trunk
changeset: 990549:9b09b06396e0
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Oct 30 09:51:22 2021 +0000
description:
indent: condense code for parsing command line arguments
Previously, the cascade of 'if' statements suggested that there were 6
different cases to be handled when in reality there are only 3: no
arguments, 1 argument, 2 arguments. Let the code express this directly.
No functional change.
diffstat:
usr.bin/indent/indent.c | 23 +++++++++--------------
1 files changed, 9 insertions(+), 14 deletions(-)
diffs (57 lines):
diff -r 54ec49ca0129 -r 9b09b06396e0 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sat Oct 30 09:42:31 2021 +0000
+++ b/usr.bin/indent/indent.c Sat Oct 30 09:51:22 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.180 2021/10/30 09:42:31 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.181 2021/10/30 09:51:22 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.180 2021/10/30 09:42:31 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.181 2021/10/30 09:51:22 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -545,31 +545,26 @@
} else if (input == NULL) {
in_name = arg;
- input = fopen(in_name, "r");
- if (input == NULL)
+ if ((input = fopen(in_name, "r")) == NULL)
err(1, "%s", in_name);
} else if (output == NULL) {
out_name = arg;
if (strcmp(in_name, out_name) == 0)
errx(1, "input and output files must be different");
- output = fopen(out_name, "w");
- if (output == NULL)
+ if ((output = fopen(out_name, "w")) == NULL)
err(1, "%s", out_name);
} else
errx(1, "too many arguments: %s", arg);
}
- if (input == NULL)
+ if (input == NULL) {
input = stdin;
- if (output == NULL) {
- if (input == stdin)
- output = stdout;
- else {
- out_name = in_name;
- bakcopy();
- }
+ output = stdout;
+ } else if (output == NULL) {
+ out_name = in_name;
+ bakcopy();
}
if (opt.comment_column <= 1)
Home |
Main Index |
Thread Index |
Old Index