ltlfilt, genltl: factor the common output options.
* src/bin/common_output.cc, src/bin/common_output.hh: New file with the common output code. * src/bin/Makefile.am: Add them. * src/bin/genltl.cc, src/bin/ltlfilt.cc: Simplify, using argp's children parser, and calling output_formula().
This commit is contained in:
parent
267183bda7
commit
e0873cc7d6
5 changed files with 155 additions and 86 deletions
|
|
@ -25,5 +25,7 @@ AM_CXXFLAGS = $(WARNING_CXXFLAGS)
|
||||||
LDADD = $(top_builddir)/src/libspot.la $(top_builddir)/lib/libgnu.a
|
LDADD = $(top_builddir)/src/libspot.la $(top_builddir)/lib/libgnu.a
|
||||||
|
|
||||||
bin_PROGRAMS = ltlfilt genltl
|
bin_PROGRAMS = ltlfilt genltl
|
||||||
ltlfilt_SOURCES = ltlfilt.cc
|
ltlfilt_SOURCES = ltlfilt.cc common_output.cc
|
||||||
genltl_SOURCES = genltl.cc
|
genltl_SOURCES = genltl.cc common_output.cc
|
||||||
|
|
||||||
|
noinst_HEADERS = common_output.hh
|
||||||
|
|
|
||||||
82
src/bin/common_output.cc
Normal file
82
src/bin/common_output.cc
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
// -*- 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_output.hh"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define OPT_SPOT 1
|
||||||
|
|
||||||
|
output_format_t output_format = spot_output;
|
||||||
|
bool full_parenth = false;
|
||||||
|
|
||||||
|
static const argp_option options[] =
|
||||||
|
{
|
||||||
|
{ "full-parentheses", 'p', 0, 0,
|
||||||
|
"output fully-parenthesized formulas", -20 },
|
||||||
|
{ "spin", 's', 0, 0, "output in Spin's syntax", -20 },
|
||||||
|
{ "spot", OPT_SPOT, 0, 0, "output in Spot's syntax (default)", -20 },
|
||||||
|
{ "utf8", '8', 0, 0, "output using UTF-8 characters", -20 },
|
||||||
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct argp output_argp = { options, parse_opt_output, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
int
|
||||||
|
parse_opt_output(int key, char*, struct argp_state*)
|
||||||
|
{
|
||||||
|
// This switch is alphabetically-ordered.
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case '8':
|
||||||
|
output_format = utf8_output;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
full_parenth = true;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
output_format = spin_output;
|
||||||
|
break;
|
||||||
|
case OPT_SPOT:
|
||||||
|
output_format = spot_output;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return ARGP_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
output_formula(const spot::ltl::formula* f)
|
||||||
|
{
|
||||||
|
switch (output_format)
|
||||||
|
{
|
||||||
|
case spot_output:
|
||||||
|
spot::ltl::to_string(f, std::cout, full_parenth);
|
||||||
|
break;
|
||||||
|
case spin_output:
|
||||||
|
spot::ltl::to_spin_string(f, std::cout, full_parenth);
|
||||||
|
break;
|
||||||
|
case utf8_output:
|
||||||
|
spot::ltl::to_utf8_string(f, std::cout, full_parenth);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::cout << "\n";
|
||||||
|
}
|
||||||
41
src/bin/common_output.hh
Normal file
41
src/bin/common_output.hh
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
// -*- 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_OUTPUT_HH
|
||||||
|
#define SPOT_BIN_COMMON_OUTPUT_HH
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <argp.h>
|
||||||
|
#include "ltlvisit/tostring.hh"
|
||||||
|
|
||||||
|
enum output_format_t { spot_output, spin_output, utf8_output };
|
||||||
|
extern output_format_t output_format;
|
||||||
|
extern bool full_parenth;
|
||||||
|
|
||||||
|
extern const struct argp output_argp;
|
||||||
|
|
||||||
|
int parse_opt_output(int key, char* arg, struct argp_state* state);
|
||||||
|
void output_formula(const spot::ltl::formula* f);
|
||||||
|
|
||||||
|
#endif // SPOT_BIN_COMMON_OUTPUT_HH
|
||||||
|
|
@ -80,8 +80,9 @@
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "misc/_config.h"
|
#include "common_output.hh"
|
||||||
|
|
||||||
|
#include "misc/_config.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
@ -90,7 +91,6 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "ltlast/allnodes.hh"
|
#include "ltlast/allnodes.hh"
|
||||||
#include "ltlvisit/tostring.hh"
|
|
||||||
#include "ltlenv/defaultenv.hh"
|
#include "ltlenv/defaultenv.hh"
|
||||||
|
|
||||||
using namespace spot;
|
using namespace spot;
|
||||||
|
|
@ -121,8 +121,6 @@ Translation. LNCS 2102\n\
|
||||||
[rv] K. Rozier and M. Vardi (Spin'07): LTL Satisfiability Checking. \
|
[rv] K. Rozier and M. Vardi (Spin'07): LTL Satisfiability Checking. \
|
||||||
LNCS 4595.\n";
|
LNCS 4595.\n";
|
||||||
|
|
||||||
#define OPT_SPOT 1
|
|
||||||
|
|
||||||
#define OPT_AND_F 2
|
#define OPT_AND_F 2
|
||||||
#define OPT_AND_FG 3
|
#define OPT_AND_FG 3
|
||||||
#define OPT_AND_GF 4
|
#define OPT_AND_GF 4
|
||||||
|
|
@ -193,13 +191,7 @@ static const argp_option options[] =
|
||||||
OPT_ALIAS(gh-u2),
|
OPT_ALIAS(gh-u2),
|
||||||
OPT_ALIAS(go-phi),
|
OPT_ALIAS(go-phi),
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
{ 0, 0, 0, 0, "Output options:", 6 },
|
{ 0, 0, 0, 0, "Output options:", -20 },
|
||||||
{ "full-parentheses", 'p', 0, 0,
|
|
||||||
"output fully-parenthesized formulas", 0 },
|
|
||||||
{ "spin", 's', 0, 0, "output in Spin's syntax", 0 },
|
|
||||||
{ "spot", OPT_SPOT, 0, 0, "output in Spot's syntax (default)", 0 },
|
|
||||||
{ "utf8", '8', 0, 0, "output using UTF-8 characters", 0 },
|
|
||||||
/**************************************************/
|
|
||||||
{ 0, 0, 0, 0, "Miscellaneous options:", -1 },
|
{ 0, 0, 0, 0, "Miscellaneous options:", -1 },
|
||||||
{ 0, 0, 0, 0, 0, 0 }
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
@ -214,9 +206,12 @@ struct job
|
||||||
typedef std::vector<job> jobs_t;
|
typedef std::vector<job> jobs_t;
|
||||||
static jobs_t jobs;
|
static jobs_t jobs;
|
||||||
|
|
||||||
enum output_format_t { spot_output, spin_output, utf8_output };
|
|
||||||
static output_format_t output_format = spot_output;
|
const struct argp_child children[] =
|
||||||
static bool full_parenth = false;
|
{
|
||||||
|
{ &output_argp, 0, 0, -20 },
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
// static int
|
// static int
|
||||||
// to_int(const char* s)
|
// to_int(const char* s)
|
||||||
|
|
@ -275,21 +270,11 @@ enqueue_job(int pattern, const char* range)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
parse_opt(int key, char* arg, struct argp_state* state)
|
parse_opt(int key, char* arg, struct argp_state*)
|
||||||
{
|
{
|
||||||
(void) state;
|
|
||||||
// This switch is alphabetically-ordered.
|
// This switch is alphabetically-ordered.
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case '8':
|
|
||||||
output_format = utf8_output;
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
full_parenth = true;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
output_format = spin_output;
|
|
||||||
break;
|
|
||||||
case OPT_AND_F:
|
case OPT_AND_F:
|
||||||
case OPT_AND_FG:
|
case OPT_AND_FG:
|
||||||
case OPT_AND_GF:
|
case OPT_AND_GF:
|
||||||
|
|
@ -310,9 +295,6 @@ parse_opt(int key, char* arg, struct argp_state* state)
|
||||||
case OPT_RV_COUNTER_LINEAR:
|
case OPT_RV_COUNTER_LINEAR:
|
||||||
enqueue_job(key, arg);
|
enqueue_job(key, arg);
|
||||||
break;
|
break;
|
||||||
case OPT_SPOT:
|
|
||||||
output_format = spot_output;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return ARGP_ERR_UNKNOWN;
|
return ARGP_ERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
@ -888,19 +870,7 @@ output_pattern(int pattern, int n)
|
||||||
error(100, 0, "internal error: pattern not implemented");
|
error(100, 0, "internal error: pattern not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (output_format)
|
output_formula(f);
|
||||||
{
|
|
||||||
case spot_output:
|
|
||||||
spot::ltl::to_string(f, std::cout, full_parenth);
|
|
||||||
break;
|
|
||||||
case spin_output:
|
|
||||||
spot::ltl::to_spin_string(f, std::cout, full_parenth);
|
|
||||||
break;
|
|
||||||
case utf8_output:
|
|
||||||
spot::ltl::to_utf8_string(f, std::cout, full_parenth);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::cout << "\n";
|
|
||||||
f->destroy();
|
f->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -931,7 +901,8 @@ main(int argc, char** argv)
|
||||||
// and display help text.
|
// and display help text.
|
||||||
argv[0] = const_cast<char*>(program_name);
|
argv[0] = const_cast<char*>(program_name);
|
||||||
|
|
||||||
const argp ap = { options, parse_opt, 0, argp_program_doc, 0, 0, 0 };
|
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, 0, 0, 0))
|
||||||
exit(err);
|
exit(err);
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,11 @@
|
||||||
#include "progname.h"
|
#include "progname.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
|
||||||
|
#include "common_output.hh"
|
||||||
|
|
||||||
#include "misc/_config.h"
|
#include "misc/_config.h"
|
||||||
#include "misc/hash.hh"
|
#include "misc/hash.hh"
|
||||||
#include "ltlparse/public.hh"
|
#include "ltlparse/public.hh"
|
||||||
#include "ltlvisit/tostring.hh"
|
|
||||||
#include "ltlvisit/simplify.hh"
|
#include "ltlvisit/simplify.hh"
|
||||||
#include "ltlvisit/length.hh"
|
#include "ltlvisit/length.hh"
|
||||||
#include "ltlast/unop.hh"
|
#include "ltlast/unop.hh"
|
||||||
|
|
@ -61,7 +62,6 @@ Exit status:\n\
|
||||||
1 if no formula were output (no match)\n\
|
1 if no formula were output (no match)\n\
|
||||||
2 if any error has been reported";
|
2 if any error has been reported";
|
||||||
|
|
||||||
#define OPT_SPOT 1
|
|
||||||
#define OPT_SKIP_ERRORS 2
|
#define OPT_SKIP_ERRORS 2
|
||||||
#define OPT_DROP_ERRORS 3
|
#define OPT_DROP_ERRORS 3
|
||||||
#define OPT_NNF 4
|
#define OPT_NNF 4
|
||||||
|
|
@ -154,20 +154,21 @@ static const argp_option options[] =
|
||||||
"match formulas implying FORMULA", 0 },
|
"match formulas implying FORMULA", 0 },
|
||||||
{ "equivalent-to", OPT_EQUIVALENT_TO, "FORMULA", 0,
|
{ "equivalent-to", OPT_EQUIVALENT_TO, "FORMULA", 0,
|
||||||
"match formulas equivalent to FORMULA", 0 },
|
"match formulas equivalent to FORMULA", 0 },
|
||||||
{ "invert-match", 'v', 0, 0, "Select non-matching formulas", 0},
|
{ "invert-match", 'v', 0, 0, "select non-matching formulas", 0},
|
||||||
/**************************************************/
|
{ "unique", 'u', 0, 0,
|
||||||
{ 0, 0, 0, 0, "Output options:", 6 },
|
"drop formulas that have already been output (not affected by -v)", 0 },
|
||||||
{ "full-parentheses", 'p', 0, 0,
|
|
||||||
"output fully-parenthesized formulas", 0 },
|
|
||||||
{ "spin", 's', 0, 0, "output in Spin's syntax", 0 },
|
|
||||||
{ "spot", OPT_SPOT, 0, 0, "output in Spot's syntax (default)", 0 },
|
|
||||||
{ "utf8", '8', 0, 0, "output using UTF-8 characters", 0 },
|
|
||||||
{ "unique", 'u', 0, 0, "drop formulas that have already been outpout", 0 },
|
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
|
{ 0, 0, 0, 0, "Output options:", -20 },
|
||||||
{ 0, 0, 0, 0, "Miscellaneous options:", -1 },
|
{ 0, 0, 0, 0, "Miscellaneous options:", -1 },
|
||||||
{ 0, 0, 0, 0, 0, 0 }
|
{ 0, 0, 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const struct argp_child children[] =
|
||||||
|
{
|
||||||
|
{ &output_argp, 0, 0, -20 },
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
struct job
|
struct job
|
||||||
{
|
{
|
||||||
const char* str;
|
const char* str;
|
||||||
|
|
@ -187,9 +188,6 @@ static bool one_match = false;
|
||||||
enum error_style_t { drop_errors, skip_errors };
|
enum error_style_t { drop_errors, skip_errors };
|
||||||
static error_style_t error_style = drop_errors;
|
static error_style_t error_style = drop_errors;
|
||||||
static bool quiet = false;
|
static bool quiet = false;
|
||||||
enum output_format_t { spot_output, spin_output, utf8_output };
|
|
||||||
static output_format_t output_format = spot_output;
|
|
||||||
static bool full_parenth = false;
|
|
||||||
static bool nnf = false;
|
static bool nnf = false;
|
||||||
static bool negate = false;
|
static bool negate = false;
|
||||||
static int level = 0;
|
static int level = 0;
|
||||||
|
|
@ -242,15 +240,11 @@ parse_formula_arg(const std::string& input)
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
parse_opt(int key, char* arg, struct argp_state* state)
|
parse_opt(int key, char* arg, struct argp_state*)
|
||||||
{
|
{
|
||||||
(void) state;
|
|
||||||
// This switch is alphabetically-ordered.
|
// This switch is alphabetically-ordered.
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case '8':
|
|
||||||
output_format = utf8_output;
|
|
||||||
break;
|
|
||||||
case 'f':
|
case 'f':
|
||||||
jobs.push_back(job(arg, false));
|
jobs.push_back(job(arg, false));
|
||||||
break;
|
break;
|
||||||
|
|
@ -260,9 +254,6 @@ parse_opt(int key, char* arg, struct argp_state* state)
|
||||||
case 'n':
|
case 'n':
|
||||||
negate = true;
|
negate = true;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
|
||||||
full_parenth = true;
|
|
||||||
break;
|
|
||||||
case 'q':
|
case 'q':
|
||||||
quiet = true;
|
quiet = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -287,9 +278,6 @@ parse_opt(int key, char* arg, struct argp_state* state)
|
||||||
error(2, 0, "invalid simplification level '%s'", arg);
|
error(2, 0, "invalid simplification level '%s'", arg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
|
||||||
output_format = spin_output;
|
|
||||||
break;
|
|
||||||
case 'u':
|
case 'u':
|
||||||
unique = true;
|
unique = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -342,9 +330,6 @@ parse_opt(int key, char* arg, struct argp_state* state)
|
||||||
case OPT_SKIP_ERRORS:
|
case OPT_SKIP_ERRORS:
|
||||||
error_style = skip_errors;
|
error_style = skip_errors;
|
||||||
break;
|
break;
|
||||||
case OPT_SPOT:
|
|
||||||
output_format = spot_output;
|
|
||||||
break;
|
|
||||||
case OPT_SYNTACTIC_SAFETY:
|
case OPT_SYNTACTIC_SAFETY:
|
||||||
syntactic_safety = true;
|
syntactic_safety = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -516,19 +501,7 @@ namespace
|
||||||
if (matched)
|
if (matched)
|
||||||
{
|
{
|
||||||
one_match = true;
|
one_match = true;
|
||||||
switch (output_format)
|
output_formula(f);
|
||||||
{
|
|
||||||
case spot_output:
|
|
||||||
spot::ltl::to_string(f, std::cout, full_parenth);
|
|
||||||
break;
|
|
||||||
case spin_output:
|
|
||||||
spot::ltl::to_spin_string(f, std::cout, full_parenth);
|
|
||||||
break;
|
|
||||||
case utf8_output:
|
|
||||||
spot::ltl::to_utf8_string(f, std::cout, full_parenth);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::cout << "\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f->destroy();
|
f->destroy();
|
||||||
|
|
@ -610,7 +583,7 @@ main(int argc, char** argv)
|
||||||
argv[0] = const_cast<char*>(program_name);
|
argv[0] = const_cast<char*>(program_name);
|
||||||
|
|
||||||
const argp ap = { options, parse_opt, "[FILENAME...]",
|
const argp ap = { options, parse_opt, "[FILENAME...]",
|
||||||
argp_program_doc, 0, 0, 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, 0, 0, 0))
|
||||||
exit(err);
|
exit(err);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue