From 601185b43da638b1c74153deae01dbd518680889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 2 Aug 2014 11:12:21 -0400 Subject: Unify parse_argv style getopt is usually good at printing out a nice error message when commandline options are invalid. It distinguishes between an unknown option and a known option with a missing arg. It is better to let it do its job and not use opterr=0 unless we actually want to suppress messages. So remove opterr=0 in the few places where it wasn't really useful. When an error in options is encountered, we should not print a lengthy help() and overwhelm the user, when we know precisely what is wrong with the commandline. In addition, since help() prints to stdout, it should not be used except when requested with -h or --help. Also, simplify things here and there. --- src/analyze/analyze.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src/analyze') diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 888f6b7a6..d0bf01468 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1255,10 +1255,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - opterr = 0; - - while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) { - + while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) switch (c) { case 'h': @@ -1323,17 +1320,11 @@ static int parse_argv(int argc, char *argv[]) { break; case '?': - log_error("Unknown option %s.", argv[optind-1]); - return -EINVAL; - - case ':': - log_error("Missing argument to %s.", argv[optind-1]); return -EINVAL; default: assert_not_reached("Unhandled option code."); } - } return 1; /* work to do */ } -- cgit v1.2.3