Changeset 1276 in Sophya


Ignore:
Timestamp:
Nov 2, 2000, 11:18:50 AM (25 years ago)
Author:
ercodmgr
Message:

Amelioration de la syntaxe de l'interpreteur, gestion de quotes, ligne suite
Commande linkff2 (2eme groupe de link, pour utilisation par CxxExecutor
Amelioration de la gestion de TMPDIR

Reza 2/11/2000

Location:
trunk/SophyaPI/PIext
Files:
9 edited

Legend:

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

    r1268 r1276  
    3434mImgApp = app;
    3535dynlink = NULL;
     36dynlink2 = NULL;
    3637RegisterCommands();
    3738}
     
    3940PIABaseExecutor::~PIABaseExecutor()
    4041{
     42  if (dynlink) delete dynlink;
     43  if (dynlink2) delete dynlink2;
    4144}
    4245
     
    124127  if (rc == 0)  cout << "PIABaseExecutor: Link from " << tokens[0] << " OK " << endl;
    125128}
     129else if (kw == "linkff2" ) {
     130  if (tokens.size() < 2) { cout << "Usage: linkff2 fnameso f1 [f2 f3]" << endl;  return(0); }
     131  string sph = "";
     132  for(int gg=0; gg<5; gg++)   tokens.push_back(sph);
     133  int rc = LinkUserFuncs2(tokens[0], tokens[1], tokens[2], tokens[3]);
     134  if (rc == 0)  cout << "PIABaseExecutor: Link2 from " << tokens[0] << " OK " << endl;
     135}
    126136else if (kw == "call" ) {
    127137  if (tokens.size() < 1) { cout << "Usage: call userf [arg1 arg2 ...]" << endl;  return(0); }
    128   UsFmap::iterator it = usfmap.find(tokens[0]);
    129   if (it == usfmap.end()) {
     138  UsFmap::iterator it;
     139  UsFmap::iterator it1 = usfmap.find(tokens[0]);
     140  UsFmap::iterator it2 = usfmap2.find(tokens[0]);
     141  if ((it1 == usfmap.end()) && (it2 == usfmap2.end()) ) {
    130142    cerr << "PIABaseExecutor: No User Function " << tokens[0] << endl;
    131143    return(0);
    132144  }
     145  if (it1 == usfmap.end())  it = it2;
     146  else it = it1;
    133147  cout << "PIABaseExecutor: Call " << tokens[0] << "( ... )" << endl;
    134148// on est oblige de faire un cast  etant donne qu'on
     
    138152  bool red = mImgApp->HasRedirectedStdOutErr();
    139153  mImgApp->RedirectStdOutErr(false);
     154#ifdef SANS_EVOLPLANCK
    140155  TRY {
    141156    tokens.erase(tokens.begin());
     
    143158  }  CATCH(merr) {
    144159    fflush(stdout);
     160    string es = PeidaExc(merr);
     161    cerr << "\n PIABaseExecutor: Call UserFunc  Exception :" << merr << es;
    145162    cout << endl;
    146     cerr << endl;
    147 //CMV_A_FAIRE    string es = PeidaExc(merr);
    148 //CMV_A_FAIRE    cerr << "PIABaseExecutor: Call UserFunc  Exception :" << merr << es;
    149     }
     163    }
     164#else
     165  try {
     166    tokens.erase(tokens.begin());
     167    fuf(tokens);
     168  }
     169  catch ( PThrowable & exc ) {
     170    cerr << "\n PIABaseExecutor: Call / Catched Exception :"
     171         << (string)typeid(exc).name() << " Msg= "
     172         << exc.Msg() << endl;
     173    cout << endl;
     174  }
     175  catch ( ... ) {
     176    cerr << "\n PIABaseExecutor: Call / Catched Exception ... "
     177         << endl;
     178    cout << endl;
     179  }
     180#endif
    150181  mImgApp->RedirectStdOutErr(red);
    151182}
     
    677708usage = "Dynamic linking of compiled user functions \n  Usage: link fnameso f1 [f2 f3]";
    678709usage += "\n  fnameso: Shared-object file name, f1,f2,f3 : User function names ";
    679 usage += "\n  Related commands: call loadmodule"; 
     710usage += "\n  Related commands: call loadmodule linkff2"; 
     711mpiac->RegisterCommand(kw, usage, this, "External Modules");
     712kw = "linkff2";
     713usage = "Dynamic linking of compiled user functions (Set 2)\n  Usage: linkff2 fnameso f1 [f2 f3]";
     714usage += "\n  fnameso: Shared-object file name, f1,f2,f3 : User function names ";
     715usage += "\n  Related commands: call link loadmodule"; 
    680716mpiac->RegisterCommand(kw, usage, this, "External Modules");
    681717kw = "call";
     
    10981134}
    10991135
     1136/* --Methode-- */
     1137int PIABaseExecutor::LinkUserFuncs2(string& fnameso, string& func1, string& func2, string& func3)
     1138{
     1139string cmd;
     1140
     1141if (dynlink2) delete dynlink2;    dynlink2 = NULL;
     1142usfmap2.clear();
     1143
     1144dynlink2 = new PDynLinkMgr(fnameso, true);
     1145if (dynlink2 == NULL) {
     1146  string sn = fnameso;
     1147  cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur ouverture SO " << sn << endl;
     1148  return(2);
     1149  }
     1150
     1151int nok=0;
     1152// on utilise donc des DlFunction  (Reza 20/08/98)  voir commentaire ds .h (pb g++)
     1153// DlUserProcFunction f = NULL;
     1154DlFunction f = NULL;
     1155if ((func1.length() < 1) || (func1 == "-") || (func1 == ".") )  goto fin;
     1156f = dynlink2->GetFunction(func1);
     1157if (f) { nok++;  usfmap2[func1] = f; }
     1158else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func1 << endl;
     1159
     1160if ((func2.length() < 1) || (func2 == "-") || (func2 == ".") )  goto fin;
     1161f = dynlink2->GetFunction(func2);
     1162if (f) { nok++;  usfmap2[func2] = f; }
     1163else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func2 << endl;
     1164
     1165if ((func3.length() < 1) || (func3 == "-") || (func3 == ".") )  goto fin;
     1166f = dynlink2->GetFunction(func3);
     1167if (f) { nok++;  usfmap2[func3] = f; }
     1168else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func3 << endl;
     1169
     1170fin:
     1171if (nok < 1) { if (dynlink2) delete dynlink2;    dynlink2 = NULL;  return(3); }
     1172else return(0);
     1173}
     1174
    11001175/* Nouvelle-Fonction */
    11011176void RegisterPIGraphicsHelp(PIACmd* piac)
  • trunk/SophyaPI/PIext/basexecut.h

    r1268 r1276  
    1919//  Link dynamique de fonction user
    2020  int           LinkUserFuncs(string& fnameso, string& func1, string& func2, string& func3);
     21  int           LinkUserFuncs2(string& fnameso, string& func1, string& func2, string& func3);
    2122//                            string& func4, string& func5);   compil avec g++ 2.7.2
    2223  PIACmd* mpiac;
     
    2829  PDynLinkMgr* dynlink;
    2930  UsFmap usfmap;
     31  PDynLinkMgr* dynlink2;
     32  UsFmap usfmap2;
    3033
    3134};
  • trunk/SophyaPI/PIext/cxxexecutor.cc

    r1270 r1276  
    509509NamedObjMgr omg;
    510510PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
    511 string key("link");
     511string key("linkff2");
    512512vector<string> arg; arg.push_back(libname); arg.push_back(func);
    513513string toks = libname + " " + func;
  • trunk/SophyaPI/PIext/nobjmgr.cc

    r1268 r1276  
    129129  char* varenv;
    130130  TmpDir = new string("");
    131   if ( (varenv=getenv("PEIDA_TMP")) != NULL )  (*TmpDir) = varenv;
    132   else if ( (varenv=getenv("TMPDIR")) != NULL )  (*TmpDir) = varenv;
     131  if ( (varenv=getenv("TMPDIR")) != NULL )  (*TmpDir) = varenv;
    133132  int l = (*TmpDir).length();
    134133  if ( (l>0) && ((*TmpDir)[l-1] != '/') )  (*TmpDir) += '/';
     
    206205if(tmpdir.length()<1) return;
    207206*TmpDir = tmpdir;
     207int l = (*TmpDir).length();
     208if ( (l>0) && ((*TmpDir)[l-1] != '/') )  (*TmpDir) += '/';
     209servnobjm->SetTmpDir(*TmpDir);
    208210}
    209211
  • trunk/SophyaPI/PIext/piacmd.cc

    r1269 r1276  
    169169  for(int kk=1; kk<args.size(); kk++) strlist.push_back(args[kk]);
    170170  typ = BT_ForeachList;
     171  blkok = true;
    171172  }
    172173else { // This is an integer or float loop
     
    189190  if (fl) {
    190191    typ = BT_ForeachFloat;
     192    blkok = true;
    191193    f1 = atof(a1.c_str());
    192194    f2 = atof(a2.c_str());
     
    196198  else {
    197199    typ = BT_ForeachInt;
     200    blkok = true;
    198201    i1 = atoi(a1.c_str());
    199202    i2 = atoi(a2.c_str());
     
    285288bloccxx = false;
    286289bloctest = false;
     290mulinecmd = "";
     291mulinefg = false;
    287292
    288293cmdhgrp["All"] = 0;
     
    490495if (s[0] == '#') return(0); // si c'est un commentaire
    491496
     497// Logique de gestion des lignes suite
     498// un \ en derniere position indique la presence d'une ligne suite
     499if (s[l-1] == '\\' ) { // Lignes suite ...
     500  mulinefg = true;
     501  mulinecmd += s.substr(0,l-1);
     502  mImgApp->GetConsole()->SetPrompt("...? ");
     503  return(0);
     504}
     505
     506if (mulinefg) {  // Il y avait des lignes suite
     507  s = mulinecmd + s;
     508  mulinecmd = "";
     509  mulinefg = false;
     510  const char * rprompt = (curblk == NULL) ? "Cmd> " : "foreach? ";
     511  mImgApp->GetConsole()->SetPrompt(rprompt);
     512}
    492513
    493514// Removing leading blanks
    494 size_t p,q,q2;
    495 l = s.length();
    496 if (l < 1)  return(0);
     515size_t p,q;
    497516
    498517p=s.find_first_not_of(" \t");
     
    534553       }
    535554    else  {
    536       char prompt[64];
    537       sprintf(prompt, "foreach-%d? ", felevel);
    538       mImgApp->GetConsole()->SetPrompt(prompt);
     555      //      char prompt[64];
     556      //      sprintf(prompt, "foreach-%d? ", felevel);
     557      mImgApp->GetConsole()->SetPrompt("foreach? ");
    539558      }
    540559    return(0);
     
    544563
    545564// Nous ne sommes donc pas dans un bloc ....  Substitution de variables
    546 
     565string s2;
     566int rcs ;
    547567// Execution de code C++
    548568
     
    553573    return(99);
    554574  }
    555   if (s[1] == '@') { // Sans substitution des variables $
    556     return(cxxe->ExecuteCXX(s.substr(2)));
    557   } else { // Avec substitution de variables $
    558     string s2;
    559     SubstituteVars(s, s2);
     575  // Sans substitution des variables $
     576  if (s[1] == '@') return(cxxe->ExecuteCXX(s.substr(2)));
     577  else { // AVEC substitution des variables $
     578    rcs = SubstituteVars(s, s2);
     579    if (rcs) return(rcs);
    560580    return(cxxe->ExecuteCXX(s2.substr(1)));   
    561581  }
     
    563583
    564584
    565 string s2;
    566 SubstituteVars(s, s2);
     585rcs = SubstituteVars(s, s2);
     586if (rcs) return(rcs);
    567587
    568588// >>>> Separating keyword and tokens
     
    579599  p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
    580600  if (p>=l) break;
    581   q = toks.find_first_of(" \t",p); // la fin du token;
     601  if ( (toks[p] == '\'') || (toks[p] == '"') ) {
     602    q = toks.find(toks[p],p+1);
     603    if (q>=l)  {
     604      cerr << "Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl;
     605      return(2);
     606    }
     607    p++;
     608  }
     609  else {
     610    q = toks.find_first_of(" \t",p); // la fin du token;
     611  }
    582612  string token = toks.substr(p,q-p);
    583613  tokens.push_back(token);
     
    629659while (p < l) {
    630660  q = s.find('$',p);
     661  if (q > l) break;
     662  q2 = s.find('\'',p);
     663  if ((q2 < l) && (q2 < q)) {  // On saute la chaine delimitee par ' '
     664    q2 = s.find('\'',q2+1);
     665    if (q2 >= l) {
     666      cerr << " Syntax error - Unbalenced  quotes !!! " << endl;
     667      return(1);
     668      }
     669    s2 += s.substr(p, q2-p+1);
     670    p = q2+1;  continue; 
     671  }
    631672  //  cout << "DBG: " << s2 << " p= " << p << " q= " << q << " L= " << l << endl;
    632   if (q > l) break;
    633673  if ((q>0) && (s[q-1] == '\\')) {   // Escape character \$
    634674     s2 += (s.substr(p,q-1-p) + '$') ; p = q+1;
     
    636676     }
    637677  if (q >= l-1) {
    638       cerr << " Syntax error !!! " << endl;
    639       return(0);
     678      cerr << " Syntax error - line ending with $ !!! " << endl;
     679      return(2);
    640680      }
    641681  vn = "";
     
    643683    q2 = s.find('}',q+1);
    644684    if (q2 >= l) {
    645       cerr << " Syntax error !!! " << endl;
    646       return(0);
     685      cerr << " Syntax error -  Unbalenced  brace {} !!! " << endl;
     686      return(3);
    647687      }
    648688    vn = s.substr(q+2,q2-q-2);
     
    652692    q2 = s.find(']',q+1);
    653693    if (q2 >= l) {
    654       cerr << " Syntax error !!! " << endl;
    655       return(0);
     694      cerr << " Syntax error - Unbalenced  brace [] !!! " << endl;
     695      return(4);
    656696      }
    657697    vn = s.substr(q+2,q2-q-2);
    658698    if ( (vn.length() < 1) || (!omg.HasVar(vn)) )  {
    659699      cerr << " Error: Undefined variable " << vn << " ! " << endl;
    660       return(0);
     700      return(5);
    661701      }
    662702    vn = omg.GetVar(vn);
     
    664704    }
    665705  else {
    666     q2 = s.find_first_of(" .:/,]()$",q+1);
     706    q2 = s.find_first_of(" .:/,]()$\"'",q+1);
    667707    if (q2 > l) q2 = l;
    668708    vn = s.substr(q+1, q2-q-1);
     
    670710  if ( (vn.length() < 1) || (!omg.HasVar(vn)) )  {
    671711    cerr << " Error: Undefined variable " << vn << " ! " << endl;
    672     return(0);
     712    return(5);
    673713    }
    674714  s2 += (s.substr(p, q-p) + omg.GetVar(vn));
     
    705745    return(0);
    706746    }
    707   string xx = tokens[1];
    708   for (int kk=2; kk<tokens.size(); kk++)  xx += (' ' + tokens[kk] );
    709   omg.SetVar(tokens[0], xx);
     747  //  string xx = tokens[1];
     748  //  for (int kk=2; kk<tokens.size(); kk++)  xx += (' ' + tokens[kk] );
     749  omg.SetVar(tokens[0], tokens[1]);
    710750  }
    711751
     
    756796  }
    757797else if (kw == "echo") {
    758   for (int kk=0; kk<tokens.size(); kk++)  cout << tokens[kk] << " " ;
     798  for (int ii=0; ii<tokens.size(); ii++)
     799    cout << tokens[ii] << " " ;
    759800  cout << endl;
    760   }
    761 
     801 }
    762802else if (kw == "readstdin") {
    763803  if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: readstdin varname" << endl;  return(0); }
     
    816856else if (kw == "shell") {
    817857  if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl;  return(0); }
    818   system(toks.c_str());
    819   }
     858  string cmd;
     859  for (int ii=0; ii<tokens.size(); ii++)
     860    cmd += (tokens[ii] + ' ');
     861  system(cmd.c_str());
     862  }
     863
    820864//  Execution d'une commande enregistree
    821 // CMV c'est ici qu'il faut passer la string
    822865else rc = ExecuteCommand(kw, tokens, toks);
    823866
     
    894937// Setting $0 ... $99 variables
    895938int k;
    896 CmdVarList::iterator it;
    897939char buff[32];
    898940// First, we clear all previous values
  • trunk/SophyaPI/PIext/piacmd.h

    r1268 r1276  
    134134//  Pour stocker les variables definies par l'interpreteur
    135135  typedef map<string, string, less<string> > CmdVarList;
    136   //  CmdVarList mVars;     Liste des variables
    137136  CmdVarList mAliases;  // Liste des alias
    138137
     
    143142  bool bloctest;            // On est ds un bloc test
    144143  bool bloccxx;             // On est ds un bloc code C++
    145   string codecxx;
     144  string codecxx;           // Bloc de code C++
     145  bool mulinefg;            // Bloc multi-lignes (ligne suite)
     146  string mulinecmd;         // Commande multi-lignes
    146147
    147148  ofstream hist;       //  History file
  • trunk/SophyaPI/PIext/pistdimgapp.cc

    r1265 r1276  
    391391    mCmd->Interpret(s);
    392392    } 
    393   catch ( PThrowable exc ) {
     393  catch ( PThrowable & exc ) {
     394    cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Exception :"
     395         << (string)typeid(exc).name() << " Msg= "
     396         << exc.Msg() << endl;
    394397    cout << endl;
    395     cerr << endl;
    396     cerr << "PIStdImgApp::Process()/ Cmd->Interpret() Exception :" << exc.Msg() << endl;
    397   }
     398  }
     399  catch ( ... ) {
     400    cerr << "\n PIStdImgApp::Process()/ Cmd->Interpret() Catched Exception ..."
     401         << endl;
     402    cout << endl;
     403  }
     404
    398405#endif
    399406  SetReady();
  • trunk/SophyaPI/PIext/servnobjm.cc

    r1131 r1276  
    4949Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir)
    5050{
    51 TmpDir = tmpdir;
    52 PDynLinkMgr::SetTmpDir(tmpdir);
     51SetTmpDir(tmpdir);
    5352mImgapp = NULL;
    5453mOmg = omg;
     
    8786  if (typeid(*o) == typeid(*((*it).obj)))  return((*it).obja->Clone(o));
    8887return(new NObjMgrAdapter(o));
     88}
     89
     90/* --Methode-- */
     91void Services2NObjMgr::SetTmpDir(string const & tmpdir)
     92{
     93TmpDir = tmpdir;
     94PDynLinkMgr::SetTmpDir(tmpdir);
     95return;
    8996}
    9097
  • trunk/SophyaPI/PIext/servnobjm.h

    r1067 r1276  
    4646
    4747  inline void   SetImgApp(PIStdImgApp* app) {mImgapp = app; }
     48  void          SetTmpDir(string const & tmpdir);
    4849
    4950// Trace de fonctions 1-D , 2-D
Note: See TracChangeset for help on using the changeset viewer.