00001 #include "rulesystem.h"
00002 #include <stdio.h>
00003 #include <dirent.h>
00004
00005 #include "stree.h"
00006 #include "streeconstant.h"
00007 #include "streepin.h"
00008 #include "streevariable.h"
00009 #include "treeparser.h"
00010 #include "rtreenamedcontextrule.h"
00011 #include "namedcontext.h"
00012
00019 void RuleSystem::execute(const string &phpFileName, StatementList *phpIn, StatementList *phpOut, StatementList *tplOut) {
00020 NamedContextRule mainRule(new Constant(MAINCONTEXTNAME), runRules[MAINCONTEXTNAME],
00021 NULL, NULL, NULL, NULL, NULL);
00022 NameSpace fileNameSpace(&mainNameSpace);
00023 Node::Assignment assign;
00024 mainRule.runRules(fileNameSpace, phpIn, phpOut, tplOut, assign);
00025 mainNameSpace.importLocals(phpFileName, fileNameSpace);
00026 };
00027
00028
00029 RuleSystem::RuleSystem(int debug) {
00030
00031 DIR *rulesDir = opendir(MYRULES);
00032 struct dirent *rulesFile;
00033
00034 readdir(rulesDir);
00035 readdir(rulesDir);
00036
00037 while ((rulesFile = readdir(rulesDir))){
00038 if (strcmp(rulesFile->d_name + strlen(rulesFile->d_name) - 3,"txt")==0){
00039 cout << "Parsing rules - " << rulesFile->d_name << endl;
00040 NamedRuleList* namedRuleList =
00041 ruleParser->parse(string(MYRULES)+string(rulesFile->d_name),this, debug);
00042
00043 runRules[namedRuleList->name][namedRuleList->runTime].append(namedRuleList->rules);
00044 ruleRunTimes.insert(namedRuleList->runTime);
00045 };
00046 };
00047 courrentRunTime = ruleRunTimes.begin();
00048 };
00049
00050 bool RuleSystem::stepTime(){
00051 courrentRunTime++;
00052 if (courrentRunTime!=ruleRunTimes.end()){
00053 mainNameSpace.setRuleRunTime(*courrentRunTime);
00054 return true;
00055 } else
00056 return false;
00057 };
00058
00059 RuleSystem::~RuleSystem(){
00060
00061
00062
00063
00064
00065
00066 };
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080