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