aboutsummaryrefslogtreecommitdiffstats
path: root/iceprog
diff options
context:
space:
mode:
authorRoland Lutz <rlutz@hedmen.org>2017-06-07 19:40:54 +0200
committerRoland Lutz <rlutz@hedmen.org>2017-06-08 21:01:45 +0200
commitdbdc65b65b6862af3b7afdb4ef6c3d2a153541e5 (patch)
tree6fd78ab18e0d07a948dfc28592121a4a94f3914c /iceprog
parent1fefe355459123f7c253a4ac649ccb584a080459 (diff)
downloadicestorm-dbdc65b65b6862af3b7afdb4ef6c3d2a153541e5.tar.gz
icestorm-dbdc65b65b6862af3b7afdb4ef6c3d2a153541e5.tar.bz2
icestorm-dbdc65b65b6862af3b7afdb4ef6c3d2a153541e5.zip
iceprog: Give more information about invocation errors
Diffstat (limited to 'iceprog')
-rw-r--r--iceprog/iceprog.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c
index 5db6dc9..8f93427 100644
--- a/iceprog/iceprog.c
+++ b/iceprog/iceprog.c
@@ -32,6 +32,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -373,7 +374,10 @@ int main(int argc, char **argv)
else if (!strcmp(optarg, "B")) ifnum = INTERFACE_B;
else if (!strcmp(optarg, "C")) ifnum = INTERFACE_C;
else if (!strcmp(optarg, "D")) ifnum = INTERFACE_D;
- else help(argv[0]);
+ else
+ errx(EXIT_FAILURE,
+ "`%s' is not a valid interface (must be "
+ "`A', `B', `C', or `D')", optarg);
break;
case 'r':
read_mode = true;
@@ -413,18 +417,29 @@ int main(int argc, char **argv)
}
if (read_mode + check_mode + prog_sram + test_mode > 1)
- help(argv[0]);
+ errx(EXIT_FAILURE,
+ "options `-r'/`-R', `-c', `-S', and `-t' are mutually "
+ "exclusive");
if (bulk_erase && dont_erase)
- help(argv[0]);
+ errx(EXIT_FAILURE,
+ "options `-b' and `-n' are mutually exclusive");
- if (optind+1 != argc && !test_mode) {
- if (bulk_erase && optind == argc)
- filename = "/dev/null";
- else
- help(argv[0]);
- } else
+ if (optind + 1 == argc) {
filename = argv[optind];
+ } else if (optind != argc) {
+ warnx("too many arguments");
+ fprintf(stderr, "Try `%s --help' "
+ "for more information.\n", argv[0]);
+ return EXIT_FAILURE;
+ } else if (bulk_erase) {
+ filename = "/dev/null";
+ } else if (!test_mode) {
+ warnx("missing argument");
+ fprintf(stderr, "Try `%s --help' "
+ "for more information.\n", argv[0]);
+ return EXIT_FAILURE;
+ }
// ---------------------------------------------------------
// Initialize USB connection to FT2232H