- Timestamp:
- Nov 14, 2011, 5:18:56 PM (14 years ago)
- Location:
- trunk/SophyaLib/SysTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/commander.cc
r3814 r4034 55 55 56 56 // Differents code de retour specifiques 57 #define CMD_RETURN_RC 99900 58 #define CMD_BREAK_RC 99990 59 #define CMD_BREAKEXE_RC 99999 57 #define CMD_RETURN_RC 99900 58 #define CMD_BREAK_RC 99990 59 #define CMD_LOOPBREAK_RC 99910 60 #define CMD_BREAKALL_RC 99998 61 #define CMD_BREAKEXE_RC 99999 60 62 61 63 // ------------------------------------------------------------ … … 196 198 if (kw == "if") testlevel++; 197 199 else if (kw == "endif") testlevel--; 198 else if ((kw == "for") || (kw == "foreach")) looplevel++; 200 // bug trouve par JEC en Mai 2011 forinfile manquant ds la ligne suivante 201 else if ((kw == "for") || (kw == "foreach") || (kw == "forinfile")) looplevel++; 199 202 else if (kw == "end") looplevel--; 200 203 else if (kw == "defscript") scrdef = true; … … 217 220 line = ""; 218 221 getline(is,line); 219 if (is.good() || is.eof()) {222 if (is.good()) { // bug signale par JEC en mai 2011 || is.eof()) { 220 223 rcc = ExecuteOnce(line); 221 if ( rcc == CMD_BREAKEXE_RC)return rcc;224 if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc; 222 225 else if (rcc == CMD_BREAK_RC) break; 223 226 } 224 227 } 228 rcc=0; 225 229 } 226 230 else if (typ == BT_ForeachList) { // foreach string loop 227 231 for(unsigned int k=0; k<strlist.size(); k++) { 228 232 rcc = ExecuteOnce(strlist[k]); 229 if ( rcc == CMD_BREAKEXE_RC)return rcc;233 if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc; 230 234 else if (rcc == CMD_BREAK_RC) break; 231 } 235 } 236 rcc = 0; 232 237 } 233 238 else if (typ == BT_ForeachInt) { // Integer loop … … 241 246 string lvv = buff; 242 247 rcc = ExecuteOnce(lvv); 243 if ( rcc == CMD_BREAKEXE_RC)return rcc;248 if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc; 244 249 else if (rcc == CMD_BREAK_RC) break; 245 250 } 251 rcc = 0; 246 252 } 247 253 else if (typ == BT_ForeachFloat) { // float loop … … 254 260 string lvv = cval_dble2str(f); 255 261 rcc = ExecuteOnce(lvv); 256 if ( rcc == CMD_BREAKEXE_RC)return rcc;262 if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc; 257 263 else if (rcc == CMD_BREAK_RC) break; 258 264 } 265 rcc = 0; 259 266 } 260 267 return(rcc); … … 275 282 else 276 283 rcc = blocs[-kk-1]->Execute(); 277 if ( rcc == CMD_BREAKEXE_RC) return (rcc);284 if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc; 278 285 if (rcc == CMD_BREAK_RC) break; 279 286 } … … 346 353 if (kw == "if") testlevel++; 347 354 else if (kw == "endif") testlevel--; 348 else if ((kw == "for") || (kw == "foreach")) looplevel++; 355 // bug trouve par JEC en Mai 2011 forinfile manquant ds la ligne suivante 356 else if ((kw == "for") || (kw == "foreach") || (kw == "forinfile")) looplevel++; 349 357 else if (kw == "end") looplevel--; 350 358 else if (kw == "defscript") scrdef = true; … … 486 494 trace = false; timing = false; 487 495 gltimer = NULL; 488 felevel = 0;496 felevel_ = 0; 489 497 SetMaxLoopLimit(); 490 498 mulinecmd = ""; … … 501 509 fgexebrk = false; 502 510 503 CmdBlks.push(NULL); 504 list<char> xtx; 505 TestsStack.push(xtx); 506 curtestresult = true; 511 curtestresult_ = true; 512 PushStack(); 507 513 508 514 // Pour la numerotation et l'identification des threads … … 537 543 usage += " > else # Conditional \n"; 538 544 usage += " > endif # End of conditional if bloc \n"; 539 usage += " > break # Delete (clears) all test and loop blocs \n"; 545 usage += " > break # exit from the current loop blocs \n"; 546 usage += " > breakall # exit all loop blocs \n"; 540 547 usage += " > return # Stops command execution from a file \n"; 541 548 usage += " > defscript endscript # Command script definition \n"; … … 903 910 // On verifie si nous sommes dans un bloc (for , foreach) 904 911 if (CmdBlks.top() != NULL) { // On est dans un bloc 905 if ( (kw == "for") || (kw == "foreach") || (kw == "forinfile") ) felevel ++;906 else if (kw == "end") felevel --;912 if ( (kw == "for") || (kw == "foreach") || (kw == "forinfile") ) felevel_++; 913 else if (kw == "end") felevel_--; 907 914 908 915 int rcbex = 0; 909 if (felevel == 0) { // Il faut executer le bloc916 if (felevel_ == 0) { // Il faut executer le bloc 910 917 CommanderBloc* curb = CmdBlks.top(); 911 918 CmdBlks.top() = curb->Parent(); … … 921 928 bool ohv = histon; 922 929 histon = false; 923 if (curtestresult ) {930 if (curtestresult_) { 924 931 // We push also CommanderBloc and testresult on the stack 925 CmdBlks.push(NULL); 926 list<char> xtx; 927 TestsStack.push(xtx); 932 PushStack(); 928 933 rcbex = curb->Execute(); 929 // And CommanderBloc and TestResult from the corresponding stacks934 // And then, pop CommanderBloc and TestResult from the corresponding stacks 930 935 PopStack(false); 931 936 } … … 946 951 947 952 // Sommes-nous dans un bloc de test if then else 948 if (TestsStack.top(). size() > 0) { // Nous sommes ds un bloc if953 if (TestsStack.top().tstlist.size() > 0) { // Nous sommes ds un bloc if 949 954 if (kw == "else") { 950 if ((*tresit ) & 2) {955 if ((*tresit_) & 2) { 951 956 cerr << "Commander::Interpret()/syntax error - multiple else in if bloc \n" 952 957 << "line: " << s << endl; … … 955 960 } 956 961 else { 957 const char * npr = ((*tresit )&1) ? "else-F> " : "else-T> ";958 if ((*tresit )&1) curtestresult= false;962 const char * npr = ((*tresit_)&1) ? "else-F> " : "else-T> "; 963 if ((*tresit_)&1) curtestresult_ = false; 959 964 SetCurrentPrompt(npr); 960 (*tresit ) |= 2;965 (*tresit_) |= 2; 961 966 _xstatus = 0; 962 967 return(0); … … 964 969 } 965 970 else if (kw == "endif") { 966 list<char>::iterator dbit = tresit ;967 tresit --;968 TestsStack.top(). erase(dbit);971 list<char>::iterator dbit = tresit_; 972 tresit_--; 973 TestsStack.top().tstlist.erase(dbit); 969 974 const char * npr = "Cmd> "; 970 if (TestsStack.top(). size() > 1) {971 curtestresult = true;975 if (TestsStack.top().tstlist.size() > 1) { 976 curtestresult_ = true; 972 977 list<char>::iterator it; 973 for(it=TestsStack.top(). begin(); it!=TestsStack.top().end(); it++) {978 for(it=TestsStack.top().tstlist.begin(); it!=TestsStack.top().tstlist.end(); it++) { 974 979 // Si on n'est pas ds le else et le if est faux 975 if ( !((*it)&2) && !((*it)&1) ) curtestresult = false;980 if ( !((*it)&2) && !((*it)&1) ) curtestresult_ = false; 976 981 // Si on est ds else et le if etait vrai ! 977 if ( ((*it)&2) && ((*it)&1) ) curtestresult = false;978 if (!curtestresult ) break;982 if ( ((*it)&2) && ((*it)&1) ) curtestresult_ = false; 983 if (!curtestresult_) break; 979 984 } 980 985 981 if (!((*tresit )&2))982 npr = ((*tresit )&1) ? "if-T> " : "if-F> ";986 if (!((*tresit_)&2)) 987 npr = ((*tresit_)&1) ? "if-T> " : "if-F> "; 983 988 else 984 npr = ((*tresit )&1) ? "else-F> " : "else-T> ";985 } 986 else curtestresult = true;989 npr = ((*tresit_)&1) ? "else-F> " : "else-T> "; 990 } 991 else curtestresult_ = true; 987 992 SetCurrentPrompt(npr); 988 993 _xstatus = 0; … … 998 1003 999 1004 bool fgcont = true; 1000 if (TestsStack.top(). size() > 0) { // Resultat de if ou else1005 if (TestsStack.top().tstlist.size() > 0) { // Resultat de if ou else 1001 1006 list<char>::iterator it; 1002 for(it=TestsStack.top(). begin(); it!=TestsStack.top().end(); it++) {1007 for(it=TestsStack.top().tstlist.begin(); it!=TestsStack.top().tstlist.end(); it++) { 1003 1008 // Si on n'est pas ds le else et le if est faux 1004 1009 if ( !((*it)&2) && !((*it)&1) ) fgcont = false; … … 1017 1022 // Les mots cles break et return peuvent de sortir de boucles/scripts/execfile 1018 1023 if (kw == "break") return CMD_BREAK_RC; 1024 if (kw == "breakall") return CMD_BREAKALL_RC; 1019 1025 else if (kw == "return") { 1020 1026 _retstr = toks; … … 1049 1055 return(91); 1050 1056 } 1051 felevel ++;1057 felevel_++; 1052 1058 if (CmdBlks.top()) CmdBlks.top()->AddBloc(bloc); 1053 1059 else SetCurrentPrompt("for...> "); … … 1065 1071 } 1066 1072 char res_tst = (restst) ? 1 : 0; 1067 TestsStack.top(). push_back(res_tst);1068 if (TestsStack.top(). size() == 1) tresit = TestsStack.top().begin();1069 else tresit ++;1073 TestsStack.top().tstlist.push_back(res_tst); 1074 if (TestsStack.top().tstlist.size() == 1) tresit_ = TestsStack.top().tstlist.begin(); 1075 else tresit_++; 1070 1076 const char * npr = (restst) ? "if-T> " : "if-F> "; 1071 1077 SetCurrentPrompt(npr); … … 1717 1723 1718 1724 1719 /* --Methode-- */ 1720 int Commander::EvalRPNExpr(vector<string> & args, string & line) 1721 { 1722 // A virer - Reza 15/03/2004 1723 return(0); 1724 } 1725 1726 /* --Methode-- */ 1727 void Commander::PushStack(vector<string>& args) 1728 { 1729 // We push the argument list (args) on the stack 1730 ArgsStack.push(args); 1725 1726 /* --Methode-- */ 1727 void Commander::PushStack(vector<string>* pargs) 1728 { 1729 // We push the argument list (args) on the stack if not NULL 1730 if (pargs != NULL) ArgsStack.push(*pargs); 1731 1731 // We push also CommanderBloc and testresult on the stack 1732 1732 CmdBlks.push(NULL); 1733 list<char> xtx; 1734 TestsStack.push(xtx); 1735 1733 if (TestsStack.size()>0) { 1734 TestsStack.top().tstresit=tresit_; 1735 TestsStack.top().tstcurres=curtestresult_; 1736 } 1737 TstStatus tstat; 1738 tstat.tstcurres=curtestresult_; 1739 TestsStack.push(tstat); 1736 1740 } 1737 1741 … … 1749 1753 CmdBlks.pop(); 1750 1754 TestsStack.pop(); 1755 tresit_=TestsStack.top().tstresit; 1756 curtestresult_=TestsStack.top().tstcurres; 1751 1757 } 1752 1758 -
trunk/SophyaLib/SysTools/commander.h
r3572 r4034 97 97 virtual string& GetUsage(const string& kw); 98 98 99 inline void SetMaxLoopLimit(int_8 lim=0) { maxlooplimit = lim; }100 inline int_8 GetMaxLoopLimit() { return maxlooplimit ; }99 inline void SetMaxLoopLimit(int_8 lim=0) { maxlooplimit_ = lim; } 100 inline int_8 GetMaxLoopLimit() { return maxlooplimit_; } 101 101 102 102 string GetCurrentPrompt() { return curprompt; } … … 147 147 int EvaluateTest(vector<string> & args, 148 148 string & line, bool & res); 149 int EvalRPNExpr(vector<string> & args, string & line);150 149 151 150 // variable de l'interpreteur = valeur - accepte la syntaxe de type varname[index] … … 166 165 virtual void ShowMessage(const char * msg, int att); 167 166 168 void PushStack(vector<string> & args); 167 void PushStack(vector<string> * pargs); 168 inline void PushStack() { PushStack(NULL); return; } 169 inline void PushStack(vector<string> & args) { PushStack(&args); return; } 169 170 void PopStack(bool psta=true); 170 171 … … 229 230 // Gestion des blocs de commandes et tests (if) 230 231 stack< CommanderBloc * > CmdBlks; // Bloc de commande courant (foreach, ...) 231 int felevel; // foreach-for level 232 int_8 maxlooplimit; // Limite maximum des boucles 233 stack< list<char> > TestsStack; // Stack des resultats de test 234 list<char>::iterator tresit; // Test courant 235 bool curtestresult; // Resultat courant des tests 232 int felevel_; // foreach-for level 233 int_8 maxlooplimit_; // Limite maximum des boucles 234 /*! \cond Pour supprimer la documentation par doxygen */ 235 typedef struct {list<char> tstlist; list<char>::iterator tstresit; bool tstcurres; } TstStatus; 236 /*! \endcond */ 237 stack< TstStatus > TestsStack; // Stack des resultats de test 238 list<char>::iterator tresit_; // Test courant 239 bool curtestresult_; // Resultat courant des tests 236 240 237 241 // Controle du flot d'execution
Note:
See TracChangeset
for help on using the changeset viewer.