From 703a913bd188f1338d3f2cb27428227006e916aa Mon Sep 17 00:00:00 2001 From: Roland Lutz Date: Wed, 7 Jun 2017 19:46:08 +0200 Subject: iceprog: Add option `--help' --- iceprog/iceprog.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'iceprog') diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c index 31b7a2f..7f0830c 100644 --- a/iceprog/iceprog.c +++ b/iceprog/iceprog.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -342,7 +343,6 @@ void help(const char *progname) fprintf(stderr, "This means that some data after the written data (or even before when -o is\n"); fprintf(stderr, "used) may be erased as well.\n"); fprintf(stderr, "\n"); - exit(1); } int main(int argc, char **argv) @@ -360,9 +360,15 @@ int main(int argc, char **argv) const char *devstr = NULL; enum ftdi_interface ifnum = INTERFACE_A; + static struct option long_options[] = { + {"help", no_argument, NULL, -2}, + {NULL, 0, NULL, 0} + }; + int opt; char *endptr; - while ((opt = getopt(argc, argv, "d:I:rR:o:cbnStv")) != -1) + while ((opt = getopt_long(argc, argv, "d:I:rR:o:cbnStv", + long_options, NULL)) != -1) { switch (opt) { @@ -419,8 +425,14 @@ int main(int argc, char **argv) case 'v': verbose = true; break; - default: + case -2: help(argv[0]); + return EXIT_SUCCESS; + default: + /* error message has already been printed */ + fprintf(stderr, "Try `%s --help' " + "for more information.\n", argv[0]); + return EXIT_FAILURE; } } -- cgit v1.2.3