and fail miserably if error messages for an option depends on another one :)
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- cli_classic.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/cli_classic.c b/cli_classic.c index 7ce74e5..9693c43 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -178,22 +178,23 @@ int main(int argc, char *argv[]) int ret = 0;
static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh"; - static const struct option long_options[] = { - {"read", 1, NULL, 'r'}, - {"write", 1, NULL, 'w'}, - {"erase", 0, NULL, 'E'}, - {"verify", 1, NULL, 'v'}, - {"noverify", 0, NULL, 'n'}, - {"chip", 1, NULL, 'c'}, - {"verbose", 0, NULL, 'V'}, - {"force", 0, NULL, 'f'}, - {"layout", 1, NULL, 'l'}, - {"image", 1, NULL, 'i'}, - {"list-supported", 0, NULL, 'L'}, - {"list-supported-wiki", 0, NULL, 'z'}, - {"programmer", 1, NULL, 'p'}, - {"help", 0, NULL, 'h'}, - {"version", 0, NULL, 'R'}, + static int blub = 0; + static struct option long_options[] = { + {"read", 1, &blub, 'r'}, + {"write", 1, &blub, 'w'}, + {"erase", 0, &blub, 'E'}, + {"verify", 1, &blub, 'v'}, + {"noverify", 0, &blub, 'n'}, + {"chip", 1, &blub, 'c'}, + {"verbose", 0, &blub, 'V'}, + {"force", 0, &blub, 'f'}, + {"layout", 1, &blub, 'l'}, + {"image", 1, &blub, 'i'}, + {"list-supported", 0, &blub, 'L'}, + {"list-supported-wiki", 0, &blub, 'z'}, + {"programmer", 1, &blub, 'p'}, + {"help", 0, &blub, 'h'}, + {"version", 0, &blub, 'R'}, {NULL, 0, NULL, 0}, };
@@ -213,6 +214,13 @@ int main(int argc, char *argv[]) */ while ((opt = getopt_long(argc, argv, optstring, long_options, &option_index)) != EOF) { + int long_opt = 0; + if (opt == 0) { + long_opt = 1; + opt = long_options[option_index].val; + } + printf("long_opt = %d\n", long_opt); + switch (opt) { case 'r': if (++operation_specified > 1) { @@ -240,8 +248,9 @@ int main(int argc, char *argv[]) cli_classic_abort_usage(); } if (dont_verify_it) { - fprintf(stderr, "--verify and --noverify are" - "mutually exclusive. Aborting.\n"); + fprintf(stderr, "%s and --noverify are " + "mutually exclusive. Aborting.\n", + long_opt ? "--verify" : "-v"); cli_classic_abort_usage(); } filename = strdup(optarg); @@ -249,8 +258,9 @@ int main(int argc, char *argv[]) break; case 'n': if (verify_it) { - fprintf(stderr, "--verify and --noverify are" - "mutually exclusive. Aborting.\n"); + fprintf(stderr, "--verify and %s are " + "mutually exclusive. Aborting.\n", + long_opt ? "--noverify" : "-n"); cli_classic_abort_usage(); } dont_verify_it = 1;