ltlfilt: update the exit status in the same way as grep
* src/bin/ltlfilt.cc: Do it.
This commit is contained in:
parent
24a8c03192
commit
267183bda7
1 changed files with 21 additions and 18 deletions
|
|
@ -55,7 +55,11 @@ to the extent permitted by law.";
|
||||||
const char* argp_program_bug_address = "<" SPOT_PACKAGE_BUGREPORT ">";
|
const char* argp_program_bug_address = "<" SPOT_PACKAGE_BUGREPORT ">";
|
||||||
|
|
||||||
const char argp_program_doc[] ="\
|
const char argp_program_doc[] ="\
|
||||||
Read a list of formulas and output them back after some optional processing.";
|
Read a list of formulas and output them back after some optional processing.\v\
|
||||||
|
Exit status:\n\
|
||||||
|
0 if some formulas were output (skipped syntax errors do not count)\n\
|
||||||
|
1 if no formula were output (no match)\n\
|
||||||
|
2 if any error has been reported";
|
||||||
|
|
||||||
#define OPT_SPOT 1
|
#define OPT_SPOT 1
|
||||||
#define OPT_SKIP_ERRORS 2
|
#define OPT_SKIP_ERRORS 2
|
||||||
|
|
@ -178,6 +182,8 @@ struct job
|
||||||
typedef std::vector<job> jobs_t;
|
typedef std::vector<job> jobs_t;
|
||||||
static jobs_t jobs;
|
static jobs_t jobs;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
@ -218,7 +224,7 @@ to_int(const char* s)
|
||||||
char* endptr;
|
char* endptr;
|
||||||
int res = strtol(s, &endptr, 10);
|
int res = strtol(s, &endptr, 10);
|
||||||
if (*endptr)
|
if (*endptr)
|
||||||
error(1, 0, "failed to parse '%s' as an integer.", s);
|
error(2, 0, "failed to parse '%s' as an integer.", s);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,7 +235,7 @@ parse_formula_arg(const std::string& input)
|
||||||
spot::ltl::parse_error_list pel;
|
spot::ltl::parse_error_list pel;
|
||||||
const spot::ltl::formula* f = spot::ltl::parse(input, pel);
|
const spot::ltl::formula* f = spot::ltl::parse(input, pel);
|
||||||
if (spot::ltl::format_parse_errors(std::cerr, input, pel))
|
if (spot::ltl::format_parse_errors(std::cerr, input, pel))
|
||||||
error(1, 0, "parse error when parsing an argument");
|
error(2, 0, "parse error when parsing an argument");
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,7 +284,7 @@ parse_opt(int key, char* arg, struct argp_state* state)
|
||||||
level = arg[0] = '0';
|
level = arg[0] = '0';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
error(1, 0, "invalid simplification level '%s'", arg);
|
error(2, 0, "invalid simplification level '%s'", arg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
|
|
@ -373,7 +379,7 @@ parse_opt(int key, char* arg, struct argp_state* state)
|
||||||
case OPT_EQUIVALENT_TO:
|
case OPT_EQUIVALENT_TO:
|
||||||
{
|
{
|
||||||
if (equivalent_to)
|
if (equivalent_to)
|
||||||
error(1, 0, "only one --equivalent-to option can be given");
|
error(2, 0, "only one --equivalent-to option can be given");
|
||||||
equivalent_to = parse_formula_arg(arg);
|
equivalent_to = parse_formula_arg(arg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -418,21 +424,15 @@ namespace
|
||||||
if (f)
|
if (f)
|
||||||
f->destroy();
|
f->destroy();
|
||||||
|
|
||||||
if (error_style == drop_errors)
|
|
||||||
return 1;
|
|
||||||
if (error_style == skip_errors)
|
if (error_style == skip_errors)
|
||||||
{
|
std::cout << input << std::endl;
|
||||||
std::cout << input << std::endl;
|
else
|
||||||
return 1;
|
assert(error_style == drop_errors);
|
||||||
}
|
return !quiet;
|
||||||
assert(!"unreachable");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (negate)
|
if (negate)
|
||||||
{
|
f = spot::ltl::unop::instance(spot::ltl::unop::Not, f);
|
||||||
f = spot::ltl::unop::instance(spot::ltl::unop::Not, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level)
|
if (level)
|
||||||
{
|
{
|
||||||
|
|
@ -515,6 +515,7 @@ namespace
|
||||||
|
|
||||||
if (matched)
|
if (matched)
|
||||||
{
|
{
|
||||||
|
one_match = true;
|
||||||
switch (output_format)
|
switch (output_format)
|
||||||
{
|
{
|
||||||
case spot_output:
|
case spot_output:
|
||||||
|
|
@ -555,7 +556,7 @@ namespace
|
||||||
errno = 0;
|
errno = 0;
|
||||||
std::ifstream input(filename);
|
std::ifstream input(filename);
|
||||||
if (!input)
|
if (!input)
|
||||||
error(1, errno, "cannot open '%s'", filename);
|
error(2, errno, "cannot open '%s'", filename);
|
||||||
return process_stream(input, filename);
|
return process_stream(input, filename);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -595,7 +596,9 @@ run_jobs()
|
||||||
else
|
else
|
||||||
error |= processor.process_file(i->str);
|
error |= processor.process_file(i->str);
|
||||||
}
|
}
|
||||||
return error;
|
if (error)
|
||||||
|
return 2;
|
||||||
|
return one_match ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue