You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.2 KiB
78 lines
2.2 KiB
#include "debug.h" |
|
#include "init.h" |
|
#include "globals.h" |
|
|
|
static void usage(const char* prg) |
|
{ |
|
std::cout<<"Usage: "<<prg<<" [-h] [-t num] [-d] [-g] [-i] [-q] file"<<std::endl<< |
|
"-h - this help,"<<std::endl<< |
|
"-t - set number of threads,"<<std::endl<< |
|
"-d - only parse config, print it and return (with -q, nothing printing),"<<std::endl<< |
|
"-g - enable debug messages,"<<std::endl<< |
|
"-i - print information about current actions,"<<std::endl<< |
|
"-q - be quitet, ignore print directives."<<std::endl<< |
|
"-g, -i and -q are mutually exclusive."<<std::endl; |
|
} |
|
|
|
int main(int argc, char** argv) |
|
{ |
|
int ret; |
|
DepTree* DPTree; |
|
struct program_options options; |
|
|
|
// Set default options |
|
options.threads=1; |
|
options.help=options.dump=false; |
|
options.dl=NORMAL; |
|
options.config=0; |
|
|
|
// Parse options |
|
ret=ParseOptions(argc,argv,options); |
|
if(ret!=0 || options.config==0) {usage(argv[0]); return 1;} |
|
if(options.help) {usage(argv[0]); return 0;} |
|
|
|
SetDebugLevel(options.dl); |
|
|
|
COUT(INFO)<<"Parse config file "<<options.config<<" "; |
|
ret=ParseConfigFile(options.config); if(ret!=0) { ClearGlobals(); return 1;} |
|
COUT(INFO)<<"Ok"<<std::endl; |
|
if(G_tosave.size()==0 && G_toprint.size()==0) |
|
{ |
|
COUT(WARNING)<<"No actions needed, exiting"<<std::endl; |
|
ClearGlobals(); |
|
return 0; |
|
} |
|
|
|
{ |
|
UsedType used, all; |
|
for(auto& i:G_vars) all.insert(i.first); |
|
unsigned int tot=G_vars.size(); |
|
|
|
DPTree=new DepTree; |
|
COUT(INFO)<<"Building dependency tree "; |
|
ret=BuildDepTree(DPTree,used); if(ret!=0) { ClearGlobals(); delete DPTree; return 1;} |
|
COUT(INFO)<<"Ok"<<std::endl; |
|
|
|
COUT(INFO)<<"Remove unneeded definitions: "; |
|
for(auto& i:all) if(used.count(i)==0) { delete G_vars[i]; G_vars.erase(i);}; |
|
COUT(INFO)<<(tot-G_vars.size())<<" removed, "<<G_vars.size()<<" remains."<<std::endl; |
|
} |
|
|
|
RegisterArifmeticFunctions(); |
|
|
|
COUT(INFO)<<"Checking functions "; |
|
ret=CheckFunctions(); if(ret!=0) { ClearGlobals(); delete DPTree; return 1;} |
|
COUT(INFO)<<"Ok"<<std::endl; |
|
|
|
if(options.dump) DumpConfig(); |
|
else |
|
{ |
|
COUT(INFO)<<"Evaluate tree "; |
|
ret=DPTree->EvaluateTree(); if(ret!=0) { ClearGlobals(); delete DPTree; return 1;} |
|
COUT(INFO)<<"Ok"<<std::endl; |
|
} |
|
|
|
ClearGlobals(); |
|
delete DPTree; |
|
return 0; |
|
}
|
|
|