bin: add the --output to tools that output formulas

* src/bin/common_output.cc, src/bin/common_output.hh: Add option
--output.
* src/ltltest/ltlfilt.test, src/ltltest/rand.test: Add tests.
* NEWS, doc/org/ioltl.org: Document it.
This commit is contained in:
Alexandre Duret-Lutz 2015-02-15 23:50:48 +01:00
parent e22a800fe4
commit 78def4f8ca
6 changed files with 96 additions and 15 deletions

View file

@ -52,6 +52,10 @@ static const argp_option options[] =
-20 },
{ "format", OPT_FORMAT, "FORMAT", 0,
"specify how each line should be output (default: \"%f\")", -20 },
{ "output", 'o', "FORMAT", 0,
"send output to a file named FORMAT instead of standard output. The"
" first formula sent to a file truncates it unless FORMAT starts"
" with '>>'.", 0 },
{ 0, 0, 0, 0, 0, 0 }
};
@ -195,6 +199,9 @@ namespace
}
static formula_printer* format = 0;
static std::ostringstream outputname;
static formula_printer* outputnamer = 0;
static std::map<std::string, std::unique_ptr<output_file>> outputfiles;
int
parse_opt_output(int key, char* arg, struct argp_state*)
@ -208,6 +215,9 @@ parse_opt_output(int key, char* arg, struct argp_state*)
case 'l':
output_format = lbt_output;
break;
case 'o':
outputnamer = new formula_printer(outputname, arg);
break;
case 'p':
full_parenth = true;
break;
@ -237,10 +247,11 @@ parse_opt_output(int key, char* arg, struct argp_state*)
}
void
static void
output_formula(std::ostream& out,
const spot::ltl::formula* f, const char* filename, int linenum,
const char* prefix, const char* suffix)
const spot::ltl::formula* f,
const char* filename = nullptr, int linenum = 0,
const char* prefix = nullptr, const char* suffix = nullptr)
{
if (!format)
{
@ -257,15 +268,40 @@ output_formula(std::ostream& out,
}
}
void
::printable_formula::print(std::ostream& os, const char*) const
{
output_formula(os, val_);
}
void
output_formula_checked(const spot::ltl::formula* f,
const char* filename, int linenum,
const char* prefix, const char* suffix)
{
if (output_format == quiet_output || output_format == count_output)
if (output_format == count_output)
{
if (outputnamer)
throw std::runtime_error
("options --output and --count are incompatible");
return;
}
if (output_format == quiet_output)
return;
output_formula(std::cout, f, filename, linenum, prefix, suffix);
std::cout << '\n';
std::ostream* out = &std::cout;
if (outputnamer)
{
outputname.str("");
formula_with_location fl = { f, filename, linenum, prefix, suffix };
outputnamer->print(fl);
std::string fname = outputname.str();
auto p = outputfiles.emplace(fname, nullptr);
if (p.second)
p.first->second.reset(new output_file(fname.c_str()));
out = &p.first->second->ostream();
}
output_formula(*out, f, filename, linenum, prefix, suffix);
*out << '\n';
// Make sure we abort if we can't write to std::cout anymore
// (like disk full or broken pipe with SIGPIPE ignored).
check_cout();

View file

@ -23,9 +23,12 @@
#include "common_sys.hh"
#include <argp.h>
#include <map>
#include <memory>
#include "ltlast/formula.hh"
#include "tgbaalgos/stats.hh"
#include "common_output.hh"
#include "common_file.hh"
enum output_format_t { spot_output, spin_output, utf8_output,
lbt_output, wring_output, latex_output,
@ -38,9 +41,6 @@ extern const struct argp output_argp;
int parse_opt_output(int key, char* arg, struct argp_state* state);
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);
@ -58,10 +58,7 @@ public:
}
virtual void
print(std::ostream& os, const char*) const
{
output_formula(os, val_);
}
print(std::ostream& os, const char*) const;
};
class aut_stat_printer: protected spot::stat_printer
@ -73,6 +70,8 @@ public:
declare('f', &formula_); // Override the formula printer.
}
using spot::formater::set_output;
std::ostream&
print(const spot::const_tgba_digraph_ptr& aut,
const spot::ltl::formula* f = 0,