bin: fix handling of -o '>>-' in the close/reopen path
* tests/core/serial.test: Add test case. * bin/common_file.cc: Fix it.
This commit is contained in:
parent
0923f8efe2
commit
61e43edde8
2 changed files with 25 additions and 6 deletions
|
|
@ -47,16 +47,13 @@ output_file::output_file(const char* name, bool force_append)
|
||||||
void
|
void
|
||||||
output_file::reopen_for_append(const std::string& name)
|
output_file::reopen_for_append(const std::string& name)
|
||||||
{
|
{
|
||||||
if (of_ && of_->is_open()) // nothing to do
|
if (os_ == &std::cout || of_->is_open()) // nothing to do
|
||||||
return;
|
return;
|
||||||
const char* cname = name.c_str();
|
const char* cname = name.c_str();
|
||||||
if (cname[0] == '>' && cname[1] == '>')
|
if (cname[0] == '>' && cname[1] == '>')
|
||||||
cname += 2;
|
cname += 2;
|
||||||
if (name[0] == '-' && name[1] == 0)
|
// the name cannot be "-" at this point, otherwise os_ would be
|
||||||
{
|
// equal to std::cout.
|
||||||
os_ = &std::cout;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
of_->open(cname, std::ios_base::app);
|
of_->open(cname, std::ios_base::app);
|
||||||
if (!*of_)
|
if (!*of_)
|
||||||
error(2, errno, "cannot reopen '%s'", cname);
|
error(2, errno, "cannot reopen '%s'", cname);
|
||||||
|
|
|
||||||
|
|
@ -91,3 +91,25 @@ cat >expected <<EOF
|
||||||
5 pass2
|
5 pass2
|
||||||
EOF
|
EOF
|
||||||
diff out expected
|
diff out expected
|
||||||
|
|
||||||
|
# The case where the output filename is a computed "-".
|
||||||
|
ltl2tgba 1 --name '-' > naut-.hoa
|
||||||
|
for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
|
||||||
|
ltl2tgba 1 --name "file$i" > naut$i.hoa
|
||||||
|
done
|
||||||
|
autfilt naut*.hoa naut*.hoa --output='>>%M' --format=%M > stdout
|
||||||
|
cat >expected <<EOF
|
||||||
|
-
|
||||||
|
-
|
||||||
|
EOF
|
||||||
|
diff stdout expected
|
||||||
|
cat >expected7 <<EOF
|
||||||
|
file7
|
||||||
|
file7
|
||||||
|
EOF
|
||||||
|
diff file7 expected7
|
||||||
|
cat >expected15 <<EOF
|
||||||
|
file15
|
||||||
|
file15
|
||||||
|
EOF
|
||||||
|
diff file15 expected15
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue