bin: overhaul default input selection

If no input have been specified, and the standard input is not a tty all
tools now default to reading it.  If standard input is a tty, all tools
display an error message.  Additionally, - is now a shorthand for -F- in
all tools.

* NEWS: Summarize this.
* bin/common_finput.cc, bin/common_finput.hh (check_no_formulas,
check_no_automaton): New functions that implement the above istty()
logic.
* bin/autfilt.cc, bin/dstar2tgba.cc, bin/ltl2tgba.cc, bin/ltl2tgta.cc,
bin/ltlcross.cc, bin/ltldo.cc, bin/ltlgrind.cc: Use these function,
and recognize '-' if it was not the case.
* tests/core/acc_word.test, tests/core/ltldo.test,
tests/core/minusx.test, tests/core/readsave.test,
tests/core/unambig.test: Adjust some tests to exercise this.
* doc/org/autfilt.org, doc/org/csv.org, doc/org/dstar2tgba.org,
doc/org/ltl2tgba.org, doc/org/ltlcross.org, doc/org/ltlfilt.org,
doc/org/oaut.org: Adjust the documentation and simplify some
examples.
This commit is contained in:
Alexandre Duret-Lutz 2016-07-19 21:55:12 +02:00
parent abff7eba8e
commit dd6875d5fe
22 changed files with 119 additions and 54 deletions

View file

@ -1116,8 +1116,7 @@ main(int argc, char** argv)
if (pref_set && !level_set)
level = spot::postprocessor::High;
if (jobs.empty())
jobs.emplace_back("-", true);
check_no_automaton();
if (opt->are_isomorphic)
{

View file

@ -18,10 +18,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "common_finput.hh"
#include "common_setup.hh"
#include "error.h"
#include <fstream>
#include <cstring>
#include <unistd.h>
enum {
OPT_LBT = 1,
@ -353,3 +355,25 @@ job_processor::run()
}
return error;
}
void check_no_formula()
{
if (!jobs.empty())
return;
if (isatty(STDIN_FILENO))
error(2, 0, "No formula to translate? Run '%s --help' for help.\n"
"Use '%s -' to force reading formulas from the standard "
"input.", program_name, program_name);
jobs.emplace_back("-", true);
}
void check_no_automaton()
{
if (!jobs.empty())
return;
if (isatty(STDIN_FILENO))
error(2, 0, "No automaton to process? Run '%s --help' for help.\n"
"Use '%s -' to force reading automata from the standard "
"input.", program_name, program_name);
jobs.emplace_back("-", true);
}

View file

@ -77,3 +77,8 @@ public:
char* prefix;
char* suffix;
};
// Report and error message or add a default job depending on whether
// the input is a tty.
void check_no_formula();
void check_no_automaton();

View file

@ -180,8 +180,7 @@ main(int argc, char** argv)
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, nullptr, nullptr))
exit(err);
if (jobs.empty())
jobs.emplace_back("-", true);
check_no_automaton();
spot::postprocessor post(&extra_options);
post.set_pref(pref | comp | sbacc);

View file

@ -97,7 +97,10 @@ parse_opt(int key, char* arg, struct argp_state*)
break;
case ARGP_KEY_ARG:
// FIXME: use stat() to distinguish filename from string?
jobs.emplace_back(arg, false);
if (*arg == '-' && !arg[1])
jobs.emplace_back(arg, true);
else
jobs.emplace_back(arg, false);
break;
default:
@ -164,9 +167,7 @@ main(int argc, char** argv)
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, nullptr, nullptr))
exit(err);
if (jobs.empty())
error(2, 0, "No formula to translate? Run '%s --help' for usage.",
program_name);
check_no_formula();
try
{

View file

@ -24,6 +24,7 @@
#include <fstream>
#include <argp.h>
#include <unistd.h>
#include "error.h"
#include "common_setup.hh"
@ -147,7 +148,10 @@ parse_opt(int key, char* arg, struct argp_state*)
break;
case ARGP_KEY_ARG:
// FIXME: use stat() to distinguish filename from string?
jobs.emplace_back(arg, false);
if (*arg == '-' && !arg[1])
jobs.emplace_back(arg, true);
else
jobs.emplace_back(arg, false);
break;
default:
@ -226,9 +230,7 @@ main(int argc, char** argv)
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, nullptr, nullptr))
exit(err);
if (jobs.empty())
error(2, 0, "No formula to translate? Run '%s --help' for usage.",
program_name);
check_no_formula();
try
{

View file

@ -408,7 +408,10 @@ parse_opt(int key, char* arg, struct argp_state*)
products = 0;
break;
case ARGP_KEY_ARG:
translators.push_back(arg);
if (arg[0] == '-' && !arg[1])
jobs.emplace_back(arg, true);
else
translators.push_back(arg);
break;
case OPT_AUTOMATA:
opt_automata = true;
@ -1443,8 +1446,7 @@ main(int argc, char** argv)
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, nullptr, nullptr))
exit(err);
if (jobs.empty())
jobs.emplace_back("-", 1);
check_no_formula();
if (translators.empty())
error(2, 0, "No translator to run? Run '%s --help' for usage.",

View file

@ -146,7 +146,10 @@ parse_opt(int key, char* arg, struct argp_state*)
errors_opt = XARGMATCH("--errors", arg, errors_args, errors_types);
break;
case ARGP_KEY_ARG:
translators.push_back(arg);
if (arg[0] == '-' && !arg[1])
jobs.emplace_back(arg, true);
else
translators.push_back(arg);
break;
default:
return ARGP_ERR_UNKNOWN;
@ -356,8 +359,7 @@ main(int argc, char** argv)
if (int err = argp_parse(&ap, argc, argv, ARGP_NO_HELP, nullptr, nullptr))
exit(err);
if (jobs.empty())
jobs.emplace_back("-", 1);
check_no_formula();
if (translators.empty())
error(2, 0, "No translator to run? Run '%s --help' for usage.",

View file

@ -189,8 +189,7 @@ main(int argc, char* argv[])
mut_opts |= opt_all;
if (jobs.empty())
jobs.push_back(job("-", true));
check_no_formula();
mutate_processor processor;
if (processor.run())