Changeset 4034 in Sophya for trunk


Ignore:
Timestamp:
Nov 14, 2011, 5:18:56 PM (14 years ago)
Author:
ansari
Message:

1/ Corrections dans commander.cc des bugs de forinfile et boucles imbriquees
2/ Différentiation instruction break et breakall - gestion correcte des if
lors de la sortie de boucle. Reza 14/11/2011

Location:
trunk/SophyaLib/SysTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SysTools/commander.cc

    r3814 r4034  
    5555
    5656// 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
    6062
    6163// ------------------------------------------------------------
     
    196198  if (kw == "if")  testlevel++;
    197199  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++;
    199202  else if (kw == "end")  looplevel--;
    200203  else if (kw == "defscript")  scrdef = true;
     
    217220    line = "";
    218221    getline(is,line);
    219     if (is.good() || is.eof()) {
     222    if (is.good()) { // bug signale par JEC en mai 2011 || is.eof()) {
    220223      rcc = ExecuteOnce(line);
    221       if (rcc == CMD_BREAKEXE_RC) return rcc;
     224      if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc;
    222225      else if (rcc == CMD_BREAK_RC)  break;
    223226    }
    224227  }
     228  rcc=0;
    225229}
    226230else if (typ == BT_ForeachList) {  // foreach string loop
    227231  for(unsigned int k=0; k<strlist.size(); k++) {
    228232    rcc = ExecuteOnce(strlist[k]);
    229     if (rcc == CMD_BREAKEXE_RC) return rcc;
     233    if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc;
    230234    else if (rcc == CMD_BREAK_RC)  break;
    231   } 
     235  }
     236  rcc = 0; 
    232237}
    233238else if (typ == BT_ForeachInt)  { // Integer loop
     
    241246    string lvv = buff;
    242247    rcc = ExecuteOnce(lvv);
    243     if (rcc == CMD_BREAKEXE_RC) return rcc;
     248    if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc;
    244249    else if (rcc == CMD_BREAK_RC)  break;
    245250  }
     251  rcc = 0;
    246252}
    247253else if (typ == BT_ForeachFloat)  { // float loop
     
    254260    string lvv = cval_dble2str(f);
    255261    rcc = ExecuteOnce(lvv);
    256     if (rcc == CMD_BREAKEXE_RC) return rcc;
     262    if ((rcc == CMD_BREAKEXE_RC) || (rcc == CMD_BREAKALL_RC)) return rcc;
    257263    else if (rcc == CMD_BREAK_RC)  break;
    258264  }
     265  rcc = 0;
    259266}
    260267return(rcc);
     
    275282    else
    276283      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;
    278285    if (rcc == CMD_BREAK_RC)  break;   
    279286  }
     
    346353  if (kw == "if")  testlevel++;
    347354  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++;
    349357  else if (kw == "end")  looplevel--;
    350358  else if (kw == "defscript")  scrdef = true;
     
    486494trace = false;   timing = false;
    487495gltimer = NULL;
    488 felevel = 0;
     496felevel_ = 0;
    489497SetMaxLoopLimit();
    490498mulinecmd = "";
     
    501509 fgexebrk = false;
    502510
    503 CmdBlks.push(NULL);
    504 list<char> xtx;
    505 TestsStack.push(xtx);
    506 curtestresult = true;
     511curtestresult_ = true;
     512PushStack();
    507513
    508514// Pour la numerotation et l'identification des threads
     
    537543usage += "  > else          # Conditional  \n";
    538544usage += "  > endif         # End of conditional if bloc \n";
    539 usage += "  > break         # Delete (clears) all test and loop blocs \n";
     545usage += "  > break         # exit from the current loop blocs \n";
     546usage += "  > breakall      # exit all loop blocs \n";
    540547usage += "  > return        # Stops command execution from a file \n";
    541548usage += "  > defscript endscript # Command script definition \n";
     
    903910// On verifie si nous sommes dans un bloc (for , foreach)
    904911if (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_--;
    907914
    908915  int rcbex = 0;
    909   if (felevel == 0) { // Il faut executer le bloc
     916  if (felevel_ == 0) { // Il faut executer le bloc
    910917    CommanderBloc* curb = CmdBlks.top();
    911918    CmdBlks.top() = curb->Parent();
     
    921928    bool ohv = histon;
    922929    histon = false;
    923     if (curtestresult) {
     930    if (curtestresult_) {
    924931      // We push also CommanderBloc and testresult on the stack
    925       CmdBlks.push(NULL);
    926       list<char> xtx;
    927       TestsStack.push(xtx);
     932      PushStack();
    928933      rcbex = curb->Execute();
    929       // And CommanderBloc and TestResult from the corresponding stacks
     934      // And then, pop CommanderBloc and TestResult from the corresponding stacks
    930935      PopStack(false);
    931936    }
     
    946951
    947952// Sommes-nous dans un bloc de test if then else
    948 if (TestsStack.top().size() > 0) {  // Nous sommes ds un bloc if
     953if (TestsStack.top().tstlist.size() > 0) {  // Nous sommes ds un bloc if
    949954  if (kw == "else") {
    950     if ((*tresit) & 2) {
     955    if ((*tresit_) & 2) {
    951956      cerr << "Commander::Interpret()/syntax error - multiple else in if bloc \n"
    952957           << "line: " << s << endl;
     
    955960    }
    956961    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;
    959964      SetCurrentPrompt(npr);
    960       (*tresit) |= 2;
     965      (*tresit_) |= 2;
    961966      _xstatus = 0;
    962967      return(0);
     
    964969  }
    965970  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);
    969974    const char * npr = "Cmd> ";
    970     if (TestsStack.top().size() > 1) {
    971       curtestresult = true;
     975    if (TestsStack.top().tstlist.size() > 1) {
     976      curtestresult_ = true;
    972977      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++) {
    974979        // 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;
    976981        // 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;
    979984      }
    980985     
    981       if (!((*tresit)&2))
    982         npr = ((*tresit)&1) ? "if-T> " : "if-F> ";
     986      if (!((*tresit_)&2))
     987        npr = ((*tresit_)&1) ? "if-T> " : "if-F> ";
    983988      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;
    987992    SetCurrentPrompt(npr);
    988993    _xstatus = 0;
     
    9981003
    9991004bool fgcont = true;
    1000 if (TestsStack.top().size() > 0) { // Resultat de if ou else
     1005if (TestsStack.top().tstlist.size() > 0) { // Resultat de if ou else
    10011006  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++) {
    10031008    // Si on n'est pas ds le else et le if est faux
    10041009    if ( !((*it)&2) && !((*it)&1) )  fgcont = false;
     
    10171022// Les mots cles break et return peuvent de sortir de boucles/scripts/execfile
    10181023if (kw == "break") return CMD_BREAK_RC;
     1024if (kw == "breakall") return CMD_BREAKALL_RC;
    10191025else if (kw == "return")  {
    10201026  _retstr = toks;
     
    10491055    return(91);
    10501056    }
    1051   felevel++;
     1057  felevel_++;
    10521058  if (CmdBlks.top())  CmdBlks.top()->AddBloc(bloc);
    10531059  else  SetCurrentPrompt("for...> ");
     
    10651071  }
    10661072  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_++;
    10701076  const char * npr = (restst) ? "if-T> " : "if-F> ";
    10711077  SetCurrentPrompt(npr);
     
    17171723
    17181724 
    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-- */
     1727void 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);
    17311731  // We push also CommanderBloc and testresult on the stack
    17321732  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);
    17361740}
    17371741
     
    17491753  CmdBlks.pop();
    17501754  TestsStack.pop();
     1755  tresit_=TestsStack.top().tstresit;
     1756  curtestresult_=TestsStack.top().tstcurres;
    17511757}
    17521758
  • trunk/SophyaLib/SysTools/commander.h

    r3572 r4034  
    9797  virtual string&       GetUsage(const string& kw);
    9898
    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_; }
    101101
    102102  string                GetCurrentPrompt() { return curprompt; }
     
    147147  int           EvaluateTest(vector<string> & args,
    148148                             string & line, bool & res);
    149   int           EvalRPNExpr(vector<string> & args, string & line);
    150149
    151150  // variable de l'interpreteur = valeur - accepte la syntaxe de type varname[index]
     
    166165  virtual void  ShowMessage(const char * msg, int att);
    167166
    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; }
    169170  void          PopStack(bool psta=true);
    170171
     
    229230  // Gestion des blocs de commandes et tests (if)
    230231  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
    236240
    237241  // Controle du flot d'execution
Note: See TracChangeset for help on using the changeset viewer.