[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 */
|
---|
| 442 | static string GetStringFrStdin()
|
---|
| 443 | {
|
---|
| 444 | #ifndef __mac__
|
---|
| 445 | /* On vide le buffer X-Window */
|
---|
| 446 | XFlush(PIXDisplay());
|
---|
| 447 | #endif
|
---|
| 448 | char buff[128];
|
---|
| 449 | fgets(buff, 128, stdin);
|
---|
| 450 | buff[127] = '\0';
|
---|
| 451 | return((string)buff);
|
---|
| 452 | }
|
---|
| 453 |
|
---|
[293] | 454 | /* --Methode-- */
|
---|
| 455 | int PIACmd::Interpret(string& s)
|
---|
| 456 | {
|
---|
[333] | 457 | int rc = 0;
|
---|
[165] | 458 | cmdtok tokens;
|
---|
[349] | 459 | CmdVarList::iterator it;
|
---|
[165] | 460 |
|
---|
[349] | 461 | // Removing leading blanks
|
---|
| 462 | size_t p,q,q2,l;
|
---|
| 463 | l = s.length();
|
---|
| 464 | if (l < 1) return(0);
|
---|
| 465 | if (s[0] == '#') return(0); // si c'est un commentaire
|
---|
| 466 | p=s.find_first_not_of(" \t");
|
---|
| 467 | if (p < l) s = s.substr(p);
|
---|
| 468 | // else return(0);
|
---|
[165] | 469 |
|
---|
[349] | 470 | // On enregistre les commandes
|
---|
| 471 | if (histon) hist << s << endl;
|
---|
| 472 |
|
---|
| 473 |
|
---|
[165] | 474 | string toks,kw;
|
---|
| 475 |
|
---|
[349] | 476 | // >>>> Substitution d'alias (1er mot)
|
---|
| 477 | int als = 0;
|
---|
| 478 | while (als < 2) {
|
---|
| 479 | p = s.find_first_not_of(" ");
|
---|
| 480 | s = s.substr(p);
|
---|
| 481 | p = 0;
|
---|
| 482 | q = s.find_first_of(" ");
|
---|
| 483 | l = s.length();
|
---|
| 484 | string w1 = (q < l) ? s.substr(p,q-p) : s.substr(p);
|
---|
| 485 | it = mAliases.find(w1);
|
---|
| 486 | if (it != mAliases.end()) s = (*it).second + s.substr(q);
|
---|
| 487 | else als++;
|
---|
| 488 | als++;
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | // >>>> Separating keyword
|
---|
[165] | 492 | if (q < l)
|
---|
| 493 | { kw = s.substr(p,q-p); toks = s.substr(q, l-q); }
|
---|
| 494 | else { kw = s.substr(p,l-p); toks = ""; }
|
---|
| 495 |
|
---|
[349] | 496 | // On verifie si nous sommes dans un bloc
|
---|
| 497 | if ( (curblk != NULL) && (kw != "foreach") ) { // On est dans un bloc
|
---|
| 498 | if (kw != "end") { curblk->AddLine(s); return(0); }
|
---|
| 499 | else {
|
---|
| 500 | PIACmdBloc* curb = curblk;
|
---|
| 501 | curblk = curb->Parent();
|
---|
| 502 | felevel--;
|
---|
| 503 | if (curblk == NULL) {
|
---|
| 504 | mImgApp->GetConsole()->SetPrompt("Cmd> ");
|
---|
| 505 | // cout << " *DBG* Executing bloc " << endl;
|
---|
| 506 | curb->Execute();
|
---|
| 507 | }
|
---|
| 508 | else {
|
---|
| 509 | char prompt[64];
|
---|
[353] | 510 | sprintf(prompt, "foreach-%d? ", felevel);
|
---|
[349] | 511 | mImgApp->GetConsole()->SetPrompt(prompt);
|
---|
| 512 | }
|
---|
| 513 | return(0);
|
---|
| 514 | }
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | // Nous ne sommes donc pas dans un bloc ....
|
---|
| 518 |
|
---|
| 519 | // >>>> Variable substitution
|
---|
| 520 | string s2="";
|
---|
| 521 | p = 0;
|
---|
| 522 | l = s.length();
|
---|
| 523 | string vn;
|
---|
| 524 | while (p < l) {
|
---|
| 525 | q = s.find('$',p);
|
---|
| 526 | // cout << "DBG: " << s2 << " p= " << p << " q= " << q << " L= " << l << endl;
|
---|
| 527 | if (q > l) break;
|
---|
| 528 | if ((q>0) && (s[q-1] == '\\')) { // Escape character \$
|
---|
| 529 | s2 += (s.substr(p,q-1-p) + '$') ; p = q+1;
|
---|
| 530 | continue;
|
---|
| 531 | }
|
---|
| 532 | if (q >= l-1) {
|
---|
| 533 | cerr << " Syntax error !!! " << endl;
|
---|
| 534 | return(0);
|
---|
| 535 | }
|
---|
| 536 | vn = "";
|
---|
| 537 | if ( s[q+1] == '{' ) { // Variable in the form ${name}
|
---|
| 538 | q2 = s.find('}',q+1);
|
---|
| 539 | if (q2 >= l) {
|
---|
| 540 | cerr << " Syntax error !!! " << endl;
|
---|
| 541 | return(0);
|
---|
| 542 | }
|
---|
| 543 | vn = s.substr(q+2,q2-q-2);
|
---|
| 544 | q2++;
|
---|
| 545 | }
|
---|
| 546 | else if ( s[q+1] == '[' ) { // Variable in the form $[varname] -> This is $$varname
|
---|
| 547 | q2 = s.find(']',q+1);
|
---|
| 548 | if (q2 >= l) {
|
---|
| 549 | cerr << " Syntax error !!! " << endl;
|
---|
| 550 | return(0);
|
---|
| 551 | }
|
---|
| 552 | vn = s.substr(q+2,q2-q-2);
|
---|
| 553 | it = mVars.find(vn);
|
---|
| 554 | if ( (vn.length() < 1) || (it == mVars.end()) ) {
|
---|
| 555 | cerr << " Error: Undefined variable " << vn << " ! " << endl;
|
---|
| 556 | return(0);
|
---|
| 557 | }
|
---|
| 558 | vn = mVars[vn];
|
---|
| 559 | q2++;
|
---|
| 560 | }
|
---|
| 561 | else {
|
---|
| 562 | q2 = s.find_first_of(" .:/,]()$",q+1);
|
---|
| 563 | if (q2 > l) q2 = l;
|
---|
| 564 | vn = s.substr(q+1, q2-q-1);
|
---|
| 565 | }
|
---|
| 566 | it = mVars.find(vn);
|
---|
| 567 | if ( (vn.length() < 1) || (it == mVars.end()) ) {
|
---|
| 568 | cerr << " Error: Undefined variable " << vn << " ! " << endl;
|
---|
| 569 | return(0);
|
---|
| 570 | }
|
---|
| 571 | s2 += (s.substr(p, q-p) + (*it).second);
|
---|
| 572 | p = q2;
|
---|
| 573 | }
|
---|
| 574 | if (p < l) s2 += s.substr(p);
|
---|
| 575 |
|
---|
| 576 | p = s2.find_first_not_of(" \t");
|
---|
| 577 | if (p < l) s2 = s2.substr(p);
|
---|
| 578 |
|
---|
| 579 |
|
---|
| 580 | // >>>> Separating keyword and tokens
|
---|
| 581 | q = s2.find(' ');
|
---|
| 582 | l = s2.length();
|
---|
| 583 | if (q < l)
|
---|
| 584 | { kw = s2.substr(0,q); toks = s2.substr(q, l-q); }
|
---|
| 585 | else { kw = s2; toks = ""; }
|
---|
| 586 |
|
---|
[165] | 587 | q = 0;
|
---|
| 588 | while (q < l) {
|
---|
[349] | 589 | p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
|
---|
[165] | 590 | if (p>=l) break;
|
---|
[349] | 591 | q = toks.find_first_of(" \t",p); // la fin du token;
|
---|
[165] | 592 | string token = toks.substr(p,q-p);
|
---|
| 593 | tokens.push_back(token);
|
---|
| 594 | }
|
---|
| 595 |
|
---|
[349] | 596 |
|
---|
| 597 | // Si c'est un foreach, on cree un nouveau bloc
|
---|
| 598 | if (kw == "foreach") {
|
---|
| 599 | // cout << " *DBG* We got a foreach... " << endl;
|
---|
| 600 | PIACmdBloc* bloc = new PIACmdBloc(this, curblk, tokens);
|
---|
| 601 | if (!bloc->CheckOK()) {
|
---|
| 602 | cerr << "foreach syntax Error ! " << endl;
|
---|
| 603 | delete bloc;
|
---|
| 604 | return(0);
|
---|
| 605 | }
|
---|
| 606 | felevel++;
|
---|
| 607 | if (curblk) curblk->AddBloc(bloc);
|
---|
| 608 | else {
|
---|
| 609 | char prompt[64];
|
---|
| 610 | sprintf(prompt, "foreach-%d> ", felevel);
|
---|
| 611 | mImgApp->GetConsole()->SetPrompt(prompt);
|
---|
| 612 | }
|
---|
| 613 | curblk = bloc;
|
---|
| 614 | // cout << " *DBG* New Bloc created ... " << endl;
|
---|
| 615 | return(0);
|
---|
[293] | 616 | }
|
---|
[165] | 617 |
|
---|
[349] | 618 |
|
---|
[165] | 619 | // cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl;
|
---|
| 620 | // for(int ii=0; ii<tokens.size(); ii++)
|
---|
| 621 | // cout << "arg[ " << ii << " ] : " << tokens[ii] << endl;
|
---|
| 622 |
|
---|
| 623 | // >>>>>>>>>>> Commande d'interpreteur
|
---|
[349] | 624 | else if (kw == "helpwindow") ShowHelpWindow();
|
---|
[293] | 625 | else if (kw == "help") {
|
---|
[330] | 626 | if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl;
|
---|
[293] | 627 | else {
|
---|
[330] | 628 | string kwh = "piacmd";
|
---|
| 629 | cout << GetUsage(kwh) << endl;
|
---|
[293] | 630 | }
|
---|
[165] | 631 | }
|
---|
| 632 |
|
---|
| 633 | else if (kw == "set") {
|
---|
[293] | 634 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); }
|
---|
[349] | 635 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 636 | cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
|
---|
| 637 | return(0);
|
---|
| 638 | }
|
---|
| 639 | string xx = tokens[1];
|
---|
| 640 | for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk] );
|
---|
[333] | 641 | mVars[tokens[0]] = xx;
|
---|
[165] | 642 | }
|
---|
[349] | 643 |
|
---|
| 644 | else if (kw == "getvar") {
|
---|
| 645 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: getvar newvarname varname" << endl; return(0); }
|
---|
| 646 | it = mVars.find(tokens[1]);
|
---|
| 647 | if (it == mVars.end()) {
|
---|
| 648 | cerr << "Error - No " << tokens[1] << " Variable " << endl;
|
---|
| 649 | return(0);
|
---|
| 650 | }
|
---|
| 651 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 652 | cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
|
---|
| 653 | return(0);
|
---|
| 654 | }
|
---|
| 655 | mVars[tokens[0]] = (*it).second;
|
---|
| 656 | }
|
---|
| 657 |
|
---|
| 658 | else if (kw == "alias") {
|
---|
| 659 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: alias aliasname string" << endl; return(0); }
|
---|
| 660 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 661 | cerr << "PIACmd::Interpret()/Error alias name should start with alphabetic" << endl;
|
---|
| 662 | return(0);
|
---|
| 663 | }
|
---|
| 664 | string xx = tokens[1];
|
---|
| 665 | for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk]);
|
---|
| 666 | mAliases[tokens[0]] = xx;
|
---|
| 667 | }
|
---|
| 668 |
|
---|
[333] | 669 | else if (kw == "setol") {
|
---|
| 670 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: setol varname objnamepattern" << endl; return(0); }
|
---|
[349] | 671 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 672 | cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
|
---|
| 673 | return(0);
|
---|
| 674 | }
|
---|
[333] | 675 | vector<string> ol;
|
---|
[349] | 676 | mObjMgr->GetObjList(tokens[1], ol);
|
---|
| 677 | string vol;
|
---|
| 678 | if (ol.size() < 1) vol = "";
|
---|
| 679 | else {
|
---|
| 680 | vol = ol[0];
|
---|
| 681 | for (int kk=1; kk<ol.size(); kk++) vol += (' ' + ol[kk]);
|
---|
| 682 | }
|
---|
[333] | 683 | mVars[tokens[0]] = vol;
|
---|
| 684 | }
|
---|
[293] | 685 | else if (kw == "unset") {
|
---|
| 686 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); }
|
---|
[165] | 687 | CmdVarList::iterator it = mVars.find(tokens[0]);
|
---|
| 688 | if (it != mVars.end()) mVars.erase(it);
|
---|
[293] | 689 | else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl;
|
---|
[165] | 690 | }
|
---|
[333] | 691 | else if (kw == "echo") {
|
---|
| 692 | for (int kk=0; kk<tokens.size(); kk++) cout << tokens[kk] << " " ;
|
---|
| 693 | cout << endl;
|
---|
| 694 | }
|
---|
[353] | 695 |
|
---|
| 696 | else if (kw == "readstdin") {
|
---|
| 697 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: readstdin varname" << endl; return(0); }
|
---|
| 698 | if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
|
---|
| 699 | cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
|
---|
| 700 | return(0);
|
---|
| 701 | }
|
---|
[357] | 702 | mImgApp->GetConsole()->AddStr(">>> Reading From StdIn \n", PIVA_Magenta);
|
---|
| 703 | cout << tokens[0] << " ? " << endl;
|
---|
| 704 | mVars[tokens[0]] = GetStringFrStdin();
|
---|
[353] | 705 | }
|
---|
| 706 |
|
---|
[165] | 707 | else if (kw == "listvars") {
|
---|
[293] | 708 | cout << "PIACmd::Interpret() Variable List , VarName = Value \n";
|
---|
[165] | 709 | CmdVarList::iterator it;
|
---|
| 710 | for(it = mVars.begin(); it != mVars.end(); it++)
|
---|
| 711 | cout << (*it).first << " = " << (*it).second << "\n";
|
---|
| 712 | cout << endl;
|
---|
| 713 | }
|
---|
[353] | 714 | else if (kw == "listalias") {
|
---|
| 715 | cout << "PIACmd::Interpret() Alias List , AliasName = Value \n";
|
---|
| 716 | CmdVarList::iterator it;
|
---|
| 717 | for(it = mAliases.begin(); it != mAliases.end(); it++)
|
---|
| 718 | cout << (*it).first << " = " << (*it).second << "\n";
|
---|
| 719 | cout << endl;
|
---|
| 720 | }
|
---|
| 721 | else if (kw == "listcommands") {
|
---|
[330] | 722 | cout << "---- PIACmd::Interpret() Command Variable List ----- \n";
|
---|
[293] | 723 | CmdExmap::iterator it;
|
---|
| 724 | int kc = 0;
|
---|
| 725 | for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
|
---|
| 726 | cout << (*it).first << " ";
|
---|
| 727 | kc++;
|
---|
| 728 | if (kc >= 5) { cout << "\n"; kc = 0; }
|
---|
| 729 | }
|
---|
| 730 | cout << endl;
|
---|
| 731 | }
|
---|
| 732 | else if (kw == "traceon") { cout << "PIACmd::Interpret() -> Trace ON mode " << endl; trace = true; }
|
---|
| 733 | else if (kw == "traceoff") { cout << "PIACmd::Interpret() -> Trace OFF mode " << endl; trace = false; }
|
---|
[165] | 734 | else if (kw == "timingon") {
|
---|
[293] | 735 | cout << "PIACmd::Interpret() -> Timing ON mode " << endl;
|
---|
| 736 | if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true;
|
---|
| 737 | }
|
---|
[165] | 738 | else if (kw == "timingoff") {
|
---|
[293] | 739 | cout << "PIACmd::Interpret() -> Timing OFF mode " << endl;
|
---|
| 740 | if (gltimer) delete gltimer; gltimer = NULL; timing = false;
|
---|
| 741 | }
|
---|
[165] | 742 | else if (kw == "exec") {
|
---|
[293] | 743 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: exec filename" << endl; return(0); }
|
---|
[349] | 744 | ExecFile(tokens[0], tokens);
|
---|
[165] | 745 | }
|
---|
| 746 | else if (kw == "shell") {
|
---|
[293] | 747 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl; return(0); }
|
---|
[165] | 748 | system(toks.c_str());
|
---|
| 749 | }
|
---|
[293] | 750 | // Execution d'une commande enregistree
|
---|
[333] | 751 | else rc = ExecuteCommand(kw, tokens);
|
---|
[165] | 752 |
|
---|
| 753 | if (timing) gltimer->Split();
|
---|
[333] | 754 | return(rc);
|
---|
[165] | 755 | }
|
---|
| 756 |
|
---|
[333] | 757 | /* --Methode-- */
|
---|
| 758 | int PIACmd::ExecuteCommandLine(string& line)
|
---|
| 759 | {
|
---|
| 760 | cmdtok tokens;
|
---|
| 761 | if (line.length() < 1) return(0);
|
---|
[165] | 762 |
|
---|
[333] | 763 | string toks,kw;
|
---|
| 764 | size_t p = line.find_first_not_of(" ");
|
---|
| 765 | line = line.substr(p);
|
---|
| 766 | p = 0;
|
---|
| 767 | size_t q = line.find_first_of(" ");
|
---|
| 768 | size_t l = line.length();
|
---|
| 769 |
|
---|
| 770 | if (q < l)
|
---|
| 771 | { kw = line.substr(p,q-p); toks = line.substr(q, l-q); }
|
---|
| 772 | else { kw = line.substr(p,l-p); toks = ""; }
|
---|
| 773 |
|
---|
| 774 | q = 0;
|
---|
| 775 | while (q < l) {
|
---|
| 776 | p = toks.find_first_not_of(" ",q+1); // au debut d'un token
|
---|
| 777 | if (p>=l) break;
|
---|
| 778 | q = toks.find_first_of(" ",p); // la fin du token;
|
---|
| 779 | string token = toks.substr(p,q-p);
|
---|
| 780 | tokens.push_back(token);
|
---|
| 781 | }
|
---|
| 782 |
|
---|
| 783 | return(ExecuteCommand(kw, tokens));
|
---|
| 784 | }
|
---|
| 785 |
|
---|
[165] | 786 | /* --Methode-- */
|
---|
[333] | 787 | int PIACmd::ExecuteCommand(string& keyw, vector<string>& args)
|
---|
| 788 | {
|
---|
| 789 | int rc = -1;
|
---|
| 790 | CmdExmap::iterator it = cmdexmap.find(keyw);
|
---|
| 791 | if (it == cmdexmap.end()) cout << "No such command : " << keyw << " ! " << endl;
|
---|
| 792 | else {
|
---|
| 793 | if ((*it).second.cex) rc = (*it).second.cex->Execute(keyw, args);
|
---|
| 794 | else cout << "Dont know how to execute " << keyw << " ? " << endl;
|
---|
| 795 | }
|
---|
| 796 | return(rc);
|
---|
| 797 | }
|
---|
| 798 |
|
---|
| 799 | /* --Methode-- */
|
---|
[349] | 800 | int PIACmd::ExecFile(string& file, vector<string>& args)
|
---|
[165] | 801 | {
|
---|
[293] | 802 | char line_buff[512];
|
---|
| 803 | FILE *fip;
|
---|
[165] | 804 |
|
---|
[293] | 805 | if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
|
---|
| 806 | cerr << "PIACmd::Exec() Error opening file " << file << endl;
|
---|
| 807 | hist << "##! PIACmd::Exec() Error opening file " << file << endl;
|
---|
| 808 | return(0);
|
---|
[165] | 809 | }
|
---|
[349] | 810 |
|
---|
| 811 | // hist << "### Executing commands from " << file << endl;
|
---|
| 812 |
|
---|
| 813 | // Setting $0 ... $99 variables
|
---|
| 814 | int k;
|
---|
| 815 | CmdVarList::iterator it;
|
---|
| 816 | char buff[32];
|
---|
| 817 | // First, we clear all previous values
|
---|
| 818 | string vn="#";
|
---|
| 819 | it = mVars.find(vn);
|
---|
| 820 | if (it != mVars.end()) mVars.erase(it);
|
---|
| 821 | for(k=0; k<99; k++) {
|
---|
| 822 | sprintf(buff,"%d",k);
|
---|
| 823 | vn = buff;
|
---|
| 824 | it = mVars.find(vn);
|
---|
| 825 | if (it != mVars.end()) mVars.erase(it);
|
---|
| 826 | }
|
---|
| 827 | // We then set them
|
---|
| 828 | vn="#";
|
---|
| 829 | sprintf(buff,"%d",(int)args.size());
|
---|
| 830 | mVars[vn] = buff;
|
---|
| 831 | for(k=0; k<args.size(); k++) {
|
---|
| 832 | sprintf(buff,"%d",k);
|
---|
| 833 | vn = buff;
|
---|
| 834 | mVars[vn] = args[k];
|
---|
| 835 | }
|
---|
| 836 |
|
---|
[293] | 837 | if (trace) {
|
---|
| 838 | mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta);
|
---|
| 839 | mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
|
---|
| 840 | mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta);
|
---|
| 841 | }
|
---|
[165] | 842 |
|
---|
[349] | 843 | histon = false;
|
---|
[293] | 844 | while (fgets(line_buff,511,fip) != NULL)
|
---|
| 845 | {
|
---|
| 846 | if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta);
|
---|
| 847 | line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */
|
---|
| 848 | string line(line_buff);
|
---|
| 849 | Interpret(line);
|
---|
[165] | 850 | }
|
---|
[357] | 851 | histon = true;
|
---|
[349] | 852 |
|
---|
| 853 | // hist << "### End of Exec( " << file << " ) " << endl;
|
---|
[293] | 854 | if (trace) {
|
---|
| 855 | mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta);
|
---|
| 856 | mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
|
---|
| 857 | mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta);
|
---|
[165] | 858 | }
|
---|
| 859 |
|
---|
| 860 | return(0);
|
---|
| 861 | }
|
---|
| 862 |
|
---|
[293] | 863 |
|
---|
| 864 | static string* videstr = NULL;
|
---|
| 865 | /* --Methode-- */
|
---|
| 866 | string& PIACmd::GetUsage(const string& kw)
|
---|
[165] | 867 | {
|
---|
[330] | 868 | bool fndok = false;
|
---|
[293] | 869 | CmdExmap::iterator it = cmdexmap.find(kw);
|
---|
[330] | 870 | if (it == cmdexmap.end()) {
|
---|
| 871 | it = helpexmap.find(kw);
|
---|
| 872 | if (it != helpexmap.end()) fndok = true;
|
---|
[165] | 873 | }
|
---|
[330] | 874 | else fndok = true;
|
---|
| 875 | if (fndok) return( (*it).second.us );
|
---|
| 876 | // Keyword pas trouve
|
---|
| 877 | if (videstr == NULL) videstr = new string("");
|
---|
| 878 | *videstr = "Nothing known about " + kw + " ?? ";
|
---|
| 879 | return(*videstr);
|
---|
| 880 |
|
---|
[165] | 881 | }
|
---|
| 882 |
|
---|
[293] | 883 | /* --Methode-- */
|
---|
| 884 | void PIACmd::ShowHelpWindow()
|
---|
[165] | 885 | {
|
---|
[293] | 886 | helpwin->Show();
|
---|
[165] | 887 | }
|
---|
[357] | 888 |
|
---|
| 889 |
|
---|