Changeset 1262 in Sophya
- Timestamp:
- Oct 27, 2000, 6:30:28 PM (25 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/cxxexecutor.cc
r1247 r1262 96 96 mpiac->RegisterCommand(kw, usage, this, hgrp); 97 97 98 99 100 //// A VIRER quand variable de objmanager OK --> Pour Reza101 kw = "c++setvar";102 usage = "c++setvar: Setting test variable \n";103 usage+= "Usage: c++setvar varname varcontent ";104 mpiac->RegisterCommand(kw, usage, this, hgrp);105 106 kw = "c++getvar";107 usage = "c++getvar: Getting test variable content\n";108 usage+= "Usage: c++getvar varname ";109 mpiac->RegisterCommand(kw, usage, this, hgrp);110 111 kw = "c++varlist";112 usage = "c++getvar: Printing test variable list\n";113 usage+= "Usage: c++varlist ";114 mpiac->RegisterCommand(kw, usage, this, hgrp);115 //// A VIRER quand variable de objmanager OK --> Pour Reza116 98 117 99 } … … 222 204 223 205 /* --Methode-- */ 206 int CxxExecutor::ExecuteCxx(string const & code) 207 { 208 int rc; 209 210 mUserCodeFn = ""; 211 mUserCodeFn = "cxx_spiapp.h"; 212 ofstream os(mUserCodeFn.c_str(),ios::out); 213 if(!os) {cout<<"CxxExecutor::ExecuteCxx(): unable to open " 214 <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;} 215 216 os << code ; 217 os << endl ; 218 219 cout<<"CxxExecutor: User code filled from standard input into " 220 <<mUserCodeFn<<endl; 221 222 rc = CrFile(); if(rc) return(1); 223 rc = Compile(); if(rc) return(1); 224 rc = Link(); if(rc) return(1); 225 rc = Call(); if(rc) return(1); 226 return(rc); 227 } 228 229 /* --Methode-- */ 224 230 int CxxExecutor::CrFile(string cfilename,string func) 225 231 { … … 362 368 for(it=varlist.Begin(); it!=varlist.End(); it++) { 363 369 string key = (*it).first; 364 os<<"___nomobj = \""<<key<<"\";"<<endl; 365 os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl; 370 if (isalpha(key[0]) ) { 371 os<<"___nomobj = \""<<key<<"\";"<<endl; 372 os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl; 373 } 366 374 } 367 375 -
trunk/SophyaPI/PIext/cxxexecutor.h
r1237 r1262 24 24 25 25 virtual int Execute(string& keyw,vector<string>& args); 26 27 int ExecuteCxx(string const & code); 26 28 27 29 int CrFile(string cfilename="cxx_spiapp.cc",string func="usercxx"); -
trunk/SophyaPI/PIext/cxxexecwin.cc
r1251 r1262 92 92 dap->SetBusy(); 93 93 mBut[0]->SetUnSensitive(); 94 // $CHECK$ REZA + CMV 23/10/2000 - Faire quelque chose de mieux ici 95 vector<string> vs; 96 int rc; 97 vs.push_back(mText->GetText()); 98 rc = cxxex->FillUserCode(vs, 0); 99 if (rc) break; 100 rc = cxxex->CrFile(); 101 if (rc) break; 102 rc = cxxex->Compile(); 103 if (rc) break; 104 rc = cxxex->Link(); 105 if (rc) break; 106 rc = cxxex->Call(); 107 if (rc) break; 108 // End de $CHECK$ REZA + CMV 23/10/2000 94 cxxex->ExecuteCxx(mText->GetText()); 109 95 mBut[0]->SetSensitive(); 110 96 dap->SetReady(); -
trunk/SophyaPI/PIext/piacmd.cc
r1251 r1262 130 130 class PIACmdBloc { 131 131 public: 132 PIACmdBloc(PIACmd* piac, PIACmdBloc* par, vector<string>& args); 133 ~PIACmdBloc(); 132 enum BType { BT_None, BT_ForeachList, BT_ForeachInt, BT_ForeachFloat }; 133 134 PIACmdBloc(PIACmd* piac, PIACmdBloc* par, vector<string>& args); 135 ~PIACmdBloc(); 134 136 inline PIACmdBloc* Parent() { return(parent); } 135 inline bool CheckOK() { return ((typ >= 0) ? true : false); }137 inline bool CheckOK() { return blkok; } 136 138 inline void AddLine(string& line) 137 139 { lines.push_back(line); bloclineid.push_back(lines.size()); } … … 142 144 PIACmd* piacmd; 143 145 PIACmdBloc* parent; 144 int typ; // 0 foreach , 1 integer loop, 2 float loop 146 bool blkok; // true -> block OK 147 BType typ; // foreach , integer loop, float loop, test 145 148 string varname; 146 149 vector<string> strlist; … … 157 160 piacmd = piac; 158 161 parent = par; 159 typ = -1; 162 blkok = false; 163 typ = BT_None; 160 164 i1 = 0; i2 = -1; di = 1; 161 165 f1 = 0.; f2 = -1.; df = 1.; 162 166 if ((args.size() < 2) || !isalpha((int)args[0][0]) ) return; 163 167 varname = args[0]; 164 if (isalpha((int)args[1][0]) ) { // This is a foreach -integer bloc168 if (isalpha((int)args[1][0]) ) { // This is a foreach bloc with string list 165 169 for(int kk=1; kk<args.size(); kk++) strlist.push_back(args[kk]); 166 typ = 0;170 typ = BT_ForeachList; 167 171 } 168 172 else { // This is an integer or float loop … … 184 188 else a2 = aa; 185 189 if (fl) { 186 typ = 2;190 typ = BT_ForeachFloat; 187 191 f1 = atof(a1.c_str()); 188 192 f2 = atof(a2.c_str()); … … 191 195 } 192 196 else { 193 typ = 1;197 typ = BT_ForeachInt; 194 198 i1 = atoi(a1.c_str()); 195 199 i2 = atoi(a2.c_str()); … … 216 220 int kk=0; 217 221 char buff[32]; 218 if (typ == 0) // foreach string loop222 if (typ == BT_ForeachList) // foreach string loop 219 223 for(k=0; k<strlist.size(); k++) { 220 224 cmd = "set " + varname + " " + strlist[k]; … … 226 230 } 227 231 } 228 else if (typ == 1) // Integer loop232 else if (typ == BT_ForeachInt) // Integer loop 229 233 for(int i=i1; i<i2; i+=di) { 230 234 k++; … … 242 246 } 243 247 } 244 else if (typ == 2) // float loop248 else if (typ == BT_ForeachFloat) // float loop 245 249 for(float f=f1; f<f2; f+=df) { 246 250 k++; … … 279 283 curblk = NULL; 280 284 felevel = 0; 285 bloccxx = false; 286 bloctest = false; 281 287 282 288 cmdhgrp["All"] = 0; … … 449 455 450 456 451 // Pour le decoupage des commandes en lignes452 typedef vector<string> cmdtok;453 457 454 458 /* Fonction */ … … 474 478 { 475 479 int rc = 0; 476 cmdtok tokens; 477 CmdVarList::iterator it; 478 479 // Removing leading blanks 480 size_t p,q,q2,l; 480 NamedObjMgr omg; 481 482 // On saute de commandes vides 483 size_t l; 481 484 l = s.length(); 482 485 if (l < 1) return(0); 486 487 // On enregistre les commandes 488 if (histon) hist << s << endl; 489 483 490 if (s[0] == '#') return(0); // si c'est un commentaire 491 492 493 // Removing leading blanks 494 size_t p,q,q2; 495 l = s.length(); 496 if (l < 1) return(0); 497 484 498 p=s.find_first_not_of(" \t"); 485 499 if (p < l) s = s.substr(p); 486 // else return(0);487 488 // On enregistre les commandes489 if (histon) hist << s << endl;490 491 492 string toks,kw;493 500 494 501 // >>>> Substitution d'alias (1er mot) 502 CmdVarList::iterator it; 495 503 p = 0; 496 504 q = s.find_first_of(" \t"); … … 508 516 509 517 // >>>> Separating keyword 518 string toks,kw; 510 519 if (q < l) 511 520 { kw = s.substr(p,q-p); toks = s.substr(q, l-q); } … … 533 542 } 534 543 535 // Nous ne sommes donc pas dans un bloc .... 536 537 // >>>> Variable substitution 538 string s2=""; 544 545 // Nous ne sommes donc pas dans un bloc .... Substitution de variables 546 547 // Execution de code C++ 548 549 if (s[0] == '@') { 550 CxxExecutor * cxxe = dynamic_cast<CxxExecutor *>(cxxexec); 551 if (cxxe == NULL) { 552 cerr << "PIACmd::Interpret() - BUG !!! Not a CxxExecutor " << endl; 553 return(99); 554 } 555 // Sans substitution des variables $ 556 if (s[1] == '@') return(cxxe->ExecuteCxx(s.substr(2))); 557 else { // Avec substitution de variables $ 558 string s2; 559 SubstituteVars(s, s2); 560 return(cxxe->ExecuteCxx(s2.substr(1))); 561 } 562 } 563 564 565 string s2; 566 SubstituteVars(s, s2); 567 568 // >>>> Separating keyword and tokens 569 vector<string> tokens; 570 571 q = s2.find(' '); 572 l = s2.length(); 573 if (q < l) 574 { kw = s2.substr(0,q); toks = s2.substr(q, l-q); } 575 else { kw = s2; toks = ""; } 576 577 q = 0; 578 while (q < l) { 579 p = toks.find_first_not_of(" \t",q+1); // au debut d'un token 580 if (p>=l) break; 581 q = toks.find_first_of(" \t",p); // la fin du token; 582 string token = toks.substr(p,q-p); 583 tokens.push_back(token); 584 } 585 586 587 // Si c'est un foreach, on cree un nouveau bloc 588 if (kw == "foreach") { 589 // cout << " *DBG* We got a foreach... " << endl; 590 PIACmdBloc* bloc = new PIACmdBloc(this, curblk, tokens); 591 if (!bloc->CheckOK()) { 592 cerr << "foreach syntax Error ! " << endl; 593 delete bloc; 594 return(0); 595 } 596 felevel++; 597 if (curblk) curblk->AddBloc(bloc); 598 else { 599 char prompt[64]; 600 sprintf(prompt, "foreach-%d> ", felevel); 601 mImgApp->GetConsole()->SetPrompt(prompt); 602 } 603 curblk = bloc; 604 // cout << " *DBG* New Bloc created ... " << endl; 605 return(0); 606 } 607 608 else rc = ExecuteCommandLine(kw, tokens, toks); 609 return(rc); 610 611 // cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl; 612 // for(int ii=0; ii<tokens.size(); ii++) 613 // cout << "arg[ " << ii << " ] : " << tokens[ii] << endl; 614 615 } 616 617 /* --Methode-- */ 618 int PIACmd::SubstituteVars(string & s, string & s2) 619 // Variable substitution 620 { 621 NamedObjMgr omg; 622 623 size_t p,q,q2,l; 624 625 s2=""; 539 626 p = 0; 540 627 l = s.length(); … … 569 656 } 570 657 vn = s.substr(q+2,q2-q-2); 571 it = mVars.find(vn); 572 if ( (vn.length() < 1) || (it == mVars.end()) ) { 658 if ( (vn.length() < 1) || (!omg.HasVar(vn)) ) { 573 659 cerr << " Error: Undefined variable " << vn << " ! " << endl; 574 660 return(0); 575 661 } 576 vn = mVars[vn];662 vn = omg.GetVar(vn); 577 663 q2++; 578 664 } … … 582 668 vn = s.substr(q+1, q2-q-1); 583 669 } 584 it = mVars.find(vn); 585 if ( (vn.length() < 1) || (it == mVars.end()) ) { 670 if ( (vn.length() < 1) || (!omg.HasVar(vn)) ) { 586 671 cerr << " Error: Undefined variable " << vn << " ! " << endl; 587 672 return(0); 588 673 } 589 s2 += (s.substr(p, q-p) + (*it).second);674 s2 += (s.substr(p, q-p) + omg.GetVar(vn)); 590 675 p = q2; 591 676 } … … 595 680 if (p < l) s2 = s2.substr(p); 596 681 597 598 // >>>> Separating keyword and tokens 599 q = s2.find(' '); 600 l = s2.length(); 601 if (q < l) 602 { kw = s2.substr(0,q); toks = s2.substr(q, l-q); } 603 else { kw = s2; toks = ""; } 604 605 q = 0; 606 while (q < l) { 607 p = toks.find_first_not_of(" \t",q+1); // au debut d'un token 608 if (p>=l) break; 609 q = toks.find_first_of(" \t",p); // la fin du token; 610 string token = toks.substr(p,q-p); 611 tokens.push_back(token); 612 } 613 614 615 // Si c'est un foreach, on cree un nouveau bloc 616 if (kw == "foreach") { 617 // cout << " *DBG* We got a foreach... " << endl; 618 PIACmdBloc* bloc = new PIACmdBloc(this, curblk, tokens); 619 if (!bloc->CheckOK()) { 620 cerr << "foreach syntax Error ! " << endl; 621 delete bloc; 622 return(0); 623 } 624 felevel++; 625 if (curblk) curblk->AddBloc(bloc); 626 else { 627 char prompt[64]; 628 sprintf(prompt, "foreach-%d> ", felevel); 629 mImgApp->GetConsole()->SetPrompt(prompt); 630 } 631 curblk = bloc; 632 // cout << " *DBG* New Bloc created ... " << endl; 633 return(0); 634 } 635 636 637 // cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl; 638 // for(int ii=0; ii<tokens.size(); ii++) 639 // cout << "arg[ " << ii << " ] : " << tokens[ii] << endl; 682 return(0); 683 } 684 685 /* --Methode-- */ 686 int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks) 687 { 688 int rc = 0; 689 NamedObjMgr omg; 640 690 641 691 // >>>>>>>>>>> Commande d'interpreteur 642 elseif (kw == "helpwindow") ShowHelpWindow();692 if (kw == "helpwindow") ShowHelpWindow(); 643 693 else if (kw == "help") { 644 694 if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl; … … 657 707 string xx = tokens[1]; 658 708 for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk] ); 659 mVars[tokens[0]] = xx;709 omg.SetVar(tokens[0], xx); 660 710 } 661 711 662 712 else if (kw == "getvar") { 663 713 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: getvar newvarname varname" << endl; return(0); } 664 it = mVars.find(tokens[1]); 665 if (it == mVars.end()) { 714 if (!omg.HasVar(tokens[1])) { 666 715 cerr << "Error - No " << tokens[1] << " Variable " << endl; 667 716 return(0); … … 671 720 return(0); 672 721 } 673 mVars[tokens[0]] = (*it).second;722 omg.SetVar(tokens[0], omg.GetVar(tokens[1]) ); 674 723 } 675 724 … … 699 748 for (int kk=1; kk<ol.size(); kk++) vol += (' ' + ol[kk]); 700 749 } 701 mVars[tokens[0]] = vol;750 omg.SetVar(tokens[0], vol); 702 751 } 703 752 else if (kw == "unset") { 704 753 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); } 705 CmdVarList::iterator it = mVars.find(tokens[0]); 706 if (it != mVars.end()) mVars.erase(it); 754 if (omg.HasVar(tokens[0])) omg.DeleteVar(tokens[0]) ; 707 755 else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl; 708 756 } … … 720 768 mImgApp->GetConsole()->AddStr(">>> Reading From StdIn \n", PIVA_Magenta); 721 769 cout << tokens[0] << " ? " << endl; 722 mVars[tokens[0]] = GetStringFrStdin(this);770 omg.SetVar(tokens[0], GetStringFrStdin(this) ); 723 771 } 724 772 725 773 else if (kw == "listvars") { 726 774 cout << "PIACmd::Interpret() Variable List , VarName = Value \n"; 727 CmdVarList::iterator it; 728 for(it = mVars.begin(); it != mVars.end(); it++) 729 cout << (*it).first << " = " << (*it).second << "\n"; 775 DVList& varlist = omg.GetVarList(); 776 DVList::ValList::const_iterator it; 777 string value; 778 for(it = varlist.Begin(); it != varlist.End(); it++) { 779 value = (string)((*it).second.elval); 780 cout << (*it).first << " = " << value << "\n"; 781 } 730 782 cout << endl; 731 783 } … … 774 826 775 827 /* --Methode-- */ 776 int PIACmd::ExecuteCommandLine(string& line) 777 { 778 cmdtok tokens; 828 int PIACmd::ParseLineExecute(string& line) 829 { 830 vector<string> tokens; 831 779 832 if (line.length() < 1) return(0); 780 833 … … 843 896 char buff[32]; 844 897 // First, we clear all previous values 898 NamedObjMgr omg; 845 899 string vn="#"; 846 it = mVars.find(vn); 847 if (it != mVars.end()) mVars.erase(it); 900 omg.DeleteVar(vn); 848 901 for(k=0; k<99; k++) { 849 902 sprintf(buff,"%d",k); 850 903 vn = buff; 851 it = mVars.find(vn); 852 if (it != mVars.end()) mVars.erase(it); 904 omg.DeleteVar(vn); 853 905 } 854 906 // We then set them 907 string vval; 855 908 vn="#"; 856 909 sprintf(buff,"%d",(int)args.size()); 857 mVars[vn] = buff;910 omg.SetVar(vn, buff); 858 911 for(k=0; k<args.size(); k++) { 859 912 sprintf(buff,"%d",k); 860 913 vn = buff; 861 mVars[vn] = args[k];914 omg.SetVar(vn, args[k]); 862 915 } 863 916 -
trunk/SophyaPI/PIext/piacmd.h
r1251 r1262 12 12 #include <string> 13 13 #include <vector> 14 #include <list> 14 15 #include <map> 15 16 #include <functional> … … 78 79 79 80 virtual int Interpret(string& line); 80 virtual int ExecuteCommandLine(string& line);81 virtual int ParseLineExecute(string& line); 81 82 virtual int ExecuteCommand(string& keyw, vector<string>& args); 82 83 virtual int ExecFile(string& file, vector<string>& args); … … 99 100 protected: 100 101 virtual int CheckHelpGrp(string& grp); 102 int ExecuteCommandLine(string & keyw, vector<string> & args, 103 string & toks); 104 105 int SubstituteVars(string & s, string & s2); 106 bool EvaluateTest(vector<string> & args); 101 107 102 108 NamedObjMgr* mObjMgr; … … 128 134 // Pour stocker les variables definies par l'interpreteur 129 135 typedef map<string, string, less<string> > CmdVarList; 130 CmdVarList mVars; //Liste des variables136 // CmdVarList mVars; Liste des variables 131 137 CmdVarList mAliases; // Liste des alias 132 138 133 139 PIACmdBloc * curblk; // Bloc de commande courant (foreach, ...) 134 140 int felevel; // foreah level 141 list<bool> testresult; // Resultat des test if 142 list<bool>::iterator tresit; // Test courant 143 bool bloctest; // On est ds un bloc test 144 bool bloccxx; // On est ds un bloc code C++ 145 string codecxx; 135 146 136 147 ofstream hist; // History file
Note:
See TracChangeset
for help on using the changeset viewer.