bin: factor exception-handling code

* bin/common_setup.cc, bin/common_setup.hh: Define a protected_main()
function that deal with exceptions.
* bin/autcross.cc, bin/autfilt.cc, bin/dstar2tgba.cc, bin/genaut.cc,
bin/genltl.cc, bin/ltl2tgba.cc, bin/ltl2tgta.cc, bin/ltlcross.cc,
bin/ltldo.cc, bin/ltlfilt.cc, bin/ltlgrind.cc, bin/ltlsynt.cc,
bin/randaut.cc, bin/randltl.cc: Use it for all tools.
This commit is contained in:
Alexandre Duret-Lutz 2018-05-16 18:35:59 +02:00
parent fc0ed01a45
commit 645bb55622
16 changed files with 328 additions and 386 deletions

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2017 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
// Copyright (C) 2017, 2018 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -134,29 +134,22 @@ run_jobs()
int
main(int argc, char** argv)
{
strcpy(F_doc, "the name of the pattern");
strcpy(L_doc, "the argument of the pattern");
setup(argv);
return protected_main(argv, [&] {
strcpy(F_doc, "the name of the pattern");
strcpy(L_doc, "the argument of the pattern");
const argp ap = { options, parse_opt, nullptr, argp_program_doc,
children, nullptr, nullptr };
const argp ap = { options, parse_opt, nullptr, argp_program_doc,
children, nullptr, nullptr };
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, nullptr, nullptr))
exit(err);
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, nullptr, nullptr))
exit(err);
if (jobs.empty())
error(1, 0, "Nothing to do. Try '%s --help' for more information.",
program_name);
if (jobs.empty())
error(1, 0, "Nothing to do. Try '%s --help' for more information.",
program_name);
try
{
run_jobs();
}
catch (const std::runtime_error& e)
{
error(2, 0, "%s", e.what());
}
flush_cout();
return 0;
flush_cout();
return 0;
});
}