Changeset 2214 in Sophya for trunk/SophyaPI/PIext
- Timestamp:
- Oct 17, 2002, 10:56:11 AM (23 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/piacmd.cc
r2203 r2214 9 9 #include "pdlmgr.h" 10 10 #include "ctimer.h" 11 #include "strutil.h" 11 12 // #include "dlftypes.h" 12 13 … … 272 273 return(parent); 273 274 } 275 276 // ------------------ 277 // Classe PIACmdScript 278 // ------------------ 279 class PIACmdScript { 280 public: 281 PIACmdScript(); 282 virtual ~PIACmdScript(); 283 }; 274 284 275 285 // ------------------------------------------------------------ … … 542 552 543 553 // >>>> Substitution d'alias (1er mot) 544 Cmd VarList::iterator it;554 CmdStrList::iterator it; 545 555 p = 0; 546 556 q = s.find_first_of(" \t"); … … 756 766 // Variable substitution 757 767 { 758 NamedObjMgr omg;768 NamedObjMgr& omg = *mObjMgr; 759 769 760 770 size_t p,q,q2,l; … … 763 773 p = 0; 764 774 l = s.length(); 765 string vn ;775 string vn, vv; 766 776 while (p < l) { 767 777 q = s.find('$',p); … … 803 813 } 804 814 vn = s.substr(q+2,q2-q-2); 805 if ( (vn.length() < 1) || (!omg.HasVar(vn)) ) { 806 cerr << " Error: Undefined variable " << vn << " ! " << endl; 807 return(5); 808 } 809 vn = omg.GetVar(vn); 815 if (!GetVar(vn, vv)) return(5); 816 vn = vv; 810 817 q2++; 811 818 } … … 815 822 vn = s.substr(q+1, q2-q-1); 816 823 } 817 if ( (vn.length() < 1) || (!omg.HasVar(vn)) ) { 818 cerr << " Error: Undefined variable " << vn << " ! " << endl; 819 return(5); 820 } 821 s2 += (s.substr(p, q-p) + omg.GetVar(vn)); 824 if (!GetVar(vn, vv)) return(5); 825 s2 += (s.substr(p, q-p) + vv); 822 826 p = q2; 823 827 } … … 828 832 829 833 return(0); 834 } 835 836 /* --Methode-- */ 837 bool PIACmd::GetVar(string & vn, string & vv) 838 { 839 NamedObjMgr& omg = *mObjMgr; 840 if (vn.length() < 1) { 841 cerr << " PIACmd::SubstituteVar/Error: length(varname=" << vn << ")<1 !" << endl; 842 vv = ""; return(false); 843 } 844 // Variable de type $# $0 $1 ... (argument de .pic ou de script) 845 int ka = 0; 846 if (vn == "#") { 847 if (ArgsStack.empty()) { 848 cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! " 849 << " ($" << vn << ")" << endl; 850 vv = ""; return(false); 851 } 852 char buff[32]; 853 long an = ArgsStack.top().size(); 854 sprintf(buff,"%ld", an); 855 vv = buff; 856 } 857 else if (ctoi(vn.c_str(), &ka) > 0) { // $0 $1 $2 ... 858 if (ArgsStack.empty()) { 859 cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! " 860 << " ($" << vn << ")" << endl; 861 vv = ""; return(false); 862 } 863 if ( (ka < 0) || (ka >= ArgsStack.top().size()) ) { 864 cerr << " PIACmd::SubstituteVar/Error: Undefined variable ! " 865 << " ($" << vn << ")" << endl; 866 vv = ""; return(false); 867 } 868 vv = ArgsStack.top()[ka]; 869 } 870 else { // variable ordinaire geree par NamedObjMgr 871 if ( (!omg.HasVar(vn)) ) { 872 cerr << " PIACmd::SubstituteVarError: Undefined variable " 873 << vn << " ! " << endl; 874 vv = ""; return(false); 875 } 876 vv = omg.GetVar(vn); 877 } 878 879 return(true); 830 880 } 831 881 … … 955 1005 else if (kw == "listalias") { 956 1006 cout << "PIACmd::Interpret() Alias List , AliasName = Value \n"; 957 Cmd VarList::iterator it;1007 CmdStrList::iterator it; 958 1008 for(it = mAliases.begin(); it != mAliases.end(); it++) 959 1009 cout << (*it).first << " = " << (*it).second << "\n"; … … 1072 1122 // hist << "### Executing commands from " << file << endl; 1073 1123 1074 // Setting $0 ... $99 variables 1075 int k; 1076 char buff[32]; 1077 // First, we clear all previous values 1078 NamedObjMgr omg; 1079 string vn="#"; 1080 omg.DeleteVar(vn); 1081 for(k=0; k<99; k++) { 1082 sprintf(buff,"%d",k); 1083 vn = buff; 1084 omg.DeleteVar(vn); 1085 } 1086 // We then set them 1087 string vval; 1088 vn="#"; 1089 sprintf(buff,"%d",(int)args.size()); 1090 omg.SetVar(vn, buff); 1091 for(k=0; k<args.size(); k++) { 1092 sprintf(buff,"%d",k); 1093 vn = buff; 1094 omg.SetVar(vn, args[k]); 1095 } 1124 // We push the argument list (args) on the stack 1125 ArgsStack.push(args); 1096 1126 1097 1127 if (trace) { … … 1118 1148 mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta); 1119 1149 } 1150 1151 // We remove the argument list (args) from the stack 1152 ArgsStack.pop(); 1120 1153 1121 1154 return(0); -
trunk/SophyaPI/PIext/piacmd.h
r2203 r2214 13 13 #include <vector> 14 14 #include <list> 15 #include <stack> 15 16 #include <map> 16 17 #include <functional> … … 53 54 class CxxOptionWind; // Option de CxxExecutor 54 55 55 class PIACmdBloc; 56 class PIACmdBloc; // Bloc de type foreach / for de l'interpreteur PIACmd 57 class PIACmdScript; // Script de commandes defini ds l'interpreteur PIACmd 56 58 57 59 // --------------------------------------------------------------------- … … 107 109 int EvaluateTest(vector<string> & args, 108 110 string & line, bool & res); 111 bool GetVar(string & vn, string & vv); 109 112 110 113 NamedObjMgr* mObjMgr; … … 137 140 InterpMap interpmap; 138 141 139 // Pour stocker les variables definies par l'interpreteur 140 typedef map<string, string, less<string> > CmdVarList; 141 CmdVarList mAliases; // Liste des alias 142 // Pour stocker les scripts definis ds l'interpreteur 143 typedef map<string, PIACmdScript*, less<string> > ScriptList; 144 ScriptList mScripts; // Liste des scripts 145 146 // Pour stocker les alias definies par l'interpreteur 147 typedef map<string, string, less<string> > CmdStrList; 148 CmdStrList mAliases; // Liste des alias 149 150 // Le stack pour les arguments des .pic et des scripts 151 stack< vector<string> > ArgsStack; 142 152 143 153 PIACmdBloc * curblk; // Bloc de commande courant (foreach, ...)
Note:
See TracChangeset
for help on using the changeset viewer.