diff --git a/src/bin/common_setup.cc b/src/bin/common_setup.cc index 5004aaed2..2b36080e8 100644 --- a/src/bin/common_setup.cc +++ b/src/bin/common_setup.cc @@ -19,6 +19,7 @@ #include "common_setup.hh" #include "argp.h" +#include const char* argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; @@ -29,9 +30,10 @@ display_version(FILE *stream, struct argp_state*) fputs(" (" PACKAGE_STRING ")\n\ \n\ Copyright (C) 2012 Laboratoire de Recherche et Développement de l'Epita.\n\ -This is free software; see the source for copying conditions. There is NO\n\ -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,\n\ -to the extent permitted by law.\n", stream); +License GPLv3+: \ +GNU GPL version 3 or later .\n\ +This is free software: you are free to change and redistribute it.\n\ +There is NO WARRANTY, to the extent permitted by law.\n", stream); } void @@ -43,4 +45,49 @@ setup(char** argv) argv[0] = const_cast(program_name); argp_program_version_hook = display_version; + + argp_err_exit_status = 2; } + + +// argp's default behavior of offering -? for --help is just too silly. +// I mean, come on, why not also add -* to Darwinise more shell users? +// We disable this option as well as -V (because --version don't need +// a short version). +#define OPT_VERSION 1 +#define OPT_HELP 2 +#define OPT_USAGE 3 +static const argp_option options[] = + { + { "version", OPT_VERSION, 0, 0, "print program version", -1 }, + { "help", OPT_HELP, 0, 0, "print this help", -1 }, + // We support this option just in case, but we don't advertise it. + { "usage", OPT_USAGE, 0, OPTION_HIDDEN, "show short usage", -1 }, + { 0, 0, 0, 0, 0, 0 } + }; + +static int +parse_opt_misc(int key, char*, struct argp_state* state) +{ + // This switch is alphabetically-ordered. + switch (key) + { + case OPT_VERSION: + display_version(state->out_stream, state); + exit(0); + break; + case OPT_HELP: + argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP); + break; + case OPT_USAGE: + argp_state_help(state, state->out_stream, + ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK); + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + + +const struct argp misc_argp = { options, parse_opt_misc, 0, 0, 0, 0, 0 }; diff --git a/src/bin/common_setup.hh b/src/bin/common_setup.hh index 3d0613803..50ef32822 100644 --- a/src/bin/common_setup.hh +++ b/src/bin/common_setup.hh @@ -25,4 +25,6 @@ void setup(char** progname); +extern const struct argp misc_argp; + #endif // SPOT_BIN_COMMON_SETUP_HH diff --git a/src/bin/genltl.cc b/src/bin/genltl.cc index e6db3e198..fd7b7c9fb 100644 --- a/src/bin/genltl.cc +++ b/src/bin/genltl.cc @@ -185,6 +185,7 @@ static jobs_t jobs; const struct argp_child children[] = { { &output_argp, 0, 0, -20 }, + { &misc_argp, 0, 0, -1 }, { 0, 0, 0, 0 } }; @@ -840,7 +841,7 @@ main(int argc, char** argv) const argp ap = { options, parse_opt, 0, argp_program_doc, children, 0, 0 }; - if (int err = argp_parse(&ap, argc, argv, 0, 0, 0)) + if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, 0, 0)) exit(err); if (jobs.empty()) diff --git a/src/bin/ltl2tgba.cc b/src/bin/ltl2tgba.cc index 73df7189b..252e344e5 100644 --- a/src/bin/ltl2tgba.cc +++ b/src/bin/ltl2tgba.cc @@ -96,6 +96,7 @@ const struct argp_child children[] = { { &finput_argp, 0, 0, 1 }, { &post_argp, 0, 0, 20 }, + { &misc_argp, 0, 0, -1 }, { 0, 0, 0, 0 } }; @@ -239,7 +240,7 @@ main(int argc, char** argv) const argp ap = { options, parse_opt, "[FORMULA...]", argp_program_doc, children, 0, 0 }; - if (int err = argp_parse(&ap, argc, argv, 0, 0, 0)) + if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, 0, 0)) exit(err); if (jobs.empty()) diff --git a/src/bin/ltl2tgta.cc b/src/bin/ltl2tgta.cc index 4e0ecd87e..cdf7a42fb 100644 --- a/src/bin/ltl2tgta.cc +++ b/src/bin/ltl2tgta.cc @@ -85,6 +85,7 @@ const struct argp_child children[] = { { &finput_argp, 0, 0, 1 }, { &post_argp, 0, 0, 20 }, + { &misc_argp, 0, 0, -1 }, { 0, 0, 0, 0 } }; @@ -244,7 +245,7 @@ main(int argc, char** argv) const argp ap = { options, parse_opt, "[FORMULA...]", argp_program_doc, children, 0, 0 }; - if (int err = argp_parse(&ap, argc, argv, 0, 0, 0)) + if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, 0, 0)) exit(err); if (jobs.empty()) diff --git a/src/bin/ltlcheck.cc b/src/bin/ltlcheck.cc index cfe2eea7f..35ab365f5 100644 --- a/src/bin/ltlcheck.cc +++ b/src/bin/ltlcheck.cc @@ -130,6 +130,7 @@ static const argp_option options[] = const struct argp_child children[] = { { &finput_argp, 0, 0, 1 }, + { &misc_argp, 0, 0, -1 }, { 0, 0, 0, 0 } }; @@ -1057,7 +1058,7 @@ main(int argc, char** argv) const argp ap = { options, parse_opt, "[COMMANDFMT...]", argp_program_doc, children, 0, 0 }; - if (int err = argp_parse(&ap, argc, argv, 0, 0, 0)) + if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, 0, 0)) exit(err); if (jobs.empty()) diff --git a/src/bin/ltlfilt.cc b/src/bin/ltlfilt.cc index e691b15da..abe3bede4 100644 --- a/src/bin/ltlfilt.cc +++ b/src/bin/ltlfilt.cc @@ -148,6 +148,7 @@ const struct argp_child children[] = { { &finput_argp, 0, 0, 1 }, { &output_argp, 0, 0, -20 }, + { &misc_argp, 0, 0, -1 }, { 0, 0, 0, 0 } }; @@ -500,7 +501,7 @@ main(int argc, char** argv) const argp ap = { options, parse_opt, "[FILENAME...]", argp_program_doc, children, 0, 0 }; - if (int err = argp_parse(&ap, argc, argv, 0, 0, 0)) + if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, 0, 0)) exit(err); if (jobs.empty()) diff --git a/src/bin/randltl.cc b/src/bin/randltl.cc index 46a214bdc..35fe9d1d0 100644 --- a/src/bin/randltl.cc +++ b/src/bin/randltl.cc @@ -115,6 +115,7 @@ static const argp_option options[] = const struct argp_child children[] = { { &output_argp, 0, 0, -20 }, + { &misc_argp, 0, 0, -1 }, { 0, 0, 0, 0 } }; @@ -244,7 +245,7 @@ main(int argc, char** argv) const argp ap = { options, parse_opt, "PROP...", argp_program_doc, children, 0, 0 }; - if (int err = argp_parse(&ap, argc, argv, 0, 0, 0)) + if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, 0, 0)) exit(err); spot::ltl::random_formula* rf = 0;