Changeset 1562 in Sophya for trunk/SophyaPI/PIext
- Timestamp:
- Jul 4, 2001, 1:10:28 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/piacmd.cc
r1539 r1562 132 132 enum BType { BT_None, BT_ForeachList, BT_ForeachInt, BT_ForeachFloat }; 133 133 134 PIACmdBloc(PIACmd* piac, PIACmdBloc* par, vector<string>& args);134 PIACmdBloc(PIACmd* piac, PIACmdBloc* par, string& kw, vector<string>& args); 135 135 ~PIACmdBloc(); 136 136 inline PIACmdBloc* Parent() { return(parent); } … … 156 156 157 157 /* --Methode-- */ 158 PIACmdBloc::PIACmdBloc(PIACmd* piac, PIACmdBloc* par, vector<string>& args)158 PIACmdBloc::PIACmdBloc(PIACmd* piac, PIACmdBloc* par, string& kw, vector<string>& args) 159 159 { 160 160 piacmd = piac; … … 165 165 f1 = 0.; f2 = -1.; df = 1.; 166 166 if ((args.size() < 2) || !isalpha((int)args[0][0]) ) return; 167 varname = args[0]; 168 if (isalpha((int)args[1][0]) ) { // This is a foreach bloc with string list 167 if ((kw != "foreach") && (kw != "for")) return; 168 varname = args[0]; // $CHECK$ Variable name should be checked 169 //if (isalpha((int)args[1][0]) ) { This is a foreach bloc with string list 170 if (kw == "foreach" ) { // This is a foreach bloc with string list 169 171 for(int kk=1; kk<args.size(); kk++) strlist.push_back(args[kk]); 170 172 typ = BT_ForeachList; … … 309 311 usage += " > readstdin varname # reads a line from stdin into $varname \n"; 310 312 usage += " > foreach varname string-list # Loop \n"; 311 usage += " > for each varname i1:i2[:di]# Integer loop \n";312 usage += " > for each varname f1:f2[:df]# Float loop \n";313 usage += " > for varname i1:i2[:di] # Integer loop \n"; 314 usage += " > for varname f1:f2[:df] # Float loop \n"; 313 315 usage += " > end # end loops \n"; 314 316 usage += " > listvars # List of variable names and values \n"; … … 509 511 mulinecmd = ""; 510 512 mulinefg = false; 511 const char * rprompt = (curblk == NULL) ? "Cmd> " : "for each? ";513 const char * rprompt = (curblk == NULL) ? "Cmd> " : "for...? "; 512 514 mImgApp->GetConsole()->SetPrompt(rprompt); 513 515 } … … 541 543 else { kw = s.substr(p,l-p); toks = ""; } 542 544 543 // On verifie si nous sommes dans un bloc 544 if ( (curblk != NULL) && (kw != "foreach") ) { // On est dans un bloc 545 if (kw != "end") { curblk->AddLine(s); return(0); } 546 else { 545 // les mot-cle end else endif doivent etre le seul mot de la ligne 546 if ( (kw == "end") || (kw == "else") || (kw == "endif") ) { 547 size_t ltk = toks.length(); 548 if (toks.find_first_not_of(" \t") < ltk) { 549 cerr << "PIACmd::Interpret()/syntax error near end else endif \n" 550 << "line: " << s << endl; 551 return(1); 552 } 553 } 554 555 // On verifie si nous sommes dans un bloc (for , foreach) 556 if (curblk != NULL) { // On est dans un bloc 557 if ( (kw == "for") || (kw == "foreach")) felevel++; 558 else if (kw == "end") felevel--; 559 if (felevel == 0) { // Il faut executer le bloc 547 560 PIACmdBloc* curb = curblk; 548 561 curblk = curb->Parent(); 549 felevel--; 550 if (curblk == NULL) { 551 mImgApp->GetConsole()->SetPrompt("Cmd> "); 562 mImgApp->GetConsole()->SetPrompt("Cmd> "); 552 563 // cout << " *DBG* Executing bloc " << endl; 553 curb->Execute(); 554 } 555 else { 556 // char prompt[64]; 557 // sprintf(prompt, "foreach-%d? ", felevel); 558 mImgApp->GetConsole()->SetPrompt("foreach? "); 559 } 564 bool ohv = histon; 565 histon = false; 566 curb->Execute(); 567 histon = ohv; 568 } 569 else curblk->AddLine(s); 570 return(0); 571 } 572 573 // Sommes-nous dans un bloc de test if then else 574 if (testresult.size() > 0) { // Nous sommes ds un bloc if 575 if (kw == "endif") { 576 list<bool>::iterator dbit = tresit; 577 tresit--; 578 testresult.erase(dbit); 560 579 return(0); 561 562 563 580 } 581 } 582 if ((testresult.size() > 0) && !(*tresit)) return(0); 564 583 565 584 // Nous ne sommes donc pas dans un bloc .... Substitution de variables … … 616 635 617 636 618 // Si c'est un for each, on cree un nouveau bloc619 if ( kw == "foreach") {637 // Si c'est un for/foreach, on cree un nouveau bloc 638 if ((kw == "foreach") || (kw == "for")) { 620 639 // cout << " *DBG* We got a foreach... " << endl; 621 PIACmdBloc* bloc = new PIACmdBloc(this, curblk, tokens);640 PIACmdBloc* bloc = new PIACmdBloc(this, curblk, kw, tokens); 622 641 if (!bloc->CheckOK()) { 623 cerr << "for each syntax Error ! " << endl;642 cerr << "for/foreach syntax Error ! " << endl; 624 643 delete bloc; 625 644 return(0); … … 627 646 felevel++; 628 647 if (curblk) curblk->AddBloc(bloc); 629 else { 630 char prompt[64]; 631 sprintf(prompt, "foreach-%d> ", felevel); 632 mImgApp->GetConsole()->SetPrompt(prompt); 633 } 648 else mImgApp->GetConsole()->SetPrompt("for...> "); 634 649 curblk = bloc; 635 650 // cout << " *DBG* New Bloc created ... " << endl; 636 651 return(0); 637 652 } 638 653 else if (kw == "if") { // Un test 654 bool res_tst = EvaluateTest(tokens); 655 testresult.push_back(res_tst); 656 if (testresult.size() == 1) tresit = testresult.begin(); 657 else tresit++; 658 } 639 659 else rc = ExecuteCommandLine(kw, tokens, toks); 640 660 return(rc); … … 705 725 } 706 726 else { 707 q2 = s.find_first_of(" .: /,]()$\"'",q+1);727 q2 = s.find_first_of(" .:+-*/,[](){}&|!$\"'",q+1); 708 728 if (q2 > l) q2 = l; 709 729 vn = s.substr(q+1, q2-q-1); … … 722 742 723 743 return(0); 744 } 745 746 /* --Methode-- */ 747 bool PIACmd::EvaluateTest(vector<string> & args) 748 { 749 if (args.size() < 2) { 750 cerr << " PIACmd::EvaluateTest()/Warning - args.size() < 2 " << endl; 751 return true; 752 } 753 else return(args[0] == args[1]); 724 754 } 725 755 … … 970 1000 } 971 1001 1002 bool ohv = histon; 972 1003 histon = false; 973 1004 while (fgets(line_buff,511,fip) != NULL) … … 978 1009 Interpret(line); 979 1010 } 980 histon = true;1011 histon = ohv; 981 1012 982 1013 // hist << "### End of Exec( " << file << " ) " << endl;
Note:
See TracChangeset
for help on using the changeset viewer.