From: Niels Möller Date: Fri, 22 Oct 2010 07:45:11 +0000 (+0200) Subject: (main): Added long options. Deleted -?, and fixed handling of bad X-Git-Tag: nettle_2.2_release_20110711~221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f19a068ded953e58994ec3251e9984b9e75bfcd2;p=thirdparty%2Fnettle.git (main): Added long options. Deleted -?, and fixed handling of bad options. Renamed -s to -q (long option --quiet). Rev: nettle/examples/eratosthenes.c:1.10 --- diff --git a/examples/eratosthenes.c b/examples/eratosthenes.c index 287aaa35..293aa0da 100644 --- a/examples/eratosthenes.c +++ b/examples/eratosthenes.c @@ -243,12 +243,23 @@ main (int argc, char **argv) int verbose = 0; int c; - while ( (c = getopt(argc, argv, "?svb:")) != -1) + enum { OPT_HELP = 300 }; + static const struct option options[] = + { + /* Name, args, flag, val */ + { "help", no_argument, NULL, OPT_HELP }, + { "verbose", no_argument, NULL, 'v' }, + { "block-size", required_argument, NULL, 'b' }, + { "quiet", required_argument, NULL, 'q' }, + { NULL, 0, NULL, 0} + }; + + while ( (c = getopt_long(argc, argv, "svb:", options, NULL)) != -1) switch (c) { - case '?': + case OPT_HELP: usage(); - return EXIT_FAILURE; + return EXIT_SUCCESS; case 'b': block_nbits = CHAR_BIT * atosize(optarg); if (!block_nbits) @@ -258,7 +269,7 @@ main (int argc, char **argv) } break; - case 's': + case 'q': silent = 1; break; @@ -266,6 +277,9 @@ main (int argc, char **argv) verbose++; break; + case '?': + return EXIT_FAILURE; + default: abort(); }