Skip to content
Snippets Groups Projects
Commit f19a068d authored by Niels Möller's avatar Niels Möller
Browse files

(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
parent 2f5356bd
No related branches found
No related tags found
No related merge requests found
...@@ -243,12 +243,23 @@ main (int argc, char **argv) ...@@ -243,12 +243,23 @@ main (int argc, char **argv)
int verbose = 0; int verbose = 0;
int c; 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) switch (c)
{ {
case '?': case OPT_HELP:
usage(); usage();
return EXIT_FAILURE; return EXIT_SUCCESS;
case 'b': case 'b':
block_nbits = CHAR_BIT * atosize(optarg); block_nbits = CHAR_BIT * atosize(optarg);
if (!block_nbits) if (!block_nbits)
...@@ -258,7 +269,7 @@ main (int argc, char **argv) ...@@ -258,7 +269,7 @@ main (int argc, char **argv)
} }
break; break;
case 's': case 'q':
silent = 1; silent = 1;
break; break;
...@@ -266,6 +277,9 @@ main (int argc, char **argv) ...@@ -266,6 +277,9 @@ main (int argc, char **argv)
verbose++; verbose++;
break; break;
case '?':
return EXIT_FAILURE;
default: default:
abort(); abort();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment