From 2a952e107509cbc743b351e32663bfc8c6df9211 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 29 Dec 2015 13:17:37 +0100 Subject: add sys_select (WIP) and fix source from stdin --- runtime.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'runtime.cpp') diff --git a/runtime.cpp b/runtime.cpp index 19108cd..9fbb3c5 100644 --- a/runtime.cpp +++ b/runtime.cpp @@ -7,9 +7,12 @@ #include #include #include +#include #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 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 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 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"); + } } -- cgit v1.2.3-54-g00ecf