ltl2tgba: Add a --csv-escape option and document CSV I/O.
* src/bin/common_output.cc, src/bin/common_output.hh: (output_formula_checked, aut_stat_printer): New. * src/bin/genltl.cc, src/bin/randltl.cc, src/bin/ltlfilt.cc: Call output_formula_checked() instead of output_formula(). * src/bin/ltl2tgba.cc: Use aut_stat_printer and add option --csv-escape. * doc/org/csv.org: New file to document CSV I/O. * doc/Makefile.am: Add it. * doc/org/ioltl.org, doc/org/ltlfilt.org, doc/org/ltl2tgba.org, doc/org/tools.org: Link to csv.org
This commit is contained in:
parent
0faea814da
commit
846e33b9e5
13 changed files with 399 additions and 39 deletions
|
|
@ -24,6 +24,7 @@
|
|||
#include "ltlvisit/tostring.hh"
|
||||
#include "ltlvisit/lbt.hh"
|
||||
#include "misc/formater.hh"
|
||||
#include "misc/escape.hh"
|
||||
#include "common_cout.hh"
|
||||
#include "error.h"
|
||||
|
||||
|
|
@ -31,9 +32,11 @@
|
|||
#define OPT_WRING 2
|
||||
#define OPT_LATEX 3
|
||||
#define OPT_FORMAT 4
|
||||
#define OPT_CSV 5
|
||||
|
||||
output_format_t output_format = spot_output;
|
||||
bool full_parenth = false;
|
||||
bool escape_csv = false;
|
||||
|
||||
static const argp_option options[] =
|
||||
{
|
||||
|
|
@ -45,6 +48,8 @@ static const argp_option options[] =
|
|||
{ "wring", OPT_WRING, 0, 0, "output in Wring's syntax", -20 },
|
||||
{ "utf8", '8', 0, 0, "output using UTF-8 characters", -20 },
|
||||
{ "latex", OPT_LATEX, 0, 0, "output using LaTeX macros", -20 },
|
||||
{ "csv-escape", OPT_CSV, 0, 0, "quote the formula for use in a CSV file",
|
||||
-20 },
|
||||
{ "format", OPT_FORMAT, "FORMAT", 0,
|
||||
"specify how each line should be output (default: \"%f\")", -20 },
|
||||
{ 0, 0, 0, 0, 0, 0 }
|
||||
|
|
@ -102,6 +107,26 @@ stream_formula(std::ostream& out,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
stream_escapable_formula(std::ostream& os,
|
||||
const spot::ltl::formula* f,
|
||||
const char* filename, int linenum)
|
||||
{
|
||||
if (escape_csv)
|
||||
{
|
||||
std::ostringstream out;
|
||||
stream_formula(out, f, filename, linenum);
|
||||
os << '"';
|
||||
spot::escape_rfc4180(os, out.str());
|
||||
os << '"';
|
||||
}
|
||||
else
|
||||
{
|
||||
stream_formula(os, f, filename, linenum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
struct formula_with_location
|
||||
|
|
@ -127,10 +152,7 @@ namespace
|
|||
virtual void
|
||||
print(std::ostream& os, const char*) const
|
||||
{
|
||||
stream_formula(os,
|
||||
val_->f,
|
||||
val_->filename,
|
||||
val_->line);
|
||||
stream_escapable_formula(os, val_->f, val_->filename, val_->line);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -189,6 +211,9 @@ parse_opt_output(int key, char* arg, struct argp_state*)
|
|||
case 's':
|
||||
output_format = spin_output;
|
||||
break;
|
||||
case OPT_CSV:
|
||||
escape_csv = true;
|
||||
break;
|
||||
case OPT_LATEX:
|
||||
output_format = latex_output;
|
||||
break;
|
||||
|
|
@ -210,25 +235,33 @@ parse_opt_output(int key, char* arg, struct argp_state*)
|
|||
|
||||
|
||||
void
|
||||
output_formula(const spot::ltl::formula* f, const char* filename, int linenum,
|
||||
output_formula(std::ostream& out,
|
||||
const spot::ltl::formula* f, const char* filename, int linenum,
|
||||
const char* prefix, const char* suffix)
|
||||
{
|
||||
if (!format)
|
||||
{
|
||||
if (prefix)
|
||||
std::cout << prefix << ",";
|
||||
stream_formula(std::cout, f, filename, linenum);
|
||||
out << prefix << ",";
|
||||
stream_escapable_formula(out, f, filename, linenum);
|
||||
if (suffix)
|
||||
std::cout << "," << suffix;
|
||||
out << "," << suffix;
|
||||
}
|
||||
else
|
||||
{
|
||||
formula_with_location fl = { f, filename, linenum, prefix, suffix };
|
||||
format->print(fl);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
output_formula_checked(const spot::ltl::formula* f,
|
||||
const char* filename, int linenum,
|
||||
const char* prefix, const char* suffix)
|
||||
{
|
||||
output_formula(std::cout, f, filename, linenum, prefix, suffix);
|
||||
std::cout << std::endl;
|
||||
// Make sure we abort if we can't write to std::cout anymore
|
||||
// (like disk full or broken pipe with SIGPIPE ignored).
|
||||
std::cout << std::endl;
|
||||
check_cout();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,18 +24,63 @@
|
|||
|
||||
#include <argp.h>
|
||||
#include "ltlast/formula.hh"
|
||||
#include "tgbaalgos/stats.hh"
|
||||
#include "common_output.hh"
|
||||
|
||||
enum output_format_t { spot_output, spin_output, utf8_output,
|
||||
lbt_output, wring_output, latex_output };
|
||||
extern output_format_t output_format;
|
||||
extern bool full_parenth;
|
||||
extern bool escape_csv;
|
||||
|
||||
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,
|
||||
void output_formula(std::ostream& os, const spot::ltl::formula* f,
|
||||
const char* filename = 0, int linenum = 0,
|
||||
const char* prefix = 0, const char* suffix = 0);
|
||||
void output_formula_checked(const spot::ltl::formula* f,
|
||||
const char* filename = 0, int linenum = 0,
|
||||
const char* prefix = 0, const char* suffix = 0);
|
||||
|
||||
|
||||
class printable_formula:
|
||||
public spot::printable_value<const spot::ltl::formula*>
|
||||
{
|
||||
public:
|
||||
printable_formula&
|
||||
operator=(const spot::ltl::formula* new_val)
|
||||
{
|
||||
val_ = new_val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual void
|
||||
print(std::ostream& os, const char*) const
|
||||
{
|
||||
output_formula(os, val_);
|
||||
}
|
||||
};
|
||||
|
||||
class aut_stat_printer: protected spot::stat_printer
|
||||
{
|
||||
public:
|
||||
aut_stat_printer(std::ostream& os, const char* format)
|
||||
: spot::stat_printer(os, format)
|
||||
{
|
||||
declare('f', &formula_); // Override the formula printer.
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
print(const spot::tgba* aut, const spot::ltl::formula* f = 0,
|
||||
double run_time = -1.)
|
||||
{
|
||||
formula_ = f;
|
||||
return this->spot::stat_printer::print(aut, f, run_time);
|
||||
}
|
||||
|
||||
printable_formula formula_;
|
||||
};
|
||||
|
||||
#endif // SPOT_BIN_COMMON_OUTPUT_HH
|
||||
|
|
|
|||
|
|
@ -846,7 +846,7 @@ output_pattern(int pattern, int n)
|
|||
f = r;
|
||||
}
|
||||
|
||||
output_formula(f, class_name[pattern - 1], n);
|
||||
output_formula_checked(f, class_name[pattern - 1], n);
|
||||
f->destroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include "common_r.hh"
|
||||
#include "common_cout.hh"
|
||||
#include "common_finput.hh"
|
||||
#include "common_output.hh"
|
||||
#include "common_post.hh"
|
||||
|
||||
#include "ltlast/formula.hh"
|
||||
|
|
@ -55,6 +56,7 @@ If multiple formulas are supplied, several automata will be output.";
|
|||
#define OPT_LBTT 3
|
||||
#define OPT_SPOT 4
|
||||
#define OPT_STATS 5
|
||||
#define OPT_CSV 6
|
||||
|
||||
static const argp_option options[] =
|
||||
{
|
||||
|
|
@ -67,6 +69,8 @@ static const argp_option options[] =
|
|||
"of the given formula)", 0 },
|
||||
/**************************************************/
|
||||
{ 0, 0, 0, 0, "Output format:", 3 },
|
||||
{ "csv-escape", OPT_CSV, 0, 0, "quote formula output by %f in --format "
|
||||
"for use in CSV file", 0 },
|
||||
{ "dot", OPT_DOT, 0, 0, "GraphViz's format (default)", 0 },
|
||||
{ "lbtt", OPT_LBTT, "t", OPTION_ARG_OPTIONAL,
|
||||
"LBTT's format (add =t to force transition-based acceptance even"
|
||||
|
|
@ -127,6 +131,7 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
{
|
||||
case '8':
|
||||
spot::enable_utf8();
|
||||
output_format = utf8_output;
|
||||
break;
|
||||
case 'B':
|
||||
type = spot::postprocessor::BA;
|
||||
|
|
@ -146,6 +151,9 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
error(2, 0, "failed to parse --options near '%s'", opt);
|
||||
}
|
||||
break;
|
||||
case OPT_CSV:
|
||||
escape_csv = true;
|
||||
break;
|
||||
case OPT_DOT:
|
||||
format = Dot;
|
||||
break;
|
||||
|
|
@ -194,7 +202,7 @@ namespace
|
|||
{
|
||||
public:
|
||||
spot::translator& trans;
|
||||
spot::stat_printer statistics;
|
||||
aut_stat_printer statistics;
|
||||
|
||||
trans_processor(spot::translator& trans)
|
||||
: trans(trans), statistics(std::cout, stats)
|
||||
|
|
|
|||
|
|
@ -577,7 +577,7 @@ namespace
|
|||
if (matched)
|
||||
{
|
||||
one_match = true;
|
||||
output_formula(f, filename, linenum, prefix, suffix);
|
||||
output_formula_checked(f, filename, linenum, prefix, suffix);
|
||||
}
|
||||
f->destroy();
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -396,7 +396,7 @@ main(int argc, char** argv)
|
|||
error(2, 0, "failed to generate a new unique formula after %d trials",
|
||||
MAX_TRIALS);
|
||||
static int count = 0;
|
||||
output_formula(f, 0, ++count);
|
||||
output_formula_checked(f, 0, ++count);
|
||||
f->destroy();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue