From 489f719dc17e1d5ec4f739132c4d3500b54ff54b Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sat, 29 Sep 2012 17:09:26 +0200 Subject: [PATCH] bin: factor the calls to set_program_name(). * src/bin/common_setup.cc, src/bin/common_setup.hh: New files. * src/bin/Makefile.am: Add them. * src/bin/genltl.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc, src/bin/ltlfilt.cc, src/bin/randltl.cc: Adjust. --- src/bin/Makefile.am | 2 ++ src/bin/common_setup.cc | 31 +++++++++++++++++++++++++++++++ src/bin/common_setup.hh | 30 ++++++++++++++++++++++++++++++ src/bin/genltl.cc | 17 ++--------------- src/bin/ltl2tgba.cc | 7 ++----- src/bin/ltl2tgta.cc | 7 ++----- src/bin/ltlfilt.cc | 7 ++----- src/bin/randltl.cc | 7 ++----- 8 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 src/bin/common_setup.cc create mode 100644 src/bin/common_setup.hh diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index d6f3d3018..00951add5 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -40,6 +40,8 @@ libcommon_a_SOURCES = \ common_range.hh \ common_r.cc \ common_r.hh \ + common_setup.cc \ + common_setup.hh \ common_sys.hh bin_PROGRAMS = ltlfilt genltl randltl ltl2tgba ltl2tgta diff --git a/src/bin/common_setup.cc b/src/bin/common_setup.cc new file mode 100644 index 000000000..7f31a4204 --- /dev/null +++ b/src/bin/common_setup.cc @@ -0,0 +1,31 @@ +// -*- coding: utf-8 -*- +// Copyright (C) 2012 Laboratoire de Recherche et Développement de +// l'Epita (LRDE). +// +// This file is part of Spot, a model checking library. +// +// Spot is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Spot is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Spot; see the file COPYING. If not, write to the Free +// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +#include "common_setup.hh" + +void +setup(char** argv) +{ + // Simplify the program name, because argp() uses it to report + // errors and display help text. + set_program_name(argv[0]); + argv[0] = const_cast(program_name); +} diff --git a/src/bin/common_setup.hh b/src/bin/common_setup.hh new file mode 100644 index 000000000..17989d6a6 --- /dev/null +++ b/src/bin/common_setup.hh @@ -0,0 +1,30 @@ +// -*- coding: utf-8 -*- +// Copyright (C) 2012 Laboratoire de Recherche et Développement de +// l'Epita (LRDE). +// +// This file is part of Spot, a model checking library. +// +// Spot is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Spot is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Spot; see the file COPYING. If not, write to the Free +// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +#ifndef SPOT_BIN_COMMON_SETUP_HH +#define SPOT_BIN_COMMON_SETUP_HH + +#include "common_sys.hh" +#include "progname.h" + +void setup(char** progname); + +#endif // SPOT_BIN_COMMON_SETUP_HH diff --git a/src/bin/genltl.cc b/src/bin/genltl.cc index df2024f19..a6b02420c 100644 --- a/src/bin/genltl.cc +++ b/src/bin/genltl.cc @@ -74,10 +74,10 @@ #include #include #include -#include "progname.h" #include "error.h" #include +#include "common_setup.hh" #include "common_output.hh" #include "common_range.hh" @@ -201,16 +201,6 @@ const struct argp_child children[] = { 0, 0, 0, 0 } }; -// static int -// to_int(const char* s) -// { -// char* endptr; -// int res = strtol(s, &endptr, 10); -// if (*endptr) -// error(2, 0, "failed to parse '%s' as an integer.", s); -// return res; -// } - static void enqueue_job(int pattern, const char* range_str) { @@ -858,10 +848,7 @@ run_jobs() int main(int argc, char** argv) { - set_program_name(argv[0]); - // Simplify the program name, because argp() uses it to report errors - // and display help text. - argv[0] = const_cast(program_name); + setup(argv); const argp ap = { options, parse_opt, 0, argp_program_doc, children, 0, 0 }; diff --git a/src/bin/ltl2tgba.cc b/src/bin/ltl2tgba.cc index 2441a17f8..29583885b 100644 --- a/src/bin/ltl2tgba.cc +++ b/src/bin/ltl2tgba.cc @@ -25,9 +25,9 @@ #include #include -#include "progname.h" #include "error.h" +#include "common_setup.hh" #include "common_r.hh" #include "common_cout.hh" #include "common_finput.hh" @@ -246,10 +246,7 @@ namespace int main(int argc, char** argv) { - set_program_name(argv[0]); - // Simplify the program name, because argp() uses it to report errors - // and display help text. - argv[0] = const_cast(program_name); + setup(argv); const argp ap = { options, parse_opt, "[FORMULA...]", argp_program_doc, children, 0, 0 }; diff --git a/src/bin/ltl2tgta.cc b/src/bin/ltl2tgta.cc index f27dae450..482417483 100644 --- a/src/bin/ltl2tgta.cc +++ b/src/bin/ltl2tgta.cc @@ -26,9 +26,9 @@ #include #include -#include "progname.h" #include "error.h" +#include "common_setup.hh" #include "common_r.hh" #include "common_cout.hh" #include "common_finput.hh" @@ -251,10 +251,7 @@ namespace int main(int argc, char** argv) { - set_program_name(argv[0]); - // Simplify the program name, because argp() uses it to report errors - // and display help text. - argv[0] = const_cast(program_name); + setup(argv); const argp ap = { options, parse_opt, "[FORMULA...]", argp_program_doc, children, 0, 0 }; diff --git a/src/bin/ltlfilt.cc b/src/bin/ltlfilt.cc index 0f4a3edff..e2c051d7d 100644 --- a/src/bin/ltlfilt.cc +++ b/src/bin/ltlfilt.cc @@ -27,9 +27,9 @@ #include #include #include -#include "progname.h" #include "error.h" +#include "common_setup.hh" #include "common_finput.hh" #include "common_output.hh" #include "common_cout.hh" @@ -501,10 +501,7 @@ namespace int main(int argc, char** argv) { - set_program_name(argv[0]); - // Simplify the program name, because argp() uses it to report errors - // and display help text. - argv[0] = const_cast(program_name); + setup(argv); const argp ap = { options, parse_opt, "[FILENAME...]", argp_program_doc, children, 0, 0 }; diff --git a/src/bin/randltl.cc b/src/bin/randltl.cc index 7aa9b1e78..85711662e 100644 --- a/src/bin/randltl.cc +++ b/src/bin/randltl.cc @@ -26,9 +26,9 @@ #include #include #include -#include "progname.h" #include "error.h" +#include "common_setup.hh" #include "common_output.hh" #include "common_range.hh" #include "common_r.hh" @@ -252,10 +252,7 @@ parse_opt(int key, char* arg, struct argp_state*) int main(int argc, char** argv) { - set_program_name(argv[0]); - // Simplify the program name, because argp() uses it to report errors - // and display help text. - argv[0] = const_cast(program_name); + setup(argv); const argp ap = { options, parse_opt, "PROP...", argp_program_doc, children, 0, 0 };