Skip to content

Commit

Permalink
Shell: Implement specifying fds in file redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
karolba authored and awesomekling committed Dec 5, 2019
1 parent cf7910f commit 7ed8a46
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Shell/Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Parser.h"
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>

void Parser::commit_token()
{
Expand Down Expand Up @@ -102,6 +103,28 @@ Vector<Command> Parser::parse()
m_state = State::InDoubleQuotes;
break;
}
if (isdigit(ch)) {
if (i != m_input.length() - 1) {
char next_ch = m_input.characters()[i + 1];
if (next_ch == '>') {
commit_token();
begin_redirect_write(ch - '0');
++i;

// Search for another > for append.
m_state = State::InWriteAppendOrRedirectionPath;
break;
}
if (next_ch == '<') {
commit_token();
begin_redirect_read(ch - '0');
++i;

m_state = State::InRedirectionPath;
break;
}
}
}
m_token.append(ch);
break;
case State::InWriteAppendOrRedirectionPath:
Expand Down

0 comments on commit 7ed8a46

Please sign in to comment.