Changeset 1276 in Sophya
- Timestamp:
- Nov 2, 2000, 11:18:50 AM (25 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/basexecut.cc
r1268 r1276 34 34 mImgApp = app; 35 35 dynlink = NULL; 36 dynlink2 = NULL; 36 37 RegisterCommands(); 37 38 } … … 39 40 PIABaseExecutor::~PIABaseExecutor() 40 41 { 42 if (dynlink) delete dynlink; 43 if (dynlink2) delete dynlink2; 41 44 } 42 45 … … 124 127 if (rc == 0) cout << "PIABaseExecutor: Link from " << tokens[0] << " OK " << endl; 125 128 } 129 else 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 } 126 136 else if (kw == "call" ) { 127 137 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()) ) { 130 142 cerr << "PIABaseExecutor: No User Function " << tokens[0] << endl; 131 143 return(0); 132 144 } 145 if (it1 == usfmap.end()) it = it2; 146 else it = it1; 133 147 cout << "PIABaseExecutor: Call " << tokens[0] << "( ... )" << endl; 134 148 // on est oblige de faire un cast etant donne qu'on … … 138 152 bool red = mImgApp->HasRedirectedStdOutErr(); 139 153 mImgApp->RedirectStdOutErr(false); 154 #ifdef SANS_EVOLPLANCK 140 155 TRY { 141 156 tokens.erase(tokens.begin()); … … 143 158 } CATCH(merr) { 144 159 fflush(stdout); 160 string es = PeidaExc(merr); 161 cerr << "\n PIABaseExecutor: Call UserFunc Exception :" << merr << es; 145 162 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 150 181 mImgApp->RedirectStdOutErr(red); 151 182 } … … 677 708 usage = "Dynamic linking of compiled user functions \n Usage: link fnameso f1 [f2 f3]"; 678 709 usage += "\n fnameso: Shared-object file name, f1,f2,f3 : User function names "; 679 usage += "\n Related commands: call loadmodule"; 710 usage += "\n Related commands: call loadmodule linkff2"; 711 mpiac->RegisterCommand(kw, usage, this, "External Modules"); 712 kw = "linkff2"; 713 usage = "Dynamic linking of compiled user functions (Set 2)\n Usage: linkff2 fnameso f1 [f2 f3]"; 714 usage += "\n fnameso: Shared-object file name, f1,f2,f3 : User function names "; 715 usage += "\n Related commands: call link loadmodule"; 680 716 mpiac->RegisterCommand(kw, usage, this, "External Modules"); 681 717 kw = "call"; … … 1098 1134 } 1099 1135 1136 /* --Methode-- */ 1137 int PIABaseExecutor::LinkUserFuncs2(string& fnameso, string& func1, string& func2, string& func3) 1138 { 1139 string cmd; 1140 1141 if (dynlink2) delete dynlink2; dynlink2 = NULL; 1142 usfmap2.clear(); 1143 1144 dynlink2 = new PDynLinkMgr(fnameso, true); 1145 if (dynlink2 == NULL) { 1146 string sn = fnameso; 1147 cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur ouverture SO " << sn << endl; 1148 return(2); 1149 } 1150 1151 int nok=0; 1152 // on utilise donc des DlFunction (Reza 20/08/98) voir commentaire ds .h (pb g++) 1153 // DlUserProcFunction f = NULL; 1154 DlFunction f = NULL; 1155 if ((func1.length() < 1) || (func1 == "-") || (func1 == ".") ) goto fin; 1156 f = dynlink2->GetFunction(func1); 1157 if (f) { nok++; usfmap2[func1] = f; } 1158 else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func1 << endl; 1159 1160 if ((func2.length() < 1) || (func2 == "-") || (func2 == ".") ) goto fin; 1161 f = dynlink2->GetFunction(func2); 1162 if (f) { nok++; usfmap2[func2] = f; } 1163 else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func2 << endl; 1164 1165 if ((func3.length() < 1) || (func3 == "-") || (func3 == ".") ) goto fin; 1166 f = dynlink2->GetFunction(func3); 1167 if (f) { nok++; usfmap2[func3] = f; } 1168 else cerr << "PIABaseExecutor/LinkUserFuncs2_Erreur: Erreur linking " << func3 << endl; 1169 1170 fin: 1171 if (nok < 1) { if (dynlink2) delete dynlink2; dynlink2 = NULL; return(3); } 1172 else return(0); 1173 } 1174 1100 1175 /* Nouvelle-Fonction */ 1101 1176 void RegisterPIGraphicsHelp(PIACmd* piac) -
trunk/SophyaPI/PIext/basexecut.h
r1268 r1276 19 19 // Link dynamique de fonction user 20 20 int LinkUserFuncs(string& fnameso, string& func1, string& func2, string& func3); 21 int LinkUserFuncs2(string& fnameso, string& func1, string& func2, string& func3); 21 22 // string& func4, string& func5); compil avec g++ 2.7.2 22 23 PIACmd* mpiac; … … 28 29 PDynLinkMgr* dynlink; 29 30 UsFmap usfmap; 31 PDynLinkMgr* dynlink2; 32 UsFmap usfmap2; 30 33 31 34 }; -
trunk/SophyaPI/PIext/cxxexecutor.cc
r1270 r1276 509 509 NamedObjMgr omg; 510 510 PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter(); 511 string key("link ");511 string key("linkff2"); 512 512 vector<string> arg; arg.push_back(libname); arg.push_back(func); 513 513 string toks = libname + " " + func; -
trunk/SophyaPI/PIext/nobjmgr.cc
r1268 r1276 129 129 char* varenv; 130 130 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; 133 132 int l = (*TmpDir).length(); 134 133 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/'; … … 206 205 if(tmpdir.length()<1) return; 207 206 *TmpDir = tmpdir; 207 int l = (*TmpDir).length(); 208 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/'; 209 servnobjm->SetTmpDir(*TmpDir); 208 210 } 209 211 -
trunk/SophyaPI/PIext/piacmd.cc
r1269 r1276 169 169 for(int kk=1; kk<args.size(); kk++) strlist.push_back(args[kk]); 170 170 typ = BT_ForeachList; 171 blkok = true; 171 172 } 172 173 else { // This is an integer or float loop … … 189 190 if (fl) { 190 191 typ = BT_ForeachFloat; 192 blkok = true; 191 193 f1 = atof(a1.c_str()); 192 194 f2 = atof(a2.c_str()); … … 196 198 else { 197 199 typ = BT_ForeachInt; 200 blkok = true; 198 201 i1 = atoi(a1.c_str()); 199 202 i2 = atoi(a2.c_str()); … … 285 288 bloccxx = false; 286 289 bloctest = false; 290 mulinecmd = ""; 291 mulinefg = false; 287 292 288 293 cmdhgrp["All"] = 0; … … 490 495 if (s[0] == '#') return(0); // si c'est un commentaire 491 496 497 // Logique de gestion des lignes suite 498 // un \ en derniere position indique la presence d'une ligne suite 499 if (s[l-1] == '\\' ) { // Lignes suite ... 500 mulinefg = true; 501 mulinecmd += s.substr(0,l-1); 502 mImgApp->GetConsole()->SetPrompt("...? "); 503 return(0); 504 } 505 506 if (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 } 492 513 493 514 // Removing leading blanks 494 size_t p,q,q2; 495 l = s.length(); 496 if (l < 1) return(0); 515 size_t p,q; 497 516 498 517 p=s.find_first_not_of(" \t"); … … 534 553 } 535 554 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? "); 539 558 } 540 559 return(0); … … 544 563 545 564 // Nous ne sommes donc pas dans un bloc .... Substitution de variables 546 565 string s2; 566 int rcs ; 547 567 // Execution de code C++ 548 568 … … 553 573 return(99); 554 574 } 555 if (s[1] == '@') {// Sans substitution des variables $556 557 } else { // Avec substitution devariables $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); 560 580 return(cxxe->ExecuteCXX(s2.substr(1))); 561 581 } … … 563 583 564 584 565 string s2;566 SubstituteVars(s, s2);585 rcs = SubstituteVars(s, s2); 586 if (rcs) return(rcs); 567 587 568 588 // >>>> Separating keyword and tokens … … 579 599 p = toks.find_first_not_of(" \t",q+1); // au debut d'un token 580 600 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 } 582 612 string token = toks.substr(p,q-p); 583 613 tokens.push_back(token); … … 629 659 while (p < l) { 630 660 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 } 631 672 // cout << "DBG: " << s2 << " p= " << p << " q= " << q << " L= " << l << endl; 632 if (q > l) break;633 673 if ((q>0) && (s[q-1] == '\\')) { // Escape character \$ 634 674 s2 += (s.substr(p,q-1-p) + '$') ; p = q+1; … … 636 676 } 637 677 if (q >= l-1) { 638 cerr << " Syntax error !!! " << endl;639 return( 0);678 cerr << " Syntax error - line ending with $ !!! " << endl; 679 return(2); 640 680 } 641 681 vn = ""; … … 643 683 q2 = s.find('}',q+1); 644 684 if (q2 >= l) { 645 cerr << " Syntax error !!! " << endl;646 return( 0);685 cerr << " Syntax error - Unbalenced brace {} !!! " << endl; 686 return(3); 647 687 } 648 688 vn = s.substr(q+2,q2-q-2); … … 652 692 q2 = s.find(']',q+1); 653 693 if (q2 >= l) { 654 cerr << " Syntax error !!! " << endl;655 return( 0);694 cerr << " Syntax error - Unbalenced brace [] !!! " << endl; 695 return(4); 656 696 } 657 697 vn = s.substr(q+2,q2-q-2); 658 698 if ( (vn.length() < 1) || (!omg.HasVar(vn)) ) { 659 699 cerr << " Error: Undefined variable " << vn << " ! " << endl; 660 return( 0);700 return(5); 661 701 } 662 702 vn = omg.GetVar(vn); … … 664 704 } 665 705 else { 666 q2 = s.find_first_of(" .:/,]()$ ",q+1);706 q2 = s.find_first_of(" .:/,]()$\"'",q+1); 667 707 if (q2 > l) q2 = l; 668 708 vn = s.substr(q+1, q2-q-1); … … 670 710 if ( (vn.length() < 1) || (!omg.HasVar(vn)) ) { 671 711 cerr << " Error: Undefined variable " << vn << " ! " << endl; 672 return( 0);712 return(5); 673 713 } 674 714 s2 += (s.substr(p, q-p) + omg.GetVar(vn)); … … 705 745 return(0); 706 746 } 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]); 710 750 } 711 751 … … 756 796 } 757 797 else 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] << " " ; 759 800 cout << endl; 760 } 761 801 } 762 802 else if (kw == "readstdin") { 763 803 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: readstdin varname" << endl; return(0); } … … 816 856 else if (kw == "shell") { 817 857 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 820 864 // Execution d'une commande enregistree 821 // CMV c'est ici qu'il faut passer la string822 865 else rc = ExecuteCommand(kw, tokens, toks); 823 866 … … 894 937 // Setting $0 ... $99 variables 895 938 int k; 896 CmdVarList::iterator it;897 939 char buff[32]; 898 940 // First, we clear all previous values -
trunk/SophyaPI/PIext/piacmd.h
r1268 r1276 134 134 // Pour stocker les variables definies par l'interpreteur 135 135 typedef map<string, string, less<string> > CmdVarList; 136 // CmdVarList mVars; Liste des variables137 136 CmdVarList mAliases; // Liste des alias 138 137 … … 143 142 bool bloctest; // On est ds un bloc test 144 143 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 146 147 147 148 ofstream hist; // History file -
trunk/SophyaPI/PIext/pistdimgapp.cc
r1265 r1276 391 391 mCmd->Interpret(s); 392 392 } 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; 394 397 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 398 405 #endif 399 406 SetReady(); -
trunk/SophyaPI/PIext/servnobjm.cc
r1131 r1276 49 49 Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir) 50 50 { 51 TmpDir = tmpdir; 52 PDynLinkMgr::SetTmpDir(tmpdir); 51 SetTmpDir(tmpdir); 53 52 mImgapp = NULL; 54 53 mOmg = omg; … … 87 86 if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o)); 88 87 return(new NObjMgrAdapter(o)); 88 } 89 90 /* --Methode-- */ 91 void Services2NObjMgr::SetTmpDir(string const & tmpdir) 92 { 93 TmpDir = tmpdir; 94 PDynLinkMgr::SetTmpDir(tmpdir); 95 return; 89 96 } 90 97 -
trunk/SophyaPI/PIext/servnobjm.h
r1067 r1276 46 46 47 47 inline void SetImgApp(PIStdImgApp* app) {mImgapp = app; } 48 void SetTmpDir(string const & tmpdir); 48 49 49 50 // Trace de fonctions 1-D , 2-D
Note:
See TracChangeset
for help on using the changeset viewer.