diff --git a/include/cling/Interpreter/Interpreter.h b/include/cling/Interpreter/Interpreter.h index e472bbf2..24ddfbf6 100644 --- a/include/cling/Interpreter/Interpreter.h +++ b/include/cling/Interpreter/Interpreter.h @@ -120,7 +120,6 @@ namespace cling { }; enum RedirectStream { - kSTDIN, kSTDOUT, kSTDERR, kSTDBOTH @@ -181,13 +180,9 @@ namespace cling { /// bool m_RawInputEnabled; - ///flag redirect + ///flag redirect out bool m_RedirectEnabled; - //bool m_AppendOut; - - //bool m_AppendErr; - std::string m_FileOut; std::string m_FileErr; diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index 3575a18a..e9ba5aec 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -138,29 +138,25 @@ namespace cling { } Interpreter::MaybeRedirectOutputRAII::MaybeRedirectOutputRAII(Interpreter* i) - :m_Interpreter(i) { + :m_Interpreter(i), terminalOut(0), terminalErr(0) { - if (m_Interpreter->isRedirectEnabled()) { - if (!m_Interpreter->m_FileOut.empty()) { - terminalOut = ttyname(STDOUT_FILENO); - stdout = freopen(m_Interpreter->m_FileOut.c_str(), "a", stdout); - } - if (!m_Interpreter->m_FileErr.empty()) { - terminalErr = ttyname(STDERR_FILENO); - stderr = freopen(m_Interpreter->m_FileErr.c_str(), "a", stderr); - } + if (!m_Interpreter->m_FileOut.empty()) { + terminalOut = ttyname(STDOUT_FILENO); + stdout = freopen(m_Interpreter->m_FileOut.c_str(), "a", stdout); + } + if (!m_Interpreter->m_FileErr.empty()) { + terminalErr = ttyname(STDERR_FILENO); + stderr = freopen(m_Interpreter->m_FileErr.c_str(), "a", stderr); } } void Interpreter::MaybeRedirectOutputRAII::pop() { - if(m_Interpreter->isRedirectEnabled()) { - if (terminalOut) { - stdout = freopen(terminalOut, "w", stdout); - } - if (terminalErr) { - stderr = freopen(terminalErr, "w", stderr); - } + if (terminalOut) { + stdout = freopen(terminalOut, "w", stdout); + } + if (terminalErr) { + stderr = freopen(terminalErr, "w", stderr); } } @@ -1090,18 +1086,16 @@ namespace cling { void Interpreter::setOutStream(llvm::StringRef file, RedirectStream stream, bool append) { - if (isRedirectEnabled()) { - if (stream == kSTDOUT || stream == kSTDBOTH) { - m_FileOut = file; - if (!append) { - FILE* f = fopen(m_FileOut.c_str(), "w"); - } + if (stream == kSTDOUT || stream == kSTDBOTH) { + m_FileOut = file; + if (!append && !m_FileOut.empty()) { + FILE* f = fopen(m_FileOut.c_str(), "w"); } - if (stream == kSTDERR || stream == kSTDBOTH) { - m_FileErr = file; - if (!append) { - FILE* f = fopen(m_FileErr.c_str(), "w"); - } + } + if (stream == kSTDERR || stream == kSTDBOTH) { + m_FileErr = file; + if (!append && !m_FileErr.empty()) { + FILE* f = fopen(m_FileErr.c_str(), "w"); } } } diff --git a/lib/MetaProcessor/MetaLexer.cpp b/lib/MetaProcessor/MetaLexer.cpp index 4ae05d61..924707a4 100644 --- a/lib/MetaProcessor/MetaLexer.cpp +++ b/lib/MetaProcessor/MetaLexer.cpp @@ -113,7 +113,7 @@ namespace cling { case '/' : Tok.setKind(tok::slash); break; case '\\' : Tok.setKind(tok::backslash); break; case '>' : Tok.setKind(tok::greater); break; - case '%' : Tok.setKind(tok::ampersand); break; + case '&' : Tok.setKind(tok::ampersand); break; case '\0' : Tok.setKind(tok::eof); Tok.setLength(0); break;// if static call default: Tok.setLength(0); break; } diff --git a/lib/MetaProcessor/MetaLexer.h b/lib/MetaProcessor/MetaLexer.h index 4a6b8eba..0c92f48a 100644 --- a/lib/MetaProcessor/MetaLexer.h +++ b/lib/MetaProcessor/MetaLexer.h @@ -33,7 +33,7 @@ namespace cling { slash, // "/" backslash, // "\" greater, // ">" - ampersand, // "&" + ampersand, // "&" ident, // (a-zA-Z)[(0-9a-zA-Z)*] raw_ident, // .*^(' '|'\t') comment, // // diff --git a/lib/MetaProcessor/MetaParser.cpp b/lib/MetaProcessor/MetaParser.cpp index bfaf9538..923bce6f 100644 --- a/lib/MetaProcessor/MetaParser.cpp +++ b/lib/MetaProcessor/MetaParser.cpp @@ -163,6 +163,7 @@ namespace cling { } if (getCurTok().is(tok::ampersand)) { stream = cling::Interpreter::kSTDBOTH; + consumeToken(); } if (getCurTok().is(tok::greater)) { bool append = false; diff --git a/lib/MetaProcessor/MetaSema.cpp b/lib/MetaProcessor/MetaSema.cpp index c3f38f10..36a82772 100644 --- a/lib/MetaProcessor/MetaSema.cpp +++ b/lib/MetaProcessor/MetaSema.cpp @@ -49,13 +49,17 @@ namespace cling { bool append) { if (!file.str().empty()) { - m_Interpreter.enableRedirect(true); + //m_Interpreter.enableRedirect(true); m_Interpreter.setOutStream(file, stream, append); return AR_Success; } else { - m_Interpreter.enableRedirect(); + m_Interpreter.setOutStream(file, stream, append); + return AR_Success; } + //else { + //m_Interpreter.enableRedirect(); + //} return AR_Failure; }