bin: generalized shorthands for ltldo and ltlcross

* src/bin/common_trans.cc: Skip leading directories, and
do not require that the prefix is followed by space of 0.
* src/tests/ltldo.test: Add a test.
* doc/org/ltlcross.org: Update.
This commit is contained in:
Alexandre Duret-Lutz 2015-06-02 18:20:47 +02:00
parent 6298918497
commit 203d07693d
3 changed files with 31 additions and 3 deletions

View file

@ -58,6 +58,12 @@ void show_shorthands()
std::cout << " "
<< std::left << std::setw(12) << s.prefix
<< s.suffix << '\n';
std::cout
<< ("\nAny {name} and directory component is skipped for the purpose of\n"
"matching those prefixes. So for instance\n"
" '{DRA} ~/mytools/ltl2dstar-0.5.2'\n"
"will changed into\n"
" '{DRA} ~/mytools/ltl2dstar-0.5.2 --output-format=hoa %L %O'\n");
}
@ -84,15 +90,28 @@ translator_spec::translator_spec(const char* spec)
}
}
}
// If we recognize a shorthand, add the suffixes.
// If there is no % in the string, look for a known
// command from our shorthand list. If we find it,
// add the suffix.
bool allocated = false;
if (!strchr(cmd, '%'))
{
// Skip any leading directory name.
auto basename = cmd;
auto pos = cmd;
while (*pos)
{
if (*pos == '/')
basename = pos + 1;
else if (*pos == ' ')
break;
++pos;
}
// Match a shorthand.
for (auto& p: shorthands)
{
int n = strlen(p.prefix);
if (strncmp(cmd, p.prefix, n) == 0 &&
(cmd[n] == 0 || cmd[n] == ' '))
if (strncmp(basename, p.prefix, n) == 0)
{
int m = strlen(p.suffix);
int q = strlen(cmd);