Changeset 1565 in Sophya for trunk/SophyaPI/PIext/piacmd.cc
- Timestamp:
- Jul 4, 2001, 6:07:47 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/piacmd.cc
r1562 r1565 227 227 if (typ == BT_ForeachList) // foreach string loop 228 228 for(k=0; k<strlist.size(); k++) { 229 cmd = "set " + varname + " " + strlist[k];229 cmd = "set " + varname + " '" + strlist[k] + "'"; 230 230 piacmd->Interpret(cmd); 231 231 for(kj=0; kj<bloclineid.size(); kj++) { … … 288 288 curblk = NULL; 289 289 felevel = 0; 290 bloccxx = false;291 bloctest = false;292 290 mulinecmd = ""; 293 291 mulinefg = false; … … 314 312 usage += " > for varname f1:f2[:df] # Float loop \n"; 315 313 usage += " > end # end loops \n"; 314 usage += " > if test then # Conditional test : a == != < > <= >= b \n"; 315 usage += " > else # Conditional \n"; 316 usage += " > endif # End of conditional if bloc \n"; 317 usage += " > break # Delete (clears) all test and loop blocs \n"; 318 usage += " > return # Stops command execution from a file \n"; 316 319 usage += " > listvars # List of variable names and values \n"; 317 320 usage += " > listalias # List of alias names and values \n"; … … 553 556 } 554 557 558 if (kw == "break") { 559 PIACmdBloc* curb = curblk; 560 while (curb) { 561 PIACmdBloc* dblk = curb; 562 curb = curb->Parent(); 563 delete dblk; 564 } 565 testresult.clear(); 566 return(0); 567 } 568 else if (kw == "return") return(77777); 569 555 570 // On verifie si nous sommes dans un bloc (for , foreach) 556 571 if (curblk != NULL) { // On est dans un bloc … … 570 585 return(0); 571 586 } 587 else if (kw == "end") { 588 cerr << "PIACmd::Interpret()/syntax error - end outside for/foreach bloc \n" 589 << "line: " << s << endl; 590 return(1); 591 } 572 592 573 593 // Sommes-nous dans un bloc de test if then else 574 594 if (testresult.size() > 0) { // Nous sommes ds un bloc if 575 if (kw == "endif") { 576 list<bool>::iterator dbit = tresit; 595 if (kw == "else") { 596 if ((*tresit) & 2) { 597 cerr << "PIACmd::Interpret()/syntax error - multiple else in if bloc \n" 598 << "line: " << s << endl; 599 return(1); 600 } 601 else { 602 char * npr = ((*tresit)&1) ? "else-F> " : "else-T> "; 603 mImgApp->GetConsole()->SetPrompt(npr); 604 (*tresit) |= 2; 605 return(0); 606 } 607 } 608 else if (kw == "endif") { 609 list<char>::iterator dbit = tresit; 577 610 tresit--; 578 611 testresult.erase(dbit); 612 char * npr = "Cmd> "; 613 if (testresult.size() > 1) { 614 if (!((*tresit)&2)) 615 npr = ((*tresit)&1) ? "if-T> " : "if-F> "; 616 else 617 npr = ((*tresit)&1) ? "else-F> " : "else-T> "; 618 } 619 mImgApp->GetConsole()->SetPrompt(npr); 579 620 return(0); 580 621 } 581 } 582 if ((testresult.size() > 0) && !(*tresit)) return(0); 622 } 623 else if ((kw == "else") || (kw == "endif")) { 624 cerr << "PIACmd::Interpret()/syntax error - else,endif outside if bloc \n" 625 << "line: " << s << endl; 626 return(1); 627 } 628 629 bool fgcont = true; 630 if (testresult.size() > 0) { // Resultat de if ou else 631 list<char>::iterator it; 632 for(it=testresult.begin(); it!=testresult.end(); it++) { 633 // Si on n'est pas ds le else et le if est faux 634 if ( !((*it)&2) && !((*it)&1) ) fgcont = false; 635 // Si on est ds else et le if etait vrai ! 636 if ( ((*it)&2) && ((*it)&1) ) fgcont = false; 637 if (!fgcont) break; 638 } 639 } 640 641 if ((!fgcont) && (kw != "if")) return(0); 642 583 643 584 644 // Nous ne sommes donc pas dans un bloc .... Substitution de variables … … 622 682 q = toks.find(toks[p],p+1); 623 683 if (q>=l) { 624 cerr << " Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl;684 cerr << "PIACmd::Interpret()/Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl; 625 685 return(2); 626 686 } … … 640 700 PIACmdBloc* bloc = new PIACmdBloc(this, curblk, kw, tokens); 641 701 if (!bloc->CheckOK()) { 642 cerr << " for/foreach syntax Error ! " << endl;702 cerr << "PIACmd::Interpret() for/foreach syntax Error ! " << endl; 643 703 delete bloc; 644 return( 0);704 return(1); 645 705 } 646 706 felevel++; … … 651 711 return(0); 652 712 } 653 else if (kw == "if") { // Un test 654 bool res_tst = EvaluateTest(tokens); 713 else if (kw == "if") { // Un test if 714 bool restst = true; 715 int rct = EvaluateTest(tokens, s, restst); 716 if (rct) { 717 cerr << "PIACmd::Interpret() if syntax Error ! " << endl; 718 return(1); 719 } 720 char res_tst = (restst) ? 1 : 0; 655 721 testresult.push_back(res_tst); 656 722 if (testresult.size() == 1) tresit = testresult.begin(); 657 723 else tresit++; 658 } 724 char * npr = (restst) ? "if-T> " : "if-F> "; 725 mImgApp->GetConsole()->SetPrompt(npr); 726 } 727 // Execution de commandes 659 728 else rc = ExecuteCommandLine(kw, tokens, toks); 660 729 return(rc); … … 745 814 746 815 /* --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]); 816 int PIACmd::EvaluateTest(vector<string> & args, string & line, bool & res) 817 { 818 res = true; 819 if ((args.size() < 4) || (args[3] != "then")) return(1); 820 if (args[1] == "==") res = (args[0] == args[2]); 821 else if (args[1] == "!=") res = (args[0] != args[2]); 822 else if (args[1] == "<") 823 res = (atof(args[0].c_str()) < atof(args[2].c_str())); 824 else if (args[1] == ">") 825 res = (atof(args[0].c_str()) > atof(args[2].c_str())); 826 else if (args[1] == "<=") 827 res = (atof(args[0].c_str()) <= atof(args[2].c_str())); 828 else if (args[1] == ">=") 829 res = (atof(args[0].c_str()) >= atof(args[2].c_str())); 830 else return(2); 831 return(0); 754 832 } 755 833 … … 1007 1085 line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */ 1008 1086 string line(line_buff); 1009 Interpret(line);1087 if (Interpret(line) == 77777) break; 1010 1088 } 1011 1089 histon = ohv;
Note:
See TracChangeset
for help on using the changeset viewer.