Changeset 2483 in Sophya for trunk/SophyaLib/SysTools
- Timestamp:
- Dec 22, 2003, 12:41:46 AM (22 years ago)
- Location:
- trunk/SophyaLib/SysTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/commander.cc
r2473 r2483 10 10 11 11 12 namespace SOPHYA { 12 13 // ------------------------------------------------------------ 13 14 // Bloc de commandes (Foreach, ...) … … 21 22 class CommanderBloc { 22 23 public: 23 enum BType { BT_None, BT_ForeachList, BT_ForeachInt, BT_ForeachFloat }; 24 enum BType { BT_None, BT_ForeachList, BT_ForeachInt, BT_ForeachFloat, 25 BT_ForeachLineInFile }; 24 26 25 27 CommanderBloc(Commander* piac, CommanderBloc* par, string& kw, vector<string>& args); … … 44 46 BType typ; // foreach , integer loop, float loop, test 45 47 string varname; 48 string filename; // forinfile bloc 46 49 vector<string> strlist; 47 50 vector<string> lines; … … 68 71 69 72 if ((args.size() < 2) || !isalpha((int)args[0][0]) ) return; 70 if ((kw != "foreach") && (kw != "for") ) return;73 if ((kw != "foreach") && (kw != "for") && (kw != "forinfile")) return; 71 74 varname = args[0]; // $CHECK$ Variable name should be checked 72 75 //if (isalpha((int)args[1][0]) ) { This is a foreach bloc with string list 73 if (kw == "foreach" ) { // This is a foreach bloc with string list 76 if (kw == "forinfile") { 77 filename = args[1]; 78 blkok = true; 79 } 80 else if (kw == "foreach" ) { // This is a foreach bloc with string list 74 81 if ((args[1] != "(") || (args[args.size()-1] != ")") ) return; 75 82 for(int kk=2; kk<args.size()-1; kk++) strlist.push_back(args[kk]); 76 83 typ = BT_ForeachList; 77 84 blkok = true; 78 85 } 79 86 else { // This is an integer or float loop 80 87 size_t l = args[1].length(); … … 144 151 int mxloop = _commander->GetMaxLoopLimit(); 145 152 146 if (typ == BT_ForeachList) // foreach string loop 153 if (typ == BT_ForeachLineInFile) { // foreach line in file loop 154 } 155 else if (typ == BT_ForeachList) // foreach string loop 147 156 for(k=0; k<strlist.size(); k++) { 148 157 cmd = "set " + varname + " '" + strlist[k] + "'"; … … 313 322 spromptmul = "Cmd> "; 314 323 SetCurrentPrompt(spromptmul); 324 SetDefaultPrompt(spromptmul); 315 325 curscript = NULL; 326 327 _xstatus = 0; 328 _retstr = ""; 316 329 317 330 CmdBlks.push(NULL); … … 612 625 cerr << "Commander::Interpret()/syntax error near end else endif endscript \n" 613 626 << "line: " << s << endl; 614 return(1); 627 _xstatus = 91; 628 return(91); 615 629 } 616 630 } … … 633 647 SetCurrentPrompt("Cmd> "); 634 648 curscript = NULL; 649 _xstatus = 0; 635 650 return(0); 636 651 } … … 640 655 SetCurrentPrompt("Cmd> "); 641 656 curscript = NULL; 642 return(2); 657 _xstatus = 92; 658 return(92); 643 659 } 644 660 } 645 661 else curscript->AddLine(s, kw); 662 _xstatus = 0; 646 663 return(0); 647 664 } … … 658 675 << " within for/foreach bloc ! " << endl; 659 676 delete curb; 660 return(2); 677 _xstatus = 93; 678 return(93); 661 679 } 662 680 // cout << " *DBG* Executing bloc " << endl; … … 672 690 PopStack(false); 673 691 } 692 SetCurrentPrompt(defprompt); 674 693 delete curb; 675 694 histon = ohv; 676 695 } 677 696 else CmdBlks.top()->AddLine(s, kw); 697 _xstatus = 0; 678 698 return(0); 679 699 } … … 681 701 cerr << "Commander::Interpret()/syntax error - end outside for/foreach bloc \n" 682 702 << "line: " << s << endl; 683 return(1); 703 _xstatus = 94; 704 return(94); 684 705 } 685 706 … … 690 711 cerr << "Commander::Interpret()/syntax error - multiple else in if bloc \n" 691 712 << "line: " << s << endl; 692 return(1); 713 _xstatus = 95; 714 return(95); 693 715 } 694 716 else { … … 697 719 SetCurrentPrompt(npr); 698 720 (*tresit) |= 2; 721 _xstatus = 0; 699 722 return(0); 700 723 } … … 723 746 else curtestresult = true; 724 747 SetCurrentPrompt(npr); 748 _xstatus = 0; 725 749 return(0); 726 750 } … … 729 753 cerr << "Commander::Interpret()/syntax error - else,endif outside if bloc \n" 730 754 << "line: " << s << endl; 731 return(1); 755 _xstatus = 91; 756 return(91); 732 757 } 733 758 … … 744 769 } 745 770 746 if ((!fgcont) && (kw != "if")) return(0); 771 if ((!fgcont) && (kw != "if")) { 772 _xstatus = 0; 773 return(0); 774 } 747 775 748 776 749 777 // Les mots cles break et return peuvent de sortir de boucles/scripts/execfile 750 778 if (kw == "break") return(77766); 751 else if (kw == "return") return(77777); 779 else if (kw == "return") { 780 _retstr = toks; 781 return(77777); 782 } 752 783 753 784 // Nous ne sommes donc pas dans un bloc .... Substitution de variables … … 759 790 cerr << "Commander::Interpret()/syntax error in SubstituteVars() \n" 760 791 << "line: " << s << endl; 761 return(rcs); 792 _xstatus = 99; 793 return(99); 762 794 } 763 795 // >>>> Separating keyword and tokens … … 767 799 768 800 // Si c'est un for/foreach, on cree un nouveau bloc 769 if ((kw == "foreach") || (kw == "for") ) {801 if ((kw == "foreach") || (kw == "for") || (kw == "forinfile") ) { 770 802 // cout << " *DBG* We got a foreach... " << endl; 771 803 CommanderBloc* bloc = new CommanderBloc(this, CmdBlks.top(), kw, tokens); … … 773 805 cerr << "Commander::Interpret() for/foreach syntax Error ! " << endl; 774 806 delete bloc; 775 return(1); 807 _xstatus = 91; 808 return(91); 776 809 } 777 810 felevel++; … … 787 820 if (rct) { 788 821 cerr << "Commander::Interpret() if syntax Error ! " << "line: " << s << endl; 789 return(1); 822 _xstatus = 91; 823 return(91); 790 824 } 791 825 char res_tst = (restst) ? 1 : 0; … … 802 836 if (rcev) { 803 837 cerr << "Commander::Interpret() evaluation (RPN) syntax Error ! " << "line: " << s << endl; 804 return(1); 838 _xstatus = 98; 839 return(98); 805 840 } 806 841 return(0); … … 815 850 else { 816 851 cerr << "Commander::Interpret() No script name in defscript" << "line: " << s << endl; 817 return(1); 852 _xstatus = 91; 853 return(91); 818 854 } 819 855 } … … 832 868 // Execution de commandes 833 869 else rc = ExecuteCommandLine(kw, tokens, toks); 870 _xstatus = rc; 834 871 return(rc); 835 872 } … … 941 978 } 942 979 vn = s.substr(q+2,q2-q-2); 943 if (! GetVar(vn, vv)) return(5);980 if (!Var2Str(vn, vv)) return(5); 944 981 vn = vv; 945 982 q2++; … … 961 998 if (isalpha(sia[0])) { 962 999 string sia2; 963 if (! GetVar(sia, sia2) || (sia2.length() < 1)) {1000 if (!Var2Str(sia, sia2) || (sia2.length() < 1)) { 964 1001 cerr << " Syntax error - in $varname[index] : $" 965 1002 << vn << "[" << sia <<"]" << endl; … … 976 1013 } 977 1014 } 978 if (!GetVar(vn, vv)) return(5);979 1015 if (iarr < 0) { 1016 if (!Var2Str(vn, vv)) return(5); 980 1017 s2 += (s.substr(p, q-p) + vv); 981 1018 p = q2; 982 1019 } 983 1020 else { 984 vector<string> vs; 985 FillVStringFrString(vv, vs); 986 if (iarr >= vs.size()) { 1021 if (! Var2Str(vn, iarr, vv) ) { 987 1022 cerr << " Substitution error - word index out of range in " 988 1023 << "$varname[iarr] : $" << vn << "[" << iarr <<"]" << endl; 989 1024 return(4); 990 1025 } 991 else s2 += (s.substr(p, q-p) + v s[iarr]);1026 else s2 += (s.substr(p, q-p) + vv); 992 1027 p = q3+1; 993 1028 } … … 1002 1037 1003 1038 /* --Methode-- */ 1004 bool Commander:: GetVar(string& vn, string & vv)1039 bool Commander::Var2Str(string const & vn, string & vv) 1005 1040 { 1006 1041 if (vn.length() < 1) { … … 1010 1045 // Variable de type $# $0 $1 ... (argument de .pic ou de script) 1011 1046 int ka = 0; 1047 char buff[32]; 1048 1012 1049 if (vn == "#") { 1013 1050 if (ArgsStack.empty()) { … … 1035 1072 } 1036 1073 else if (vn[0] == '#') { // Variable de type $#vname --> size(vname) 1037 vn = vn.substr(1);1038 if ( !HasVariable(vn)) {1074 CmdVarList::iterator it = variables.find(vn.substr(1)); 1075 if (it == variables.end()) { 1039 1076 cerr << " Commander::SubstituteVarError: Undefined variable " 1040 1077 << vn << " ! " << endl; 1041 1078 vv = ""; return(false); 1042 1079 } 1043 vn = GetVariable(vn); 1044 vector<string> vs; 1045 FillVStringFrString(vn, vs); 1046 char buff[32]; 1047 sprintf(buff,"%d", (int)vs.size()); 1080 sprintf(buff,"%d", (int)(*it).second.size()); 1048 1081 vv = buff; return(true); 1049 } 1050 else { // variable ordinaire geree par NamedObjMgr 1051 if ( (!HasVariable(vn)) ) { 1082 } 1083 else if (vn == "status") { 1084 sprintf(buff,"%d", _xstatus); 1085 vv = buff; 1086 return true; 1087 } 1088 else if (vn == "retstr") { 1089 vv = _retstr; 1090 return true; 1091 } 1092 else { // Variable de l'interpreteur, ou de l'environnement application , env. global 1093 if (GetVar(vn, vv)) return true; 1094 else if (GetVarApp(vn, vv)) return true; 1095 else if (GetVarEnv(vn, vv)) return true; 1096 else { 1052 1097 cerr << " Commander::SubstituteVarError: Undefined variable " 1053 1098 << vn << " ! " << endl; 1054 vv = ""; return(false); 1055 } 1056 vv = GetVariable(vn); return(true); 1057 } 1058 1059 return(false); 1060 } 1061 /* --Methode-- */ 1062 string Commander::GetVariable(string const & key) 1063 { 1064 if ((key.length() < 1) || (! isalpha(key[0])) ) { 1065 cout << "Commander::GetVariable( " << key << ") Bad VarName " << endl; 1066 return(""); 1067 } 1068 // cout << " DEBUG::GetVar " << variables << endl; 1069 return(variables.GetS(key)); 1070 } 1071 1072 /* --Methode-- */ 1073 bool Commander::HasVariable(string const & key) 1074 { 1075 if ((key.length() < 1) || (! isalpha(key[0])) ) { 1076 cout << "Commander::HasVar( " << key << ") Bad VarName " << endl; 1099 vv = ""; return false; 1100 } 1101 } 1102 1103 return false; 1104 } 1105 1106 /* --Methode-- */ 1107 bool Commander::SetVariable(string const & vn, string const & vv) 1108 { 1109 // On verifie si le nom est de type vname[idx] 1110 size_t p,q,l; 1111 l = vn.length(); 1112 p = vn.find('['); 1113 if (p < l) { 1114 q = vn.find(']'); 1115 if (q != (l-1)) { 1116 cout << "Commander::Str2Var/SetVar() - Bad varname with []: " 1117 << vn << endl; 1118 return false; 1119 } 1120 string vna = vn.substr(0, p); 1121 string sia = vn.substr(p+1, q-(p+1)); 1122 if (isalpha(sia[0])) { 1123 string sia2; 1124 if (!Var2Str(sia, sia2) || (sia2.length() < 1)) { 1125 cerr << "Commander::Str2Var/SetVar() Syntax error- varname[index]:" 1126 << vn << endl; 1127 return false; 1128 } 1129 sia = sia2; 1130 } 1131 int iarr; 1132 int rcdia = ctoi(sia.c_str(), &iarr); 1133 if (rcdia < 0) { 1134 cerr << "Commander::Str2Var/SetVar() Syntax error- varname[iarr]: " 1135 << vn << endl; 1136 return false; 1137 } 1138 return SetVar(vna, iarr, vv); 1139 } 1140 else { 1141 if (vn == "status") { 1142 _xstatus = atoi(vv.c_str()); 1143 return true; 1144 } 1145 else if (vn == "retstr") { 1146 _retstr = vv; 1147 return true; 1148 } 1149 else return SetVar(vn, vv); 1150 } 1151 } 1152 1153 /* --Methode-- */ 1154 bool Commander::GetVar(string const & vn, string & vv) 1155 { 1156 CmdVarList::iterator it = variables.find(vn); 1157 if (it == variables.end()) { 1158 vv = ""; 1159 return false; 1160 } 1161 vv = (*it).second[0]; 1162 if ((*it).second.size() > 1) { 1163 for(int k=1; k<(*it).second.size(); k++) { 1164 vv += ' '; vv += (*it).second[k]; 1165 } 1166 } 1167 return true; 1168 } 1169 1170 /* --Methode-- */ 1171 bool Commander::GetVar(string const & vn, int idx, string & vv) 1172 { 1173 vv = ""; 1174 CmdVarList::iterator it = variables.find(vn); 1175 if (it == variables.end()) return false; 1176 if ((idx < 0) || (idx > (*it).second.size()-1)) 1177 return false; 1178 vv = (*it).second[idx]; 1179 return true; 1180 } 1181 1182 /* --Methode-- */ 1183 bool Commander::GetVar(string const & vn, vector<string> & vv) 1184 { 1185 vv.clear(); 1186 // vv.erase(vv.begin(),vv.end()); 1187 CmdVarList::iterator it = variables.find(vn); 1188 if (it == variables.end()) return false; 1189 vv = (*it).second; 1190 return true; 1191 } 1192 1193 /* --Methode-- */ 1194 bool Commander::SetVar(string const & vn, string const & val) 1195 { 1196 if ( !CheckVarName(vn) ) { 1197 cerr << "Commander::SetVar( " << vn << " ...) Bad VarName " << endl; 1077 1198 return(false); 1078 1199 } 1079 return(variables.HasKey(key)); 1080 } 1081 1082 /* --Methode-- */ 1083 bool Commander::SetVar(string const & key, string const & val) 1084 { 1085 if ((key.length() < 1) || (! isalpha(key[0])) ) { 1086 cout << "Commander::SetVar( " << key << " ...) Bad VarName " << endl; 1200 bool fg = false; 1201 vector<string> nouv; 1202 nouv.push_back(val); 1203 CmdVarList::iterator it = variables.find(vn); 1204 if (it == variables.end()) variables[vn] = nouv; 1205 else { 1206 (*it).second = nouv; 1207 fg = true; 1208 } 1209 return fg; 1210 } 1211 1212 /* --Methode-- */ 1213 bool Commander::SetVar(string const & vn, int idx, string const & val) 1214 { 1215 if ( !CheckVarName(vn) ) { 1216 cerr << "Commander::SetVar( " << vn << " ,idx, ...) Bad VarName " << endl; 1087 1217 return(false); 1088 1218 } 1089 bool fg = variables.HasKey(key); 1090 variables.SetS(key, val); 1091 // cout << " DEBUG::SetVar " << variables << endl; 1219 if ((vn == "status") || (vn == "retstr")) { 1220 cerr << "Commander::SetVar(vn,idx,val) ERROR - special var status/retstr " 1221 << endl; 1222 return(false); 1223 } 1224 if (idx < 0) { 1225 cout << "Commander::SetVar(vn," << idx << ",...) Error idx < 0" << endl; 1226 return(false); 1227 } 1228 bool fg = false; 1229 CmdVarList::iterator it = variables.find(vn); 1230 if (it == variables.end()) { 1231 vector<string> nouv; 1232 for(int j=0; j<idx; j++) nouv.push_back(""); 1233 nouv.push_back(val); 1234 variables[vn] = nouv; 1235 } 1236 else { 1237 if (idx >= (*it).second.size()) 1238 for(int j=(*it).second.size(); j<idx; j++) (*it).second.push_back(""); 1239 (*it).second.push_back(val); 1240 fg = true; 1241 } 1092 1242 return fg; 1093 1243 } 1094 1244 1095 1245 /* --Methode-- */ 1096 bool Commander:: DeleteVar(string const & key)1097 { 1098 if ( (key.length() < 1) || (! isalpha(key[0])) ){1099 c out << "Commander::DeleteVar( " << key << ") Bad VarName " << endl;1246 bool Commander::SetVar(string const & vn, vector<string> const & val) 1247 { 1248 if ( !CheckVarName(vn) ) { 1249 cerr << "Commander::SetVar( " << vn << " ...) Bad VarName " << endl; 1100 1250 return(false); 1101 1251 } 1102 return(variables.DeleteKey(key)); 1103 } 1104 1105 /* --Methode-- */ 1106 void Commander::ListVars() 1107 { 1108 cout << " ---- Commander::ListVars() List of defined variables ---- " 1252 if ((vn == "status") || (vn == "retstr")) { 1253 cerr << "Commander::SetVar(vn, vector<string>) ERROR - special var status/retstr " 1254 << endl; 1255 return(false); 1256 } 1257 bool fg = false; 1258 CmdVarList::iterator it = variables.find(vn); 1259 if (it == variables.end()) variables[vn] = val; 1260 else { 1261 (*it).second = val; 1262 fg = true; 1263 } 1264 return fg; 1265 } 1266 1267 /* --Methode-- */ 1268 bool Commander::CheckVarName(string const & vn) 1269 { 1270 size_t l,k; 1271 l = vn.length(); 1272 if (l < 1) return false; 1273 if (!isalpha(vn[0])) return false; 1274 for(k=1; k<l; k++) 1275 if ((!isalnum(vn[k])) && (vn[k] != '_')) return false; 1276 return true; 1277 } 1278 1279 /* --Methode-- */ 1280 bool Commander::DeleteVar(string const & vn) 1281 { 1282 CmdVarList::iterator it = variables.find(vn); 1283 if (it == variables.end()) { 1284 cerr << "Commander::DeleteVar() Var " << vn << " undefined!" << endl; 1285 return false; 1286 } 1287 variables.erase(it); 1288 return true; 1289 } 1290 1291 /* --Methode-- */ 1292 void Commander::ListVar() 1293 { 1294 cout << " ---- Commander::ListVar() List of defined variables ---- " 1109 1295 << endl; 1110 cout << variables; 1296 CmdVarList::iterator it; 1297 for(it = variables.begin(); it != variables.end(); it++) { 1298 string vn = (*it).first; 1299 int vs = (*it).second.size(); 1300 cout << vn << " -> Size= " << vs << endl; 1301 } 1111 1302 cout << "---------------------------------------------------------- " 1112 1303 << endl; 1113 1304 } 1305 1306 /* --Methode-- */ 1307 bool Commander::GetVarApp(string const & vn, string & vv) 1308 { 1309 vv = ""; 1310 cout << " Commander::GetVarApp() Not available ! " << endl; 1311 return false; 1312 } 1313 1314 /* --Methode-- */ 1315 bool Commander::SetVarApp(string const & vn, string const & vv) 1316 { 1317 cout << " Commander::SetVarApp() Not available ! " << endl; 1318 return false; 1319 } 1320 1321 /* --Methode-- */ 1322 bool Commander::DeleteVarApp(string const & vn) 1323 { 1324 cout << " Commander::DeleteVarApp() Not available ! " << endl; 1325 return false; 1326 } 1327 1328 /* --Methode-- */ 1329 void Commander::ListVarApp() 1330 { 1331 cout << " Commander::ListVarApp() Not available ! " << endl; 1332 return; 1333 } 1334 1335 1336 /* --Methode-- */ 1337 bool Commander::GetVarEnv(string const & vn, string & vv) 1338 { 1339 vv = ""; 1340 cout << " Commander::GetVarEnv() Not available ! " << endl; 1341 return false; 1342 } 1343 1344 /* --Methode-- */ 1345 bool Commander::SetVarEnv(string const & vn, string const & vv) 1346 { 1347 cout << " Commander::SetVarEnv() Not available ! " << endl; 1348 return false; 1349 } 1350 1351 /* --Methode-- */ 1352 bool Commander::DeleteVarEnv(string const & vn) 1353 { 1354 cout << " Commander::DeleteVarEnv() Not available ! " << endl; 1355 return false; 1356 } 1357 1358 /* --Methode-- */ 1359 void Commander::ListVarEnv() 1360 { 1361 cout << " Commander::ListVarEnv() Not available ! " << endl; 1362 return; 1363 } 1364 1114 1365 1115 1366 /* --Methode-- */ … … 1228 1479 } 1229 1480 else if (args.size() == 2) { 1230 SetVar (args[0], args[1]);1481 SetVariable(args[0], args[1]); 1231 1482 return(0); 1232 1483 } … … 1415 1666 sprintf(buff, "%g", x); 1416 1667 string res = buff; 1417 SetVar (args[0], res);1668 SetVariable(args[0], res); 1418 1669 return(0); 1419 1670 } … … 1461 1712 1462 1713 else if (kw == "set") { 1463 if (tokens.size() < 2) { cout << "Commander::Interpret() Usage: set varname string" << endl; return(0); } 1464 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) { 1465 cerr << "Commander::Interpret()/Error Variable name should start with alphabetic" << endl; 1466 return(0); 1467 } 1468 // string xx = tokens[1]; 1469 // for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk] ); 1470 SetVar(tokens[0], tokens[1]); 1471 } 1472 1714 if (tokens.size() < 2) { cout << "Commander::Interpret() Usage: set varname value" << endl; return(0); } 1715 if (tokens.size() == 2) 1716 SetVariable(tokens[0], tokens[1]); 1717 else { 1718 vector<string> vv; 1719 for(int k=1; k<tokens.size(); k++) vv.push_back(tokens[k]); 1720 SetVar(tokens[0], vv); 1721 } 1722 return 0; 1723 } 1724 /* RZDELETE 1473 1725 else if (kw == "getvar") { 1474 1726 if (tokens.size() < 2) { cout << "Commander::Interpret() Usage: getvar newvarname varname" << endl; return(0); } … … 1483 1735 SetVar(tokens[0], GetVariable(tokens[1]) ); 1484 1736 } 1485 1737 END-RZDELETE */ 1486 1738 else if (kw == "alias") { 1487 1739 if (tokens.size() < 2) { cout << "Commander::Interpret() Usage: alias aliasname string" << endl; return(0); } … … 1489 1741 cerr << "Commander::Interpret()/Error alias name should start with alphabetic" << endl; 1490 1742 return(0); 1491 1743 } 1492 1744 string xx = tokens[1]; 1493 1745 for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk]); 1494 1746 mAliases[tokens[0]] = xx; 1495 } 1496 1497 else if (kw == "unset") { 1498 if (tokens.size() < 1) { cout << "Commander::Interpret() Usage: unset varname" << endl; return(0); } 1499 if (HasVariable(tokens[0])) DeleteVar(tokens[0]) ; 1500 else cerr << "Commander::Interpret() No variable with name " << tokens[0] << endl; 1501 } 1502 else if (kw == "rpneval") { // Evaluation d'expression en notation polonaise inverse 1747 } 1748 1749 else if ( (kw == "unset") || (kw == "clearvar") ) { 1750 if (tokens.size() < 1) { 1751 cout << "Commander::Interpret() Usage: unset/clearvar varname" << endl; 1752 return(0); 1753 } 1754 else DeleteVar(tokens[0]); 1755 } 1756 // Evaluation d'expression en notation polonaise inverse 1757 else if (kw == "rpneval") { 1503 1758 return(EvalRPNExpr(tokens, toks)); 1504 1759 } … … 1529 1784 } 1530 1785 1531 else if (kw == "listvar s") ListVars();1786 else if (kw == "listvar") ListVar(); 1532 1787 else if (kw == "listalias") { 1533 1788 cout << "Commander::Interpret() Alias List , AliasName = Value \n"; … … 1897 2152 1898 2153 1899 2154 } // End of namespace SOPHYA 2155 -
trunk/SophyaLib/SysTools/commander.h
r2473 r2483 22 22 #include "ctimer.h" 23 23 24 namespace SOPHYA { 24 25 // Classe definissant l'interface pour un executeur de commande 25 26 … … 49 50 class CommanderScript; // Script de commandes defini ds l'interpreteur Commander 50 51 51 /*52 //! Interface definition for SOPHYA::Commander help manager53 class CommanderHelpMgr {54 public :55 CommanderHelpMgr();56 virtual ~CommanderHelpMgr();57 virtual void AddHelpGroup(const char * hgrp, int gid);58 virtual void AddHelpItem(const char * hitem);59 virtual void ClearHelpList();60 virtual void Activate();61 }62 */63 64 65 52 //! A simple command interpreter with c-shell like syntax with dynamic load capability. 66 53 … … 104 91 inline CmdInterpreter* CurrentInterpreter() { return(curcmdi); } 105 92 106 107 // Utilitaire pour decoupage en mot 93 // Utilitaire pour decoupage en mot 108 94 static int LineToWords(string& line, string& kw, vector<string>& tokens, 109 95 string& toks, bool uq=true); … … 123 109 int EvalRPNExpr(vector<string> & args, string & line); 124 110 125 virtual bool GetVar(string & vn, string & vv); 126 virtual string GetVariable(string const & vn); 127 virtual bool HasVariable(string const & vn); 111 // Acces aux variables 112 virtual bool Var2Str(string const & vn, string & vv); 113 inline bool Var2Str(string const & vn, int idx, string & vv) 114 { return GetVar(vn, idx, vv); } 115 inline bool Var2Str(string const & vn, vector<string> & vv) 116 { return GetVar(vn, vv); } 117 118 // ----- Action / gestion des variables propres de l'interpreteur 119 // Verifie l'existence de la variable nomme vn et retourne sa valeur ds vv 120 // Retourne false si la variable n'existe pas 121 virtual bool SetVariable(string const & vn, string const & vv); 122 virtual bool GetVar(string const & vn, string & vv); 123 virtual bool GetVar(string const & vn, int idx, string & vv); 124 virtual bool GetVar(string const & vn, vector<string> & vv); 128 125 virtual bool SetVar(string const & vn, string const & vv); 126 virtual bool SetVar(string const & vn, int idx, string const & vv); 127 virtual bool SetVar(string const & vn, vector<string> const & vv); 128 virtual bool CheckVarName(string const & vn); 129 129 virtual bool DeleteVar(string const & vn); 130 virtual void ListVars(); 130 virtual void ListVar(); 131 // Variables de l'environnement application 132 virtual bool GetVarApp(string const & vn, string & vv); 133 virtual bool SetVarApp(string const & vn, string const & vv); 134 virtual bool DeleteVarApp(string const & vn); 135 virtual void ListVarApp(); 136 // Variables d'environnement globales 137 virtual bool GetVarEnv(string const & vn, string & vv); 138 virtual bool SetVarEnv(string const & vn, string const & vv); 139 virtual bool DeleteVarEnv(string const & vn); 140 virtual void ListVarEnv(); 131 141 132 142 virtual string GetTmpDir(); … … 134 144 virtual void SetCurrentPrompt(const char* pr); 135 145 inline void SetCurrentPrompt(string const & pr) { SetCurrentPrompt(pr.c_str()); } 146 inline void SetDefaultPrompt(string const & pr) { defprompt = pr; } 136 147 137 148 virtual void ShowMessage(const char * msg, int att); … … 143 154 144 155 // Gestion des variables 145 DVList variables; 156 typedef map< string, vector<string>, less<string> > CmdVarList; 157 CmdVarList variables; 146 158 147 159 // Pour enregistrer la liste de commandes et leurs executeurs et le help … … 168 180 CommanderScript* curscript; // Script en cours de definition 169 181 170 // Pour stocker les alias definies par l'interpreteur 182 // Code de retour execution commande 183 int _xstatus; 184 // Valeur de retour (par l'instruction return) - 185 string _retstr; 186 187 // Pour stocker les alias definies par l'interpreteur 171 188 typedef map<string, string, less<string> > CmdStrList; 172 189 CmdStrList mAliases; // Liste des alias 173 190 174 // Le stack pour les arguments des .pic et des scripts191 // Le stack pour les arguments des .pic et des scripts 175 192 stack< vector<string> > ArgsStack; 176 // Stack pour les Prompts193 // Stack pour les Prompts 177 194 stack<string> PromptStack; 178 195 196 // Gestion des blocs de commandes et tests (if) 179 197 stack< CommanderBloc * > CmdBlks; // Bloc de commande courant (foreach, ...) 180 198 int felevel; // foreach-for level … … 184 202 bool curtestresult; // Resultat courant des tests 185 203 204 // Commande splitees sur plusieurs lignes 186 205 bool mulinefg; // Bloc multi-lignes (ligne suite) 187 206 string mulinecmd; // Commande multi-lignes 207 208 // Texte de prompt (attente de commande) 188 209 string spromptmul; // Prompt console avant multi-ligne 189 string curprompt; 190 210 string curprompt; // Prompt courant 211 string defprompt; // Prompt par defaut 212 213 // Gestion d'historique, trace, timing des commandes 191 214 ofstream hist; // History file 192 215 bool histon; // True -> history file … … 195 218 Timer* gltimer; // pour Display CPU Time 196 219 220 friend class CommanderBloc; 221 friend class CommanderScript; 222 197 223 }; 198 224 225 } // namespace SOPHYA 199 226 200 227 /* end of ifdef COMMANDER_H_SEEN */
Note:
See TracChangeset
for help on using the changeset viewer.