Changeset 2218 in Sophya for trunk/SophyaPI/PIext


Ignore:
Timestamp:
Oct 21, 2002, 5:38:02 PM (23 years ago)
Author:
ansari
Message:

Suite amelioration interpreteur PIACmd , variables de type $#varname
et $varname[indexvar] - Reza 21/10/2002

Location:
trunk/SophyaPI/PIext
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/nobjmgr.cc

    r2180 r2218  
    218218bool NamedObjMgr::SetVar(string const & key, string const & val)
    219219{
     220  if ((key.length() < 1) || (! isalpha(key[0])) )   {
     221    cout << "NamedObjMgr::SetVar( " << key << " ...) Bad VarName " << endl;
     222    return(false);
     223  }
    220224#ifdef SANS_EVOLPLANCK
    221225  bool fg = true;
     
    231235bool NamedObjMgr::HasVar(string const & key)
    232236{
     237  if ((key.length() < 1) || (! isalpha(key[0])) )   {
     238    cout << "NamedObjMgr::HasVar( " << key << ") Bad VarName " << endl;
     239    return(false);
     240  }
    233241#ifdef SANS_EVOLPLANCK
    234242  DVList::ValList::const_iterator it;
     
    244252bool NamedObjMgr::DeleteVar(string const & key)
    245253{
     254  if ((key.length() < 1) || (! isalpha(key[0])) )   {
     255    cout << "NamedObjMgr::DeleteVar( " << key << ") Bad VarName " << endl;
     256    return(false);
     257  }
    246258#ifdef SANS_EVOLPLANCK
    247259  return(false);
     
    254266string NamedObjMgr::GetVar(string const & key)
    255267{
     268  if ((key.length() < 1) || (! isalpha(key[0])) )   {
     269    cout << "NamedObjMgr::GetVar( " << key << ") Bad VarName " << endl;
     270    return("");
     271  }
    256272  //  cout << " DEBUG::GetVar " << *myVars << endl;
    257273  return(myVars->GetS(key));
     
    503519
    504520myNObj++;
    505 if (nobj.length() < 1) {
     521if ((nobj.length() < 1) || (! isalpha(nobj[0]) ) ) {
     522  cout << "NamedObjMgr::AddObj() bad object name " << nobj ;
    506523  sprintf(buff,"O%d", myNObj);
    507524  nobj = buff;
     525  cout << " changed to " << nobj << endl;
    508526  }
    509527
     
    580598  cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
    581599  return(false);
    582   }
     600}
    583601nom = '/' + r1 + '/' + n1;
    584602nomnew = '/' + r2 + '/' + n2;
     
    587605  cout << "NamedObjMgr::RenameObj() Error -  No " << nom << " object !" << endl;
    588606  return(false);
    589   }
     607}
     608if ((n2.length() < 1) || (! isalpha(n2[0])) ) {
     609  cout << "NamedObjMgr::RenameObj() Error -  bad new object name" << n2 << endl;
     610  return(false);
     611}
    590612NObjList::iterator it2 = myObjs->find(nomnew);
    591613if (it2 != myObjs->end()) {
     
    15011523size_t p = nom.find('/');
    15021524if (p < nom.length()) nom = nom.substr(0,p);
    1503 if (nom.length() < 1)  return(false);
     1525if ((nom.length() < 1) || (! isalpha(nom[0]) ) )  return(false);
    15041526return(true);
    15051527}
  • trunk/SophyaPI/PIext/piacmd.cc

    r2215 r2218  
    889889      q3 = s.find_first_of("]",q2+1);
    890890      string sia = s.substr(q2+1, q3-q2-1);
     891      if (sia.length() < 1) {
     892        cerr << " Syntax error - in $varname[index] : $" 
     893             << vn << "[" << sia <<"]" << endl;
     894        return(4);
     895      }
     896      if (isalpha(sia[0])) {
     897        string sia2;
     898        if (!GetVar(sia, sia2) || (sia2.length() < 1)) {
     899          cerr << " Syntax error - in $varname[index] : $" 
     900               << vn << "[" << sia <<"]" << endl;
     901        return(4);       
     902        }
     903        sia = sia2;
     904      }
    891905      int rcdia = ctoi(sia.c_str(), &iarr);
    892906      if (rcdia < 0) {
     
    936950    cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
    937951         << " ($" << vn << ")" << endl;
    938     vv = ""; return(false);
     952    vv = "";  return(false);
    939953  }
    940954  char buff[32];
    941955  long an = ArgsStack.top().size();
    942956  sprintf(buff,"%ld", an);
    943   vv = buff;
     957  vv = buff;  return(true);
    944958}
    945959else if (ctoi(vn.c_str(), &ka) > 0) {  // $0 $1 $2 ...
     
    954968    vv = ""; return(false);
    955969  }
    956   vv = ArgsStack.top()[ka];
    957 }
     970  vv = ArgsStack.top()[ka];  return(true);
     971}
     972else if (vn[0] == '#') {  // Variable de type $#vname --> size(vname)
     973  vn = vn.substr(1);
     974  if (!omg.HasVar(vn) ) {
     975    cerr << " PIACmd::SubstituteVarError: Undefined variable "
     976         << vn << " ! " << endl;
     977    vv = "";  return(false);
     978  }
     979  vn = omg.GetVar(vn);
     980  vector<string> vs;
     981  FillVStringFrString(vn, vs);
     982  char buff[32];
     983  sprintf(buff,"%d", (int)vs.size());
     984  vv = buff; return(true);
     985  }
    958986else {  // variable ordinaire geree par NamedObjMgr
    959987  if ( (!omg.HasVar(vn)) )  {
    960988    cerr << " PIACmd::SubstituteVarError: Undefined variable "
    961989         << vn << " ! " << endl;
    962     vv = ""; return(false);
    963   }
    964   vv = omg.GetVar(vn);
    965 }
    966 
    967 return(true);
     990    vv = "";  return(false);
     991  }
     992  vv = omg.GetVar(vn);  return(true);
     993}
     994
     995return(false);
    968996}
    969997
Note: See TracChangeset for help on using the changeset viewer.