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