[293] | 1 | #include "piacmd.h"
|
---|
[165] | 2 | #include <stdio.h>
|
---|
| 3 | #include <stdlib.h>
|
---|
[349] | 4 | #include <ctype.h>
|
---|
[165] | 5 | #include <math.h>
|
---|
| 6 |
|
---|
[293] | 7 | #include "basexecut.h"
|
---|
[165] | 8 |
|
---|
[293] | 9 | #include "pdlmgr.h"
|
---|
[165] | 10 | #include "ctimer.h"
|
---|
[293] | 11 | // #include "dlftypes.h"
|
---|
[165] | 12 |
|
---|
[293] | 13 | #include "pistdimgapp.h"
|
---|
[165] | 14 | #include "nobjmgr.h"
|
---|
[361] | 15 | #include "piafitting.h"
|
---|
[165] | 16 |
|
---|
[293] | 17 | #include PISTDWDG_H
|
---|
| 18 | #include PILIST_H
|
---|
[165] | 19 |
|
---|
[293] | 20 | // ------------------------------------------------------------
|
---|
[349] | 21 | // Gestion d'une fenetre d'aide interactive
|
---|
| 22 | // Classe PIAHelpWind
|
---|
[293] | 23 | // ------------------------------------------------------------
|
---|
[165] | 24 |
|
---|
[293] | 25 | class PIAHelpWind : public PIWindow {
|
---|
| 26 | public :
|
---|
| 27 | PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd);
|
---|
| 28 | virtual ~PIAHelpWind();
|
---|
[330] | 29 | virtual void Show();
|
---|
[293] | 30 | virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
|
---|
[330] | 31 | inline void AddHelpGroup(const char * hgrp, int gid)
|
---|
| 32 | { hgrpom->AppendItem(hgrp, 20000+gid); }
|
---|
| 33 | inline void ClearHelpList()
|
---|
| 34 | { mNitem=0; hitemlist->DeleteAllItems(); }
|
---|
[293] | 35 | inline void AddHelpItem(const char * hitem)
|
---|
[330] | 36 | { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
|
---|
[293] | 37 | protected :
|
---|
| 38 | PIStdImgApp* dap;
|
---|
| 39 | PIACmd* piac;
|
---|
| 40 | int mNitem;
|
---|
| 41 | PIList* hitemlist;
|
---|
[330] | 42 | PIOptMenu* hgrpom;
|
---|
[293] | 43 | PIButton * mBut;
|
---|
| 44 | PILabel * mLab;
|
---|
| 45 | PIText* mTxt;
|
---|
| 46 | };
|
---|
[165] | 47 |
|
---|
[293] | 48 | /* --Methode-- */
|
---|
| 49 | PIAHelpWind::PIAHelpWind(PIStdImgApp *par, PIACmd* piacmd)
|
---|
| 50 | : PIWindow((PIMsgHandler *)par, "Help-PIApp", PIWK_normal, 400, 300, 100, 350)
|
---|
| 51 | {
|
---|
| 52 | dap = par;
|
---|
| 53 | piac = piacmd;
|
---|
| 54 | mNitem = 0;
|
---|
[330] | 55 | SetMsg(77);
|
---|
[165] | 56 |
|
---|
[293] | 57 | int bsx, bsy;
|
---|
| 58 | int tsx, tsy;
|
---|
| 59 | int spx, spy;
|
---|
| 60 | PIApplicationPrefCompSize(bsx, bsy);
|
---|
| 61 | spx = bsx/6; spy = bsy/6;
|
---|
| 62 | tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy;
|
---|
| 63 | SetSize(tsx,tsy);
|
---|
[330] | 64 | hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy);
|
---|
| 65 | hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 66 | hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy);
|
---|
[293] | 67 | hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 68 | // hitemlist->SetBorderWidth(2);
|
---|
[324] | 69 | mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
|
---|
| 70 | // mTxt->SetMutiLineMode(true);
|
---|
[293] | 71 | mTxt->SetTextEditable(false);
|
---|
| 72 | mTxt->SetText("");
|
---|
| 73 | mTxt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 74 | mLab = new PILabel(this, "helpitem", bsx*4, bsy, bsx*2.5+2*spx, tsy-spy-bsy);
|
---|
| 75 | mLab->SetBorderWidth(1);
|
---|
| 76 | mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 77 | mLab->SetLabel("");
|
---|
[330] | 78 | mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
|
---|
[293] | 79 | mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 80 | }
|
---|
[165] | 81 |
|
---|
| 82 | /* --Methode-- */
|
---|
[293] | 83 | PIAHelpWind::~PIAHelpWind()
|
---|
| 84 | {
|
---|
[330] | 85 | delete hgrpom;
|
---|
[293] | 86 | delete hitemlist;
|
---|
| 87 | delete mTxt;
|
---|
| 88 | delete mLab;
|
---|
| 89 | delete mBut;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /* --Methode-- */
|
---|
| 93 | void PIAHelpWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
|
---|
| 94 | {
|
---|
| 95 | PIMessage um = UserMsg(msg);
|
---|
[330] | 96 | if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
|
---|
[293] | 97 | Hide();
|
---|
| 98 | return;
|
---|
| 99 | }
|
---|
[330] | 100 | else if ( (um >= 20000) && (sender == hgrpom)) { // Selection de groupe de Help
|
---|
| 101 | mTxt->SetText("");
|
---|
| 102 | mLab->SetLabel("");
|
---|
| 103 | piac->UpdateHelpList(this, um-20000);
|
---|
| 104 | }
|
---|
| 105 | else if ( (um > 100) && (sender == hitemlist) && (ModMsg(msg) == PIMsg_Select) ) {
|
---|
[293] | 106 | string s = hitemlist->GetSelectionStr();
|
---|
| 107 | mTxt->SetText(piac->GetUsage(s));
|
---|
| 108 | mLab->SetLabel(s);
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[330] | 112 | /* --Methode-- */
|
---|
| 113 | void PIAHelpWind::Show()
|
---|
| 114 | {
|
---|
| 115 | hgrpom->SetValue(20000); // Groupe All
|
---|
| 116 | mTxt->SetText("");
|
---|
| 117 | mLab->SetLabel("");
|
---|
| 118 | piac->UpdateHelpList(this, 0);
|
---|
| 119 | PIWindow::Show();
|
---|
| 120 | }
|
---|
[293] | 121 |
|
---|
[349] | 122 | // ------------------------------------------------------------
|
---|
| 123 | // Bloc de commandes (Foreach, ...)
|
---|
| 124 | // Classe PIACmdBloc
|
---|
| 125 | // ------------------------------------------------------------
|
---|
| 126 |
|
---|
| 127 | class PIACmdBloc {
|
---|
| 128 | public:
|
---|
| 129 | PIACmdBloc(PIACmd* piac, PIACmdBloc* par, vector<string>& args);
|
---|
| 130 | ~PIACmdBloc();
|
---|
| 131 | inline PIACmdBloc* Parent() { return(parent); }
|
---|
| 132 | inline bool CheckOK() { return((typ >= 0) ? true : false); }
|
---|
| 133 | inline void AddLine(string& line)
|
---|
| 134 | { lines.push_back(line); bloclineid.push_back(lines.size()); }
|
---|
| 135 | inline void AddBloc(PIACmdBloc* blk)
|
---|
| 136 | { blocs.push_back(blk); bloclineid.push_back(-blocs.size()); }
|
---|
| 137 | PIACmdBloc* Execute();
|
---|
| 138 | protected:
|
---|
| 139 | PIACmd* piacmd;
|
---|
| 140 | PIACmdBloc* parent;
|
---|
| 141 | int typ; // 0 foreach , 1 integer loop, 2 float loop
|
---|
| 142 | string varname;
|
---|
| 143 | vector<string> strlist;
|
---|
| 144 | vector<string> lines;
|
---|
| 145 | vector<PIACmdBloc *> blocs;
|
---|
| 146 | vector<int> bloclineid;
|
---|
| 147 | int i1,i2,di;
|
---|
| 148 | float f1,f2,df;
|
---|
| 149 | };
|
---|
| 150 |
|
---|
| 151 | /* --Methode-- */
|
---|
| 152 | PIACmdBloc::PIACmdBloc(PIACmd* piac, PIACmdBloc* par, vector<string>& args)
|
---|
| 153 | {
|
---|
| 154 | piacmd = piac;
|
---|
| 155 | parent = par;
|
---|
| 156 | typ = -1;
|
---|
| 157 | i1 = 0; i2 = -1; di = 1;
|
---|
| 158 | f1 = 0.; f2 = -1.; df = 1.;
|
---|
| 159 | if ((args.size() < 2) || !isalpha((int)args[0][0]) ) return;
|
---|
| 160 | varname = args[0];
|
---|
| 161 | if (isalpha((int)args[1][0]) ) { // This is a foreach-integer bloc
|
---|
| 162 | for(int kk=1; kk<args.size(); kk++) strlist.push_back(args[kk]);
|
---|
| 163 | typ = 0;
|
---|
| 164 | }
|
---|
| 165 | else { // This is an integer or float loop
|
---|
| 166 | size_t l = args[1].length();
|
---|
| 167 | size_t p = args[1].find(':');
|
---|
| 168 | size_t pp = args[1].find('.');
|
---|
| 169 | bool fl = (pp < l) ? true : false; // Float loop or integer loop
|
---|
| 170 | if (p >= l) return; // Syntaxe error
|
---|
| 171 | string a1 = args[1].substr(0, p);
|
---|
| 172 | string aa = args[1].substr(p+1);
|
---|
| 173 | p = aa.find(':');
|
---|
| 174 | string a2, a3;
|
---|
| 175 | bool hasa3 = false;
|
---|
| 176 | if (p < aa.length() ) {
|
---|
| 177 | a2 = aa.substr(0,p);
|
---|
| 178 | a3 = aa.substr(p+1);
|
---|
| 179 | hasa3 = true;
|
---|
| 180 | }
|
---|
| 181 | else a2 = aa;
|
---|
| 182 | if (fl) {
|
---|
| 183 | typ = 2;
|
---|
| 184 | f1 = atof(a1.c_str());
|
---|
| 185 | f2 = atof(a2.c_str());
|
---|
| 186 | if (hasa3) df = atof(a3.c_str());
|
---|
| 187 | else df = 1.;
|
---|
| 188 | }
|
---|
| 189 | else {
|
---|
| 190 | typ = 1;
|
---|
| 191 | i1 = atoi(a1.c_str());
|
---|
| 192 | i2 = atoi(a2.c_str());
|
---|
| 193 | if (hasa3) di = atoi(a3.c_str());
|
---|
| 194 | else di = 1;
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | /* --Methode-- */
|
---|
| 200 | PIACmdBloc::~PIACmdBloc()
|
---|
| 201 | {
|
---|
| 202 | for(int k=0; k<blocs.size(); k++) delete blocs[k];
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | /* --Methode-- */
|
---|
| 206 | PIACmdBloc* PIACmdBloc::Execute()
|
---|
| 207 | {
|
---|
| 208 | // cout << " DBG * PIACmdBloc::Execute() " << typ << " - " << bloclineid.size() <<
|
---|
| 209 | // " I1,I2=" << i1 << " , " << i2 << " , " << di << endl;
|
---|
| 210 | string cmd;
|
---|
| 211 | int k=0;
|
---|
| 212 | int kj=0;
|
---|
| 213 | int kk=0;
|
---|
| 214 | char buff[32];
|
---|
| 215 | if (typ == 0) // foreach string loop
|
---|
| 216 | for(k=0; k<strlist.size(); k++) {
|
---|
| 217 | cmd = "set " + varname + " " + strlist[k];
|
---|
| 218 | piacmd->Interpret(cmd);
|
---|
| 219 | for(kj=0; kj<bloclineid.size(); kj++) {
|
---|
| 220 | kk = bloclineid[kj];
|
---|
| 221 | if (kk > 0) piacmd->Interpret(lines[kk-1]);
|
---|
| 222 | else blocs[-kk-1]->Execute();
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 | else if (typ == 1) // Integer loop
|
---|
| 226 | for(int i=i1; i<i2; i+=di) {
|
---|
| 227 | k++;
|
---|
| 228 | if (++k > 9999) {
|
---|
| 229 | cout << ">>> Maximum PIACmdBloc loop limit (9999) -> break " << endl;
|
---|
| 230 | break;
|
---|
| 231 | }
|
---|
| 232 | sprintf(buff, " %d", i);
|
---|
| 233 | cmd = "set " + varname + buff;
|
---|
| 234 | piacmd->Interpret(cmd);
|
---|
| 235 | for(kj=0; kj<bloclineid.size(); kj++) {
|
---|
| 236 | kk = bloclineid[kj];
|
---|
| 237 | if (kk > 0) piacmd->Interpret(lines[kk-1]);
|
---|
| 238 | else blocs[-kk-1]->Execute();
|
---|
| 239 | }
|
---|
| 240 | }
|
---|
| 241 | else if (typ == 2) // float loop
|
---|
| 242 | for(float f=f1; f<f2; f+=df) {
|
---|
| 243 | k++;
|
---|
| 244 | if (++k > 9999) {
|
---|
| 245 | cout << ">>> Maximum PIACmdBloc loop limit (9999) -> break " << endl;
|
---|
| 246 | break;
|
---|
| 247 | }
|
---|
| 248 | sprintf(buff, " %g", f);
|
---|
| 249 | cmd = "set " + varname + buff;
|
---|
| 250 | piacmd->Interpret(cmd);
|
---|
| 251 | for(kj=0; kj<bloclineid.size(); kj++) {
|
---|
| 252 | kk = bloclineid[kj];
|
---|
| 253 | if (kk > 0) piacmd->Interpret(lines[kk-1]);
|
---|
| 254 | else blocs[-kk-1]->Execute();
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | return(parent);
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | // ------------------------------------------------------------
|
---|
| 262 | // Classe PIACmd
|
---|
| 263 | // ------------------------------------------------------------
|
---|
| 264 |
|
---|
[293] | 265 | static PIACmd* curpiacmd = NULL;
|
---|
| 266 | /* --Methode-- */
|
---|
[165] | 267 | PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
|
---|
| 268 | {
|
---|
[293] | 269 | mObjMgr = omg;
|
---|
[165] | 270 | mImgApp = app;
|
---|
| 271 | system("cp history.pic hisold.pic");
|
---|
| 272 | hist.open("history.pic");
|
---|
[349] | 273 | histon = true;
|
---|
[165] | 274 | trace = false; timing = false;
|
---|
| 275 | gltimer = NULL;
|
---|
[349] | 276 | curblk = NULL;
|
---|
| 277 | felevel = 0;
|
---|
[293] | 278 |
|
---|
[330] | 279 | cmdhgrp["All"] = 0;
|
---|
| 280 | cmdgrpid = 1;
|
---|
| 281 | cmdhgrp["Commands"] = 1;
|
---|
[293] | 282 | helpwin = new PIAHelpWind(app, this);
|
---|
[330] | 283 | helpwin->AddHelpGroup("All", 0);
|
---|
| 284 | helpwin->AddHelpGroup("Commands", 1);
|
---|
[293] | 285 |
|
---|
| 286 | string kw = "piacmd";
|
---|
| 287 | string usage;
|
---|
| 288 | usage = ">>> (piacmd) Interpreter's keywords : \n";
|
---|
[349] | 289 | usage += " > set varname string # To set a variable, $varname \n";
|
---|
| 290 | usage += " > get newvarname varname # To set a newvariable, equal to $varname \n";
|
---|
[333] | 291 | usage += " > setol varname patt # Fills varname with object list \n";
|
---|
[293] | 292 | usage += " > unset varname # clear variable definition \n";
|
---|
[333] | 293 | usage += " > echo string # output string \n";
|
---|
[353] | 294 | usage += " > alias name string # define a command alias \n";
|
---|
| 295 | usage += " > readstdin varname # reads a line from stdin into $varname \n";
|
---|
[349] | 296 | usage += " > foreach varname string-list # Loop \n";
|
---|
| 297 | usage += " > foreach varname i1:i2[:di] # Integer loop \n";
|
---|
| 298 | usage += " > foreach varname f1:f2[:df] # Float loop \n";
|
---|
| 299 | usage += " > end # end loops \n";
|
---|
[353] | 300 | usage += " > listvars # List of variable names and values \n";
|
---|
| 301 | usage += " > listalias # List of alias names and values \n";
|
---|
| 302 | usage += " > listcommands # List of all known commands \n";
|
---|
| 303 | usage += " > exec filename # Execute commands from file \n";
|
---|
[293] | 304 | usage += " > shell comand_string # Execute shell command \n";
|
---|
| 305 | usage += " > help <command_name> # <command_name> usage info \n";
|
---|
| 306 | usage += " > helpwindow # Displays help window \n";
|
---|
[349] | 307 | usage += " > timingon timingoff traceon traceoff \n";
|
---|
[330] | 308 | string grp = "Commands";
|
---|
| 309 | RegisterHelp(kw, usage, grp);
|
---|
[293] | 310 |
|
---|
| 311 | basexec = new PIABaseExecutor(this, omg, app);
|
---|
[361] | 312 | fitexec = new PIAFitter(this, app);
|
---|
[293] | 313 | AddInterpreter(this);
|
---|
| 314 | curcmdi = this;
|
---|
[165] | 315 | }
|
---|
| 316 |
|
---|
| 317 | /* --Methode-- */
|
---|
| 318 | PIACmd::~PIACmd()
|
---|
| 319 | {
|
---|
| 320 | hist.close();
|
---|
| 321 | if (gltimer) { delete gltimer; gltimer = NULL; }
|
---|
[293] | 322 | Modmap::iterator it;
|
---|
| 323 | for(it = modmap.begin(); it != modmap.end(); it++) {
|
---|
| 324 | string name = (*it).first + "_end";
|
---|
| 325 | DlModuleInitEndFunction fend = (*it).second->GetFunction(name);
|
---|
| 326 | if (fend) fend();
|
---|
| 327 | delete (*it).second;
|
---|
| 328 | }
|
---|
| 329 | delete helpwin;
|
---|
| 330 | if (curpiacmd == this) curpiacmd = NULL;
|
---|
[361] | 331 | delete basexec;
|
---|
| 332 | delete fitexec;
|
---|
[165] | 333 | }
|
---|
| 334 |
|
---|
| 335 | /* --Methode-- */
|
---|
[293] | 336 | PIACmd* PIACmd::GetInterpreter()
|
---|
[165] | 337 | {
|
---|
[293] | 338 | return(curpiacmd);
|
---|
| 339 | }
|
---|
[165] | 340 |
|
---|
[293] | 341 | /* --Methode-- */
|
---|
| 342 | string PIACmd::Name()
|
---|
| 343 | {
|
---|
| 344 | return("piacmd");
|
---|
| 345 | }
|
---|
[165] | 346 |
|
---|
[293] | 347 | /* --Methode-- */
|
---|
[330] | 348 | void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string grp)
|
---|
[293] | 349 | {
|
---|
[330] | 350 | if (!ce) {
|
---|
| 351 | RegisterHelp(keyw, usage, grp);
|
---|
| 352 | return;
|
---|
| 353 | }
|
---|
| 354 | int gid = CheckHelpGrp(grp);
|
---|
[293] | 355 | cmdex cme;
|
---|
[330] | 356 | cme.group = gid;
|
---|
[293] | 357 | cme.us = usage;
|
---|
| 358 | cme.cex = ce;
|
---|
| 359 | cmdexmap[keyw] = cme;
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 | /* --Methode-- */
|
---|
[330] | 363 | void PIACmd::RegisterHelp(string& keyw, string& usage, string& grp)
|
---|
| 364 | {
|
---|
| 365 | int gid = CheckHelpGrp(grp);
|
---|
| 366 | cmdex cme;
|
---|
| 367 | cme.group = gid;
|
---|
| 368 | cme.us = usage;
|
---|
| 369 | cme.cex = NULL;
|
---|
| 370 | helpexmap[keyw] = cme;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | /* --Methode-- */
|
---|
| 374 | int PIACmd::CheckHelpGrp(string& grp)
|
---|
| 375 | {
|
---|
| 376 | int gid=0;
|
---|
| 377 | CmdHGroup::iterator it = cmdhgrp.find(grp);
|
---|
| 378 | if (it == cmdhgrp.end()) {
|
---|
| 379 | cmdgrpid++; gid = cmdgrpid;
|
---|
| 380 | cmdhgrp[grp] = gid;
|
---|
| 381 | helpwin->AddHelpGroup(grp.c_str(), gid);
|
---|
| 382 | }
|
---|
| 383 | else gid = (*it).second;
|
---|
| 384 | return(gid);
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | /* --Methode-- */
|
---|
| 388 | void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
|
---|
| 389 | {
|
---|
| 390 | helpwin->ClearHelpList();
|
---|
| 391 | CmdExmap::iterator it;
|
---|
| 392 | for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
|
---|
| 393 | if ( (gid != 0) && ((*it).second.group != gid) ) continue;
|
---|
| 394 | helpwin->AddHelpItem((*it).first.c_str());
|
---|
| 395 | }
|
---|
| 396 | for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
|
---|
| 397 | if ( (gid != 0) && ((*it).second.group != gid) ) continue;
|
---|
| 398 | helpwin->AddHelpItem((*it).first.c_str());
|
---|
| 399 | }
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | /* --Methode-- */
|
---|
[293] | 403 | void PIACmd::LoadModule(string& fnameso, string& name)
|
---|
| 404 | {
|
---|
| 405 | PDynLinkMgr * dynlink = new PDynLinkMgr(fnameso, false);
|
---|
| 406 | if (dynlink == NULL) {
|
---|
| 407 | cerr << "PIACmd/LoadModule_Error: Pb opening SO " << fnameso << endl;
|
---|
| 408 | return;
|
---|
[165] | 409 | }
|
---|
[293] | 410 | string fname = name + "_init";
|
---|
| 411 | DlModuleInitEndFunction finit = dynlink->GetFunction(fname);
|
---|
| 412 | if (!finit) {
|
---|
| 413 | cerr << "PIACmd/LoadModule_Error: Pb linking " << fname << endl;
|
---|
| 414 | return;
|
---|
[165] | 415 | }
|
---|
[293] | 416 | cout << "PIACmd/LoadModule_Info: Initialisation module" << name
|
---|
| 417 | << " " << fname << "() ..." << endl;
|
---|
| 418 | finit();
|
---|
| 419 | modmap[name] = dynlink;
|
---|
| 420 | return;
|
---|
| 421 | }
|
---|
[165] | 422 |
|
---|
[293] | 423 | /* --Methode-- */
|
---|
| 424 | void PIACmd::AddInterpreter(CmdInterpreter * cl)
|
---|
| 425 | {
|
---|
| 426 | if (!cl) return;
|
---|
[349] | 427 | interpmap[cl->Name()] = cl;}
|
---|
[165] | 428 |
|
---|
| 429 | /* --Methode-- */
|
---|
[293] | 430 | void PIACmd::SelInterpreter(string& name)
|
---|
[165] | 431 | {
|
---|
[293] | 432 | InterpMap::iterator it = interpmap.find(name);
|
---|
| 433 | if (it == interpmap.end()) return;
|
---|
| 434 | curcmdi = (*it).second;
|
---|
| 435 | }
|
---|
[165] | 436 |
|
---|
[293] | 437 |
|
---|
| 438 | // Pour le decoupage des commandes en lignes
|
---|
| 439 | typedef vector<string> cmdtok;
|
---|
| 440 |
|
---|
[357] | 441 | /* Fonction */
|
---|
[368] | 442 | static string GetStringFrStdin(PIACmd* piac)
|
---|
[357] | 443 | {
|
---|
[368] | 444 | PIStdImgApp* piapp = piac->GetImgApp();
|
---|
| 445 | if (piapp) {
|
---|
| 446 | PIBaseWdg* wdg = piapp->CurrentBaseWdg();
|
---|
| 447 | if (wdg) wdg->Refresh();
|
---|
[357] | 448 | #ifndef __mac__
|
---|
[368] | 449 | /* On vide le buffer X-Window */
|
---|
[374] | 450 | XSync(PIXDisplay(),False);
|
---|
[357] | 451 | #endif
|
---|
[368] | 452 | }
|
---|
[357] | 453 | char buff[128];
|
---|
| 454 | fgets(buff, 128, stdin);
|
---|
| 455 | buff[127] = '\0';
|
---|
| 456 | return((string)buff);
|
---|
| 457 | }
|
---|
| 458 |
|
---|
[293] | 459 | /* --Methode-- */
|
---|
| 460 | int PIACmd::Interpret(string& s)
|
---|
| 461 | {
|
---|
[333] | 462 | int rc = 0;
|
---|
[165] | 463 | cmdtok tokens;
|
---|
[349] | 464 | CmdVarList::iterator it;
|
---|
[165] | 465 |
|
---|
[349] | 466 | // Removing leading blanks
|
---|
| 467 | size_t p,q,q2,l;
|
---|
| 468 | l = s.length();
|
---|
| 469 | if (l < 1) return(0);
|
---|
| 470 | if (s[0] == '#') return(0); // si c'est un commentaire
|
---|
| 471 | p=s.find_first_not_of(" \t");
|
---|
| 472 | if (p < l) s = s.substr(p);
|
---|
| 473 | // else return(0);
|
---|
[165] | 474 |
|
---|
[349] | 475 | // On enregistre les commandes
|
---|
| 476 | if (histon) hist << s << endl;
|
---|
| 477 |
|
---|
| 478 |
|
---|
[165] | 479 | string toks,kw;
|
---|
| 480 |
|
---|
[349] | 481 | // >>>> Substitution d'alias (1er mot)
|
---|
[449] | 482 | p = 0;
|
---|
| 483 | q = s.find_first_of(" \t");
|
---|
| 484 | l = s.length();
|
---|
| 485 | string w1 = (q < l) ? s.substr(p,q-p) : s.substr(p);
|
---|
| 486 | it = mAliases.find(w1);
|
---|
| 487 | if (it != mAliases.end()) {
|
---|
| 488 | s = (q < l) ? ((*it).second + s.substr(q)) : (*it).second ;
|
---|
| 489 | l = s.length();
|
---|
| 490 | p=s.find_first_not_of(" \t");
|
---|
| 491 | if (p < l) s = s.substr(p);
|
---|
[349] | 492 | p = 0;
|
---|
| 493 | q = s.find_first_of(" ");
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | // >>>> Separating keyword
|
---|
[165] | 497 | if (q < l)
|
---|
| 498 | { kw = s.substr(p,q-p); toks = s.substr(q, l-q); }
|
---|
| 499 | else { kw = s.substr(p,l-p); toks = ""; }
|
---|
| 500 |
|
---|
[349] | 501 | // On verifie si nous sommes dans un bloc
|
---|
| 502 | if ( (curblk != NULL) && (kw != "foreach") ) { // On est dans un bloc
|
---|
| 503 | if (kw != "end") { curblk->AddLine(s); return(0); }
|
---|
| 504 | else {
|
---|
| 505 | PIACmdBloc* curb = curblk;
|
---|
| 506 | curblk = curb->Parent();
|
---|
| 507 | felevel--;
|
---|
| 508 | if (curblk == NULL) {
|
---|
| 509 | mImgApp->GetConsole()->SetPrompt("Cmd> ");
|
---|
| 510 | // cout << " *DBG* Executing bloc " << endl;
|
---|
| 511 | curb->Execute();
|
---|
| 512 | }
|
---|
| 513 | else {
|
---|
| 514 | char prompt[64];
|
---|
[353] | 515 | sprintf(prompt, "foreach-%d? ", felevel);
|
---|
[349] | 516 | mImgApp->GetConsole()->SetPrompt(prompt);
|
---|
| 517 | }
|
---|
| 518 | return(0);
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | // Nous ne sommes donc pas dans un bloc ....
|
---|
| 523 |
|
---|
| 524 | // >>>> Variable substitution
|
---|
| 525 | string s2="";
|
---|
| 526 | p = 0;
|
---|
| 527 | l = s.length();
|
---|
| 528 | string vn;
|
---|
| 529 | while (p < l) {
|
---|
| 530 | q = s.find('$',p);
|
---|
| 531 | // cout << "DBG: " << s2 << " p= " << p << " q= " << q << " L= " << l << endl;
|
---|
| 532 | if (q > l) break;
|
---|
| 533 | if ((q>0) && (s[q-1] == '\\')) { // Escape character \$
|
---|
| 534 | s2 += (s.substr(p,q-1-p) + '$') ; p = q+1;
|
---|
| 535 | continue;
|
---|
| 536 | }
|
---|
| 537 | if (q >= l-1) {
|
---|
| 538 | cerr << " Syntax error !!! " << endl;
|
---|
| 539 | return(0);
|
---|
| 540 | }
|
---|
| 541 | vn = "";
|
---|
| 542 | if ( s[q+1] == '{' ) { // Variable in the form ${name}
|
---|
| 543 | q2 = s.find('}',q+1);
|
---|
| 544 | if (q2 >= l) {
|
---|
| 545 | cerr << " Syntax error !!! " << endl;
|
---|
| 546 | return(0);
|
---|
| 547 | }
|
---|
| 548 | vn = s.substr(q+2,q2-q-2);
|
---|
| 549 | q2++;
|
---|
| 550 | }
|
---|
| 551 | else if ( s[q+1] == '[' ) { // Variable in the form $[varname] -> This is $$varname
|
---|
| 552 | q2 = s.find(']',q+1);
|
---|
| 553 | if (q2 >= l) {
|
---|
| 554 | cerr << " Syntax error !!! " << endl;
|
---|
| 555 | return(0);
|
---|
| 556 | }
|
---|
| 557 | vn = s.substr(q+2,q2-q-2);
|
---|
| 558 | it = mVars.find(vn);
|
---|
| 559 | if ( (vn.length() < 1) || (it == mVars.end()) ) {
|
---|
| 560 | cerr << " Error: Undefined variable " << vn << " ! " << endl;
|
---|
| 561 | return(0);
|
---|
| 562 | }
|
---|
| 563 | vn = mVars[vn];
|
---|
| 564 | q2++;
|
---|
| 565 | }
|
---|
| 566 | else {
|
---|
| 567 | q2 = s.find_first_of(" .:/,]()$",q+1);
|
---|
| 568 | if (q2 > l) q2 = l;
|
---|
| 569 | vn = s.substr(q+1, q2-q-1);
|
---|
| 570 | }
|
---|
| 571 | it = mVars.find(vn);
|
---|
| 572 | if ( (vn.length() < 1) || (it == mVars.end()) ) {
|
---|
| 573 | cerr << " Error: Undefined variable " << vn << " ! " << endl;
|
---|
| 574 | return(0);
|
---|
| 575 | }
|
---|
| 576 | s2 += (s.substr(p, q-p) + (*it).second);
|
---|
| 577 | p = q2;
|
---|
| 578 | }
|
---|
| 579 | if (p < l) s2 += s.substr(p);
|
---|
| 580 |
|
---|
| 581 | p = s2.find_first_not_of(" \t");
|
---|
| 582 | if (p < l) s2 = s2.substr(p);
|
---|
| 583 |
|
---|
| 584 |
|
---|
| 585 | // >>>> Separating keyword and tokens
|
---|
| 586 | q = s2.find(' ');
|
---|
| 587 | l = s2.length();
|
---|
| 588 | if (q < l)
|
---|
| 589 | { kw = s2.substr(0,q); toks = s2.substr(q, l-q); }
|
---|
| 590 | else { kw = s2; toks = ""; }
|
---|
| 591 |
|
---|
[165] | 592 | q = 0;
|
---|
| 593 | while (q < l) {
|
---|
[349] | 594 | p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
|
---|
[165] | 595 | if (p>=l) break;
|
---|
[349] | 596 | q = toks.find_first_of(" \t",p); // la fin du token;
|
---|
[165] | 597 | string token = toks.substr(p,q-p);
|
---|
| 598 | tokens.push_back(token);
|
---|
| 599 | }
|
---|
| 600 |
|
---|
[349] | 601 |
|
---|
| 602 | // Si c'est un foreach, on cree un nouveau bloc
|
---|
| 603 | if (kw == "foreach") {
|
---|
| 604 | // cout << " *DBG* We got a foreach... " << endl;
|
---|
| 605 | PIACmdBloc* bloc = new PIACmdBloc(this, curblk, tokens);
|
---|
| 606 | if (!bloc->CheckOK()) {
|
---|
| 607 | cerr << "foreach syntax Error ! " << endl;
|
---|
| 608 | delete bloc;
|
---|
| 609 | return(0);
|
---|
| 610 | }
|
---|
| 611 | felevel++;
|
---|
| 612 | if (curblk) curblk->AddBloc(bloc);
|
---|
| 613 | else {
|
---|
| 614 | char prompt[64];
|
---|
| 615 | sprintf(prompt, "foreach-%d> ", felevel);
|
---|
| 616 | mImgApp->GetConsole()->SetPrompt(prompt);
|
---|
| 617 | }
|
---|
| 618 | curblk = bloc;
|
---|
| 619 | // cout << " *DBG* New Bloc created ... " << endl;
|
---|
| 620 | return(0);
|
---|
[293] | 621 | }
|
---|
[165] | 622 |
|
---|
[349] | 623 |
|
---|
[165] | 624 | // cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl;
|
---|
| 625 | // for(int ii=0; ii<tokens.size(); ii++)
|
---|
| 626 | // cout << "arg[ " << ii << " ] : " << tokens[ii] << endl;
|
---|
| 627 |
|
---|
| 628 | // >>>>>>>>>>> Commande d'interpreteur
|
---|
[349] | 629 | else if (kw == "helpwindow") ShowHelpWindow();
|
---|
[293] | 630 | else if (kw == "help") {
|
---|
[330] | 631 | if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl;
|
---|
[293] | 632 | else {
|
---|
[330] | 633 | string kwh = "piacmd";
|
---|
| 634 | cout << GetUsage(kwh) << endl;
|
---|
[293] | 635 | }
|
---|
[165] | 636 | }
|
---|
| 637 |
|
---|
| 638 | else if (kw == "set") {
|
---|
[293] | 639 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); }
|
---|
[349] | 640 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 641 | cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
|
---|
| 642 | return(0);
|
---|
| 643 | }
|
---|
| 644 | string xx = tokens[1];
|
---|
| 645 | for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk] );
|
---|
[333] | 646 | mVars[tokens[0]] = xx;
|
---|
[165] | 647 | }
|
---|
[349] | 648 |
|
---|
| 649 | else if (kw == "getvar") {
|
---|
| 650 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: getvar newvarname varname" << endl; return(0); }
|
---|
| 651 | it = mVars.find(tokens[1]);
|
---|
| 652 | if (it == mVars.end()) {
|
---|
| 653 | cerr << "Error - No " << tokens[1] << " Variable " << endl;
|
---|
| 654 | return(0);
|
---|
| 655 | }
|
---|
| 656 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 657 | cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
|
---|
| 658 | return(0);
|
---|
| 659 | }
|
---|
| 660 | mVars[tokens[0]] = (*it).second;
|
---|
| 661 | }
|
---|
| 662 |
|
---|
| 663 | else if (kw == "alias") {
|
---|
| 664 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: alias aliasname string" << endl; return(0); }
|
---|
| 665 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 666 | cerr << "PIACmd::Interpret()/Error alias name should start with alphabetic" << endl;
|
---|
| 667 | return(0);
|
---|
| 668 | }
|
---|
| 669 | string xx = tokens[1];
|
---|
| 670 | for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk]);
|
---|
| 671 | mAliases[tokens[0]] = xx;
|
---|
| 672 | }
|
---|
| 673 |
|
---|
[333] | 674 | else if (kw == "setol") {
|
---|
| 675 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: setol varname objnamepattern" << endl; return(0); }
|
---|
[349] | 676 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 677 | cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
|
---|
| 678 | return(0);
|
---|
| 679 | }
|
---|
[333] | 680 | vector<string> ol;
|
---|
[349] | 681 | mObjMgr->GetObjList(tokens[1], ol);
|
---|
| 682 | string vol;
|
---|
| 683 | if (ol.size() < 1) vol = "";
|
---|
| 684 | else {
|
---|
| 685 | vol = ol[0];
|
---|
| 686 | for (int kk=1; kk<ol.size(); kk++) vol += (' ' + ol[kk]);
|
---|
| 687 | }
|
---|
[333] | 688 | mVars[tokens[0]] = vol;
|
---|
| 689 | }
|
---|
[293] | 690 | else if (kw == "unset") {
|
---|
| 691 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); }
|
---|
[165] | 692 | CmdVarList::iterator it = mVars.find(tokens[0]);
|
---|
| 693 | if (it != mVars.end()) mVars.erase(it);
|
---|
[293] | 694 | else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl;
|
---|
[165] | 695 | }
|
---|
[333] | 696 | else if (kw == "echo") {
|
---|
| 697 | for (int kk=0; kk<tokens.size(); kk++) cout << tokens[kk] << " " ;
|
---|
| 698 | cout << endl;
|
---|
| 699 | }
|
---|
[353] | 700 |
|
---|
| 701 | else if (kw == "readstdin") {
|
---|
| 702 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: readstdin varname" << endl; return(0); }
|
---|
| 703 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 704 | cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
|
---|
| 705 | return(0);
|
---|
| 706 | }
|
---|
[357] | 707 | mImgApp->GetConsole()->AddStr(">>> Reading From StdIn \n", PIVA_Magenta);
|
---|
| 708 | cout << tokens[0] << " ? " << endl;
|
---|
[368] | 709 | mVars[tokens[0]] = GetStringFrStdin(this);
|
---|
[353] | 710 | }
|
---|
| 711 |
|
---|
[165] | 712 | else if (kw == "listvars") {
|
---|
[293] | 713 | cout << "PIACmd::Interpret() Variable List , VarName = Value \n";
|
---|
[165] | 714 | CmdVarList::iterator it;
|
---|
| 715 | for(it = mVars.begin(); it != mVars.end(); it++)
|
---|
| 716 | cout << (*it).first << " = " << (*it).second << "\n";
|
---|
| 717 | cout << endl;
|
---|
| 718 | }
|
---|
[353] | 719 | else if (kw == "listalias") {
|
---|
| 720 | cout << "PIACmd::Interpret() Alias List , AliasName = Value \n";
|
---|
| 721 | CmdVarList::iterator it;
|
---|
| 722 | for(it = mAliases.begin(); it != mAliases.end(); it++)
|
---|
| 723 | cout << (*it).first << " = " << (*it).second << "\n";
|
---|
| 724 | cout << endl;
|
---|
| 725 | }
|
---|
| 726 | else if (kw == "listcommands") {
|
---|
[330] | 727 | cout << "---- PIACmd::Interpret() Command Variable List ----- \n";
|
---|
[293] | 728 | CmdExmap::iterator it;
|
---|
| 729 | int kc = 0;
|
---|
| 730 | for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
|
---|
| 731 | cout << (*it).first << " ";
|
---|
| 732 | kc++;
|
---|
| 733 | if (kc >= 5) { cout << "\n"; kc = 0; }
|
---|
| 734 | }
|
---|
| 735 | cout << endl;
|
---|
| 736 | }
|
---|
| 737 | else if (kw == "traceon") { cout << "PIACmd::Interpret() -> Trace ON mode " << endl; trace = true; }
|
---|
| 738 | else if (kw == "traceoff") { cout << "PIACmd::Interpret() -> Trace OFF mode " << endl; trace = false; }
|
---|
[165] | 739 | else if (kw == "timingon") {
|
---|
[293] | 740 | cout << "PIACmd::Interpret() -> Timing ON mode " << endl;
|
---|
| 741 | if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true;
|
---|
| 742 | }
|
---|
[165] | 743 | else if (kw == "timingoff") {
|
---|
[293] | 744 | cout << "PIACmd::Interpret() -> Timing OFF mode " << endl;
|
---|
| 745 | if (gltimer) delete gltimer; gltimer = NULL; timing = false;
|
---|
| 746 | }
|
---|
[165] | 747 | else if (kw == "exec") {
|
---|
[293] | 748 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: exec filename" << endl; return(0); }
|
---|
[349] | 749 | ExecFile(tokens[0], tokens);
|
---|
[165] | 750 | }
|
---|
| 751 | else if (kw == "shell") {
|
---|
[293] | 752 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl; return(0); }
|
---|
[165] | 753 | system(toks.c_str());
|
---|
| 754 | }
|
---|
[293] | 755 | // Execution d'une commande enregistree
|
---|
[333] | 756 | else rc = ExecuteCommand(kw, tokens);
|
---|
[165] | 757 |
|
---|
| 758 | if (timing) gltimer->Split();
|
---|
[333] | 759 | return(rc);
|
---|
[165] | 760 | }
|
---|
| 761 |
|
---|
[333] | 762 | /* --Methode-- */
|
---|
| 763 | int PIACmd::ExecuteCommandLine(string& line)
|
---|
| 764 | {
|
---|
| 765 | cmdtok tokens;
|
---|
| 766 | if (line.length() < 1) return(0);
|
---|
[165] | 767 |
|
---|
[333] | 768 | string toks,kw;
|
---|
| 769 | size_t p = line.find_first_not_of(" ");
|
---|
| 770 | line = line.substr(p);
|
---|
| 771 | p = 0;
|
---|
| 772 | size_t q = line.find_first_of(" ");
|
---|
| 773 | size_t l = line.length();
|
---|
| 774 |
|
---|
| 775 | if (q < l)
|
---|
| 776 | { kw = line.substr(p,q-p); toks = line.substr(q, l-q); }
|
---|
| 777 | else { kw = line.substr(p,l-p); toks = ""; }
|
---|
| 778 |
|
---|
| 779 | q = 0;
|
---|
| 780 | while (q < l) {
|
---|
| 781 | p = toks.find_first_not_of(" ",q+1); // au debut d'un token
|
---|
| 782 | if (p>=l) break;
|
---|
| 783 | q = toks.find_first_of(" ",p); // la fin du token;
|
---|
| 784 | string token = toks.substr(p,q-p);
|
---|
| 785 | tokens.push_back(token);
|
---|
| 786 | }
|
---|
| 787 |
|
---|
| 788 | return(ExecuteCommand(kw, tokens));
|
---|
| 789 | }
|
---|
| 790 |
|
---|
[165] | 791 | /* --Methode-- */
|
---|
[333] | 792 | int PIACmd::ExecuteCommand(string& keyw, vector<string>& args)
|
---|
| 793 | {
|
---|
| 794 | int rc = -1;
|
---|
| 795 | CmdExmap::iterator it = cmdexmap.find(keyw);
|
---|
| 796 | if (it == cmdexmap.end()) cout << "No such command : " << keyw << " ! " << endl;
|
---|
| 797 | else {
|
---|
| 798 | if ((*it).second.cex) rc = (*it).second.cex->Execute(keyw, args);
|
---|
| 799 | else cout << "Dont know how to execute " << keyw << " ? " << endl;
|
---|
| 800 | }
|
---|
| 801 | return(rc);
|
---|
| 802 | }
|
---|
| 803 |
|
---|
| 804 | /* --Methode-- */
|
---|
[349] | 805 | int PIACmd::ExecFile(string& file, vector<string>& args)
|
---|
[165] | 806 | {
|
---|
[293] | 807 | char line_buff[512];
|
---|
| 808 | FILE *fip;
|
---|
[165] | 809 |
|
---|
[293] | 810 | if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
|
---|
[384] | 811 | if (file.find('.') >= file.length()) {
|
---|
| 812 | cout << "PIACmd::Exec(): Error opening file " << file << endl;
|
---|
| 813 | file += ".pic";
|
---|
| 814 | cout << " Trying file " << file << endl;
|
---|
| 815 | fip = fopen(file.c_str(),"r");
|
---|
| 816 | }
|
---|
| 817 | }
|
---|
| 818 |
|
---|
| 819 | if(fip == NULL) {
|
---|
[293] | 820 | cerr << "PIACmd::Exec() Error opening file " << file << endl;
|
---|
| 821 | hist << "##! PIACmd::Exec() Error opening file " << file << endl;
|
---|
| 822 | return(0);
|
---|
[165] | 823 | }
|
---|
[349] | 824 |
|
---|
| 825 | // hist << "### Executing commands from " << file << endl;
|
---|
| 826 |
|
---|
| 827 | // Setting $0 ... $99 variables
|
---|
| 828 | int k;
|
---|
| 829 | CmdVarList::iterator it;
|
---|
| 830 | char buff[32];
|
---|
| 831 | // First, we clear all previous values
|
---|
| 832 | string vn="#";
|
---|
| 833 | it = mVars.find(vn);
|
---|
| 834 | if (it != mVars.end()) mVars.erase(it);
|
---|
| 835 | for(k=0; k<99; k++) {
|
---|
| 836 | sprintf(buff,"%d",k);
|
---|
| 837 | vn = buff;
|
---|
| 838 | it = mVars.find(vn);
|
---|
| 839 | if (it != mVars.end()) mVars.erase(it);
|
---|
| 840 | }
|
---|
| 841 | // We then set them
|
---|
| 842 | vn="#";
|
---|
| 843 | sprintf(buff,"%d",(int)args.size());
|
---|
| 844 | mVars[vn] = buff;
|
---|
| 845 | for(k=0; k<args.size(); k++) {
|
---|
| 846 | sprintf(buff,"%d",k);
|
---|
| 847 | vn = buff;
|
---|
| 848 | mVars[vn] = args[k];
|
---|
| 849 | }
|
---|
| 850 |
|
---|
[293] | 851 | if (trace) {
|
---|
| 852 | mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta);
|
---|
| 853 | mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
|
---|
| 854 | mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta);
|
---|
| 855 | }
|
---|
[165] | 856 |
|
---|
[349] | 857 | histon = false;
|
---|
[293] | 858 | while (fgets(line_buff,511,fip) != NULL)
|
---|
| 859 | {
|
---|
| 860 | if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta);
|
---|
| 861 | line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */
|
---|
| 862 | string line(line_buff);
|
---|
| 863 | Interpret(line);
|
---|
[165] | 864 | }
|
---|
[357] | 865 | histon = true;
|
---|
[349] | 866 |
|
---|
| 867 | // hist << "### End of Exec( " << file << " ) " << endl;
|
---|
[293] | 868 | if (trace) {
|
---|
| 869 | mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta);
|
---|
| 870 | mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
|
---|
| 871 | mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta);
|
---|
[165] | 872 | }
|
---|
| 873 |
|
---|
| 874 | return(0);
|
---|
| 875 | }
|
---|
| 876 |
|
---|
[293] | 877 |
|
---|
| 878 | static string* videstr = NULL;
|
---|
| 879 | /* --Methode-- */
|
---|
| 880 | string& PIACmd::GetUsage(const string& kw)
|
---|
[165] | 881 | {
|
---|
[330] | 882 | bool fndok = false;
|
---|
[293] | 883 | CmdExmap::iterator it = cmdexmap.find(kw);
|
---|
[330] | 884 | if (it == cmdexmap.end()) {
|
---|
| 885 | it = helpexmap.find(kw);
|
---|
| 886 | if (it != helpexmap.end()) fndok = true;
|
---|
[165] | 887 | }
|
---|
[330] | 888 | else fndok = true;
|
---|
| 889 | if (fndok) return( (*it).second.us );
|
---|
| 890 | // Keyword pas trouve
|
---|
| 891 | if (videstr == NULL) videstr = new string("");
|
---|
| 892 | *videstr = "Nothing known about " + kw + " ?? ";
|
---|
| 893 | return(*videstr);
|
---|
| 894 |
|
---|
[165] | 895 | }
|
---|
| 896 |
|
---|
[293] | 897 | /* --Methode-- */
|
---|
| 898 | void PIACmd::ShowHelpWindow()
|
---|
[165] | 899 | {
|
---|
[293] | 900 | helpwin->Show();
|
---|
[165] | 901 | }
|
---|
[357] | 902 |
|
---|
| 903 |
|
---|