Commit e9ded494 authored by Niels Möller's avatar Niels Möller
Browse files

* examples/rsa-keygen.c (main): Added long options. Deleted -?,

and fixed handling of bad options.

* examples/next-prime.c (main): Deleted -?, and fixed handling of
bad options.
* examples/random-prime.c (main): Likewise.

Rev: nettle/examples/random-prime.c:1.4
Rev: nettle/examples/rsa-keygen.c:1.3
parent ff0c3e27
...@@ -65,16 +65,17 @@ main(int argc, char **argv) ...@@ -65,16 +65,17 @@ main(int argc, char **argv)
clock_t start; clock_t start;
clock_t end; clock_t end;
enum { OPT_HELP = 300 };
static const struct option options[] = static const struct option options[] =
{ {
/* Name, args, flag, val */ /* Name, args, flag, val */
{ "help", no_argument, NULL, '?' }, { "help", no_argument, NULL, OPT_HELP },
{ "verbose", no_argument, NULL, 'v' }, { "verbose", no_argument, NULL, 'v' },
{ "random", required_argument, NULL, 'r' }, { "random", required_argument, NULL, 'r' },
{ NULL, 0, NULL, 0} { NULL, 0, NULL, 0}
}; };
while ( (c = getopt_long(argc, argv, "v?r:", options, NULL)) != -1) while ( (c = getopt_long(argc, argv, "vr:", options, NULL)) != -1)
switch (c) switch (c)
{ {
case 'v': case 'v':
...@@ -83,8 +84,10 @@ main(int argc, char **argv) ...@@ -83,8 +84,10 @@ main(int argc, char **argv)
case 'r': case 'r':
random_file = optarg; random_file = optarg;
break; break;
case '?': case OPT_HELP:
usage(); usage();
return EXIT_SUCCESS;
case '?':
return EXIT_FAILURE; return EXIT_FAILURE;
default: default:
abort(); abort();
......
...@@ -51,7 +51,6 @@ progress(void *ctx, int c) ...@@ -51,7 +51,6 @@ progress(void *ctx, int c)
fputc(c, stderr); fputc(c, stderr);
} }
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
...@@ -67,7 +66,16 @@ main(int argc, char **argv) ...@@ -67,7 +66,16 @@ main(int argc, char **argv)
struct nettle_buffer pub_buffer; struct nettle_buffer pub_buffer;
struct nettle_buffer priv_buffer; struct nettle_buffer priv_buffer;
while ( (c = getopt(argc, argv, "o:r:")) != -1) enum { OPT_HELP = 300 };
static const struct option options[] =
{
/* Name, args, flag, val */
{ "help", no_argument, NULL, OPT_HELP },
{ "random", required_argument, NULL, 'r' },
{ NULL, 0, NULL, 0}
};
while ( (c = getopt_long(argc, argv, "o:r:", options, NULL)) != -1)
switch (c) switch (c)
{ {
case 'o': case 'o':
...@@ -77,14 +85,14 @@ main(int argc, char **argv) ...@@ -77,14 +85,14 @@ main(int argc, char **argv)
case 'r': case 'r':
random_name = optarg; random_name = optarg;
break; break;
case OPT_HELP:
printf("FIXME: Usage information.\n");
return EXIT_SUCCESS;
case '?': case '?':
if (isprint (optopt))
werror("Unknown option `-%c'.\n", optopt);
else
werror("Unknown option character `\\x%x'.\n",
optopt);
return EXIT_FAILURE; return EXIT_FAILURE;
default: default:
abort(); abort();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment