source: Sophya/trunk/SophyaPI/PIext/piacmd.cc@ 2214

Last change on this file since 2214 was 2214, checked in by ansari, 23 years ago

Gestion des arguments des .pic (-tcsh ...) dans un stack , separe de la liste des variables , Reza 17/10/02

File size: 36.4 KB
Line 
1#include "piacmd.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <ctype.h>
5#include <math.h>
6
7#include "basexecut.h"
8
9#include "pdlmgr.h"
10#include "ctimer.h"
11#include "strutil.h"
12// #include "dlftypes.h"
13
14#include "pistdimgapp.h"
15#include "nobjmgr.h"
16#include "piafitting.h"
17#include "pawexecut.h"
18#include "cxxexecutor.h"
19#include "cxxexecwin.h"
20#include "contmodex.h"
21#include "flowmodex.h"
22
23#include PISTDWDG_H
24#include PILIST_H
25
26// ------------------------------------------------------------
27// Gestion d'une fenetre d'aide interactive
28// Classe PIAHelpWind
29// ------------------------------------------------------------
30
31class PIAHelpWind : public PIWindow {
32public :
33 PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd);
34 virtual ~PIAHelpWind();
35 virtual void Show();
36 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
37 inline void AddHelpGroup(const char * hgrp, int gid)
38 { hgrpom->AppendItem(hgrp, 20000+gid); }
39 inline void ClearHelpList()
40 { mNitem=0; hitemlist->DeleteAllItems(); }
41 inline void AddHelpItem(const char * hitem)
42 { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
43protected :
44 PIStdImgApp* dap;
45 PIACmd* piac;
46 int mNitem;
47 PIList* hitemlist;
48 PIOptMenu* hgrpom;
49 PIButton * mBut;
50 PILabel * mLab;
51 PIText* mTxt;
52};
53
54/* --Methode-- */
55PIAHelpWind::PIAHelpWind(PIStdImgApp *par, PIACmd* piacmd)
56 : PIWindow((PIMsgHandler *)par, "Help-PIApp", PIWK_normal, 400, 300, 100, 350)
57{
58dap = par;
59piac = piacmd;
60mNitem = 0;
61SetMsg(77);
62
63int bsx, bsy;
64int tsx, tsy;
65int spx, spy;
66PIApplicationPrefCompSize(bsx, bsy);
67spx = bsx/6; spy = bsy/6;
68tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy;
69SetSize(tsx,tsy);
70hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy);
71hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
72hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy);
73hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
74// hitemlist->SetBorderWidth(2);
75mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
76// mTxt->SetMutiLineMode(true);
77mTxt->SetTextEditable(false);
78mTxt->SetText("");
79mTxt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
80mLab = new PILabel(this, "helpitem", bsx*4, bsy, bsx*2.5+2*spx, tsy-spy-bsy);
81mLab->SetBorderWidth(1);
82mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
83mLab->SetLabel("");
84mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
85mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
86}
87
88/* --Methode-- */
89PIAHelpWind::~PIAHelpWind()
90{
91delete hgrpom;
92delete hitemlist;
93delete mTxt;
94delete mLab;
95delete mBut;
96}
97
98/* --Methode-- */
99void PIAHelpWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
100{
101PIMessage um = UserMsg(msg);
102if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
103 Hide();
104 return;
105 }
106else if ( (um >= 20000) && (sender == hgrpom)) { // Selection de groupe de Help
107 mTxt->SetText("");
108 mLab->SetLabel("");
109 piac->UpdateHelpList(this, um-20000);
110}
111else if ( (um > 100) && (sender == hitemlist) && (ModMsg(msg) == PIMsg_Select) ) {
112 string s = hitemlist->GetSelectionStr();
113 mTxt->SetText(piac->GetUsage(s));
114 mLab->SetLabel(s);
115 }
116}
117
118/* --Methode-- */
119void PIAHelpWind::Show()
120{
121hgrpom->SetValue(20000); // Groupe All
122mTxt->SetText("");
123mLab->SetLabel("");
124piac->UpdateHelpList(this, 0);
125PIWindow::Show();
126}
127
128// ------------------------------------------------------------
129// Bloc de commandes (Foreach, ...)
130// Classe PIACmdBloc
131// ------------------------------------------------------------
132
133class PIACmdBloc {
134public:
135 enum BType { BT_None, BT_ForeachList, BT_ForeachInt, BT_ForeachFloat };
136
137 PIACmdBloc(PIACmd* piac, PIACmdBloc* par, string& kw, vector<string>& args);
138 ~PIACmdBloc();
139 inline PIACmdBloc* Parent() { return(parent); }
140 inline bool CheckOK() { return blkok; }
141 inline void AddLine(string& line)
142 { lines.push_back(line); bloclineid.push_back(lines.size()); }
143 inline void AddBloc(PIACmdBloc* blk)
144 { blocs.push_back(blk); bloclineid.push_back(-blocs.size()); }
145 PIACmdBloc* Execute();
146protected:
147 PIACmd* piacmd;
148 PIACmdBloc* parent;
149 bool blkok; // true -> block OK
150 BType typ; // foreach , integer loop, float loop, test
151 string varname;
152 vector<string> strlist;
153 vector<string> lines;
154 vector<PIACmdBloc *> blocs;
155 vector<int> bloclineid;
156 int i1,i2,di;
157 float f1,f2,df;
158};
159
160/* --Methode-- */
161PIACmdBloc::PIACmdBloc(PIACmd* piac, PIACmdBloc* par, string& kw, vector<string>& args)
162{
163piacmd = piac;
164parent = par;
165blkok = false;
166typ = BT_None;
167i1 = 0; i2 = -1; di = 1;
168f1 = 0.; f2 = -1.; df = 1.;
169if ((args.size() < 2) || !isalpha((int)args[0][0]) ) return;
170if ((kw != "foreach") && (kw != "for")) return;
171varname = args[0]; // $CHECK$ Variable name should be checked
172//if (isalpha((int)args[1][0]) ) { This is a foreach bloc with string list
173if (kw == "foreach" ) { // This is a foreach bloc with string list
174 for(int kk=1; kk<args.size(); kk++) strlist.push_back(args[kk]);
175 typ = BT_ForeachList;
176 blkok = true;
177 }
178else { // This is an integer or float loop
179 size_t l = args[1].length();
180 size_t p = args[1].find(':');
181 size_t pp = args[1].find('.');
182 bool fl = (pp < l) ? true : false; // Float loop or integer loop
183 if (p >= l) return; // Syntaxe error
184 string a1 = args[1].substr(0, p);
185 string aa = args[1].substr(p+1);
186 p = aa.find(':');
187 string a2, a3;
188 bool hasa3 = false;
189 if (p < aa.length() ) {
190 a2 = aa.substr(0,p);
191 a3 = aa.substr(p+1);
192 hasa3 = true;
193 }
194 else a2 = aa;
195 if (fl) {
196 typ = BT_ForeachFloat;
197 blkok = true;
198 f1 = atof(a1.c_str());
199 f2 = atof(a2.c_str());
200 if (hasa3) df = atof(a3.c_str());
201 else df = 1.;
202 }
203 else {
204 typ = BT_ForeachInt;
205 blkok = true;
206 i1 = atoi(a1.c_str());
207 i2 = atoi(a2.c_str());
208 if (hasa3) di = atoi(a3.c_str());
209 else di = 1;
210 }
211 }
212}
213
214/* --Methode-- */
215PIACmdBloc::~PIACmdBloc()
216{
217for(int k=0; k<blocs.size(); k++) delete blocs[k];
218}
219
220/* --Methode-- */
221PIACmdBloc* PIACmdBloc::Execute()
222{
223// cout << " DBG * PIACmdBloc::Execute() " << typ << " - " << bloclineid.size() <<
224// " I1,I2=" << i1 << " , " << i2 << " , " << di << endl;
225string cmd;
226int k=0;
227int kj=0;
228int kk=0;
229char buff[32];
230if (typ == BT_ForeachList) // foreach string loop
231 for(k=0; k<strlist.size(); k++) {
232 cmd = "set " + varname + " '" + strlist[k] + "'";
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 }
240else if (typ == BT_ForeachInt) // Integer loop
241 for(int i=i1; i<i2; i+=di) {
242 k++;
243 if (++k > 9999) {
244 cout << ">>> Maximum PIACmdBloc loop limit (9999) -> break " << endl;
245 break;
246 }
247 sprintf(buff, " %d", i);
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 }
256else if (typ == BT_ForeachFloat) // float loop
257 for(float f=f1; f<f2; f+=df) {
258 k++;
259 if (++k > 9999) {
260 cout << ">>> Maximum PIACmdBloc loop limit (9999) -> break " << endl;
261 break;
262 }
263 sprintf(buff, " %g", f);
264 cmd = "set " + varname + buff;
265 piacmd->Interpret(cmd);
266 for(kj=0; kj<bloclineid.size(); kj++) {
267 kk = bloclineid[kj];
268 if (kk > 0) piacmd->Interpret(lines[kk-1]);
269 else blocs[-kk-1]->Execute();
270 }
271 }
272
273return(parent);
274}
275
276// ------------------
277// Classe PIACmdScript
278// ------------------
279class PIACmdScript {
280public:
281 PIACmdScript();
282 virtual ~PIACmdScript();
283};
284
285// ------------------------------------------------------------
286// Classe PIACmd
287// ------------------------------------------------------------
288
289static PIACmd* curpiacmd = NULL;
290/* --Methode-- */
291PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
292{
293mObjMgr = omg;
294mImgApp = app;
295system("cp history.pic hisold.pic");
296hist.open("history.pic");
297histon = true;
298trace = false; timing = false;
299gltimer = NULL;
300curblk = NULL;
301felevel = 0;
302mulinecmd = "";
303mulinefg = false;
304
305cmdhgrp["All"] = 0;
306cmdgrpid = 1;
307cmdhgrp["Commands"] = 1;
308helpwin = new PIAHelpWind(app, this);
309helpwin->AddHelpGroup("All", 0);
310helpwin->AddHelpGroup("Commands", 1);
311
312string kw = "piacmd";
313string usage;
314usage = ">>> (piacmd) Interpreter's keywords : \n";
315usage += " > set varname string # To set a variable, $varname \n";
316usage += " > get newvarname varname # To set a newvariable, equal to $varname \n";
317usage += " > setol varname patt # Fills varname with object list \n";
318usage += " > unset varname # clear variable definition \n";
319usage += " > echo string # output string \n";
320usage += " > alias name string # define a command alias \n";
321usage += " > readstdin varname # reads a line from stdin into $varname \n";
322usage += " > foreach varname string-list # Loop \n";
323usage += " > for varname i1:i2[:di] # Integer loop \n";
324usage += " > for varname f1:f2[:df] # Float loop \n";
325usage += " > end # end loops \n";
326usage += " > if test then # Conditional test : a == != < > <= >= b \n";
327usage += " > else # Conditional \n";
328usage += " > endif # End of conditional if bloc \n";
329usage += " > break # Delete (clears) all test and loop blocs \n";
330usage += " > return # Stops command execution from a file \n";
331usage += " > listvars # List of variable names and values \n";
332usage += " > listalias # List of alias names and values \n";
333usage += " > listcommands # List of all known commands \n";
334usage += " > exec filename # Execute commands from file \n";
335usage += " > help <command_name> # <command_name> usage info \n";
336usage += " > helpwindow # Displays help window \n";
337usage += " > timingon timingoff traceon traceoff \n";
338string grp = "Commands";
339RegisterHelp(kw, usage, grp);
340
341kw = "shell execute";
342usage = "> shell command_string # Execute shell command\n";
343usage += "> cshell command_string # Execute cshell command\n";
344usage += "---Exemples:\n";
345usage += " > shell ls\n";
346usage += " > cshell echo '$LD_LIBRARY_PATH'; map2cl -h; ls\n";
347usage += " > shell myfile.csh [arg1] [arg2] [...]\n";
348usage += " (where the first line of \"myfile.csh\" is \"#!/bin/csh\")\n";
349RegisterHelp(kw, usage, grp);
350
351basexec = new PIABaseExecutor(this, omg, app);
352fitexec = new PIAFitter(this, app);
353pawexec = new PAWExecutor(this, app);
354CxxExecutor * cxxe = new CxxExecutor(this, app);
355cxxexec = cxxe;
356
357ContModExecutor *cntxx = new ContModExecutor(this, app);//_OP_
358cntexec = cntxx; //_OP_
359FlowModExecutor *flwxx = new FlowModExecutor(this, app);//_OP_
360flwexec = flwxx; //_OP_
361
362cxxoptwin = new CxxOptionWind(app, cxxe);
363cxxexwin = new CxxExecWind(app, cxxe);
364
365AddInterpreter(this);
366curcmdi = this;
367}
368
369/* --Methode-- */
370PIACmd::~PIACmd()
371{
372hist.close();
373if (gltimer) { delete gltimer; gltimer = NULL; }
374Modmap::iterator it;
375for(it = modmap.begin(); it != modmap.end(); it++) {
376 string name = (*it).first + "_end";
377 DlModuleInitEndFunction fend = (*it).second->GetFunction(name);
378 if (fend) fend();
379 delete (*it).second;
380 }
381delete helpwin;
382delete cxxexwin;
383delete cxxoptwin;
384if (curpiacmd == this) curpiacmd = NULL;
385delete basexec;
386delete fitexec;
387delete pawexec;
388delete cxxexec;
389}
390
391/* --Methode-- */
392PIACmd* PIACmd::GetInterpreter()
393{
394return(curpiacmd);
395}
396
397/* --Methode-- */
398string PIACmd::Name()
399{
400return("piacmd");
401}
402
403/* --Methode-- */
404void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string grp)
405{
406if (!ce) {
407 RegisterHelp(keyw, usage, grp);
408 return;
409 }
410int gid = CheckHelpGrp(grp);
411cmdex cme;
412cme.group = gid;
413cme.us = usage;
414cme.cex = ce;
415cmdexmap[keyw] = cme;
416}
417
418/* --Methode-- */
419void PIACmd::RegisterHelp(string& keyw, string& usage, string& grp)
420{
421int gid = CheckHelpGrp(grp);
422cmdex cme;
423cme.group = gid;
424cme.us = usage;
425cme.cex = NULL;
426helpexmap[keyw] = cme;
427}
428
429/* --Methode-- */
430int PIACmd::CheckHelpGrp(string& grp)
431{
432int gid=0;
433CmdHGroup::iterator it = cmdhgrp.find(grp);
434if (it == cmdhgrp.end()) {
435 cmdgrpid++; gid = cmdgrpid;
436 cmdhgrp[grp] = gid;
437 helpwin->AddHelpGroup(grp.c_str(), gid);
438 }
439else gid = (*it).second;
440return(gid);
441}
442
443/* --Methode-- */
444void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
445{
446helpwin->ClearHelpList();
447CmdExmap::iterator it;
448for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
449 if ( (gid != 0) && ((*it).second.group != gid) ) continue;
450 helpwin->AddHelpItem((*it).first.c_str());
451 }
452for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
453 if ( (gid != 0) && ((*it).second.group != gid) ) continue;
454 helpwin->AddHelpItem((*it).first.c_str());
455 }
456}
457
458/* --Methode-- */
459void PIACmd::LoadModule(string& fnameso, string& name)
460{
461PDynLinkMgr * dynlink = new PDynLinkMgr(fnameso, false);
462if (dynlink == NULL) {
463 cerr << "PIACmd/LoadModule_Error: Pb opening SO " << fnameso << endl;
464 return;
465 }
466string fname = name + "_init";
467DlModuleInitEndFunction finit = dynlink->GetFunction(fname);
468if (!finit) {
469 cerr << "PIACmd/LoadModule_Error: Pb linking " << fname << endl;
470 return;
471 }
472cout << "PIACmd/LoadModule_Info: Initialisation module" << name
473 << " " << fname << "() ..." << endl;
474finit();
475modmap[name] = dynlink;
476return;
477}
478
479/* --Methode-- */
480void PIACmd::AddInterpreter(CmdInterpreter * cl)
481{
482if (!cl) return;
483interpmap[cl->Name()] = cl;}
484
485/* --Methode-- */
486void PIACmd::SelInterpreter(string& name)
487{
488InterpMap::iterator it = interpmap.find(name);
489if (it == interpmap.end()) return;
490curcmdi = (*it).second;
491}
492
493
494
495/* Fonction */
496static string GetStringFrStdin(PIACmd* piac)
497{
498PIStdImgApp* piapp = piac->GetImgApp();
499if (piapp) {
500 PIBaseWdg* wdg = piapp->CurrentBaseWdg();
501 if (wdg) wdg->Refresh();
502#ifndef __mac__
503 /* On vide le buffer X-Window */
504 XSync(PIXDisplay(),False);
505#endif
506}
507char buff[128];
508fgets(buff, 128, stdin);
509buff[127] = '\0';
510return((string)buff);
511}
512
513/* --Methode-- */
514int PIACmd::Interpret(string& s)
515{
516int rc = 0;
517NamedObjMgr omg;
518
519// On saute de commandes vides
520size_t l;
521l = s.length();
522if (l < 1) return(0);
523
524// On enregistre les commandes
525if (histon) hist << s << endl;
526
527if (s[0] == '#') return(0); // si c'est un commentaire
528
529// Logique de gestion des lignes suite
530// un \ en derniere position indique la presence d'une ligne suite
531size_t lnb = s.find_last_not_of(' ');
532if (s[lnb] == '\\' ) { // Lignes suite ...
533 mulinefg = true;
534 mulinecmd += s.substr(0,lnb);
535 mImgApp->GetConsole()->SetPrompt("...? ");
536 return(0);
537}
538
539if (mulinefg) { // Il y avait des lignes suite
540 s = mulinecmd + s;
541 mulinecmd = "";
542 mulinefg = false;
543 const char * rprompt = (curblk == NULL) ? "Cmd> " : "for...? ";
544 mImgApp->GetConsole()->SetPrompt(rprompt);
545}
546
547// Removing leading blanks
548size_t p,q;
549
550p=s.find_first_not_of(" \t");
551if (p < l) s = s.substr(p);
552
553// >>>> Substitution d'alias (1er mot)
554CmdStrList::iterator it;
555p = 0;
556q = s.find_first_of(" \t");
557l = s.length();
558string w1 = (q < l) ? s.substr(p,q-p) : s.substr(p);
559it = mAliases.find(w1);
560if (it != mAliases.end()) {
561 s = (q < l) ? ((*it).second + s.substr(q)) : (*it).second ;
562 l = s.length();
563 p=s.find_first_not_of(" \t");
564 if (p < l) s = s.substr(p);
565 p = 0;
566 q = s.find_first_of(" ");
567 }
568
569// >>>> Separating keyword
570string toks,kw;
571if (q < l)
572 { kw = s.substr(p,q-p); toks = s.substr(q, l-q); }
573else { kw = s.substr(p,l-p); toks = ""; }
574
575// les mot-cle end else endif doivent etre le seul mot de la ligne
576if ( (kw == "end") || (kw == "else") || (kw == "endif") ) {
577 size_t ltk = toks.length();
578 if (toks.find_first_not_of(" \t") < ltk) {
579 cerr << "PIACmd::Interpret()/syntax error near end else endif \n"
580 << "line: " << s << endl;
581 return(1);
582 }
583}
584
585if (kw == "break") {
586 PIACmdBloc* curb = curblk;
587 while (curb) {
588 PIACmdBloc* dblk = curb;
589 curb = curb->Parent();
590 delete dblk;
591 }
592 testresult.clear();
593 return(0);
594}
595else if (kw == "return") return(77777);
596
597// On verifie si nous sommes dans un bloc (for , foreach)
598if (curblk != NULL) { // On est dans un bloc
599 if ( (kw == "for") || (kw == "foreach")) felevel++;
600 else if (kw == "end") felevel--;
601 if (felevel == 0) { // Il faut executer le bloc
602 PIACmdBloc* curb = curblk;
603 curblk = curb->Parent();
604 mImgApp->GetConsole()->SetPrompt("Cmd> ");
605 // cout << " *DBG* Executing bloc " << endl;
606 bool ohv = histon;
607 histon = false;
608 curb->Execute();
609 histon = ohv;
610 }
611 else curblk->AddLine(s);
612 return(0);
613}
614else if (kw == "end") {
615 cerr << "PIACmd::Interpret()/syntax error - end outside for/foreach bloc \n"
616 << "line: " << s << endl;
617 return(1);
618}
619
620// Sommes-nous dans un bloc de test if then else
621if (testresult.size() > 0) { // Nous sommes ds un bloc if
622 if (kw == "else") {
623 if ((*tresit) & 2) {
624 cerr << "PIACmd::Interpret()/syntax error - multiple else in if bloc \n"
625 << "line: " << s << endl;
626 return(1);
627 }
628 else {
629 const char * npr = ((*tresit)&1) ? "else-F> " : "else-T> ";
630 mImgApp->GetConsole()->SetPrompt(npr);
631 (*tresit) |= 2;
632 return(0);
633 }
634 }
635 else if (kw == "endif") {
636 list<char>::iterator dbit = tresit;
637 tresit--;
638 testresult.erase(dbit);
639 const char * npr = "Cmd> ";
640 if (testresult.size() > 1) {
641 if (!((*tresit)&2))
642 npr = ((*tresit)&1) ? "if-T> " : "if-F> ";
643 else
644 npr = ((*tresit)&1) ? "else-F> " : "else-T> ";
645 }
646 mImgApp->GetConsole()->SetPrompt(npr);
647 return(0);
648 }
649}
650else if ((kw == "else") || (kw == "endif")) {
651 cerr << "PIACmd::Interpret()/syntax error - else,endif outside if bloc \n"
652 << "line: " << s << endl;
653 return(1);
654}
655
656bool fgcont = true;
657if (testresult.size() > 0) { // Resultat de if ou else
658 list<char>::iterator it;
659 for(it=testresult.begin(); it!=testresult.end(); it++) {
660 // Si on n'est pas ds le else et le if est faux
661 if ( !((*it)&2) && !((*it)&1) ) fgcont = false;
662 // Si on est ds else et le if etait vrai !
663 if ( ((*it)&2) && ((*it)&1) ) fgcont = false;
664 if (!fgcont) break;
665 }
666}
667
668if ((!fgcont) && (kw != "if")) return(0);
669
670
671// Nous ne sommes donc pas dans un bloc .... Substitution de variables
672string s2;
673int rcs ;
674// Execution de code C++
675
676if (s[0] == '@') {
677 CxxExecutor * cxxe = dynamic_cast<CxxExecutor *>(cxxexec);
678 if (cxxe == NULL) {
679 cerr << "PIACmd::Interpret() - BUG !!! Not a CxxExecutor " << endl;
680 return(99);
681 }
682 // Sans substitution des variables $
683 if (s[1] == '@') return(cxxe->ExecuteCXX(s.substr(2)));
684 else { // AVEC substitution des variables $
685 rcs = SubstituteVars(s, s2);
686 if (rcs) return(rcs);
687 return(cxxe->ExecuteCXX(s2.substr(1)));
688 }
689}
690
691
692rcs = SubstituteVars(s, s2);
693if (rcs) return(rcs);
694
695// >>>> Separating keyword and tokens
696vector<string> tokens;
697
698q = s2.find(' ');
699l = s2.length();
700if (q < l)
701 { kw = s2.substr(0,q); toks = s2.substr(q, l-q); }
702else { kw = s2; toks = ""; }
703
704q = 0;
705while (q < l) {
706 p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
707 if (p>=l) break;
708 if ( (toks[p] == '\'') || (toks[p] == '"') ) {
709 q = toks.find(toks[p],p+1);
710 if (q>=l) {
711 cerr << "PIACmd::Interpret()/Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl;
712 return(2);
713 }
714 p++;
715 }
716 else {
717 q = toks.find_first_of(" \t",p); // la fin du token;
718 }
719 string token = toks.substr(p,q-p);
720 tokens.push_back(token);
721 }
722
723
724// Si c'est un for/foreach, on cree un nouveau bloc
725if ((kw == "foreach") || (kw == "for")) {
726 // cout << " *DBG* We got a foreach... " << endl;
727 PIACmdBloc* bloc = new PIACmdBloc(this, curblk, kw, tokens);
728 if (!bloc->CheckOK()) {
729 cerr << "PIACmd::Interpret() for/foreach syntax Error ! " << endl;
730 delete bloc;
731 return(1);
732 }
733 felevel++;
734 if (curblk) curblk->AddBloc(bloc);
735 else mImgApp->GetConsole()->SetPrompt("for...> ");
736 curblk = bloc;
737 // cout << " *DBG* New Bloc created ... " << endl;
738 return(0);
739 }
740else if (kw == "if") { // Un test if
741 bool restst = true;
742 int rct = EvaluateTest(tokens, s, restst);
743 if (rct) {
744 cerr << "PIACmd::Interpret() if syntax Error ! " << endl;
745 return(1);
746 }
747 char res_tst = (restst) ? 1 : 0;
748 testresult.push_back(res_tst);
749 if (testresult.size() == 1) tresit = testresult.begin();
750 else tresit++;
751 const char * npr = (restst) ? "if-T> " : "if-F> ";
752 mImgApp->GetConsole()->SetPrompt(npr);
753}
754// Execution de commandes
755else rc = ExecuteCommandLine(kw, tokens, toks);
756return(rc);
757
758// cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl;
759// for(int ii=0; ii<tokens.size(); ii++)
760// cout << "arg[ " << ii << " ] : " << tokens[ii] << endl;
761
762}
763
764/* --Methode-- */
765int PIACmd::SubstituteVars(string & s, string & s2)
766// Variable substitution
767{
768NamedObjMgr& omg = *mObjMgr;
769
770size_t p,q,q2,l;
771
772s2="";
773p = 0;
774l = s.length();
775string vn, vv;
776while (p < l) {
777 q = s.find('$',p);
778 if (q > l) break;
779 q2 = s.find('\'',p);
780 if ((q2 < l) && (q2 < q)) { // On saute la chaine delimitee par ' '
781 q2 = s.find('\'',q2+1);
782 if (q2 >= l) {
783 cerr << " Syntax error - Unbalenced quotes !!! " << endl;
784 return(1);
785 }
786 s2 += s.substr(p, q2-p+1);
787 p = q2+1; continue;
788 }
789 // cout << "DBG: " << s2 << " p= " << p << " q= " << q << " L= " << l << endl;
790 if ((q>0) && (s[q-1] == '\\')) { // Escape character \$
791 s2 += (s.substr(p,q-1-p) + '$') ; p = q+1;
792 continue;
793 }
794 if (q >= l-1) {
795 cerr << " Syntax error - line ending with $ !!! " << endl;
796 return(2);
797 }
798 vn = "";
799 if ( s[q+1] == '{' ) { // Variable in the form ${name}
800 q2 = s.find('}',q+1);
801 if (q2 >= l) {
802 cerr << " Syntax error - Unbalenced brace {} !!! " << endl;
803 return(3);
804 }
805 vn = s.substr(q+2,q2-q-2);
806 q2++;
807 }
808 else if ( s[q+1] == '[' ) { // Variable in the form $[varname] -> This is $$varname
809 q2 = s.find(']',q+1);
810 if (q2 >= l) {
811 cerr << " Syntax error - Unbalenced brace [] !!! " << endl;
812 return(4);
813 }
814 vn = s.substr(q+2,q2-q-2);
815 if (!GetVar(vn, vv)) return(5);
816 vn = vv;
817 q2++;
818 }
819 else {
820 q2 = s.find_first_of(" .:+-*/,[](){}&|!$\"'",q+1);
821 if (q2 > l) q2 = l;
822 vn = s.substr(q+1, q2-q-1);
823 }
824 if (!GetVar(vn, vv)) return(5);
825 s2 += (s.substr(p, q-p) + vv);
826 p = q2;
827 }
828if (p < l) s2 += s.substr(p);
829
830p = s2.find_first_not_of(" \t");
831if (p < l) s2 = s2.substr(p);
832
833return(0);
834}
835
836/* --Methode-- */
837bool PIACmd::GetVar(string & vn, string & vv)
838{
839NamedObjMgr& omg = *mObjMgr;
840if (vn.length() < 1) {
841 cerr << " PIACmd::SubstituteVar/Error: length(varname=" << vn << ")<1 !" << endl;
842 vv = ""; return(false);
843}
844// Variable de type $# $0 $1 ... (argument de .pic ou de script)
845int ka = 0;
846if (vn == "#") {
847 if (ArgsStack.empty()) {
848 cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
849 << " ($" << vn << ")" << endl;
850 vv = ""; return(false);
851 }
852 char buff[32];
853 long an = ArgsStack.top().size();
854 sprintf(buff,"%ld", an);
855 vv = buff;
856}
857else if (ctoi(vn.c_str(), &ka) > 0) { // $0 $1 $2 ...
858 if (ArgsStack.empty()) {
859 cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
860 << " ($" << vn << ")" << endl;
861 vv = ""; return(false);
862 }
863 if ( (ka < 0) || (ka >= ArgsStack.top().size()) ) {
864 cerr << " PIACmd::SubstituteVar/Error: Undefined variable ! "
865 << " ($" << vn << ")" << endl;
866 vv = ""; return(false);
867 }
868 vv = ArgsStack.top()[ka];
869}
870else { // variable ordinaire geree par NamedObjMgr
871 if ( (!omg.HasVar(vn)) ) {
872 cerr << " PIACmd::SubstituteVarError: Undefined variable "
873 << vn << " ! " << endl;
874 vv = ""; return(false);
875 }
876 vv = omg.GetVar(vn);
877}
878
879return(true);
880}
881
882/* --Methode-- */
883int PIACmd::EvaluateTest(vector<string> & args, string & line, bool & res)
884{
885 res = true;
886 if ((args.size() < 4) || (args[3] != "then")) return(1);
887 if (args[1] == "==") res = (args[0] == args[2]);
888 else if (args[1] == "!=") res = (args[0] != args[2]);
889 else if (args[1] == "<")
890 res = (atof(args[0].c_str()) < atof(args[2].c_str()));
891 else if (args[1] == ">")
892 res = (atof(args[0].c_str()) > atof(args[2].c_str()));
893 else if (args[1] == "<=")
894 res = (atof(args[0].c_str()) <= atof(args[2].c_str()));
895 else if (args[1] == ">=")
896 res = (atof(args[0].c_str()) >= atof(args[2].c_str()));
897 else return(2);
898 return(0);
899}
900
901/* --Methode-- */
902int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
903{
904int rc = 0;
905NamedObjMgr omg;
906
907// >>>>>>>>>>> Commande d'interpreteur
908if (kw == "helpwindow") ShowHelpWindow();
909else if (kw == "help") {
910 if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl;
911 else {
912 string kwh = "piacmd";
913 cout << GetUsage(kwh) << endl;
914 }
915 }
916
917else if (kw == "set") {
918 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); }
919 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
920 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
921 return(0);
922 }
923 // string xx = tokens[1];
924 // for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk] );
925 omg.SetVar(tokens[0], tokens[1]);
926 }
927
928else if (kw == "getvar") {
929 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: getvar newvarname varname" << endl; return(0); }
930 if (!omg.HasVar(tokens[1])) {
931 cerr << "Error - No " << tokens[1] << " Variable " << endl;
932 return(0);
933 }
934 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
935 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
936 return(0);
937 }
938 omg.SetVar(tokens[0], omg.GetVar(tokens[1]) );
939 }
940
941else if (kw == "alias") {
942 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: alias aliasname string" << endl; return(0); }
943 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
944 cerr << "PIACmd::Interpret()/Error alias name should start with alphabetic" << endl;
945 return(0);
946 }
947 string xx = tokens[1];
948 for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk]);
949 mAliases[tokens[0]] = xx;
950 }
951
952else if (kw == "setol") {
953 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: setol varname objnamepattern" << endl; return(0); }
954 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
955 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
956 return(0);
957 }
958 vector<string> ol;
959 mObjMgr->GetObjList(tokens[1], ol);
960 string vol;
961 if (ol.size() < 1) vol = "";
962 else {
963 vol = ol[0];
964 for (int kk=1; kk<ol.size(); kk++) vol += (' ' + ol[kk]);
965 }
966 omg.SetVar(tokens[0], vol);
967 }
968else if (kw == "unset") {
969 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); }
970 if (omg.HasVar(tokens[0])) omg.DeleteVar(tokens[0]) ;
971 else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl;
972 }
973else if (kw == "echo") {
974 for (int ii=0; ii<tokens.size(); ii++)
975 cout << tokens[ii] << " " ;
976 cout << endl;
977 }
978else if (kw == "readstdin") {
979 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: readstdin varname" << endl; return(0); }
980 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
981 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
982 return(0);
983 }
984 mImgApp->GetConsole()->AddStr(">>> Reading From StdIn \n", PIVA_Magenta);
985 cout << tokens[0] << " ? " << endl;
986 omg.SetVar(tokens[0], GetStringFrStdin(this) );
987 }
988
989else if (kw == "listvars") {
990 cout << "PIACmd::Interpret() Variable List , VarName = Value \n";
991 DVList& varlist = omg.GetVarList();
992 DVList::ValList::const_iterator it;
993 string value;
994 for(it = varlist.Begin(); it != varlist.End(); it++) {
995#ifdef SANS_EVOLPLANCK
996 MuTyV mtv = (*it).second;
997 value = (string)(mtv);
998#else
999 value = (string)((*it).second.elval);
1000#endif
1001 cout << (*it).first << " = " << value << "\n";
1002 }
1003 cout << endl;
1004 }
1005else if (kw == "listalias") {
1006 cout << "PIACmd::Interpret() Alias List , AliasName = Value \n";
1007 CmdStrList::iterator it;
1008 for(it = mAliases.begin(); it != mAliases.end(); it++)
1009 cout << (*it).first << " = " << (*it).second << "\n";
1010 cout << endl;
1011 }
1012else if (kw == "listcommands") {
1013 cout << "---- PIACmd::Interpret() Command Variable List ----- \n";
1014 CmdExmap::iterator it;
1015 int kc = 0;
1016 for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
1017 cout << (*it).first << " ";
1018 kc++;
1019 if (kc >= 5) { cout << "\n"; kc = 0; }
1020 }
1021 cout << endl;
1022 }
1023else if (kw == "traceon") { cout << "PIACmd::Interpret() -> Trace ON mode " << endl; trace = true; }
1024else if (kw == "traceoff") { cout << "PIACmd::Interpret() -> Trace OFF mode " << endl; trace = false; }
1025else if (kw == "timingon") {
1026 cout << "PIACmd::Interpret() -> Timing ON mode " << endl;
1027 if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true;
1028 }
1029else if (kw == "timingoff") {
1030 cout << "PIACmd::Interpret() -> Timing OFF mode " << endl;
1031 if (gltimer) delete gltimer; gltimer = NULL; timing = false;
1032 }
1033else if (kw == "exec") {
1034 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: exec filename" << endl; return(0); }
1035 ExecFile(tokens[0], tokens);
1036 }
1037else if (kw == "shell") {
1038 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl; return(0); }
1039 string cmd;
1040 for (int ii=0; ii<tokens.size(); ii++)
1041 cmd += (tokens[ii] + ' ');
1042 system(cmd.c_str());
1043 }
1044else if (kw == "cshell") {
1045 if(tokens.size()<1) {cout<<"PIACmd::Interpret() Usage: cshell cmdline"<<endl; return(0);}
1046 string cmd="";
1047 for(int ii=0;ii<tokens.size();ii++) cmd+=(tokens[ii]+' ');
1048 CShellExecute(cmd);
1049 }
1050
1051// Execution d'une commande enregistree
1052else rc = ExecuteCommand(kw, tokens, toks);
1053
1054if (timing) gltimer->Split();
1055return(rc);
1056}
1057
1058/* --Methode-- */
1059int PIACmd::ParseLineExecute(string& line)
1060{
1061vector<string> tokens;
1062
1063if (line.length() < 1) return(0);
1064
1065string toks,kw;
1066size_t p = line.find_first_not_of(" ");
1067line = line.substr(p);
1068p = 0;
1069size_t q = line.find_first_of(" ");
1070size_t l = line.length();
1071
1072if (q < l)
1073 { kw = line.substr(p,q-p); toks = line.substr(q, l-q); }
1074else { kw = line.substr(p,l-p); toks = ""; }
1075
1076q = 0;
1077while (q < l) {
1078 p = toks.find_first_not_of(" ",q+1); // au debut d'un token
1079 if (p>=l) break;
1080 q = toks.find_first_of(" ",p); // la fin du token;
1081 string token = toks.substr(p,q-p);
1082 tokens.push_back(token);
1083 }
1084
1085return(ExecuteCommand(kw, tokens, toks));
1086}
1087
1088/* --Methode-- */
1089int PIACmd::ExecuteCommand(string& keyw, vector<string>& args, string& toks)
1090{
1091 int rc = -1;
1092 CmdExmap::iterator it = cmdexmap.find(keyw);
1093 if (it == cmdexmap.end()) cout << "No such command : " << keyw << " ! " << endl;
1094 else {
1095 if ((*it).second.cex) rc = (*it).second.cex->Execute(keyw, args, toks);
1096 else cout << "Dont know how to execute " << keyw << " ? " << endl;
1097 }
1098 return(rc);
1099}
1100
1101/* --Methode-- */
1102int PIACmd::ExecFile(string& file, vector<string>& args)
1103{
1104char line_buff[512];
1105FILE *fip;
1106
1107if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
1108 if (file.find('.') >= file.length()) {
1109 cout << "PIACmd::Exec(): Error opening file " << file << endl;
1110 file += ".pic";
1111 cout << " Trying file " << file << endl;
1112 fip = fopen(file.c_str(),"r");
1113 }
1114 }
1115
1116if(fip == NULL) {
1117 cerr << "PIACmd::Exec() Error opening file " << file << endl;
1118 hist << "##! PIACmd::Exec() Error opening file " << file << endl;
1119 return(0);
1120 }
1121
1122// hist << "### Executing commands from " << file << endl;
1123
1124// We push the argument list (args) on the stack
1125ArgsStack.push(args);
1126
1127if (trace) {
1128 mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta);
1129 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
1130 mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta);
1131 }
1132
1133bool ohv = histon;
1134histon = false;
1135while (fgets(line_buff,511,fip) != NULL)
1136 {
1137 if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta);
1138 line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */
1139 string line(line_buff);
1140 if (Interpret(line) == 77777) break;
1141 }
1142histon = ohv;
1143
1144// hist << "### End of Exec( " << file << " ) " << endl;
1145if (trace) {
1146 mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta);
1147 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
1148 mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta);
1149 }
1150
1151// We remove the argument list (args) from the stack
1152ArgsStack.pop();
1153
1154return(0);
1155}
1156
1157/* --Methode-- */
1158int PIACmd::CShellExecute(string cmd)
1159{
1160 if(cmd.size()<=0) return -1;
1161
1162 NamedObjMgr omg;
1163 string fname = omg.GetTmpDir(); fname += "cshell_exec_pia.csh";
1164
1165 string cmdrm = "rm -f " + fname;
1166 system(cmdrm.c_str());
1167
1168 FILE *fip = fopen(fname.c_str(),"w");
1169 if(fip==NULL) {
1170 cout << "PIACmd/CShellExecute_Error: fopen("<<fname<<") failed"<<endl;
1171 return -2;
1172 }
1173 fprintf(fip,"#!/bin/csh\n\n");
1174 fprintf(fip,"%s\n",cmd.c_str());
1175 fprintf(fip,"\nexit 0\n");
1176 fclose(fip);
1177
1178 cmd = "csh "; cmd += fname;
1179 system(cmd.c_str());
1180
1181 system(cmdrm.c_str());
1182
1183 return 0;
1184}
1185
1186static string* videstr = NULL;
1187/* --Methode-- */
1188string& PIACmd::GetUsage(const string& kw)
1189{
1190bool fndok = false;
1191CmdExmap::iterator it = cmdexmap.find(kw);
1192if (it == cmdexmap.end()) {
1193 it = helpexmap.find(kw);
1194 if (it != helpexmap.end()) fndok = true;
1195 }
1196 else fndok = true;
1197if (fndok) return( (*it).second.us );
1198// Keyword pas trouve
1199if (videstr == NULL) videstr = new string("");
1200*videstr = "Nothing known about " + kw + " ?? ";
1201return(*videstr);
1202
1203}
1204
1205/* --Methode-- */
1206void PIACmd::ShowHelpWindow()
1207{
1208helpwin->Show();
1209}
1210
1211/* --Methode-- */
1212void PIACmd::ShowCxxOptionWindow()
1213{
1214cxxoptwin->Show();
1215}
1216
1217/* --Methode-- */
1218void PIACmd::ShowCxxExecWindow()
1219{
1220cxxexwin->Show();
1221}
1222
1223/* --Methode-- */
1224void PIACmd::HelptoLaTex(string const & fname)
1225{
1226FILE *fip;
1227if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1228 cout << "PIACmd::HelptoLaTex_Error: fopen( " << fname << endl;
1229 return;
1230 }
1231
1232fputs("% ----- Liste des groupes de Help ----- \n",fip);
1233fputs("List of {\\bf piapp} on-line Help groups: \n", fip);
1234fputs("\\begin{itemize} \n",fip);
1235CmdHGroup::iterator it;
1236for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++)
1237 fprintf(fip,"\\item {\\bf %s } (p. \\pageref{%s}) \n",
1238 (*it).first.c_str(), (*it).first.c_str());
1239
1240fputs("\\end{itemize} \n",fip);
1241
1242fputs("\\newpage \n",fip);
1243
1244CmdExmap::iterator ite;
1245fputs("% ----- Liste de toutes les commandes ----- \n",fip);
1246fputs("\\begin{center} \n ", fip);
1247fputs("\\rule{2cm}{1mm} List of {\\bf piapp} Help items \\rule{2cm}{1mm} \n", fip);
1248fputs("\n \n \\vspace{5mm} \n",fip);
1249fputs("\\begin{tabular}{llllll} \n", fip);
1250int kt = 0;
1251for(ite = helpexmap.begin(); ite != helpexmap.end(); ite++) {
1252 fprintf(fip,"%s & p. \\pageref{%s} ", (*ite).first.c_str(), (*ite).first.c_str() );
1253 kt++;
1254 if (kt < 3) fputs(" & ", fip);
1255 else { fputs(" \\\\ \n", fip); kt = 0; }
1256 }
1257if (kt == 1) fputs(" & & & \\\\ \n", fip);
1258else if (kt == 2) fputs(" & \\\\ \n", fip);
1259fputs("\\end{tabular} \n", fip);
1260fputs("\\end{center} \n", fip);
1261fputs("\n \n \\vspace{1cm} \n",fip);
1262
1263fputs("\\begin{center} \n ", fip);
1264fputs("\\rule{2cm}{1mm} List of {\\bf piapp} Commands \\rule{2cm}{1mm} \n", fip);
1265fputs("\n \n \\vspace{5mm} \n",fip);
1266fputs("\\begin{tabular}{llllll} \n", fip);
1267kt = 0;
1268for(ite = cmdexmap.begin(); ite != cmdexmap.end(); ite++) {
1269 fprintf(fip,"%s & p. \\pageref{%s} ", (*ite).first.c_str(), (*ite).first.c_str() );
1270 kt++;
1271 if (kt < 3) fputs(" & ", fip);
1272 else { fputs(" \\\\ \n", fip); kt = 0; }
1273 }
1274if (kt == 1) fputs(" & & & \\\\ \n", fip);
1275else if (kt == 2) fputs(" & \\\\ \n", fip);
1276fputs("\\end{tabular} \n", fip);
1277fputs("\\end{center} \n", fip);
1278// fputs("\\newline \n",fip);
1279
1280fputs("% ----- Liste des commandes dans chaque groupe ----- \n",fip);
1281fputs("\\newpage \n",fip);
1282int gid;
1283for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++) {
1284 gid = (*it).second;
1285 if (gid == 0) continue;
1286 fprintf(fip,"\\subsection{%s} \\label{%s} \n",
1287 (*it).first.c_str(), (*it).first.c_str());
1288 for(ite = helpexmap.begin(); ite != helpexmap.end(); ite++) {
1289 if ((*ite).second.group != gid) continue;
1290 fprintf(fip,"{ \\Large $ \\star \\star \\star $ } Help item {\\bf \\Large %s } \\label{%s} \n",
1291 (*ite).first.c_str(), (*ite).first.c_str());
1292 fputs("\\begin{verbatim} \n",fip);
1293 fprintf(fip,"%s\n", (*ite).second.us.c_str());
1294 fputs("\\end{verbatim} \n",fip);
1295 }
1296 for(ite = cmdexmap.begin(); ite != cmdexmap.end(); ite++) {
1297 if ((*ite).second.group != gid) continue;
1298 fprintf(fip,"{ \\Large $ \\star \\star \\star $ } Command {\\bf \\Large %s } \\label{%s} \n",
1299 (*ite).first.c_str(), (*ite).first.c_str());
1300 fputs("\\begin{verbatim} \n",fip);
1301 fprintf(fip,"%s\n", (*ite).second.us.c_str());
1302 fputs("\\end{verbatim} \n",fip);
1303 }
1304}
1305
1306fclose(fip);
1307return;
1308}
1309
1310
1311
Note: See TracBrowser for help on using the repository browser.