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:
parent
fc0ed01a45
commit
645bb55622
16 changed files with 328 additions and 386 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2017 Laboratoire de Recherche et Développement de
|
||||
// Copyright (C) 2017, 2018 Laboratoire de Recherche et Développement de
|
||||
// l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -822,8 +822,7 @@ print_stats_csv(const char* filename)
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&]() -> unsigned {
|
||||
const argp ap = { options, parse_opt, "[COMMANDFMT...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
|
|
@ -859,14 +858,14 @@ main(int argc, char** argv)
|
|||
{
|
||||
std::ostream& err = global_error();
|
||||
if (bogus_output)
|
||||
err << ("error: some error was detected during the above runs.\n"
|
||||
" Check file ")
|
||||
err << ("error: some error was detected during the above "
|
||||
"runs.\n Check file ")
|
||||
<< bogus_output_filename
|
||||
<< " for problematic automata.";
|
||||
else
|
||||
err << ("error: some error was detected during the above runs,\n"
|
||||
" please search for 'error:' messages in the above"
|
||||
" trace.");
|
||||
err << ("error: some error was detected during the above "
|
||||
"runs,\n please search for 'error:' messages"
|
||||
" in the above trace.");
|
||||
err << std::endl;
|
||||
end_error();
|
||||
}
|
||||
|
|
@ -915,4 +914,5 @@ main(int argc, char** argv)
|
|||
print_stats_csv(csv_output);
|
||||
|
||||
return global_error_flag;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1496,13 +1496,10 @@ namespace
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&] {
|
||||
const argp ap = { options, parse_opt, "[FILENAME[/COL]...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
try
|
||||
{
|
||||
// This will ensure that all objects stored in this struct are
|
||||
// destroyed before global variables.
|
||||
opt_t o;
|
||||
|
|
@ -1544,19 +1541,11 @@ main(int argc, char** argv)
|
|||
|
||||
// Diagnose unused -x options
|
||||
extra_options.report_unused_options();
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
catch (const std::invalid_argument& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
|
||||
if (automaton_format == Count)
|
||||
std::cout << match_count << std::endl;
|
||||
|
||||
check_cout();
|
||||
return !match_count;
|
||||
return match_count ? 0 : 1;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,3 +169,23 @@ const struct argp misc_argp = { options, parse_opt_misc,
|
|||
const struct argp misc_argp_hidden = { options_hidden, parse_opt_misc,
|
||||
nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr };
|
||||
|
||||
|
||||
int protected_main(char** progname, std::function<int()> mainfun)
|
||||
{
|
||||
try
|
||||
{
|
||||
setup(progname);
|
||||
return mainfun();
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
catch (const std::invalid_argument& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
SPOT_UNREACHABLE();
|
||||
return 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2012, 2013 Laboratoire de Recherche et Développement de
|
||||
// l'Epita (LRDE).
|
||||
// Copyright (C) 2012, 2013, 2018 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -21,8 +21,13 @@
|
|||
|
||||
#include "common_sys.hh"
|
||||
#include "progname.h"
|
||||
#include <functional>
|
||||
|
||||
void setup(char** progname);
|
||||
|
||||
extern const struct argp misc_argp;
|
||||
extern const struct argp misc_argp_hidden;
|
||||
|
||||
|
||||
// Call setup(progname) then Run mainfun() and handle exceptions.
|
||||
int protected_main(char** progname, std::function<int()> mainfun);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2013-2018 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -136,8 +136,7 @@ namespace
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&] {
|
||||
const argp ap = { options, parse_opt, "[FILENAME[/COL]...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
|
|
@ -151,18 +150,12 @@ main(int argc, char** argv)
|
|||
post.set_type(type);
|
||||
post.set_level(level);
|
||||
|
||||
try
|
||||
{
|
||||
dstar_processor processor(post);
|
||||
if (processor.run())
|
||||
return 2;
|
||||
|
||||
// Diagnose unused -x options
|
||||
extra_options.report_unused_options();
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,9 +134,9 @@ run_jobs()
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
return protected_main(argv, [&] {
|
||||
strcpy(F_doc, "the name of the pattern");
|
||||
strcpy(L_doc, "the argument of the pattern");
|
||||
setup(argv);
|
||||
|
||||
const argp ap = { options, parse_opt, nullptr, argp_program_doc,
|
||||
children, nullptr, nullptr };
|
||||
|
|
@ -148,15 +148,8 @@ main(int argc, char** argv)
|
|||
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;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,8 +286,7 @@ run_jobs()
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&] {
|
||||
const argp ap = { options, parse_opt, nullptr, argp_program_doc,
|
||||
children, nullptr, nullptr };
|
||||
|
||||
|
|
@ -298,15 +297,8 @@ main(int argc, char** argv)
|
|||
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;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,11 +158,10 @@ namespace
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
return protected_main(argv, [&] {
|
||||
// By default we name automata using the formula.
|
||||
opt_name = "%f";
|
||||
|
||||
setup(argv);
|
||||
|
||||
const argp ap = { options, parse_opt, "[FORMULA...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
|
|
@ -173,8 +172,6 @@ main(int argc, char** argv)
|
|||
|
||||
check_no_formula();
|
||||
|
||||
try
|
||||
{
|
||||
spot::translator trans(&extra_options);
|
||||
trans.set_type(type);
|
||||
trans.set_pref(pref | comp | sbacc | unambig | colored);
|
||||
|
|
@ -186,11 +183,6 @@ main(int argc, char** argv)
|
|||
|
||||
// Diagnose unused -x options
|
||||
extra_options.report_unused_options();
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2012-2017 Laboratoire de Recherche et Développement
|
||||
// Copyright (C) 2012-2018 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -224,8 +224,7 @@ namespace
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&] {
|
||||
const argp ap = { options, parse_opt, "[FORMULA...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
|
|
@ -236,8 +235,6 @@ main(int argc, char** argv)
|
|||
|
||||
check_no_formula();
|
||||
|
||||
try
|
||||
{
|
||||
spot::translator trans(&extra_options);
|
||||
trans.set_pref(pref | comp | sbacc);
|
||||
trans.set_type(type);
|
||||
|
|
@ -248,11 +245,6 @@ main(int argc, char** argv)
|
|||
return 2;
|
||||
// Diagnose unused -x options
|
||||
extra_options.report_unused_options();
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1591,8 +1591,7 @@ print_stats_json(const char* filename)
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&]() -> unsigned {
|
||||
const argp ap = { options, parse_opt, "[COMMANDFMT...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
|
|
@ -1622,18 +1621,19 @@ main(int argc, char** argv)
|
|||
{
|
||||
std::ostream& err = global_error();
|
||||
if (bogus_output)
|
||||
err << ("error: some error was detected during the above runs.\n"
|
||||
" Check file ")
|
||||
err << ("error: some error was detected during the above "
|
||||
"runs.\n Check file ")
|
||||
<< bogus_output_filename
|
||||
<< " for problematic formulas.";
|
||||
else
|
||||
err << ("error: some error was detected during the above runs,\n"
|
||||
" please search for 'error:' messages in the above"
|
||||
" trace.");
|
||||
err << ("error: some error was detected during the above "
|
||||
"runs,\n please search for 'error:' messages"
|
||||
" in the above trace.");
|
||||
err << std::endl;
|
||||
end_error();
|
||||
}
|
||||
else if (timeout_count == 0 && ignored_exec_fail == 0 && oom_count == 0)
|
||||
else if (timeout_count == 0
|
||||
&& ignored_exec_fail == 0 && oom_count == 0)
|
||||
{
|
||||
std::cerr << "No problem detected." << std::endl;
|
||||
}
|
||||
|
|
@ -1695,4 +1695,5 @@ main(int argc, char** argv)
|
|||
print_stats_csv(csv_output);
|
||||
|
||||
return global_error_flag;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
11
bin/ltldo.cc
11
bin/ltldo.cc
|
|
@ -445,8 +445,7 @@ namespace
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&] {
|
||||
const argp ap = { options, parse_opt, "[COMMANDFMT...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
|
|
@ -470,15 +469,9 @@ main(int argc, char** argv)
|
|||
post.set_type(type);
|
||||
post.set_level(level);
|
||||
|
||||
try
|
||||
{
|
||||
processor p(post);
|
||||
if (p.run())
|
||||
return 2;
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2012-2018 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -795,13 +795,10 @@ namespace
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&] {
|
||||
const argp ap = { options, parse_opt, "[FILENAME[/COL]...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
try
|
||||
{
|
||||
// This will ensure that all objects stored in this struct are
|
||||
// destroyed before global variables.
|
||||
opt_t o;
|
||||
|
|
@ -822,19 +819,10 @@ main(int argc, char** argv)
|
|||
ltl_processor processor(simpl);
|
||||
if (processor.run())
|
||||
return 2;
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
catch (const std::invalid_argument& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
|
||||
if (output_format == count_output)
|
||||
std::cout << match_count << std::endl;
|
||||
std::cout << match_count << '\n';
|
||||
flush_cout();
|
||||
|
||||
return one_match ? 0 : 1;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2014, 2015, 2016, 2017 Laboratoire de Recherche et
|
||||
// Copyright (C) 2014, 2015, 2016, 2017, 2018 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -183,10 +183,9 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
const argp ap = { options, parse_opt, "[FILENAME[/COL]...]", argp_program_doc,
|
||||
children, nullptr, nullptr };
|
||||
return protected_main(argv, [&] {
|
||||
const argp ap = { options, parse_opt, "[FILENAME[/COL]...]",
|
||||
argp_program_doc, children, nullptr, nullptr };
|
||||
|
||||
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, nullptr, nullptr))
|
||||
exit(err);
|
||||
|
|
@ -200,4 +199,5 @@ main(int argc, char* argv[])
|
|||
return 2;
|
||||
flush_cout();
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -416,7 +416,7 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
setup(argv);
|
||||
return protected_main(argv, [&] {
|
||||
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))
|
||||
|
|
@ -426,4 +426,5 @@ main(int argc, char **argv)
|
|||
spot::translator trans;
|
||||
ltl_processor processor(trans, input_aps, output_aps);
|
||||
return processor.run();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2012, 2013, 2014, 2015, 2016 Laboratoire de Recherche et
|
||||
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2018 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -276,15 +276,13 @@ parse_opt(int key, char* arg, struct argp_state* as)
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
return protected_main(argv, [&] {
|
||||
strcpy(F_doc, "seed number");
|
||||
strcpy(L_doc, "automaton number");
|
||||
setup(argv);
|
||||
|
||||
const argp ap = { options, parse_opt, "N|PROP...", argp_program_doc,
|
||||
children, nullptr, nullptr };
|
||||
|
||||
try
|
||||
{
|
||||
// This will ensure that all objects stored in this struct are
|
||||
// destroyed before global variables.
|
||||
opt_t o;
|
||||
|
|
@ -404,9 +402,6 @@ main(int argc, char** argv)
|
|||
if (opt_automata > 0 && automaton_num >= opt_automata)
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,13 +236,10 @@ parse_opt(int key, char* arg, struct argp_state* as)
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
setup(argv);
|
||||
|
||||
return protected_main(argv, [&] {
|
||||
const argp ap = { options, parse_opt, "N|PROP...", argp_program_doc,
|
||||
children, nullptr, nullptr };
|
||||
|
||||
try
|
||||
{
|
||||
// This will ensure that all objects stored in this struct are
|
||||
// destroyed before global variables.
|
||||
opt_t o;
|
||||
|
|
@ -319,16 +316,7 @@ main(int argc, char** argv)
|
|||
output_formula_checked(f, nullptr, nullptr, ++count);
|
||||
}
|
||||
};
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
catch (const std::invalid_argument& e)
|
||||
{
|
||||
error(2, 0, "%s", e.what());
|
||||
}
|
||||
|
||||
flush_cout();
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue