Module Name: src Committed By: rillig Date: Sat Oct 30 09:51:23 UTC 2021
Modified Files: src/usr.bin/indent: indent.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.180 -r1.181 src/usr.bin/indent/indent.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.180 src/usr.bin/indent/indent.c:1.181 --- src/usr.bin/indent/indent.c:1.180 Sat Oct 30 09:42:31 2021 +++ src/usr.bin/indent/indent.c Sat Oct 30 09:51:22 2021 @@ -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 @@ static char sccsid[] = "@(#)indent.c 5.1 #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 @@ main_parse_command_line(int argc, char * } 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)