Changeset 2214 in Sophya for trunk/SophyaPI/PIext/piacmd.cc


Ignore:
Timestamp:
Oct 17, 2002, 10:56:11 AM (23 years ago)
Author:
ansari
Message:

Gestion des arguments des .pic (-tcsh ...) dans un stack , separe de la liste des variables , Reza 17/10/02

File:
1 edited

Legend:

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

    r2203 r2214  
    99#include "pdlmgr.h"
    1010#include "ctimer.h"
     11#include "strutil.h"
    1112// #include "dlftypes.h"
    1213
     
    272273return(parent);
    273274}
     275
     276// ------------------
     277//  Classe PIACmdScript
     278// ------------------
     279class PIACmdScript {
     280public:
     281  PIACmdScript();
     282  virtual ~PIACmdScript();
     283};
    274284
    275285// ------------------------------------------------------------
     
    542552
    543553// >>>> Substitution d'alias (1er mot)
    544 CmdVarList::iterator it;
     554CmdStrList::iterator it;
    545555p = 0;
    546556q = s.find_first_of(" \t");
     
    756766//  Variable substitution 
    757767{
    758 NamedObjMgr omg;
     768NamedObjMgr& omg = *mObjMgr;
    759769
    760770size_t p,q,q2,l;
     
    763773p = 0;
    764774l = s.length();
    765 string vn;
     775string vn, vv;
    766776while (p < l) {
    767777  q = s.find('$',p);
     
    803813      }
    804814    vn = s.substr(q+2,q2-q-2);
    805     if ( (vn.length() < 1) || (!omg.HasVar(vn)) )  {
    806       cerr << " Error: Undefined variable " << vn << " ! " << endl;
    807       return(5);
    808       }
    809     vn = omg.GetVar(vn);
     815    if (!GetVar(vn, vv)) return(5);
     816    vn = vv;
    810817    q2++;
    811818    }
     
    815822    vn = s.substr(q+1, q2-q-1);
    816823    }
    817   if ( (vn.length() < 1) || (!omg.HasVar(vn)) )  {
    818     cerr << " Error: Undefined variable " << vn << " ! " << endl;
    819     return(5);
    820     }
    821   s2 += (s.substr(p, q-p) + omg.GetVar(vn));
     824  if (!GetVar(vn, vv)) return(5);
     825  s2 += (s.substr(p, q-p) + vv);
    822826  p = q2;
    823827  }
     
    828832
    829833return(0);
     834}
     835
     836/* --Methode-- */
     837bool PIACmd::GetVar(string & vn, string & vv)
     838{
     839NamedObjMgr& omg = *mObjMgr;
     840if (vn.length() < 1) {
     841  cerr << " PIACmd::SubstituteVar/Error: length(varname=" << vn << ")<1 !" << endl;
     842  vv = "";    return(false);
     843}
     844// Variable de type $# $0 $1 ... (argument de .pic ou de script)
     845int ka = 0;
     846if (vn == "#") {
     847  if (ArgsStack.empty()) {
     848    cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
     849         << " ($" << vn << ")" << endl;
     850    vv = ""; return(false);
     851  }
     852  char buff[32];
     853  long an = ArgsStack.top().size();
     854  sprintf(buff,"%ld", an);
     855  vv = buff;
     856}
     857else if (ctoi(vn.c_str(), &ka) > 0) {  // $0 $1 $2 ...
     858  if (ArgsStack.empty()) {
     859    cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
     860         << " ($" << vn << ")" << endl;
     861    vv = ""; return(false);
     862  }
     863  if ( (ka < 0) || (ka >= ArgsStack.top().size()) ) {
     864    cerr << " PIACmd::SubstituteVar/Error: Undefined variable ! "
     865         << " ($" << vn << ")" << endl;
     866    vv = ""; return(false);
     867  }
     868  vv = ArgsStack.top()[ka];
     869}
     870else {  // variable ordinaire geree par NamedObjMgr
     871  if ( (!omg.HasVar(vn)) )  {
     872    cerr << " PIACmd::SubstituteVarError: Undefined variable "
     873         << vn << " ! " << endl;
     874    vv = ""; return(false);
     875  }
     876  vv = omg.GetVar(vn);
     877}
     878
     879return(true);
    830880}
    831881
     
    9551005else if (kw == "listalias") {
    9561006  cout << "PIACmd::Interpret()  Alias List , AliasName = Value \n";
    957   CmdVarList::iterator it;
     1007  CmdStrList::iterator it;
    9581008  for(it = mAliases.begin(); it != mAliases.end(); it++) 
    9591009    cout << (*it).first << " = " <<  (*it).second << "\n";
     
    10721122// hist << "### Executing commands from " << file << endl;
    10731123
    1074 // Setting $0 ... $99 variables
    1075 int k;
    1076 char buff[32];
    1077 // First, we clear all previous values
    1078 NamedObjMgr omg;
    1079 string vn="#";
    1080 omg.DeleteVar(vn);
    1081 for(k=0; k<99; k++) {   
    1082   sprintf(buff,"%d",k);
    1083   vn = buff;
    1084   omg.DeleteVar(vn);
    1085   }
    1086 // We then set them
    1087 string vval;
    1088 vn="#";
    1089 sprintf(buff,"%d",(int)args.size());
    1090 omg.SetVar(vn, buff);
    1091 for(k=0; k<args.size(); k++) {   
    1092   sprintf(buff,"%d",k);
    1093   vn = buff;
    1094   omg.SetVar(vn, args[k]);
    1095   }
     1124// We push the argument list (args) on the stack
     1125ArgsStack.push(args);
    10961126
    10971127if (trace) {
     
    11181148  mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta);
    11191149  }
     1150
     1151// We remove the argument list (args) from the stack
     1152ArgsStack.pop();
    11201153
    11211154return(0);
Note: See TracChangeset for help on using the changeset viewer.