[293] | 1 | #include "piacmd.h"
|
---|
[165] | 2 | #include <stdio.h>
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <math.h>
|
---|
| 5 |
|
---|
[293] | 6 | #include "basexecut.h"
|
---|
[165] | 7 |
|
---|
[293] | 8 | #include "pdlmgr.h"
|
---|
[165] | 9 | #include "ctimer.h"
|
---|
[293] | 10 | // #include "dlftypes.h"
|
---|
[165] | 11 |
|
---|
[293] | 12 | #include "pistdimgapp.h"
|
---|
[165] | 13 | #include "nobjmgr.h"
|
---|
| 14 |
|
---|
[293] | 15 | #include PISTDWDG_H
|
---|
| 16 | #include PILIST_H
|
---|
[165] | 17 |
|
---|
[293] | 18 | // ------------------------------------------------------------
|
---|
| 19 | // Gestion d'une fenetre d'aide interactive
|
---|
| 20 | // ------------------------------------------------------------
|
---|
[165] | 21 |
|
---|
[293] | 22 | class PIAHelpWind : public PIWindow {
|
---|
| 23 | public :
|
---|
| 24 | PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd);
|
---|
| 25 | virtual ~PIAHelpWind();
|
---|
[330] | 26 | virtual void Show();
|
---|
[293] | 27 | virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
|
---|
[330] | 28 | inline void AddHelpGroup(const char * hgrp, int gid)
|
---|
| 29 | { hgrpom->AppendItem(hgrp, 20000+gid); }
|
---|
| 30 | inline void ClearHelpList()
|
---|
| 31 | { mNitem=0; hitemlist->DeleteAllItems(); }
|
---|
[293] | 32 | inline void AddHelpItem(const char * hitem)
|
---|
[330] | 33 | { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
|
---|
[293] | 34 | protected :
|
---|
| 35 | PIStdImgApp* dap;
|
---|
| 36 | PIACmd* piac;
|
---|
| 37 | int mNitem;
|
---|
| 38 | PIList* hitemlist;
|
---|
[330] | 39 | PIOptMenu* hgrpom;
|
---|
[293] | 40 | PIButton * mBut;
|
---|
| 41 | PILabel * mLab;
|
---|
| 42 | PIText* mTxt;
|
---|
| 43 | };
|
---|
[165] | 44 |
|
---|
[293] | 45 | /* --Methode-- */
|
---|
| 46 | PIAHelpWind::PIAHelpWind(PIStdImgApp *par, PIACmd* piacmd)
|
---|
| 47 | : PIWindow((PIMsgHandler *)par, "Help-PIApp", PIWK_normal, 400, 300, 100, 350)
|
---|
| 48 | {
|
---|
| 49 | dap = par;
|
---|
| 50 | piac = piacmd;
|
---|
| 51 | mNitem = 0;
|
---|
[330] | 52 | SetMsg(77);
|
---|
[165] | 53 |
|
---|
[293] | 54 | int bsx, bsy;
|
---|
| 55 | int tsx, tsy;
|
---|
| 56 | int spx, spy;
|
---|
| 57 | PIApplicationPrefCompSize(bsx, bsy);
|
---|
| 58 | spx = bsx/6; spy = bsy/6;
|
---|
| 59 | tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy;
|
---|
| 60 | SetSize(tsx,tsy);
|
---|
[330] | 61 | hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy);
|
---|
| 62 | hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 63 | hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy);
|
---|
[293] | 64 | hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 65 | // hitemlist->SetBorderWidth(2);
|
---|
[324] | 66 | mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
|
---|
| 67 | // mTxt->SetMutiLineMode(true);
|
---|
[293] | 68 | mTxt->SetTextEditable(false);
|
---|
| 69 | mTxt->SetText("");
|
---|
| 70 | mTxt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 71 | mLab = new PILabel(this, "helpitem", bsx*4, bsy, bsx*2.5+2*spx, tsy-spy-bsy);
|
---|
| 72 | mLab->SetBorderWidth(1);
|
---|
| 73 | mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 74 | mLab->SetLabel("");
|
---|
[330] | 75 | mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
|
---|
[293] | 76 | mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 77 | }
|
---|
[165] | 78 |
|
---|
| 79 | /* --Methode-- */
|
---|
[293] | 80 | PIAHelpWind::~PIAHelpWind()
|
---|
| 81 | {
|
---|
[330] | 82 | delete hgrpom;
|
---|
[293] | 83 | delete hitemlist;
|
---|
| 84 | delete mTxt;
|
---|
| 85 | delete mLab;
|
---|
| 86 | delete mBut;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /* --Methode-- */
|
---|
| 90 | void PIAHelpWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
|
---|
| 91 | {
|
---|
| 92 | PIMessage um = UserMsg(msg);
|
---|
[330] | 93 | if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
|
---|
[293] | 94 | Hide();
|
---|
| 95 | return;
|
---|
| 96 | }
|
---|
[330] | 97 | else if ( (um >= 20000) && (sender == hgrpom)) { // Selection de groupe de Help
|
---|
| 98 | mTxt->SetText("");
|
---|
| 99 | mLab->SetLabel("");
|
---|
| 100 | piac->UpdateHelpList(this, um-20000);
|
---|
| 101 | }
|
---|
| 102 | else if ( (um > 100) && (sender == hitemlist) && (ModMsg(msg) == PIMsg_Select) ) {
|
---|
[293] | 103 | string s = hitemlist->GetSelectionStr();
|
---|
| 104 | mTxt->SetText(piac->GetUsage(s));
|
---|
| 105 | mLab->SetLabel(s);
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[330] | 109 | /* --Methode-- */
|
---|
| 110 | void PIAHelpWind::Show()
|
---|
| 111 | {
|
---|
| 112 | hgrpom->SetValue(20000); // Groupe All
|
---|
| 113 | mTxt->SetText("");
|
---|
| 114 | mLab->SetLabel("");
|
---|
| 115 | piac->UpdateHelpList(this, 0);
|
---|
| 116 | PIWindow::Show();
|
---|
| 117 | }
|
---|
[293] | 118 |
|
---|
| 119 | static PIACmd* curpiacmd = NULL;
|
---|
| 120 | /* --Methode-- */
|
---|
[165] | 121 | PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
|
---|
| 122 | {
|
---|
[293] | 123 | mObjMgr = omg;
|
---|
[165] | 124 | mImgApp = app;
|
---|
| 125 | system("cp history.pic hisold.pic");
|
---|
| 126 | hist.open("history.pic");
|
---|
| 127 | trace = false; timing = false;
|
---|
| 128 | gltimer = NULL;
|
---|
[293] | 129 |
|
---|
[330] | 130 | cmdhgrp["All"] = 0;
|
---|
| 131 | cmdgrpid = 1;
|
---|
| 132 | cmdhgrp["Commands"] = 1;
|
---|
[293] | 133 | helpwin = new PIAHelpWind(app, this);
|
---|
[330] | 134 | helpwin->AddHelpGroup("All", 0);
|
---|
| 135 | helpwin->AddHelpGroup("Commands", 1);
|
---|
[293] | 136 |
|
---|
| 137 | string kw = "piacmd";
|
---|
| 138 | string usage;
|
---|
| 139 | usage = ">>> (piacmd) Interpreter's keywords : \n";
|
---|
| 140 | usage += " timingon timingoff traceon traceoff \n";
|
---|
| 141 | usage += " set unset listvar listcommands exec shell \n";
|
---|
| 142 | usage += " > set varname 'string' # To set a variable, $varname \n";
|
---|
| 143 | usage += " > unset varname # clear variable definition \n";
|
---|
| 144 | usage += " > listvars # List of variable names and values \n";
|
---|
| 145 | usage += " > listcommands # List of all known commands \n";
|
---|
| 146 | usage += " > exec filename # Execute commands from file \n";
|
---|
| 147 | usage += " > shell comand_string # Execute shell command \n";
|
---|
| 148 | usage += " > help <command_name> # <command_name> usage info \n";
|
---|
| 149 | usage += " > helpwindow # Displays help window \n";
|
---|
[330] | 150 | string grp = "Commands";
|
---|
| 151 | RegisterHelp(kw, usage, grp);
|
---|
[293] | 152 |
|
---|
| 153 | basexec = new PIABaseExecutor(this, omg, app);
|
---|
| 154 | AddInterpreter(this);
|
---|
| 155 | curcmdi = this;
|
---|
[165] | 156 | }
|
---|
| 157 |
|
---|
| 158 | /* --Methode-- */
|
---|
| 159 | PIACmd::~PIACmd()
|
---|
| 160 | {
|
---|
| 161 | hist.close();
|
---|
| 162 | if (gltimer) { delete gltimer; gltimer = NULL; }
|
---|
[293] | 163 | Modmap::iterator it;
|
---|
| 164 | for(it = modmap.begin(); it != modmap.end(); it++) {
|
---|
| 165 | string name = (*it).first + "_end";
|
---|
| 166 | DlModuleInitEndFunction fend = (*it).second->GetFunction(name);
|
---|
| 167 | if (fend) fend();
|
---|
| 168 | delete (*it).second;
|
---|
| 169 | }
|
---|
| 170 | delete helpwin;
|
---|
| 171 | if (curpiacmd == this) curpiacmd = NULL;
|
---|
[165] | 172 | }
|
---|
| 173 |
|
---|
| 174 | /* --Methode-- */
|
---|
[293] | 175 | PIACmd* PIACmd::GetInterpreter()
|
---|
[165] | 176 | {
|
---|
[293] | 177 | return(curpiacmd);
|
---|
| 178 | }
|
---|
[165] | 179 |
|
---|
[293] | 180 | /* --Methode-- */
|
---|
| 181 | string PIACmd::Name()
|
---|
| 182 | {
|
---|
| 183 | return("piacmd");
|
---|
| 184 | }
|
---|
[165] | 185 |
|
---|
[293] | 186 | /* --Methode-- */
|
---|
[330] | 187 | void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string grp)
|
---|
[293] | 188 | {
|
---|
[330] | 189 | if (!ce) {
|
---|
| 190 | RegisterHelp(keyw, usage, grp);
|
---|
| 191 | return;
|
---|
| 192 | }
|
---|
| 193 | int gid = CheckHelpGrp(grp);
|
---|
[293] | 194 | cmdex cme;
|
---|
[330] | 195 | cme.group = gid;
|
---|
[293] | 196 | cme.us = usage;
|
---|
| 197 | cme.cex = ce;
|
---|
| 198 | cmdexmap[keyw] = cme;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | /* --Methode-- */
|
---|
[330] | 202 | void PIACmd::RegisterHelp(string& keyw, string& usage, string& grp)
|
---|
| 203 | {
|
---|
| 204 | int gid = CheckHelpGrp(grp);
|
---|
| 205 | cmdex cme;
|
---|
| 206 | cme.group = gid;
|
---|
| 207 | cme.us = usage;
|
---|
| 208 | cme.cex = NULL;
|
---|
| 209 | helpexmap[keyw] = cme;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | /* --Methode-- */
|
---|
| 213 | int PIACmd::CheckHelpGrp(string& grp)
|
---|
| 214 | {
|
---|
| 215 | int gid=0;
|
---|
| 216 | CmdHGroup::iterator it = cmdhgrp.find(grp);
|
---|
| 217 | if (it == cmdhgrp.end()) {
|
---|
| 218 | cmdgrpid++; gid = cmdgrpid;
|
---|
| 219 | cmdhgrp[grp] = gid;
|
---|
| 220 | helpwin->AddHelpGroup(grp.c_str(), gid);
|
---|
| 221 | }
|
---|
| 222 | else gid = (*it).second;
|
---|
| 223 | return(gid);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | /* --Methode-- */
|
---|
| 227 | void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
|
---|
| 228 | {
|
---|
| 229 | helpwin->ClearHelpList();
|
---|
| 230 | CmdExmap::iterator it;
|
---|
| 231 | for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
|
---|
| 232 | if ( (gid != 0) && ((*it).second.group != gid) ) continue;
|
---|
| 233 | helpwin->AddHelpItem((*it).first.c_str());
|
---|
| 234 | }
|
---|
| 235 | for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
|
---|
| 236 | if ( (gid != 0) && ((*it).second.group != gid) ) continue;
|
---|
| 237 | helpwin->AddHelpItem((*it).first.c_str());
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | /* --Methode-- */
|
---|
[293] | 242 | void PIACmd::LoadModule(string& fnameso, string& name)
|
---|
| 243 | {
|
---|
| 244 | PDynLinkMgr * dynlink = new PDynLinkMgr(fnameso, false);
|
---|
| 245 | if (dynlink == NULL) {
|
---|
| 246 | cerr << "PIACmd/LoadModule_Error: Pb opening SO " << fnameso << endl;
|
---|
| 247 | return;
|
---|
[165] | 248 | }
|
---|
[293] | 249 | string fname = name + "_init";
|
---|
| 250 | DlModuleInitEndFunction finit = dynlink->GetFunction(fname);
|
---|
| 251 | if (!finit) {
|
---|
| 252 | cerr << "PIACmd/LoadModule_Error: Pb linking " << fname << endl;
|
---|
| 253 | return;
|
---|
[165] | 254 | }
|
---|
[293] | 255 | cout << "PIACmd/LoadModule_Info: Initialisation module" << name
|
---|
| 256 | << " " << fname << "() ..." << endl;
|
---|
| 257 | finit();
|
---|
| 258 | modmap[name] = dynlink;
|
---|
| 259 | return;
|
---|
| 260 | }
|
---|
[165] | 261 |
|
---|
[293] | 262 | /* --Methode-- */
|
---|
| 263 | void PIACmd::AddInterpreter(CmdInterpreter * cl)
|
---|
| 264 | {
|
---|
| 265 | if (!cl) return;
|
---|
| 266 | interpmap[cl->Name()] = cl;
|
---|
[165] | 267 | }
|
---|
| 268 |
|
---|
| 269 | /* --Methode-- */
|
---|
[293] | 270 | void PIACmd::SelInterpreter(string& name)
|
---|
[165] | 271 | {
|
---|
[293] | 272 | InterpMap::iterator it = interpmap.find(name);
|
---|
| 273 | if (it == interpmap.end()) return;
|
---|
| 274 | curcmdi = (*it).second;
|
---|
| 275 | }
|
---|
[165] | 276 |
|
---|
[293] | 277 |
|
---|
| 278 | // Pour le decoupage des commandes en lignes
|
---|
| 279 | typedef vector<string> cmdtok;
|
---|
| 280 |
|
---|
| 281 | /* --Methode-- */
|
---|
| 282 | int PIACmd::Interpret(string& s)
|
---|
| 283 | {
|
---|
| 284 |
|
---|
[165] | 285 | cmdtok tokens;
|
---|
| 286 | if (s.length() < 1) return(0);
|
---|
| 287 |
|
---|
| 288 | hist << s << endl; // On enregistre les commandes
|
---|
| 289 |
|
---|
| 290 | if (s[0] == '#') {
|
---|
[293] | 291 | cout << "PIACmd::Interpret() Comment-Line:" << s << endl;
|
---|
[165] | 292 | return(0);
|
---|
| 293 | }
|
---|
| 294 | string toks,kw;
|
---|
| 295 | size_t p = s.find_first_not_of(" ");
|
---|
| 296 | s = s.substr(p);
|
---|
| 297 | p = 0;
|
---|
| 298 | size_t q = s.find_first_of(" ");
|
---|
| 299 | size_t l = s.length();
|
---|
| 300 |
|
---|
| 301 | if (q < l)
|
---|
| 302 | { kw = s.substr(p,q-p); toks = s.substr(q, l-q); }
|
---|
| 303 | else { kw = s.substr(p,l-p); toks = ""; }
|
---|
| 304 |
|
---|
| 305 | q = 0;
|
---|
| 306 | while (q < l) {
|
---|
| 307 | p = toks.find_first_not_of(" ",q+1); // au debut d'un token
|
---|
| 308 | if (p>=l) break;
|
---|
| 309 | q = toks.find_first_of(" ",p); // la fin du token;
|
---|
| 310 | string token = toks.substr(p,q-p);
|
---|
| 311 | tokens.push_back(token);
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | for(int k=0; k<tokens.size(); k++) { // On remplace les $varname par la valeur de la variable
|
---|
[293] | 315 | if ((tokens[k])[0] != '$') continue;
|
---|
| 316 | CmdVarList::iterator it = mVars.find(tokens[k].substr(1));
|
---|
| 317 | if (it != mVars.end()) tokens[k] = (*it).second;
|
---|
| 318 | }
|
---|
[165] | 319 |
|
---|
| 320 | // cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl;
|
---|
| 321 | // for(int ii=0; ii<tokens.size(); ii++)
|
---|
| 322 | // cout << "arg[ " << ii << " ] : " << tokens[ii] << endl;
|
---|
| 323 |
|
---|
| 324 | // >>>>>>>>>>> Commande d'interpreteur
|
---|
[293] | 325 | if (kw == "helpwindow") ShowHelpWindow();
|
---|
| 326 | else if (kw == "help") {
|
---|
[330] | 327 | if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl;
|
---|
[293] | 328 | else {
|
---|
[330] | 329 | string kwh = "piacmd";
|
---|
| 330 | cout << GetUsage(kwh) << endl;
|
---|
[293] | 331 | }
|
---|
[165] | 332 | }
|
---|
| 333 |
|
---|
| 334 | else if (kw == "set") {
|
---|
[293] | 335 | if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); }
|
---|
[165] | 336 | mVars[tokens[0]] = tokens[1];
|
---|
| 337 | }
|
---|
[293] | 338 | else if (kw == "unset") {
|
---|
| 339 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); }
|
---|
[165] | 340 | CmdVarList::iterator it = mVars.find(tokens[0]);
|
---|
| 341 | if (it != mVars.end()) mVars.erase(it);
|
---|
[293] | 342 | else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl;
|
---|
[165] | 343 | }
|
---|
| 344 | else if (kw == "listvars") {
|
---|
[293] | 345 | cout << "PIACmd::Interpret() Variable List , VarName = Value \n";
|
---|
[165] | 346 | CmdVarList::iterator it;
|
---|
| 347 | for(it = mVars.begin(); it != mVars.end(); it++)
|
---|
| 348 | cout << (*it).first << " = " << (*it).second << "\n";
|
---|
| 349 | cout << endl;
|
---|
| 350 | }
|
---|
[293] | 351 | else if (kw == "listvars") {
|
---|
[330] | 352 | cout << "---- PIACmd::Interpret() Command Variable List ----- \n";
|
---|
[293] | 353 | CmdExmap::iterator it;
|
---|
| 354 | int kc = 0;
|
---|
| 355 | for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
|
---|
| 356 | cout << (*it).first << " ";
|
---|
| 357 | kc++;
|
---|
| 358 | if (kc >= 5) { cout << "\n"; kc = 0; }
|
---|
| 359 | }
|
---|
| 360 | cout << endl;
|
---|
| 361 | }
|
---|
| 362 | else if (kw == "traceon") { cout << "PIACmd::Interpret() -> Trace ON mode " << endl; trace = true; }
|
---|
| 363 | else if (kw == "traceoff") { cout << "PIACmd::Interpret() -> Trace OFF mode " << endl; trace = false; }
|
---|
[165] | 364 | else if (kw == "timingon") {
|
---|
[293] | 365 | cout << "PIACmd::Interpret() -> Timing ON mode " << endl;
|
---|
| 366 | if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true;
|
---|
| 367 | }
|
---|
[165] | 368 | else if (kw == "timingoff") {
|
---|
[293] | 369 | cout << "PIACmd::Interpret() -> Timing OFF mode " << endl;
|
---|
| 370 | if (gltimer) delete gltimer; gltimer = NULL; timing = false;
|
---|
| 371 | }
|
---|
[165] | 372 | else if (kw == "exec") {
|
---|
[293] | 373 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: exec filename" << endl; return(0); }
|
---|
| 374 | ExecFile(tokens[0]);
|
---|
[165] | 375 | }
|
---|
| 376 | else if (kw == "shell") {
|
---|
[293] | 377 | if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl; return(0); }
|
---|
[165] | 378 | system(toks.c_str());
|
---|
| 379 | }
|
---|
[293] | 380 | // Execution d'une commande enregistree
|
---|
| 381 | else {
|
---|
| 382 | CmdExmap::iterator it = cmdexmap.find(kw);
|
---|
| 383 | if (it == cmdexmap.end()) cout << "No such command : " << kw << " ! " << endl;
|
---|
| 384 | else {
|
---|
| 385 | if ((*it).second.cex) (*it).second.cex->Execute(kw, tokens);
|
---|
| 386 | else cout << "Dont know how to execute " << kw << " ? " << endl;
|
---|
[165] | 387 | }
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | if (timing) gltimer->Split();
|
---|
| 391 | return(0);
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 |
|
---|
| 395 | /* --Methode-- */
|
---|
[293] | 396 | int PIACmd::ExecFile(string& file)
|
---|
[165] | 397 | {
|
---|
[293] | 398 | char line_buff[512];
|
---|
| 399 | FILE *fip;
|
---|
[165] | 400 |
|
---|
[293] | 401 | if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
|
---|
| 402 | cerr << "PIACmd::Exec() Error opening file " << file << endl;
|
---|
| 403 | hist << "##! PIACmd::Exec() Error opening file " << file << endl;
|
---|
| 404 | return(0);
|
---|
[165] | 405 | }
|
---|
[293] | 406 |
|
---|
| 407 | hist << "### Executing commands from " << file << endl;
|
---|
| 408 | if (trace) {
|
---|
| 409 | mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta);
|
---|
| 410 | mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
|
---|
| 411 | mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta);
|
---|
| 412 | }
|
---|
[165] | 413 |
|
---|
[293] | 414 | while (fgets(line_buff,511,fip) != NULL)
|
---|
| 415 | {
|
---|
| 416 | if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta);
|
---|
| 417 | line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */
|
---|
| 418 | string line(line_buff);
|
---|
| 419 | Interpret(line);
|
---|
[165] | 420 | }
|
---|
[293] | 421 | hist << "### End of Exec( " << file << " ) " << endl;
|
---|
| 422 | if (trace) {
|
---|
| 423 | mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta);
|
---|
| 424 | mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
|
---|
| 425 | mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta);
|
---|
[165] | 426 | }
|
---|
| 427 |
|
---|
| 428 | return(0);
|
---|
| 429 | }
|
---|
| 430 |
|
---|
[293] | 431 |
|
---|
| 432 | static string* videstr = NULL;
|
---|
| 433 | /* --Methode-- */
|
---|
| 434 | string& PIACmd::GetUsage(const string& kw)
|
---|
[165] | 435 | {
|
---|
[330] | 436 | bool fndok = false;
|
---|
[293] | 437 | CmdExmap::iterator it = cmdexmap.find(kw);
|
---|
[330] | 438 | if (it == cmdexmap.end()) {
|
---|
| 439 | it = helpexmap.find(kw);
|
---|
| 440 | if (it != helpexmap.end()) fndok = true;
|
---|
[165] | 441 | }
|
---|
[330] | 442 | else fndok = true;
|
---|
| 443 | if (fndok) return( (*it).second.us );
|
---|
| 444 | // Keyword pas trouve
|
---|
| 445 | if (videstr == NULL) videstr = new string("");
|
---|
| 446 | *videstr = "Nothing known about " + kw + " ?? ";
|
---|
| 447 | return(*videstr);
|
---|
| 448 |
|
---|
[165] | 449 | }
|
---|
| 450 |
|
---|
[293] | 451 | /* --Methode-- */
|
---|
| 452 | void PIACmd::ShowHelpWindow()
|
---|
[165] | 453 | {
|
---|
[293] | 454 | helpwin->Show();
|
---|
[165] | 455 | }
|
---|