Change flag for redirection.

correct
This commit is contained in:
CristinaCristescu 2013-12-17 17:34:53 +01:00 committed by sftnight
parent 34dfd69b53
commit d30b5a0a23
6 changed files with 32 additions and 38 deletions

View File

@ -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;

View File

@ -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");
}
}
}

View File

@ -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;
}

View File

@ -33,7 +33,7 @@ namespace cling {
slash, // "/"
backslash, // "\"
greater, // ">"
ampersand, // "&"
ampersand, // "&"
ident, // (a-zA-Z)[(0-9a-zA-Z)*]
raw_ident, // .*^(' '|'\t')
comment, // //

View File

@ -163,6 +163,7 @@ namespace cling {
}
if (getCurTok().is(tok::ampersand)) {
stream = cling::Interpreter::kSTDBOTH;
consumeToken();
}
if (getCurTok().is(tok::greater)) {
bool append = false;

View File

@ -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;
}