diff options
Diffstat (limited to 'runtime.cpp')
-rw-r--r-- | runtime.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/runtime.cpp b/runtime.cpp index 19108cd..9fbb3c5 100644 --- a/runtime.cpp +++ b/runtime.cpp @@ -7,9 +7,12 @@ #include <functional> #include <cstring> #include <cassert> +#include <termios.h> #include "runtime.h" +extern bool input_is_stdin; + using namespace std; inline bool isword(char c){return isalpha(c)||c=='_'||c=='@'||c=='$';} @@ -94,8 +97,8 @@ vector<string> tokenise(istream &stream){ while(c=='#'){ while((c=stream.get())!='\n'&&stream); c=stream.get(); - if(!stream)break; } + if(!stream)break; if(isdigit(c)){ if(token.size()==0){ token="#"; @@ -149,7 +152,7 @@ vector<string> tokenise(istream &stream){ token+=c; } } else if(isspace(c)); - else throw string("Invalid character found in source: '")+c+'\''; + else throw string("Invalid character found in source: '")+c+"' ("+to_string((int)(unsigned char)c)+')'; } } if(token.size())tokens.push_back(move(token)); @@ -346,4 +349,13 @@ void run(vector<string> T){ //third pass, evaluate code runpasseval(T,S,functions,variables,jumpmap); + + if(!input_is_stdin){ + //restore canonical mode, since the code might have changed it to raw mode + struct termios old={0}; + if(tcgetattr(0,&old)<0)perror("tcgetattr"); + old.c_lflag|=ICANON; + old.c_lflag|=ECHO; + if(tcsetattr(0,TCSANOW,&old)<0)perror("tcsetattr"); + } } |