diff --git a/src/init.cpp b/src/init.cpp index 5346d01..5b8ca99 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -5,6 +5,11 @@ #include "globals.h" #include "arifmetic.h" #include "parser/parser.h" +// We can't include lexical.h before grammatical.h, because of strange errors, but grammatical.h only needs definition of yyscan_t +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif #include "parser/grammatical.h" // definitions for bison-bridge #define YYSTYPE CONFSTYPE @@ -13,6 +18,34 @@ #undef YYSTYPE #undef YYLTYPE + +int ParseOptions(int argc, char** argv, struct program_options& options) +{ + int opt=0; + const char* optstr="t:hdgiq"; + + optind=1; + do + { + opt=getopt(argc,argv,optstr); + switch(opt) + { + case(-1): break; + case('t'):{options.threads=atoi(optarg); if(options.threads<1) return 1; else break;} + case('h'):{options.help=true; break;} + case('d'):{options.dump=true; break;} + case('g'):{options.dl=DEBUG; break;} + case('i'):{options.dl=INFO; break;} + case('q'):{options.dl=WARNING; break;} + default: return 1; + } + } while(-1!=opt); + if(optind!=argc-1) return 1; + options.config=argv[optind]; + return 0; +} + + int ParseConfigFile(const char* config) { yyscan_t scanner; @@ -112,7 +145,7 @@ int CheckFunctions() void DumpConfig() { - for(auto& i: G_vars) COUT(INFO)<Dump()<<";"<Dump()<<";"<Dump()<<";"<Dump()<<";"<Dump()<<";"<EvaluateTree(); if(ret!=0) { ClearGlobals(); delete DPTree; return 1;} - COUT(INFO)<<"Ok"<EvaluateTree(); if(ret!=0) { ClearGlobals(); delete DPTree; return 1;} + COUT(INFO)<<"Ok"<