Redirect to file properly when no space between > and filename.

This commit is contained in:
Frederich Munch 2016-11-28 18:04:32 -05:00 committed by sftnight
parent e0ddb56b20
commit 1bf0e16d7f
2 changed files with 27 additions and 10 deletions

View File

@ -208,19 +208,17 @@ namespace cling {
llvm::StringRef file;
if (getCurTok().is(tok::greater)) {
bool append = false;
consumeToken();
// check whether we have >>
if (getCurTok().is(tok::greater)) {
append = true;
if (lookAhead(1).is(tok::greater)) {
consumeToken();
append = true;
}
// check for syntax like: 2>&1
if (getCurTok().is(tok::ampersand)) {
if (constant_FD == 0) {
if (lookAhead(1).is(tok::ampersand)) {
if (constant_FD == 0)
stream = MetaProcessor::kSTDBOTH;
}
consumeToken();
const Token& Tok = getCurTok();
const Token& Tok = lookAhead(2);
if (Tok.is(tok::constant)) {
switch (Tok.getConstant()) {
case 1: file = llvm::StringRef("&1"); break;
@ -231,11 +229,12 @@ namespace cling {
// Mark the stream name as refering to stderr or stdout, not a name
stream = MetaProcessor::RedirectionScope(stream |
MetaProcessor::kSTDSTRM);
consumeToken();
consumeToken(); // &
consumeToken(); // 1,2
}
}
}
if (!getCurTok().is(tok::eof) && !(stream & MetaProcessor::kSTDSTRM)) {
if (!lookAhead(1).is(tok::eof) && !(stream & MetaProcessor::kSTDSTRM)) {
consumeAnyStringToken(tok::eof);
if (getCurTok().is(tok::raw_ident)) {
file = getCurTok().getIdent();

View File

@ -3,6 +3,7 @@
// RUN: cat /tmp/errfile.txt | FileCheck --check-prefix=CHECK-REDIRECTERR %s
// RUN: cat /tmp/bothfile.txt | FileCheck --check-prefix=CHECK-REDIRECTBOTH %s
// RUN: cat /tmp/anotheroutfile.txt | FileCheck --check-prefix=CHECK-REDIRECTANOTHER %s
// RUN: cat /tmp/nospace.txt | FileCheck --check-prefix=CHECK-NOSPACE %s
// RUN: cat %s | %cling 2> /tmp/stderr.txt && cat /tmp/stderr.txt | FileCheck --check-prefix=CHECKERR %s
// RUN: cat %s | %cling 2>&1 | FileCheck --check-prefix=CHECKERR --check-prefix=CHECKOUT %s
@ -126,3 +127,20 @@ b = 711
c = 712
//CHECK-REDIRECTANOTHER: (int) 712
// Test redirect to filename without space
.>/tmp/nospace.txt
a = 1012
//CHECK-NOSPACE: (int) 1012
b = 1023
//CHECK-NOSPACE: (int) 1023
c = 1034
//CHECK-NOSPACE: (int) 1034
// Test append mode to filename without space
.>>/tmp/nospace.txt
a = 9915
//CHECK-NOSPACE: (int) 9915
b = 9926
//CHECK-NOSPACE: (int) 9926
c = 9937
//CHECK-NOSPACE: (int) 9937