bin: factor the code to read LTL formulas from -f or -F.
* src/bin/common_finput.cc, src/bin/common_finput.hh: Define the processor class. * src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc, src/bin/ltlfilt.cc: Simplify accordingly.
This commit is contained in:
parent
467bf378a8
commit
ecca4ba53e
5 changed files with 155 additions and 202 deletions
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
#include "common_finput.hh"
|
||||
#include "error.h"
|
||||
#include "ltlparse/public.hh"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#define OPT_LBT 1
|
||||
|
||||
|
|
@ -69,3 +72,65 @@ parse_formula(const std::string& s, spot::ltl::parse_error_list& pel)
|
|||
else
|
||||
return spot::ltl::parse(s, pel);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
job_processor::process_string(const std::string& input,
|
||||
const char* filename,
|
||||
int linenum)
|
||||
{
|
||||
spot::ltl::parse_error_list pel;
|
||||
const spot::ltl::formula* f = parse_formula(input, pel);
|
||||
|
||||
if (!f || pel.size() > 0)
|
||||
{
|
||||
if (filename)
|
||||
error_at_line(0, 0, filename, linenum, "parse error:");
|
||||
spot::ltl::format_parse_errors(std::cerr, input, pel);
|
||||
if (f)
|
||||
f->destroy();
|
||||
return 1;
|
||||
}
|
||||
return process_formula(f, filename, linenum);
|
||||
}
|
||||
|
||||
int
|
||||
job_processor::process_stream(std::istream& is,
|
||||
const char* filename)
|
||||
{
|
||||
int error = 0;
|
||||
int linenum = 0;
|
||||
std::string line;
|
||||
while (std::getline(is, line))
|
||||
error |= process_string(line, filename, ++linenum);
|
||||
return error;
|
||||
}
|
||||
|
||||
int
|
||||
job_processor::process_file(const char* filename)
|
||||
{
|
||||
// Special case for stdin.
|
||||
if (filename[0] == '-' && filename[1] == 0)
|
||||
return process_stream(std::cin, filename);
|
||||
|
||||
errno = 0;
|
||||
std::ifstream input(filename);
|
||||
if (!input)
|
||||
error(2, errno, "cannot open '%s'", filename);
|
||||
return process_stream(input, filename);
|
||||
}
|
||||
|
||||
int
|
||||
job_processor::run()
|
||||
{
|
||||
int error = 0;
|
||||
jobs_t::const_iterator i;
|
||||
for (i = jobs.begin(); i != jobs.end(); ++i)
|
||||
{
|
||||
if (!i->file_p)
|
||||
error |= process_string(i->str);
|
||||
else
|
||||
error |= process_file(i->str);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue