Commit b8ed85a3 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

bin: Adjust version display and help options.

In particular, this get rid of the ugly -? option that argp adds by
default, and we also remove -V so that we can use it for something
else later.

* src/bin/common_setup.cc, src/bin/common_setup.hh (misc_argp):
Provide support for --help/--version/--usage output, replacing argp's
default builting version.
* src/bin/genltl.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc,
src/bin/ltlcheck.cc, src/bin/ltlfilt.cc, src/bin/randltl.cc:
Call argp_parse() with ARGP_NO_HELP, and use misc_argp instead.
parent c6030df9
......@@ -19,6 +19,7 @@
#include "common_setup.hh"
#include "argp.h"
#include <cstdlib>
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 <http://gnu.org/licenses/gpl.html>.\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<char*>(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 };
......@@ -25,4 +25,6 @@
void setup(char** progname);
extern const struct argp misc_argp;
#endif // SPOT_BIN_COMMON_SETUP_HH
......@@ -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())
......
......@@ -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())
......
......@@ -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())
......
......@@ -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())
......
......@@ -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())
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment