aboutsummaryrefslogtreecommitdiffstats
path: root/iceprog
diff options
context:
space:
mode:
authorRoland Lutz <rlutz@hedmen.org>2017-06-07 19:46:08 +0200
committerRoland Lutz <rlutz@hedmen.org>2017-07-02 14:49:37 +0200
commit703a913bd188f1338d3f2cb27428227006e916aa (patch)
treeeb49389414c37ebb03fca57b887f374245af4a0b /iceprog
parent86af65cc32f2902e1f8b3bb5d8f2ce0412a94217 (diff)
downloadicestorm-703a913bd188f1338d3f2cb27428227006e916aa.tar.gz
icestorm-703a913bd188f1338d3f2cb27428227006e916aa.tar.bz2
icestorm-703a913bd188f1338d3f2cb27428227006e916aa.zip
iceprog: Add option `--help'
Diffstat (limited to 'iceprog')
-rw-r--r--iceprog/iceprog.c18
1 files changed, 15 insertions, 3 deletions
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 <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <getopt.h>
#include <errno.h>
#include <err.h>
#include <sys/types.h>
@@ -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;
}
}