Changeset 2518 in Sophya for trunk/SophyaLib/SysTools


Ignore:
Timestamp:
Mar 18, 2004, 7:15:19 PM (22 years ago)
Author:
ansari
Message:

Suite (presque finie) des modifications de l'interpreteur - gestion des variables en particulier - Reste au moins un bug ds CExpressionEvaluator - Reza 18/03/2004

Location:
trunk/SophyaLib/SysTools
Files:
3 edited

Legend:

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

    r2515 r2518  
    5959    errmsg += s;
    6060   
    61     if ((s == "+") || (s == "-"))  throw CExprException(errmsg);
    62     for(int k=0; k<l; k++) {
    63       if ((!isdigit(s[k])) && !((k==0) && (s[k] != '+') || (s[k] != '-')) )
    64         throw CExprException(errmsg);
    65     }
    66     _val = atof(s.c_str());
     61    char* lcc;
     62    _val = strtod(s.c_str(), &lcc);
     63    if (*lcc != '\0')  throw CExprException(errmsg);
    6764  }
    6865}
     
    173170  else if (func == "atan") _f1 = atan;
    174171  else if (func == "atan2") _f2 = atan2;
     172  else if (func == "sqrt") _f1 = sqrt;
     173  else if (func == "fabs") _f1 = fabs;
     174  else if (func == "floor") _f1 = floor;
    175175  else if (func == "exp") _f1 = exp;
    176176  else if (func == "log") _f1 = log;
    177177  else if (func == "log10") _f1 = log10;
    178178  else if (func == "pow") _f2 = pow;
     179  else if (func == "hypot") _f2 = hypot;
     180  else if (func == "sinh") _f1 = sinh;
     181  else if (func == "cosh") _f1 = cosh;
     182  else if (func == "tanh") _f1 = tanh;
    179183  else {
    180184    string errmsg = "CE_FuncExp::CE_FuncExp() - Uknown function " ;
  • trunk/SophyaLib/SysTools/commander.cc

    r2512 r2518  
    22#include <stdio.h>
    33#include <stdlib.h>
     4#include <unistd.h>
    45#include <ctype.h>
    56#include <math.h>
     
    1314
    1415namespace SOPHYA {
     16
     17// Differents code de retour specifiques
     18#define CMD_RETURN_RC  99900
     19#define CMD_BREAK_RC   99990
     20#define CMD_BREAKEXE_RC 99999
     21
    1522// ------------------------------------------------------------
    1623//         Bloc de commandes (Foreach, ...)   
     
    3643  inline void   AddBloc(CommanderBloc* blk) 
    3744    { blocs.push_back(blk); bloclineid.push_back(-blocs.size()); }
    38   CommanderBloc*        Execute();
     45
     46  // Execution complete du bloc (boucle)
     47  int           Execute();
     48  // Execution pour un element de bloc
     49  int           ExecuteOnce(string& lvv);
     50
    3951  inline int&   TestLevel()  { return testlevel; }
    4052  inline int&   LoopLevel()  { return looplevel; }
     
    7486if ((args.size() < 2) ||  !isalpha((int)args[0][0]) )  return;
    7587if ((kw != "foreach") && (kw != "for") && (kw != "forinfile"))  return;
    76 varname = args[0];  // $CHECK$ Variable name should be checked
     88if (!piac->CheckVarName(args[0])) return;
     89varname = args[0]; 
     90
    7791//if (isalpha((int)args[1][0]) ) {  This is a foreach bloc with string list
    7892if (kw == "forinfile") {
    7993  filename = args[1];
     94  typ = BT_ForeachLineInFile;
    8095  blkok = true;
    8196}
    8297else if (kw == "foreach" ) { // This is a foreach bloc with string list
    83   if ((args[1] != "(") || (args[args.size()-1] != ")") ) return;
    84   for(int kk=2; kk<args.size()-1; kk++) strlist.push_back(args[kk]);
     98  if ( (args[1] == "(") && (args[args.size()-1] == ")") ) {
     99    // foreach varname ( w1 w2 w3 ... )
     100    for(int kk=2; kk<args.size()-1; kk++) strlist.push_back(args[kk]);
     101  }
     102  else {
     103    // foreach varname WordVectorName
     104    if (!piac->GetVar(args[1], strlist))  return;
     105  }
     106  if (strlist.size() < 1)  return;
    85107  typ = BT_ForeachList;
    86108  blkok = true;
     
    140162
    141163/* --Methode-- */
    142 CommanderBloc* CommanderBloc::Execute()
    143 {
    144 // cout << " DBG * CommanderBloc::Execute() " << typ << " - " << bloclineid.size() <<
    145 //      " I1,I2=" << i1 << " , " << i2 << " , " << di << endl;
    146 string cmd;
     164int CommanderBloc::Execute()
     165{
    147166int k=0;
    148 int kj=0;
    149 int kk=0;
    150167char buff[32];
    151168int rcc = 0;
     
    154171
    155172if (typ == BT_ForeachLineInFile) {  // foreach line in file loop
    156 }
    157 else if (typ == BT_ForeachList)   // foreach string loop
     173  ifstream is(filename.c_str());
     174  char buff[256];
     175  string line;
     176  while (!is.eof()) {
     177    rcc = 0;
     178    is.clear();
     179    is.getline(buff, 256);
     180    line += buff; 
     181    if (is.good()) {
     182      rcc = ExecuteOnce(line);
     183      line = "";
     184    }
     185    if (rcc == CMD_BREAKEXE_RC)  return rcc;
     186    else if (rcc == CMD_BREAK_RC)  break;
     187  }
     188}
     189else if (typ == BT_ForeachList) {  // foreach string loop
    158190  for(k=0; k<strlist.size(); k++) {
    159     cmd = "set " + varname + " '" + strlist[k] + "'";
    160     _commander->Interpret(cmd);
    161     for(kj=0; kj<bloclineid.size(); kj++) {
    162       kk = bloclineid[kj];
    163       if (kk > 0)  {
    164         rcc = _commander->Interpret(lines[kk-1]);
    165         if (rcc == 77766)  break;
    166       }
    167       else blocs[-kk-1]->Execute();
    168     }
    169     if (rcc == 77766)  break;
    170   }
    171 else if (typ == BT_ForeachInt)  // Integer loop
     191    rcc = ExecuteOnce(strlist[k]);
     192    if (rcc == CMD_BREAKEXE_RC)  return rcc;
     193    else if (rcc == CMD_BREAK_RC)  break;
     194  } 
     195}
     196else if (typ == BT_ForeachInt)  { // Integer loop
    172197  for(int i=i1; i<i2; i+=di) {
    173198    k++;
     
    176201      break;
    177202      }
    178     sprintf(buff, " %d", i);
    179     cmd = "set " + varname + buff;
    180     _commander->Interpret(cmd);
    181     for(kj=0; kj<bloclineid.size(); kj++) {
    182       kk = bloclineid[kj];
    183       if (kk > 0)  {
    184         rcc = _commander->Interpret(lines[kk-1]);
    185         if (rcc == 77766)  break;
    186       }
    187       else blocs[-kk-1]->Execute();
    188     }
    189     if (rcc == 77766)  break;
    190   }
    191 else if (typ == BT_ForeachFloat)  // float loop
    192   for(float f=f1; f<f2; f+=df) {
     203    sprintf(buff, "%d", i);
     204    string lvv = buff;
     205    rcc = ExecuteOnce(lvv);
     206    if (rcc == CMD_BREAKEXE_RC)  return rcc;
     207    else if (rcc == CMD_BREAK_RC)  break;
     208  }
     209}
     210else if (typ == BT_ForeachFloat)  { // float loop
     211  for(double f=f1; f<f2; f+=df) {
    193212    k++;
    194213    if ((mxloop>0) && (k > mxloop)) {
     
    196215      break;
    197216      }
    198     sprintf(buff, " %g", f);
    199     cmd = "set " + varname + buff;
    200     _commander->Interpret(cmd);
    201     for(kj=0; kj<bloclineid.size(); kj++) {
    202       kk = bloclineid[kj];
    203       if (kk > 0)  {
    204         rcc = _commander->Interpret(lines[kk-1]);
    205         if (rcc == 77766)  break;
    206       }
    207       else blocs[-kk-1]->Execute();
    208     }
    209     if (rcc == 77766)  break;
    210   }
    211 
    212 return(parent);
     217    sprintf(buff, "%g", f);
     218    string lvv = buff;
     219    rcc = ExecuteOnce(lvv);
     220    if (rcc == CMD_BREAKEXE_RC)  return rcc;
     221    else if (rcc == CMD_BREAK_RC)  break;
     222  }
     223}
     224return(rcc);
     225}
     226
     227/* --Methode-- */
     228int CommanderBloc::ExecuteOnce(string& lvv)
     229{
     230  int kj=0;
     231  int kk=0;
     232  int rcc = 0;
     233  _commander->SetVar(varname, lvv);
     234  for(kj=0; kj<bloclineid.size(); kj++) {
     235    rcc = 0;
     236    kk = bloclineid[kj];
     237    if (kk > 0)   
     238      rcc = _commander->Interpret(lines[kk-1]);
     239    else
     240      rcc = blocs[-kk-1]->Execute();
     241    if (rcc == CMD_BREAKEXE_RC)  return (rcc);
     242    if (rcc == CMD_BREAK_RC)  break;   
     243  }
     244  return rcc;
    213245}
    214246
     
    286318int CommanderScript::Execute(vector<string>& args)
    287319{
     320  int rcc;
    288321  if (!CheckScript()) return(-1);
    289322  cout << " CommanderScript::Execute() - Executing script " << Name() << endl;
    290323  for(int k=0; k<lines.size(); k++) {
    291     if (_commander->Interpret(lines[k]) == 77777) break;
    292   }
    293   return(0);
     324    rcc = _commander->Interpret(lines[k]);
     325    if ( (rcc == CMD_BREAKEXE_RC) || (rcc == CMD_RETURN_RC) ) break;
     326  }
     327  return(rcc);
    294328}
    295329
     
    330364 _retstr = "";
    331365
     366// Controle du flot d'execution
     367 fgexebrk = false;
     368
    332369CmdBlks.push(NULL);
    333370list<char> xtx;
     
    347384usage = ">>> (Commander) Interpreter's keywords : \n";
    348385usage += "  > set varname string   # To set a variable, $varname \n";
    349 usage += "  > get newvarname varname # To set a newvariable, equal to $varname \n";
    350 usage += "  > setol varname patt     # Fills varname with object list \n";
    351386usage += "  > unset varname          # clear variable definition \n";
    352 usage += "  > rpneval varname RPNExpression # Reverse Polish Notation evaluation \n";
    353 usage += "  > varname = 'string string ...' # To set a variable, $varname  \n";
    354 usage += "  > varname = RPNExpression # RPN evaluation / result -> varname \n";
    355 usage += "  > echo string            # output string \n";
    356 usage += "  > echo2file filename string # Append the string to the specified file \n";
    357 usage += "  > alias name string      # define a command alias \n";
    358 usage += "  > readstdin varname      # reads a line from stdin into $varname \n";
    359 usage += "  > foreach varname ( string-list ) # Loop \n";
    360 usage += "  > for varname i1:i2[:di]      # Integer loop  \n";
     387usage += "  > rpneval varname RPNExpression  # Reverse Polish Notation evaluation \n";
     388usage += "  > varname = ArithmeticExpression # C-like Expression evaluation   \n";
     389usage += "  > varname = 'String'     # Set variable vname  \n";
     390usage += "  > var2words varname wordvarname [sep]    # to break varname into words  \n";
     391usage += "  > echo string            # output string \n";
     392usage += "  > echo2file filename string # Append the string to the specified file \n";
     393usage += "  > alias name string      # define a command alias \n";
     394usage += "  > foreach varname ( string-list ) # Loop \n";  
     395usage += "  > for varname i1:i2[:di]      # Integer loop  \n";  
    361396usage += "  > for varname f1:f2[:df]      # Float loop  \n";
     397usage += "  > forinfile varname FileName  # Loop over lines in file \n";
    362398usage += "  > end                         # end loops \n";
    363399usage += "  > if ( test ) then  # Conditional test : a == != < > <= >= b \n";
     
    373409usage += "  > clearcript    # Clear a script definition \n";
    374410usage += "  > exec filename # Execute commands from file \n";
    375 usage += "  > help <command_name>  # <command_name> usage info \n";
     411usage += "  > help <command_name>  # <command_name> usage info \n";   
     412usage += "  > sleep nsec  # sleep nsec seconds \n";   
     413usage += "  > readstdin varname      # reads a line from stdin into $varname \n";
    376414usage += "  > timingon  timingoff traceon  traceoff \n";
    377415RegisterHelp(kw, usage, grp);
     
    778816
    779817// Les mots cles break et return peuvent de sortir de boucles/scripts/execfile
    780 if (kw == "break") return(77766);
     818if (kw == "break") return CMD_BREAK_RC;
    781819else if (kw == "return")  {
    782820  _retstr = toks;
    783   return(77777);
     821  return CMD_RETURN_RC;
    784822}
    785823
     
    797835// >>>> Separating keyword and tokens
    798836vector<string> tokens;
     837vector<bool> qottoks;
    799838/* decoupage en mots */
    800 LineToWords(s2, kw, tokens, toks, true);
     839LineToWords(s2, kw, tokens, qottoks, toks, true);
    801840
    802841// Si c'est un for/foreach, on cree un nouveau bloc
     
    834873else if ((tokens.size() > 0) && (tokens[0] == "=")) { 
    835874  // x = Expression
    836   try {
    837     CExpressionEvaluator cex(tokens[1]);
    838     double res = cex.Value();
    839     char cbuff[64];
    840     sprintf(cbuff,"%g",res);
    841     string vv = cbuff;
    842     SetVariable(kw, vv);
    843   }
    844   catch (CExprException& cexerr) {
    845     cerr << "Commander::Interpret() evaluation Error : \n " << "line: " << s
    846          << " \n Msg=" << cexerr.Msg()  << endl;
    847     _xstatus = 98;
    848     return(98);
     875  if (qottoks[1]) {  // decodage sous forme de chaine
     876    SetVariable(kw, tokens[1]);   
     877  }
     878  else {
     879    try {
     880      double res = 0.;
     881      if (tokens.size() > 2) {
     882        string sex = tokens[1];
     883        for(int js=2; js<tokens.size(); js++)  sex += tokens[js];
     884        CExpressionEvaluator cex(sex);
     885        res = cex.Value();
     886      }
     887      else {
     888        CExpressionEvaluator cex(tokens[1]);
     889        res = cex.Value();
     890      }
     891      char cbuff[64];
     892      sprintf(cbuff,"%g",res);
     893      string vv = cbuff;
     894      SetVariable(kw, vv);
     895    }
     896    catch (CExprException& cexerr) {
     897      cerr << "Commander::Interpret() evaluation Error : \n " << "line: " << s
     898           << " \n Msg=" << cexerr.Msg()  << endl;
     899      _xstatus = 98;
     900      return(98);
     901    }
    849902  }
    850903}
     
    889942/* --Methode-- */
    890943int Commander::LineToWords(string& line, string& kw, vector<string>& tokens,
    891                         string& toks, bool uq)
     944                           vector<bool>& qottoks, string& toks, bool uq)
    892945{
    893946if (line.length() < 1)  return(0);
     
    905958q = 0;
    906959while (q < l)  {
     960  bool swq = false;  // true -> chaine delimite par ' ou "
    907961  p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
    908962  if (p>=l) break;
     
    913967      return(-1);
    914968    }
    915     p++;
     969    p++;  swq = true; 
    916970  }
    917971  else {
     
    919973  }
    920974  string token = toks.substr(p,q-p);
    921   tokens.push_back(token);  nw++;
     975  tokens.push_back(token);
     976  qottoks.push_back(swq);
     977  nw++;
    922978  }
    923979
     
    10481104{
    10491105if (vn.length() < 1) {
    1050   cerr << " Commander::SubstituteVar/Error: length(varname=" << vn << ")<1 !" << endl;
     1106  cerr << " Commander::Var2Str/Error: length(varname=" << vn << ")<1 !" << endl;
    10511107  vv = "";    return(false);
    10521108}
     
    10571113if (vn == "#") {
    10581114  if (ArgsStack.empty()) {
    1059     cerr << " Commander::SubstituteVar/Error: ArgsStack empty ! "
     1115    cerr << " Commander::Var2Str/Error: ArgsStack empty ! "
    10601116         << " ($" << vn << ")" << endl;
    10611117    vv = "";  return(false);
     
    10631119  char buff[32];
    10641120  long an = ArgsStack.top().size();
     1121  if (an > 0) an--;  // Pour se conformer a l'usage de csh : Nb args sans le $0
    10651122  sprintf(buff,"%ld", an);
    10661123  vv = buff;  return(true);
    10671124}
     1125else if (vn == "*") {
     1126  if (ArgsStack.empty()) {
     1127    cerr << " Commander::Var2Str/Error: ArgsStack empty ! "
     1128         << " ($" << vn << ")" << endl;
     1129    vv = "";  return(false);
     1130  }
     1131  vv = ArgsStack.top()[0];
     1132  for(int ssk=1; ssk<ArgsStack.top().size(); ssk++)  vv += ArgsStack.top()[ssk];
     1133  return(true);
     1134}
    10681135else if (ctoi(vn.c_str(), &ka) > 0) {  // $0 $1 $2 ...
    10691136  if (ArgsStack.empty()) {
    1070     cerr << " Commander::SubstituteVar/Error: ArgsStack empty ! "
     1137    cerr << " Commander::Var2Str/Error: ArgsStack empty ! "
    10711138         << " ($" << vn << ")" << endl;
    10721139    vv = ""; return(false);
    10731140  }
    10741141  if ( (ka < 0) || (ka >= ArgsStack.top().size()) ) {
    1075     cerr << " Commander::SubstituteVar/Error: Undefined variable ! "
     1142    cerr << " Commander::Var2Str/Error: ArgsStack index <0 or >=args.size() ! "
    10761143         << " ($" << vn << ")" << endl;
    10771144    vv = ""; return(false);
     
    10821149  CmdVarList::iterator it = variables.find(vn.substr(1));
    10831150  if (it == variables.end()) {
    1084     cerr << " Commander::SubstituteVarError: Undefined variable "
     1151    cerr << " Commander::Var2Str/Error #vname Undefined variable "
    10851152         << vn << " ! " << endl;
    10861153    vv = "";  return(false);
     
    10941161  return true;
    10951162}
    1096 else if (vn == "retstr") {
     1163else if ((vn == "retstr") || (vn == "retval")) {
    10971164  vv = _retstr;
    10981165  return true;
     
    11031170  else if (GetVarEnv(vn, vv))  return true;
    11041171  else {
    1105     cerr << " Commander::SubstituteVarError: Undefined variable "
     1172    cerr << " Commander::Var2Str/Error Undefined variable "
    11061173         << vn << " ! " << endl;
    11071174    vv = "";  return false;
     
    13161383{
    13171384  vv = "";
    1318   cout << " Commander::GetVarApp() Not available ! " << endl;
     1385  //  cout << " Commander::GetVarApp() Not available ! " << endl;
    13191386  return false;
    13201387}
     
    13231390bool Commander::SetVarApp(string const & vn, string const & vv)
    13241391{
    1325   cout << " Commander::SetVarApp() Not available ! " << endl;
     1392  //  cout << " Commander::SetVarApp() Not available ! " << endl;
    13261393  return false; 
    13271394}
     
    13301397bool Commander::DeleteVarApp(string const & vn)
    13311398{
    1332   cout << " Commander::DeleteVarApp() Not available ! " << endl;
     1399  //  cout << " Commander::DeleteVarApp() Not available ! " << endl;
    13331400  return false; 
    13341401}
     
    13371404void Commander::ListVarApp()
    13381405{
    1339   cout << " Commander::ListVarApp() Not available ! " << endl;
     1406  //  cout << " Commander::ListVarApp() Not available ! " << endl;
    13401407  return; 
    13411408}
     
    13451412bool Commander::GetVarEnv(string const & vn, string & vv)
    13461413{
    1347   vv = "";
    1348   cout << " Commander::GetVarEnv() Not available ! " << endl;
    1349   return false;
     1414  char* vev = getenv(vn.c_str());
     1415  if (vev) {
     1416    vv = vev;
     1417    return true;
     1418  }
     1419  else {
     1420    vv = "";
     1421    return false;
     1422  }
    13501423}
    13511424
     
    13531426bool Commander::SetVarEnv(string const & vn, string const & vv)
    13541427{
    1355   cout << " Commander::SetVarEnv() Not available ! " << endl;
    1356   return false; 
     1428  string pev = vn;
     1429  pev += '=';
     1430  pev += vv;
     1431  if (putenv(pev.c_str()) == 0)  return true;
     1432  else return false; 
    13571433}
    13581434
     
    13601436bool Commander::DeleteVarEnv(string const & vn)
    13611437{
    1362   cout << " Commander::DeleteVarEnv() Not available ! " << endl;
     1438  //  cout << " Commander::DeleteVarEnv() Not available ! " << endl;
    13631439  return false; 
    13641440}
     
    14601536    }
    14611537  }
     1538else if (kw == "sleep") {
     1539  if (tokens.size() < 1) {
     1540    cout << "Commander::Interpret() Usage: sleep nsec " << endl; 
     1541    return(1);
     1542  }
     1543  int nsec = atoi(tokens[0].c_str());
     1544  cout << "Commander::Interpret() sleep " << nsec << " seconds" << endl;
     1545  sleep(nsec);
     1546}
    14621547
    14631548else if (kw == "set") {
    1464   if (tokens.size() < 2) { cout << "Commander::Interpret() Usage: set varname value" << endl;  return(0); }
     1549  if (tokens.size() < 2) {
     1550    cout << "Commander::Interpret() Usage: set varname value or set vecvar ( w1 w2 ... ) " << endl; 
     1551    return(1);
     1552  }
     1553 
    14651554  if (tokens.size() == 2)
    14661555    SetVariable(tokens[0], tokens[1]);
    14671556  else {
    1468     vector<string> vv;
    1469     for(int k=1; k<tokens.size(); k++)  vv.push_back(tokens[k]);
    1470     SetVar(tokens[0], vv);
     1557    if ( (tokens[1] != "(") || (tokens[tokens.size()-1] != ")") ) {
     1558    cout << "Commander::Interpret() Usage: set vecvar ( w1 w2 ... ) " << endl; 
     1559    return(1);
     1560    }
     1561    string vname = tokens[0];
     1562    vector<string>::iterator vit;
     1563    vit = tokens.begin(); tokens.erase(vit);
     1564    vit = tokens.begin(); tokens.erase(vit);
     1565    tokens.pop_back();
     1566    SetVar(vname, tokens);
    14711567  }
    14721568  return 0;
    14731569}
    1474 /*  RZDELETE
    1475 else if (kw == "getvar") {
    1476   if (tokens.size() < 2) { cout << "Commander::Interpret() Usage: getvar newvarname varname" << endl;  return(0); }
    1477   if (!HasVariable(tokens[1])) {
    1478     cerr << "Error - No " << tokens[1] << " Variable " << endl;
    1479     return(0);
    1480     }
    1481   if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
    1482     cerr << "Commander::Interpret()/Error Variable name should start with alphabetic" << endl;
    1483     return(0);
    1484     }
    1485   SetVar(tokens[0], GetVariable(tokens[1]) );
    1486   }
    1487   END-RZDELETE */
     1570else if (kw == "var2words") {
     1571  if (tokens.size() < 2) {
     1572    cout << "Commander::Interpret() Usage: var2words varname wordvarname [sep]" << endl; 
     1573    return(1);
     1574  }
     1575  char sep = ' ';
     1576  if (tokens.size() > 2) sep = tokens[2][0];
     1577  string vv;
     1578  if (!GetVar(tokens[0], vv)) {
     1579    cout << "Commander::Interpret() var2words/Error No variable with name " << tokens[0] << endl; 
     1580    return 2;
     1581  }
     1582  vector<string> vs;
     1583  FillVStringFrString(vv, vs, sep);
     1584  SetVar(tokens[1], vs);
     1585}
    14881586else if (kw == "alias") {
    14891587  if (tokens.size() < 2) { cout << "Commander::Interpret() Usage: alias aliasname string" << endl;  return(0); }
    14901588  if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
    14911589    cerr << "Commander::Interpret()/Error alias name should start with alphabetic" << endl;
    1492     return(0);
     1590    return(1);
    14931591  }
    14941592  string xx = tokens[1];
     
    15001598  if (tokens.size() < 1) {
    15011599    cout << "Commander::Interpret() Usage: unset/clearvar varname" << endl; 
    1502     return(0);
     1600    return(1);
    15031601  }
    15041602  else DeleteVar(tokens[0]);
     
    15291627  if (tokens.size() < 1) {
    15301628    cout << "Commander::Interpret() Usage: echo2file filename [string ] " << endl; 
    1531     return(0);
     1629    return(1);
    15321630  }
    15331631  ofstream ofs(tokens[0].c_str(), ios::app);
     
    16341732{
    16351733vector<string> tokens;
     1734vector<bool> qottoks;
    16361735string kw, toks;
    16371736if (line.length() < 1)  return(0);
    1638 LineToWords(line, kw, tokens, toks, qw);
     1737LineToWords(line, kw, tokens, qottoks, toks, qw);
    16391738return(ExecuteCommand(kw, tokens, toks)); 
    16401739}
     
    16581757char line_buff[512];
    16591758FILE *fip;
    1660 
     1759int rcc = 0;
    16611760if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
    16621761  if (file.find('.') >= file.length()) {
     
    16751774
    16761775// hist << "### Executing commands from " << file << endl;
    1677 
    16781776PushStack(args);
    16791777if (trace) {
     
    16901788  line_buff[strlen(line_buff)-1] = '\0';   /*  LF/CR de la fin */
    16911789  string line(line_buff);
    1692   if (Interpret(line) == 77777) break;
     1790  rcc = Interpret(line);
     1791  if ((rcc == CMD_RETURN_RC) || (rcc == CMD_BREAKEXE_RC)) break;
    16931792  }
    16941793histon = ohv;
  • trunk/SophyaLib/SysTools/commander.h

    r2483 r2518  
    9191  inline  CmdInterpreter* CurrentInterpreter() { return(curcmdi); }
    9292
    93   //   Utilitaire pour decoupage en mot
    94   static  int   LineToWords(string& line, string& kw, vector<string>& tokens,
    95                             string& toks, bool uq=true);
    96 protected:
    97   virtual int   ParseLineExecute(string& line, bool qw=true);
    98 
    99   virtual int   ExecuteCommandLine(string & keyw, vector<string> & args,
    100                                    string & toks);
    101 
    102   virtual bool  CheckHelpGrp(string& grp, int& gid, string& desc);
    103   inline  bool  CheckHelpGrp(string& grp, int& gid)
    104   { string desc=""; return CheckHelpGrp(grp, gid, desc); }
    105 
    106   virtual int   SubstituteVars(string & s, string & s2); 
    107   int           EvaluateTest(vector<string> & args,
    108                              string & line, bool & res);
    109   int           EvalRPNExpr(vector<string> & args, string & line);
    110 
    111   // Acces aux variables
    112   virtual bool    Var2Str(string const & vn, string & vv);
    113   inline  bool    Var2Str(string const & vn, int idx, string & vv)
    114   { return GetVar(vn, idx, vv); }
    115   inline  bool    Var2Str(string const & vn, vector<string> & vv)
    116   { return GetVar(vn, vv); }
    117 
    11893  // ----- Action / gestion des variables propres de l'interpreteur
    11994  // Verifie l'existence de la variable nomme vn et retourne sa valeur ds vv
    12095  // Retourne false si la variable n'existe pas
    121   virtual bool    SetVariable(string const & vn, string const & vv);
    12296  virtual bool    GetVar(string const & vn, string & vv);
    12397  virtual bool    GetVar(string const & vn, int idx, string & vv);
     
    140114  virtual void    ListVarEnv();
    141115
     116  //   Utilitaire pour decoupage en mot
     117  static  int   LineToWords(string& line, string& kw, vector<string>& tokens,
     118                            vector<bool>& qottoks, string& toks, bool uq=true);
     119protected:
     120  virtual int   ParseLineExecute(string& line, bool qw=true);
     121
     122  virtual int   ExecuteCommandLine(string & keyw, vector<string> & args,
     123                                   string & toks);
     124
     125  virtual bool  CheckHelpGrp(string& grp, int& gid, string& desc);
     126  inline  bool  CheckHelpGrp(string& grp, int& gid)
     127  { string desc=""; return CheckHelpGrp(grp, gid, desc); }
     128
     129  virtual int   SubstituteVars(string & s, string & s2); 
     130  int           EvaluateTest(vector<string> & args,
     131                             string & line, bool & res);
     132  int           EvalRPNExpr(vector<string> & args, string & line);
     133
     134  // variable de l'interpreteur = valeur - accepte la syntaxe de type varname[index]
     135  virtual bool    SetVariable(string const & vn, string const & vv);
     136  // Acces aux variables
     137  virtual bool    Var2Str(string const & vn, string & vv);
     138  inline  bool    Var2Str(string const & vn, int idx, string & vv)
     139  { return GetVar(vn, idx, vv); }
     140  inline  bool    Var2Str(string const & vn, vector<string> & vv)
     141  { return GetVar(vn, vv); }
     142
    142143  virtual string  GetTmpDir();
    143144
     
    202203  bool curtestresult;             // Resultat courant des tests
    203204
     205  // Controle du flot d'execution
     206  bool fgexebrk;
     207
    204208  // Commande splitees sur plusieurs lignes
    205209  bool mulinefg;            // Bloc multi-lignes (ligne suite)
Note: See TracChangeset for help on using the changeset viewer.