diff options
Diffstat (limited to 'postrun.cpp')
-rw-r--r-- | postrun.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/postrun.cpp b/postrun.cpp index 2c3c97f..c880337 100644 --- a/postrun.cpp +++ b/postrun.cpp @@ -11,6 +11,8 @@ using namespace std; int g_argc; char **g_argv; +bool input_is_stdin=false; + string readfile(ifstream stream){ stream.seekg(0,ios::end); size_t len=stream.tellg(); @@ -26,24 +28,30 @@ int main(int argc,char **argv){ cerr<<"Call this interpreter with the Postrun source file"<<endl; return 1; } - g_argc=argc-2; - g_argv=argv+2; //skip this executable and the postrun file - ifstream srcf(argv[1]); - if(!srcf){ - cerr<<"Could not open file '"<<argv[1]<<"'"<<endl; - return 1; - } struct timeval tv; gettimeofday(&tv,NULL); srand(tv.tv_sec*1000000+tv.tv_usec); - //string source=readfile(srcf); + g_argc=argc-2; + g_argv=argv+2; //skip this executable and the postrun file + try { - const vector<string> tokens=tokenise(srcf); - //for(const string &tok : tokens)cerr<<'['<<tok<<"] "; cerr<<endl; + ifstream srcf; + vector<string> tokens; + if(strcmp(argv[1],"-")==0){ + tokens=tokenise(cin); + input_is_stdin=true; + } else { + srcf.open(argv[1]); + if(!srcf){ + cerr<<"Could not open file '"<<argv[1]<<"'"<<endl; + return 1; + } + tokens=tokenise(srcf); + } run(tokens); - srcf.close(); + if(srcf)srcf.close(); } catch(string e){ cerr<<"ERROR: "<<e<<endl; return 1; |