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
RevLine 
[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"
[2214]11#include "strutil.h"
[293]12// #include "dlftypes.h"
[165]13
[293]14#include "pistdimgapp.h"
[165]15#include "nobjmgr.h"
[361]16#include "piafitting.h"
[463]17#include "pawexecut.h"
[1224]18#include "cxxexecutor.h"
[1251]19#include "cxxexecwin.h"
[1828]20#include "contmodex.h"
[1920]21#include "flowmodex.h"
[165]22
[293]23#include PISTDWDG_H
24#include PILIST_H
[165]25
[293]26// ------------------------------------------------------------
[349]27// Gestion d'une fenetre d'aide interactive
28// Classe PIAHelpWind
[293]29// ------------------------------------------------------------
[165]30
[293]31class PIAHelpWind : public PIWindow {
32public :
33 PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd);
34 virtual ~PIAHelpWind();
[330]35 virtual void Show();
[293]36 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
[330]37 inline void AddHelpGroup(const char * hgrp, int gid)
38 { hgrpom->AppendItem(hgrp, 20000+gid); }
39 inline void ClearHelpList()
40 { mNitem=0; hitemlist->DeleteAllItems(); }
[293]41 inline void AddHelpItem(const char * hitem)
[330]42 { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
[293]43protected :
44 PIStdImgApp* dap;
45 PIACmd* piac;
46 int mNitem;
47 PIList* hitemlist;
[330]48 PIOptMenu* hgrpom;
[293]49 PIButton * mBut;
50 PILabel * mLab;
51 PIText* mTxt;
52};
[165]53
[293]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;
[330]61SetMsg(77);
[165]62
[293]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);
[330]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);
[293]73hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
74// hitemlist->SetBorderWidth(2);
[324]75mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
76// mTxt->SetMutiLineMode(true);
[293]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("");
[330]84mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
[293]85mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
86}
[165]87
88/* --Methode-- */
[293]89PIAHelpWind::~PIAHelpWind()
90{
[330]91delete hgrpom;
[293]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);
[330]102if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
[293]103 Hide();
104 return;
105 }
[330]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) ) {
[293]112 string s = hitemlist->GetSelectionStr();
113 mTxt->SetText(piac->GetUsage(s));
114 mLab->SetLabel(s);
115 }
116}
117
[330]118/* --Methode-- */
119void PIAHelpWind::Show()
120{
121hgrpom->SetValue(20000); // Groupe All
122mTxt->SetText("");
123mLab->SetLabel("");
124piac->UpdateHelpList(this, 0);
125PIWindow::Show();
126}
[293]127
[349]128// ------------------------------------------------------------
129// Bloc de commandes (Foreach, ...)
130// Classe PIACmdBloc
131// ------------------------------------------------------------
132
133class PIACmdBloc {
134public:
[1262]135 enum BType { BT_None, BT_ForeachList, BT_ForeachInt, BT_ForeachFloat };
136
[1562]137 PIACmdBloc(PIACmd* piac, PIACmdBloc* par, string& kw, vector<string>& args);
[1262]138 ~PIACmdBloc();
[349]139 inline PIACmdBloc* Parent() { return(parent); }
[1262]140 inline bool CheckOK() { return blkok; }
[349]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;
[1262]149 bool blkok; // true -> block OK
150 BType typ; // foreach , integer loop, float loop, test
[349]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-- */
[1562]161PIACmdBloc::PIACmdBloc(PIACmd* piac, PIACmdBloc* par, string& kw, vector<string>& args)
[349]162{
163piacmd = piac;
164parent = par;
[1262]165blkok = false;
166typ = BT_None;
[349]167i1 = 0; i2 = -1; di = 1;
168f1 = 0.; f2 = -1.; df = 1.;
169if ((args.size() < 2) || !isalpha((int)args[0][0]) ) return;
[1562]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
[349]174 for(int kk=1; kk<args.size(); kk++) strlist.push_back(args[kk]);
[1262]175 typ = BT_ForeachList;
[1276]176 blkok = true;
[349]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) {
[1262]196 typ = BT_ForeachFloat;
[1276]197 blkok = true;
[349]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 {
[1262]204 typ = BT_ForeachInt;
[1276]205 blkok = true;
[349]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];
[1262]230if (typ == BT_ForeachList) // foreach string loop
[349]231 for(k=0; k<strlist.size(); k++) {
[1565]232 cmd = "set " + varname + " '" + strlist[k] + "'";
[349]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 }
[1262]240else if (typ == BT_ForeachInt) // Integer loop
[349]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 }
[1262]256else if (typ == BT_ForeachFloat) // float loop
[349]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
[2214]276// ------------------
277// Classe PIACmdScript
278// ------------------
279class PIACmdScript {
280public:
281 PIACmdScript();
282 virtual ~PIACmdScript();
283};
284
[349]285// ------------------------------------------------------------
286// Classe PIACmd
287// ------------------------------------------------------------
288
[293]289static PIACmd* curpiacmd = NULL;
290/* --Methode-- */
[165]291PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
292{
[293]293mObjMgr = omg;
[165]294mImgApp = app;
295system("cp history.pic hisold.pic");
296hist.open("history.pic");
[349]297histon = true;
[165]298trace = false; timing = false;
299gltimer = NULL;
[349]300curblk = NULL;
301felevel = 0;
[1276]302mulinecmd = "";
303mulinefg = false;
[293]304
[330]305cmdhgrp["All"] = 0;
306cmdgrpid = 1;
307cmdhgrp["Commands"] = 1;
[293]308helpwin = new PIAHelpWind(app, this);
[330]309helpwin->AddHelpGroup("All", 0);
310helpwin->AddHelpGroup("Commands", 1);
[293]311
312string kw = "piacmd";
313string usage;
314usage = ">>> (piacmd) Interpreter's keywords : \n";
[349]315usage += " > set varname string # To set a variable, $varname \n";
316usage += " > get newvarname varname # To set a newvariable, equal to $varname \n";
[333]317usage += " > setol varname patt # Fills varname with object list \n";
[293]318usage += " > unset varname # clear variable definition \n";
[333]319usage += " > echo string # output string \n";
[353]320usage += " > alias name string # define a command alias \n";
321usage += " > readstdin varname # reads a line from stdin into $varname \n";
[349]322usage += " > foreach varname string-list # Loop \n";
[1562]323usage += " > for varname i1:i2[:di] # Integer loop \n";
324usage += " > for varname f1:f2[:df] # Float loop \n";
[349]325usage += " > end # end loops \n";
[1565]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";
[353]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";
[293]335usage += " > help <command_name> # <command_name> usage info \n";
336usage += " > helpwindow # Displays help window \n";
[349]337usage += " > timingon timingoff traceon traceoff \n";
[330]338string grp = "Commands";
339RegisterHelp(kw, usage, grp);
[293]340
[2203]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
[293]351basexec = new PIABaseExecutor(this, omg, app);
[361]352fitexec = new PIAFitter(this, app);
[463]353pawexec = new PAWExecutor(this, app);
[1251]354CxxExecutor * cxxe = new CxxExecutor(this, app);
355cxxexec = cxxe;
[1828]356
357ContModExecutor *cntxx = new ContModExecutor(this, app);//_OP_
358cntexec = cntxx; //_OP_
[1920]359FlowModExecutor *flwxx = new FlowModExecutor(this, app);//_OP_
360flwexec = flwxx; //_OP_
[1828]361
[1251]362cxxoptwin = new CxxOptionWind(app, cxxe);
363cxxexwin = new CxxExecWind(app, cxxe);
364
[293]365AddInterpreter(this);
366curcmdi = this;
[165]367}
368
369/* --Methode-- */
370PIACmd::~PIACmd()
371{
372hist.close();
373if (gltimer) { delete gltimer; gltimer = NULL; }
[293]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;
[1251]382delete cxxexwin;
383delete cxxoptwin;
[293]384if (curpiacmd == this) curpiacmd = NULL;
[361]385delete basexec;
386delete fitexec;
[463]387delete pawexec;
[1224]388delete cxxexec;
[165]389}
390
391/* --Methode-- */
[293]392PIACmd* PIACmd::GetInterpreter()
[165]393{
[293]394return(curpiacmd);
395}
[165]396
[293]397/* --Methode-- */
398string PIACmd::Name()
399{
400return("piacmd");
401}
[165]402
[293]403/* --Methode-- */
[330]404void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string grp)
[293]405{
[330]406if (!ce) {
407 RegisterHelp(keyw, usage, grp);
408 return;
409 }
410int gid = CheckHelpGrp(grp);
[293]411cmdex cme;
[330]412cme.group = gid;
[293]413cme.us = usage;
414cme.cex = ce;
415cmdexmap[keyw] = cme;
416}
417
418/* --Methode-- */
[330]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-- */
[293]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;
[165]465 }
[293]466string fname = name + "_init";
467DlModuleInitEndFunction finit = dynlink->GetFunction(fname);
468if (!finit) {
469 cerr << "PIACmd/LoadModule_Error: Pb linking " << fname << endl;
470 return;
[165]471 }
[293]472cout << "PIACmd/LoadModule_Info: Initialisation module" << name
473 << " " << fname << "() ..." << endl;
474finit();
475modmap[name] = dynlink;
476return;
477}
[165]478
[293]479/* --Methode-- */
480void PIACmd::AddInterpreter(CmdInterpreter * cl)
481{
482if (!cl) return;
[349]483interpmap[cl->Name()] = cl;}
[165]484
485/* --Methode-- */
[293]486void PIACmd::SelInterpreter(string& name)
[165]487{
[293]488InterpMap::iterator it = interpmap.find(name);
489if (it == interpmap.end()) return;
490curcmdi = (*it).second;
491}
[165]492
[293]493
494
[357]495/* Fonction */
[368]496static string GetStringFrStdin(PIACmd* piac)
[357]497{
[368]498PIStdImgApp* piapp = piac->GetImgApp();
499if (piapp) {
500 PIBaseWdg* wdg = piapp->CurrentBaseWdg();
501 if (wdg) wdg->Refresh();
[357]502#ifndef __mac__
[368]503 /* On vide le buffer X-Window */
[374]504 XSync(PIXDisplay(),False);
[357]505#endif
[368]506}
[357]507char buff[128];
508fgets(buff, 128, stdin);
509buff[127] = '\0';
510return((string)buff);
511}
512
[293]513/* --Methode-- */
514int PIACmd::Interpret(string& s)
515{
[333]516int rc = 0;
[1262]517NamedObjMgr omg;
[165]518
[1262]519// On saute de commandes vides
520size_t l;
[349]521l = s.length();
522if (l < 1) return(0);
[165]523
[349]524// On enregistre les commandes
525if (histon) hist << s << endl;
526
[1262]527if (s[0] == '#') return(0); // si c'est un commentaire
[349]528
[1276]529// Logique de gestion des lignes suite
530// un \ en derniere position indique la presence d'une ligne suite
[1539]531size_t lnb = s.find_last_not_of(' ');
532if (s[lnb] == '\\' ) { // Lignes suite ...
[1276]533 mulinefg = true;
[1539]534 mulinecmd += s.substr(0,lnb);
[1276]535 mImgApp->GetConsole()->SetPrompt("...? ");
536 return(0);
537}
[165]538
[1276]539if (mulinefg) { // Il y avait des lignes suite
540 s = mulinecmd + s;
541 mulinecmd = "";
542 mulinefg = false;
[1562]543 const char * rprompt = (curblk == NULL) ? "Cmd> " : "for...? ";
[1276]544 mImgApp->GetConsole()->SetPrompt(rprompt);
545}
546
[1262]547// Removing leading blanks
[1276]548size_t p,q;
[1262]549
550p=s.find_first_not_of(" \t");
551if (p < l) s = s.substr(p);
552
[349]553// >>>> Substitution d'alias (1er mot)
[2214]554CmdStrList::iterator it;
[449]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);
[349]565 p = 0;
566 q = s.find_first_of(" ");
567 }
568
569// >>>> Separating keyword
[1262]570string toks,kw;
[165]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
[1562]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
[1565]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
[1562]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
[349]602 PIACmdBloc* curb = curblk;
603 curblk = curb->Parent();
[1562]604 mImgApp->GetConsole()->SetPrompt("Cmd> ");
[349]605 // cout << " *DBG* Executing bloc " << endl;
[1562]606 bool ohv = histon;
607 histon = false;
608 curb->Execute();
609 histon = ohv;
610 }
611 else curblk->AddLine(s);
612 return(0);
613}
[1565]614else if (kw == "end") {
615 cerr << "PIACmd::Interpret()/syntax error - end outside for/foreach bloc \n"
616 << "line: " << s << endl;
617 return(1);
618}
[1562]619
620// Sommes-nous dans un bloc de test if then else
621if (testresult.size() > 0) { // Nous sommes ds un bloc if
[1565]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 {
[1570]629 const char * npr = ((*tresit)&1) ? "else-F> " : "else-T> ";
[1565]630 mImgApp->GetConsole()->SetPrompt(npr);
631 (*tresit) |= 2;
632 return(0);
633 }
634 }
635 else if (kw == "endif") {
636 list<char>::iterator dbit = tresit;
[1562]637 tresit--;
638 testresult.erase(dbit);
[1570]639 const char * npr = "Cmd> ";
[1565]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);
[349]647 return(0);
648 }
[1565]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);
[1562]654}
[349]655
[1565]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
[1262]671// Nous ne sommes donc pas dans un bloc .... Substitution de variables
[1276]672string s2;
673int rcs ;
[1262]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 }
[1276]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);
[1269]687 return(cxxe->ExecuteCXX(s2.substr(1)));
[1262]688 }
689}
690
691
[1276]692rcs = SubstituteVars(s, s2);
693if (rcs) return(rcs);
[1262]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;
[1276]708 if ( (toks[p] == '\'') || (toks[p] == '"') ) {
709 q = toks.find(toks[p],p+1);
710 if (q>=l) {
[1565]711 cerr << "PIACmd::Interpret()/Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl;
[1276]712 return(2);
713 }
714 p++;
715 }
716 else {
717 q = toks.find_first_of(" \t",p); // la fin du token;
718 }
[1262]719 string token = toks.substr(p,q-p);
720 tokens.push_back(token);
721 }
722
723
[1562]724// Si c'est un for/foreach, on cree un nouveau bloc
725if ((kw == "foreach") || (kw == "for")) {
[1262]726 // cout << " *DBG* We got a foreach... " << endl;
[1562]727 PIACmdBloc* bloc = new PIACmdBloc(this, curblk, kw, tokens);
[1262]728 if (!bloc->CheckOK()) {
[1565]729 cerr << "PIACmd::Interpret() for/foreach syntax Error ! " << endl;
[1262]730 delete bloc;
[1565]731 return(1);
[1262]732 }
733 felevel++;
734 if (curblk) curblk->AddBloc(bloc);
[1562]735 else mImgApp->GetConsole()->SetPrompt("for...> ");
[1262]736 curblk = bloc;
737 // cout << " *DBG* New Bloc created ... " << endl;
738 return(0);
739 }
[1565]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;
[1562]748 testresult.push_back(res_tst);
749 if (testresult.size() == 1) tresit = testresult.begin();
750 else tresit++;
[1570]751 const char * npr = (restst) ? "if-T> " : "if-F> ";
[1565]752 mImgApp->GetConsole()->SetPrompt(npr);
[1562]753}
[1565]754// Execution de commandes
[1262]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{
[2214]768NamedObjMgr& omg = *mObjMgr;
[1262]769
770size_t p,q,q2,l;
771
772s2="";
[349]773p = 0;
774l = s.length();
[2214]775string vn, vv;
[349]776while (p < l) {
777 q = s.find('$',p);
[1276]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 }
[349]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) {
[1276]795 cerr << " Syntax error - line ending with $ !!! " << endl;
796 return(2);
[349]797 }
798 vn = "";
799 if ( s[q+1] == '{' ) { // Variable in the form ${name}
800 q2 = s.find('}',q+1);
801 if (q2 >= l) {
[1276]802 cerr << " Syntax error - Unbalenced brace {} !!! " << endl;
803 return(3);
[349]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) {
[1276]811 cerr << " Syntax error - Unbalenced brace [] !!! " << endl;
812 return(4);
[349]813 }
814 vn = s.substr(q+2,q2-q-2);
[2214]815 if (!GetVar(vn, vv)) return(5);
816 vn = vv;
[349]817 q2++;
818 }
819 else {
[1562]820 q2 = s.find_first_of(" .:+-*/,[](){}&|!$\"'",q+1);
[349]821 if (q2 > l) q2 = l;
822 vn = s.substr(q+1, q2-q-1);
823 }
[2214]824 if (!GetVar(vn, vv)) return(5);
825 s2 += (s.substr(p, q-p) + vv);
[349]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
[1262]833return(0);
834}
[349]835
[1262]836/* --Methode-- */
[2214]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-- */
[1565]883int PIACmd::EvaluateTest(vector<string> & args, string & line, bool & res)
[1562]884{
[1565]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);
[1562]899}
900
901/* --Methode-- */
[1262]902int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
903{
904int rc = 0;
905NamedObjMgr omg;
[349]906
[165]907// >>>>>>>>>>> Commande d'interpreteur
[1262]908if (kw == "helpwindow") ShowHelpWindow();
[293]909else if (kw == "help") {
[330]910 if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl;
[293]911 else {
[330]912 string kwh = "piacmd";
913 cout << GetUsage(kwh) << endl;
[293]914 }
[165]915 }
916
917else if (kw == "set") {
[293]918 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); }
[349]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 }
[1276]923 // string xx = tokens[1];
924 // for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk] );
925 omg.SetVar(tokens[0], tokens[1]);
[165]926 }
[349]927
928else if (kw == "getvar") {
929 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: getvar newvarname varname" << endl; return(0); }
[1262]930 if (!omg.HasVar(tokens[1])) {
[349]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 }
[1262]938 omg.SetVar(tokens[0], omg.GetVar(tokens[1]) );
[349]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
[333]952else if (kw == "setol") {
953 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: setol varname objnamepattern" << endl; return(0); }
[349]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 }
[333]958 vector<string> ol;
[349]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 }
[1262]966 omg.SetVar(tokens[0], vol);
[333]967 }
[293]968else if (kw == "unset") {
969 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); }
[1262]970 if (omg.HasVar(tokens[0])) omg.DeleteVar(tokens[0]) ;
[293]971 else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl;
[165]972 }
[333]973else if (kw == "echo") {
[1276]974 for (int ii=0; ii<tokens.size(); ii++)
975 cout << tokens[ii] << " " ;
[333]976 cout << endl;
[1276]977 }
[353]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 }
[357]984 mImgApp->GetConsole()->AddStr(">>> Reading From StdIn \n", PIVA_Magenta);
985 cout << tokens[0] << " ? " << endl;
[1262]986 omg.SetVar(tokens[0], GetStringFrStdin(this) );
[353]987 }
988
[165]989else if (kw == "listvars") {
[293]990 cout << "PIACmd::Interpret() Variable List , VarName = Value \n";
[1262]991 DVList& varlist = omg.GetVarList();
992 DVList::ValList::const_iterator it;
993 string value;
994 for(it = varlist.Begin(); it != varlist.End(); it++) {
[1291]995#ifdef SANS_EVOLPLANCK
996 MuTyV mtv = (*it).second;
997 value = (string)(mtv);
998#else
[1262]999 value = (string)((*it).second.elval);
[1291]1000#endif
[1262]1001 cout << (*it).first << " = " << value << "\n";
1002 }
[165]1003 cout << endl;
1004 }
[353]1005else if (kw == "listalias") {
1006 cout << "PIACmd::Interpret() Alias List , AliasName = Value \n";
[2214]1007 CmdStrList::iterator it;
[353]1008 for(it = mAliases.begin(); it != mAliases.end(); it++)
1009 cout << (*it).first << " = " << (*it).second << "\n";
1010 cout << endl;
1011 }
1012else if (kw == "listcommands") {
[330]1013 cout << "---- PIACmd::Interpret() Command Variable List ----- \n";
[293]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; }
[165]1025else if (kw == "timingon") {
[293]1026 cout << "PIACmd::Interpret() -> Timing ON mode " << endl;
1027 if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true;
1028 }
[165]1029else if (kw == "timingoff") {
[293]1030 cout << "PIACmd::Interpret() -> Timing OFF mode " << endl;
1031 if (gltimer) delete gltimer; gltimer = NULL; timing = false;
1032 }
[165]1033else if (kw == "exec") {
[293]1034 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: exec filename" << endl; return(0); }
[349]1035 ExecFile(tokens[0], tokens);
[165]1036 }
1037else if (kw == "shell") {
[293]1038 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl; return(0); }
[1276]1039 string cmd;
1040 for (int ii=0; ii<tokens.size(); ii++)
1041 cmd += (tokens[ii] + ' ');
1042 system(cmd.c_str());
[165]1043 }
[2203]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 }
[1276]1050
[293]1051// Execution d'une commande enregistree
[1268]1052else rc = ExecuteCommand(kw, tokens, toks);
[165]1053
1054if (timing) gltimer->Split();
[333]1055return(rc);
[165]1056}
1057
[333]1058/* --Methode-- */
[1262]1059int PIACmd::ParseLineExecute(string& line)
[333]1060{
[1262]1061vector<string> tokens;
1062
[333]1063if (line.length() < 1) return(0);
[165]1064
[333]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
[1268]1085return(ExecuteCommand(kw, tokens, toks));
[333]1086}
1087
[165]1088/* --Methode-- */
[1268]1089int PIACmd::ExecuteCommand(string& keyw, vector<string>& args, string& toks)
[333]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 {
[1268]1095 if ((*it).second.cex) rc = (*it).second.cex->Execute(keyw, args, toks);
[333]1096 else cout << "Dont know how to execute " << keyw << " ? " << endl;
1097 }
1098 return(rc);
1099}
1100
1101/* --Methode-- */
[349]1102int PIACmd::ExecFile(string& file, vector<string>& args)
[165]1103{
[293]1104char line_buff[512];
1105FILE *fip;
[165]1106
[293]1107if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
[384]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) {
[293]1117 cerr << "PIACmd::Exec() Error opening file " << file << endl;
1118 hist << "##! PIACmd::Exec() Error opening file " << file << endl;
1119 return(0);
[165]1120 }
[349]1121
1122// hist << "### Executing commands from " << file << endl;
1123
[2214]1124// We push the argument list (args) on the stack
1125ArgsStack.push(args);
[349]1126
[293]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 }
[165]1132
[1562]1133bool ohv = histon;
[349]1134histon = false;
[293]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);
[1565]1140 if (Interpret(line) == 77777) break;
[165]1141 }
[1562]1142histon = ohv;
[349]1143
1144// hist << "### End of Exec( " << file << " ) " << endl;
[293]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);
[165]1149 }
1150
[2214]1151// We remove the argument list (args) from the stack
1152ArgsStack.pop();
1153
[165]1154return(0);
1155}
1156
[2203]1157/* --Methode-- */
1158int PIACmd::CShellExecute(string cmd)
1159{
1160 if(cmd.size()<=0) return -1;
[293]1161
[2203]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
[293]1186static string* videstr = NULL;
1187/* --Methode-- */
1188string& PIACmd::GetUsage(const string& kw)
[165]1189{
[330]1190bool fndok = false;
[293]1191CmdExmap::iterator it = cmdexmap.find(kw);
[330]1192if (it == cmdexmap.end()) {
1193 it = helpexmap.find(kw);
1194 if (it != helpexmap.end()) fndok = true;
[165]1195 }
[330]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
[165]1203}
1204
[293]1205/* --Methode-- */
1206void PIACmd::ShowHelpWindow()
[165]1207{
[293]1208helpwin->Show();
[165]1209}
[357]1210
[463]1211/* --Methode-- */
[1251]1212void PIACmd::ShowCxxOptionWindow()
1213{
1214cxxoptwin->Show();
1215}
1216
1217/* --Methode-- */
1218void PIACmd::ShowCxxExecWindow()
1219{
1220cxxexwin->Show();
1221}
1222
1223/* --Methode-- */
[463]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 }
[357]1231
[463]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++)
[484]1237 fprintf(fip,"\\item {\\bf %s } (p. \\pageref{%s}) \n",
1238 (*it).first.c_str(), (*it).first.c_str());
[463]1239
1240fputs("\\end{itemize} \n",fip);
1241
[484]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
[463]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;
[484]1286 fprintf(fip,"\\subsection{%s} \\label{%s} \n",
1287 (*it).first.c_str(), (*it).first.c_str());
[463]1288 for(ite = helpexmap.begin(); ite != helpexmap.end(); ite++) {
1289 if ((*ite).second.group != gid) continue;
[484]1290 fprintf(fip,"{ \\Large $ \\star \\star \\star $ } Help item {\\bf \\Large %s } \\label{%s} \n",
1291 (*ite).first.c_str(), (*ite).first.c_str());
[463]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;
[484]1298 fprintf(fip,"{ \\Large $ \\star \\star \\star $ } Command {\\bf \\Large %s } \\label{%s} \n",
1299 (*ite).first.c_str(), (*ite).first.c_str());
[463]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.