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.
 
 
 
 
 
 

72 lines
1.9 KiB

#include "init.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=0;
DepTree* DPTree=nullptr;
struct program_options options;
// Set default options
options.threads=1;
options.help=options.dump=false;
options.dl=NORMAL;
options.config=nullptr;
// Parse options
ret=ParseOptions(argc,argv,options);
if(ret!=0 || nullptr==options.config) {usage(argv[0]); return 1;}
if(options.help) {usage(argv[0]); return 0;}
SetDebugLevel(options.dl);
RegisterBuiltinFunctions();
{
VarType vars;
ExecType ToPrint, ToSave;
COUT(INFO)<<"Parse config file "<<options.config<<" ";
ret=ParseConfigFile(options.config,ToSave,ToPrint,vars); if(ret!=0) { ClearGlobals(); return 1;}
COUT(INFO)<<"Ok"<<std::endl;
if(ToSave.size()==0 && ToPrint.size()==0)
{
COUT(WARNING)<<"No actions needed, exiting"<<std::endl;
ClearGlobals();
return 0;
}
DPTree=new DepTree;
COUT(INFO)<<"Building dependency tree ";
ret=DPTree->CreateTree(ToSave,ToPrint,vars);
if(ret!=0) goto end;
COUT(INFO)<<"Ok"<<std::endl;
}
COUT(INFO)<<"Checking functions ";
ret=DPTree->CheckFunctions(); if(ret!=0) goto end;
COUT(INFO)<<"Ok"<<std::endl;
if(options.dump) DPTree->DumpTree();
else
{
COUT(INFO)<<"Evaluate tree ";
ret=DPTree->EvaluateTree(options.threads); if(ret!=0) goto end;
COUT(INFO)<<"Ok"<<std::endl;
}
end:
ClearGlobals();
if(nullptr!=DPTree) delete DPTree;
return (0==ret)?0:1;
}