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

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

Correction changement prompt console ds PIACmd pour les ligens suites - Reza 4/12/02

File size: 52.7 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"
[2215]12#include "strutilxx.h"
[293]13// #include "dlftypes.h"
[165]14
[293]15#include "pistdimgapp.h"
[165]16#include "nobjmgr.h"
[361]17#include "piafitting.h"
[463]18#include "pawexecut.h"
[1224]19#include "cxxexecutor.h"
[1251]20#include "cxxexecwin.h"
[1828]21#include "contmodex.h"
[1920]22#include "flowmodex.h"
[165]23
[293]24#include PISTDWDG_H
25#include PILIST_H
[165]26
[293]27// ------------------------------------------------------------
[349]28// Gestion d'une fenetre d'aide interactive
29// Classe PIAHelpWind
[293]30// ------------------------------------------------------------
[165]31
[293]32class PIAHelpWind : public PIWindow {
33public :
34 PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd);
35 virtual ~PIAHelpWind();
[330]36 virtual void Show();
[293]37 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
[330]38 inline void AddHelpGroup(const char * hgrp, int gid)
39 { hgrpom->AppendItem(hgrp, 20000+gid); }
40 inline void ClearHelpList()
41 { mNitem=0; hitemlist->DeleteAllItems(); }
[293]42 inline void AddHelpItem(const char * hitem)
[330]43 { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
[293]44protected :
45 PIStdImgApp* dap;
46 PIACmd* piac;
47 int mNitem;
48 PIList* hitemlist;
[330]49 PIOptMenu* hgrpom;
[293]50 PIButton * mBut;
51 PILabel * mLab;
52 PIText* mTxt;
53};
[165]54
[293]55/* --Methode-- */
56PIAHelpWind::PIAHelpWind(PIStdImgApp *par, PIACmd* piacmd)
57 : PIWindow((PIMsgHandler *)par, "Help-PIApp", PIWK_normal, 400, 300, 100, 350)
58{
59dap = par;
60piac = piacmd;
61mNitem = 0;
[330]62SetMsg(77);
[165]63
[293]64int bsx, bsy;
65int tsx, tsy;
66int spx, spy;
67PIApplicationPrefCompSize(bsx, bsy);
68spx = bsx/6; spy = bsy/6;
69tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy;
70SetSize(tsx,tsy);
[330]71hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy);
72hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
73hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy);
[293]74hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
75// hitemlist->SetBorderWidth(2);
[324]76mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
77// mTxt->SetMutiLineMode(true);
[293]78mTxt->SetTextEditable(false);
79mTxt->SetText("");
80mTxt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
81mLab = new PILabel(this, "helpitem", bsx*4, bsy, bsx*2.5+2*spx, tsy-spy-bsy);
82mLab->SetBorderWidth(1);
83mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
84mLab->SetLabel("");
[330]85mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
[293]86mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
87}
[165]88
89/* --Methode-- */
[293]90PIAHelpWind::~PIAHelpWind()
91{
[330]92delete hgrpom;
[293]93delete hitemlist;
94delete mTxt;
95delete mLab;
96delete mBut;
97}
98
99/* --Methode-- */
100void PIAHelpWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
101{
102PIMessage um = UserMsg(msg);
[330]103if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
[293]104 Hide();
105 return;
106 }
[330]107else if ( (um >= 20000) && (sender == hgrpom)) { // Selection de groupe de Help
108 mTxt->SetText("");
109 mLab->SetLabel("");
110 piac->UpdateHelpList(this, um-20000);
111}
112else if ( (um > 100) && (sender == hitemlist) && (ModMsg(msg) == PIMsg_Select) ) {
[293]113 string s = hitemlist->GetSelectionStr();
114 mTxt->SetText(piac->GetUsage(s));
115 mLab->SetLabel(s);
116 }
117}
118
[330]119/* --Methode-- */
120void PIAHelpWind::Show()
121{
122hgrpom->SetValue(20000); // Groupe All
123mTxt->SetText("");
124mLab->SetLabel("");
125piac->UpdateHelpList(this, 0);
126PIWindow::Show();
127}
[293]128
[349]129// ------------------------------------------------------------
130// Bloc de commandes (Foreach, ...)
131// Classe PIACmdBloc
132// ------------------------------------------------------------
133
134class PIACmdBloc {
135public:
[1262]136 enum BType { BT_None, BT_ForeachList, BT_ForeachInt, BT_ForeachFloat };
137
[1562]138 PIACmdBloc(PIACmd* piac, PIACmdBloc* par, string& kw, vector<string>& args);
[1262]139 ~PIACmdBloc();
[349]140 inline PIACmdBloc* Parent() { return(parent); }
[1262]141 inline bool CheckOK() { return blkok; }
[349]142 inline void AddLine(string& line)
143 { lines.push_back(line); bloclineid.push_back(lines.size()); }
[2215]144 void AddLine(string& line, string& kw);
[349]145 inline void AddBloc(PIACmdBloc* blk)
146 { blocs.push_back(blk); bloclineid.push_back(-blocs.size()); }
147 PIACmdBloc* Execute();
[2215]148 inline int& TestLevel() { return testlevel; }
[2236]149 inline int& LoopLevel() { return looplevel; }
150 inline bool CheckBloc()
151 { return ((testlevel == 0)&&(looplevel == 0)&&(!scrdef)); }
152
[349]153protected:
154 PIACmd* piacmd;
155 PIACmdBloc* parent;
[1262]156 bool blkok; // true -> block OK
157 BType typ; // foreach , integer loop, float loop, test
[349]158 string varname;
159 vector<string> strlist;
160 vector<string> lines;
161 vector<PIACmdBloc *> blocs;
162 vector<int> bloclineid;
163 int i1,i2,di;
164 float f1,f2,df;
[2215]165 int testlevel; // niveau d'imbrication des if
[2236]166 int looplevel; // niveau d'imbrication des for/foreach
167 bool scrdef; // true -> commande defscript ds for/foreach
[349]168};
169
170/* --Methode-- */
[1562]171PIACmdBloc::PIACmdBloc(PIACmd* piac, PIACmdBloc* par, string& kw, vector<string>& args)
[349]172{
173piacmd = piac;
174parent = par;
[1262]175blkok = false;
176typ = BT_None;
[349]177i1 = 0; i2 = -1; di = 1;
178f1 = 0.; f2 = -1.; df = 1.;
[2236]179testlevel = looplevel = 0;
180scrdef = false;
181
[349]182if ((args.size() < 2) || !isalpha((int)args[0][0]) ) return;
[1562]183if ((kw != "foreach") && (kw != "for")) return;
184varname = args[0]; // $CHECK$ Variable name should be checked
185//if (isalpha((int)args[1][0]) ) { This is a foreach bloc with string list
186if (kw == "foreach" ) { // This is a foreach bloc with string list
[2215]187 if ((args[1] != "(") || (args[args.size()-1] != ")") ) return;
188 for(int kk=2; kk<args.size()-1; kk++) strlist.push_back(args[kk]);
[1262]189 typ = BT_ForeachList;
[1276]190 blkok = true;
[349]191 }
192else { // This is an integer or float loop
193 size_t l = args[1].length();
194 size_t p = args[1].find(':');
195 size_t pp = args[1].find('.');
196 bool fl = (pp < l) ? true : false; // Float loop or integer loop
197 if (p >= l) return; // Syntaxe error
198 string a1 = args[1].substr(0, p);
199 string aa = args[1].substr(p+1);
200 p = aa.find(':');
201 string a2, a3;
202 bool hasa3 = false;
203 if (p < aa.length() ) {
204 a2 = aa.substr(0,p);
205 a3 = aa.substr(p+1);
206 hasa3 = true;
207 }
208 else a2 = aa;
209 if (fl) {
[1262]210 typ = BT_ForeachFloat;
[1276]211 blkok = true;
[349]212 f1 = atof(a1.c_str());
213 f2 = atof(a2.c_str());
214 if (hasa3) df = atof(a3.c_str());
215 else df = 1.;
216 }
217 else {
[1262]218 typ = BT_ForeachInt;
[1276]219 blkok = true;
[349]220 i1 = atoi(a1.c_str());
221 i2 = atoi(a2.c_str());
222 if (hasa3) di = atoi(a3.c_str());
223 else di = 1;
224 }
225 }
226}
227
228/* --Methode-- */
229PIACmdBloc::~PIACmdBloc()
230{
231for(int k=0; k<blocs.size(); k++) delete blocs[k];
232}
233
234/* --Methode-- */
[2215]235void PIACmdBloc::AddLine(string& line, string& kw)
236{
237 AddLine(line);
238 if (kw == "if") testlevel++;
239 else if (kw == "endif") testlevel--;
[2236]240 else if ((kw == "for") || (kw == "foreach")) looplevel++;
241 else if (kw == "end") looplevel--;
242 else if (kw == "defscript") scrdef = true;
[2215]243}
244
245/* --Methode-- */
[349]246PIACmdBloc* PIACmdBloc::Execute()
247{
248// cout << " DBG * PIACmdBloc::Execute() " << typ << " - " << bloclineid.size() <<
249// " I1,I2=" << i1 << " , " << i2 << " , " << di << endl;
250string cmd;
251int k=0;
252int kj=0;
253int kk=0;
254char buff[32];
[2215]255int rcc = 0;
256
[1262]257if (typ == BT_ForeachList) // foreach string loop
[349]258 for(k=0; k<strlist.size(); k++) {
[1565]259 cmd = "set " + varname + " '" + strlist[k] + "'";
[349]260 piacmd->Interpret(cmd);
261 for(kj=0; kj<bloclineid.size(); kj++) {
262 kk = bloclineid[kj];
[2215]263 if (kk > 0) {
264 rcc = piacmd->Interpret(lines[kk-1]);
265 if (rcc == 77766) break;
266 }
[349]267 else blocs[-kk-1]->Execute();
[2215]268 }
269 if (rcc == 77766) break;
[349]270 }
[1262]271else if (typ == BT_ForeachInt) // Integer loop
[349]272 for(int i=i1; i<i2; i+=di) {
273 k++;
274 if (++k > 9999) {
275 cout << ">>> Maximum PIACmdBloc loop limit (9999) -> break " << endl;
276 break;
277 }
278 sprintf(buff, " %d", i);
279 cmd = "set " + varname + buff;
280 piacmd->Interpret(cmd);
281 for(kj=0; kj<bloclineid.size(); kj++) {
282 kk = bloclineid[kj];
[2215]283 if (kk > 0) {
284 rcc = piacmd->Interpret(lines[kk-1]);
285 if (rcc == 77766) break;
286 }
[349]287 else blocs[-kk-1]->Execute();
[2215]288 }
289 if (rcc == 77766) break;
[349]290 }
[1262]291else if (typ == BT_ForeachFloat) // float loop
[349]292 for(float f=f1; f<f2; f+=df) {
293 k++;
294 if (++k > 9999) {
295 cout << ">>> Maximum PIACmdBloc loop limit (9999) -> break " << endl;
296 break;
297 }
298 sprintf(buff, " %g", f);
299 cmd = "set " + varname + buff;
300 piacmd->Interpret(cmd);
301 for(kj=0; kj<bloclineid.size(); kj++) {
302 kk = bloclineid[kj];
[2215]303 if (kk > 0) {
304 rcc = piacmd->Interpret(lines[kk-1]);
305 if (rcc == 77766) break;
306 }
[349]307 else blocs[-kk-1]->Execute();
[2215]308 }
309 if (rcc == 77766) break;
[349]310 }
311
312return(parent);
313}
314
[2236]315// ---------------------------------------------------------------
316// Classe PIACmdScript
317// Definition et execution d'un script de PIACmd
318// script : Une liste de commande PIACmd - Lors de l'execution,
319// les variables-argument $# $0 $1 sont definies.
320// ---------------------------------------------------------------
321
[2214]322class PIACmdScript {
323public:
[2236]324 PIACmdScript(PIACmd* piac, string const& name, string const& comm);
[2214]325 virtual ~PIACmdScript();
[2236]326
327 void AddLine(string& line, string& kw);
328 virtual int Execute(vector<string>& args);
329
330 inline string& Name() { return mName; }
331 inline string& Comment() { return mComm; }
332 inline int& TestLevel() { return testlevel; }
333 inline int& LoopLevel() { return looplevel; }
334 inline bool CheckScript()
335 { return ((testlevel == 0)&&(looplevel == 0)&&(!scrdef)&&fgok); }
336
337protected:
338 PIACmd* piacmd;
339 string mName;
340 string mComm;
341 vector<string> lines;
342 int testlevel; // niveau d'imbrication des if
343 int looplevel; // niveau d'imbrication des for/foreach
344 bool scrdef; // true -> commande defscript ds for/foreach
345 bool fgok; // Script name OK
346
[2214]347};
348
[2236]349/* --Methode-- */
350PIACmdScript::PIACmdScript(PIACmd* piac, string const& name,
351 string const& comm)
352{
353piacmd = piac;
354testlevel = looplevel = 0;
355scrdef = false;
356mName = name;
357if (!isalpha(name[0])) fgok = false;
358else fgok = true;
359mComm = comm;
360}
361
362/* --Methode-- */
363PIACmdScript::~PIACmdScript()
364{
365}
366
367/* --Methode-- */
368void PIACmdScript::AddLine(string& line, string& kw)
369{
370 if (kw == "if") testlevel++;
371 else if (kw == "endif") testlevel--;
372 else if ((kw == "for") || (kw == "foreach")) looplevel++;
373 else if (kw == "end") looplevel--;
374 else if (kw == "defscript") scrdef = true;
375 lines.push_back(line);
376}
377
378/* --Methode-- */
379int PIACmdScript::Execute(vector<string>& args)
380{
381 if (!CheckScript()) return(-1);
382 cout << " PIACmdScript::Execute() - Executing script " << Name() << endl;
383 for(int k=0; k<lines.size(); k++) {
384 if (piacmd->Interpret(lines[k]) == 77777) break;
385 }
386 return(0);
387}
388
[349]389// ------------------------------------------------------------
390// Classe PIACmd
391// ------------------------------------------------------------
392
[293]393static PIACmd* curpiacmd = NULL;
394/* --Methode-- */
[165]395PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
396{
[293]397mObjMgr = omg;
[165]398mImgApp = app;
399system("cp history.pic hisold.pic");
400hist.open("history.pic");
[349]401histon = true;
[165]402trace = false; timing = false;
403gltimer = NULL;
[349]404felevel = 0;
[2215]405
[1276]406mulinecmd = "";
407mulinefg = false;
[2274]408spromptmul = "Cmd> ";
409if (mImgApp) mImgApp->GetConsole()->SetPrompt(spromptmul);
[2236]410curscript = NULL;
[293]411
[2215]412CmdBlks.push(NULL);
413list<char> xtx;
414TestsStack.push(xtx);
415curtestresult = true;
416
[330]417cmdhgrp["All"] = 0;
418cmdgrpid = 1;
419cmdhgrp["Commands"] = 1;
[293]420helpwin = new PIAHelpWind(app, this);
[330]421helpwin->AddHelpGroup("All", 0);
422helpwin->AddHelpGroup("Commands", 1);
[293]423
424string kw = "piacmd";
425string usage;
426usage = ">>> (piacmd) Interpreter's keywords : \n";
[349]427usage += " > set varname string # To set a variable, $varname \n";
428usage += " > get newvarname varname # To set a newvariable, equal to $varname \n";
[333]429usage += " > setol varname patt # Fills varname with object list \n";
[293]430usage += " > unset varname # clear variable definition \n";
[2241]431usage += " > rpneval varname RPNExpression # Reverse Polish Notation evaluation \n";
[333]432usage += " > echo string # output string \n";
[353]433usage += " > alias name string # define a command alias \n";
434usage += " > readstdin varname # reads a line from stdin into $varname \n";
[2241]435usage += " > foreach varname ( string-list ) # Loop \n";
[1562]436usage += " > for varname i1:i2[:di] # Integer loop \n";
437usage += " > for varname f1:f2[:df] # Float loop \n";
[349]438usage += " > end # end loops \n";
[2241]439usage += " > if ( test ) then # Conditional test : a == != < > <= >= b \n";
[1565]440usage += " > else # Conditional \n";
441usage += " > endif # End of conditional if bloc \n";
442usage += " > break # Delete (clears) all test and loop blocs \n";
443usage += " > return # Stops command execution from a file \n";
[2236]444usage += " > defscript endscript # Command script definition \n";
[353]445usage += " > listvars # List of variable names and values \n";
446usage += " > listalias # List of alias names and values \n";
447usage += " > listcommands # List of all known commands \n";
[2236]448usage += " > listscripts # List of all known scripts \n";
449usage += " > clearcript # Clear a script definition \n";
[353]450usage += " > exec filename # Execute commands from file \n";
[293]451usage += " > help <command_name> # <command_name> usage info \n";
452usage += " > helpwindow # Displays help window \n";
[349]453usage += " > timingon timingoff traceon traceoff \n";
[330]454string grp = "Commands";
455RegisterHelp(kw, usage, grp);
[293]456
[2203]457kw = "shell execute";
458usage = "> shell command_string # Execute shell command\n";
459usage += "> cshell command_string # Execute cshell command\n";
460usage += "---Exemples:\n";
461usage += " > shell ls\n";
462usage += " > cshell echo '$LD_LIBRARY_PATH'; map2cl -h; ls\n";
463usage += " > shell myfile.csh [arg1] [arg2] [...]\n";
464usage += " (where the first line of \"myfile.csh\" is \"#!/bin/csh\")\n";
465RegisterHelp(kw, usage, grp);
466
[293]467basexec = new PIABaseExecutor(this, omg, app);
[361]468fitexec = new PIAFitter(this, app);
[463]469pawexec = new PAWExecutor(this, app);
[1251]470CxxExecutor * cxxe = new CxxExecutor(this, app);
471cxxexec = cxxe;
[1828]472
473ContModExecutor *cntxx = new ContModExecutor(this, app);//_OP_
474cntexec = cntxx; //_OP_
[1920]475FlowModExecutor *flwxx = new FlowModExecutor(this, app);//_OP_
476flwexec = flwxx; //_OP_
[1828]477
[1251]478cxxoptwin = new CxxOptionWind(app, cxxe);
479cxxexwin = new CxxExecWind(app, cxxe);
480
[293]481AddInterpreter(this);
482curcmdi = this;
[165]483}
484
485/* --Methode-- */
486PIACmd::~PIACmd()
487{
488hist.close();
489if (gltimer) { delete gltimer; gltimer = NULL; }
[293]490Modmap::iterator it;
491for(it = modmap.begin(); it != modmap.end(); it++) {
492 string name = (*it).first + "_end";
493 DlModuleInitEndFunction fend = (*it).second->GetFunction(name);
494 if (fend) fend();
495 delete (*it).second;
496 }
[2236]497
498for(ScriptList::iterator sit = mScripts.begin();
499 sit != mScripts.end(); sit++) delete (*sit).second;
500
[293]501delete helpwin;
[1251]502delete cxxexwin;
503delete cxxoptwin;
[293]504if (curpiacmd == this) curpiacmd = NULL;
[361]505delete basexec;
506delete fitexec;
[463]507delete pawexec;
[1224]508delete cxxexec;
[165]509}
510
511/* --Methode-- */
[293]512PIACmd* PIACmd::GetInterpreter()
[165]513{
[293]514return(curpiacmd);
515}
[165]516
[293]517/* --Methode-- */
518string PIACmd::Name()
519{
520return("piacmd");
521}
[165]522
[293]523/* --Methode-- */
[330]524void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string grp)
[293]525{
[330]526if (!ce) {
527 RegisterHelp(keyw, usage, grp);
528 return;
529 }
530int gid = CheckHelpGrp(grp);
[293]531cmdex cme;
[330]532cme.group = gid;
[293]533cme.us = usage;
534cme.cex = ce;
535cmdexmap[keyw] = cme;
536}
537
538/* --Methode-- */
[330]539void PIACmd::RegisterHelp(string& keyw, string& usage, string& grp)
540{
541int gid = CheckHelpGrp(grp);
542cmdex cme;
543cme.group = gid;
544cme.us = usage;
545cme.cex = NULL;
546helpexmap[keyw] = cme;
547}
548
549/* --Methode-- */
550int PIACmd::CheckHelpGrp(string& grp)
551{
552int gid=0;
553CmdHGroup::iterator it = cmdhgrp.find(grp);
554if (it == cmdhgrp.end()) {
555 cmdgrpid++; gid = cmdgrpid;
556 cmdhgrp[grp] = gid;
557 helpwin->AddHelpGroup(grp.c_str(), gid);
558 }
559else gid = (*it).second;
560return(gid);
561}
562
563/* --Methode-- */
564void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
565{
566helpwin->ClearHelpList();
567CmdExmap::iterator it;
568for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
569 if ( (gid != 0) && ((*it).second.group != gid) ) continue;
570 helpwin->AddHelpItem((*it).first.c_str());
571 }
572for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
573 if ( (gid != 0) && ((*it).second.group != gid) ) continue;
574 helpwin->AddHelpItem((*it).first.c_str());
575 }
576}
577
578/* --Methode-- */
[293]579void PIACmd::LoadModule(string& fnameso, string& name)
580{
581PDynLinkMgr * dynlink = new PDynLinkMgr(fnameso, false);
582if (dynlink == NULL) {
583 cerr << "PIACmd/LoadModule_Error: Pb opening SO " << fnameso << endl;
584 return;
[165]585 }
[293]586string fname = name + "_init";
587DlModuleInitEndFunction finit = dynlink->GetFunction(fname);
588if (!finit) {
589 cerr << "PIACmd/LoadModule_Error: Pb linking " << fname << endl;
590 return;
[165]591 }
[293]592cout << "PIACmd/LoadModule_Info: Initialisation module" << name
593 << " " << fname << "() ..." << endl;
594finit();
595modmap[name] = dynlink;
596return;
597}
[165]598
[293]599/* --Methode-- */
600void PIACmd::AddInterpreter(CmdInterpreter * cl)
601{
602if (!cl) return;
[349]603interpmap[cl->Name()] = cl;}
[165]604
605/* --Methode-- */
[293]606void PIACmd::SelInterpreter(string& name)
[165]607{
[293]608InterpMap::iterator it = interpmap.find(name);
609if (it == interpmap.end()) return;
610curcmdi = (*it).second;
611}
[165]612
[293]613
614
[357]615/* Fonction */
[368]616static string GetStringFrStdin(PIACmd* piac)
[357]617{
[368]618PIStdImgApp* piapp = piac->GetImgApp();
619if (piapp) {
620 PIBaseWdg* wdg = piapp->CurrentBaseWdg();
621 if (wdg) wdg->Refresh();
[357]622#ifndef __mac__
[368]623 /* On vide le buffer X-Window */
[374]624 XSync(PIXDisplay(),False);
[357]625#endif
[368]626}
[357]627char buff[128];
628fgets(buff, 128, stdin);
629buff[127] = '\0';
630return((string)buff);
631}
632
[293]633/* --Methode-- */
634int PIACmd::Interpret(string& s)
635{
[333]636int rc = 0;
[1262]637NamedObjMgr omg;
[2236]638ScriptList::iterator sit;
[165]639
[1262]640// On saute de commandes vides
641size_t l;
[349]642l = s.length();
[2285]643if (!mulinefg && (l < 1)) return(0);
[165]644
[349]645// On enregistre les commandes
646if (histon) hist << s << endl;
647
[1262]648if (s[0] == '#') return(0); // si c'est un commentaire
[349]649
[1276]650// Logique de gestion des lignes suite
651// un \ en derniere position indique la presence d'une ligne suite
[1539]652size_t lnb = s.find_last_not_of(' ');
653if (s[lnb] == '\\' ) { // Lignes suite ...
654 mulinecmd += s.substr(0,lnb);
[2285]655 if (!mulinefg) {
656 spromptmul = mImgApp->GetConsole()->GetPrompt();
657 mImgApp->GetConsole()->SetPrompt("...? ");
658 mulinefg = true;
659 }
[1276]660 return(0);
661}
[165]662
[1276]663if (mulinefg) { // Il y avait des lignes suite
664 s = mulinecmd + s;
665 mulinecmd = "";
666 mulinefg = false;
[2274]667 mImgApp->GetConsole()->SetPrompt(spromptmul);
[1276]668}
669
[1262]670// Removing leading blanks
[1276]671size_t p,q;
[1262]672
673p=s.find_first_not_of(" \t");
674if (p < l) s = s.substr(p);
675
[349]676// >>>> Substitution d'alias (1er mot)
[2214]677CmdStrList::iterator it;
[449]678p = 0;
679q = s.find_first_of(" \t");
680l = s.length();
681string w1 = (q < l) ? s.substr(p,q-p) : s.substr(p);
682it = mAliases.find(w1);
683if (it != mAliases.end()) {
684 s = (q < l) ? ((*it).second + s.substr(q)) : (*it).second ;
685 l = s.length();
686 p=s.find_first_not_of(" \t");
687 if (p < l) s = s.substr(p);
[349]688 p = 0;
689 q = s.find_first_of(" ");
690 }
691
692// >>>> Separating keyword
[1262]693string toks,kw;
[165]694if (q < l)
695 { kw = s.substr(p,q-p); toks = s.substr(q, l-q); }
696else { kw = s.substr(p,l-p); toks = ""; }
697
[1562]698// les mot-cle end else endif doivent etre le seul mot de la ligne
[2236]699if ( (kw == "end") || (kw == "else") || (kw == "endif") || (kw == "endscript") ) {
[1562]700 size_t ltk = toks.length();
701 if (toks.find_first_not_of(" \t") < ltk) {
[2236]702 cerr << "PIACmd::Interpret()/syntax error near end else endif endscript \n"
[1562]703 << "line: " << s << endl;
704 return(1);
705 }
706}
707
[2236]708// On verifie si on est en train de definir un script
709if (curscript) {
710 if (kw == "endscript") {
711 if (curscript->CheckScript()) {
712 sit = mScripts.find(curscript->Name());
713 if (sit != mScripts.end()) {
714 cout << "PIACmd::Interpret() replacing script "
715 << curscript->Name() << endl;
716 PIACmdScript* scr = mScripts[curscript->Name()];
717 mScripts.erase(sit);
718 delete scr;
719 }
720 cout << "PIACmd::Interpret() Script " << curscript->Name()
721 << " defined successfully" << endl;
722 mScripts[curscript->Name()] = curscript;
723 mImgApp->GetConsole()->SetPrompt("Cmd> ");
724 curscript = NULL;
725 return(0);
726 }
727 else {
728 cout << "PIACmd::Interpret() Error in Script " << curscript->Name()
729 << " definition " << endl;
730 mImgApp->GetConsole()->SetPrompt("Cmd> ");
731 curscript = NULL;
732 return(2);
733 }
734 }
735 else curscript->AddLine(s, kw);
736 return(0);
737}
[1562]738// On verifie si nous sommes dans un bloc (for , foreach)
[2215]739if (CmdBlks.top() != NULL) { // On est dans un bloc
[1562]740 if ( (kw == "for") || (kw == "foreach")) felevel++;
741 else if (kw == "end") felevel--;
742 if (felevel == 0) { // Il faut executer le bloc
[2215]743 PIACmdBloc* curb = CmdBlks.top();
744 CmdBlks.top() = curb->Parent();
[1562]745 mImgApp->GetConsole()->SetPrompt("Cmd> ");
[2236]746 if (!curb->CheckBloc()) {
[2215]747 cerr << "PIACmd::Interpret()/syntax error - unbalenced if ... endif"
748 << " within for/foreach bloc ! " << endl;
749 delete curb;
750 return(2);
751 }
[349]752 // cout << " *DBG* Executing bloc " << endl;
[1562]753 bool ohv = histon;
754 histon = false;
[2215]755 if (curtestresult) {
756 // We push also PIACmdBloc and testresult on the stack
757 CmdBlks.push(NULL);
758 list<char> xtx;
759 TestsStack.push(xtx);
760 curb->Execute();
761 // And PIACmdBloc and TestResult from the corresponding stacks
762 PopStack(false);
763 }
764 delete curb;
[1562]765 histon = ohv;
766 }
[2215]767 else CmdBlks.top()->AddLine(s, kw);
[1562]768 return(0);
769}
[1565]770else if (kw == "end") {
771 cerr << "PIACmd::Interpret()/syntax error - end outside for/foreach bloc \n"
772 << "line: " << s << endl;
773 return(1);
774}
[1562]775
776// Sommes-nous dans un bloc de test if then else
[2215]777if (TestsStack.top().size() > 0) { // Nous sommes ds un bloc if
[1565]778 if (kw == "else") {
779 if ((*tresit) & 2) {
780 cerr << "PIACmd::Interpret()/syntax error - multiple else in if bloc \n"
781 << "line: " << s << endl;
782 return(1);
783 }
784 else {
[1570]785 const char * npr = ((*tresit)&1) ? "else-F> " : "else-T> ";
[2215]786 if ((*tresit)&1) curtestresult = false;
[1565]787 mImgApp->GetConsole()->SetPrompt(npr);
788 (*tresit) |= 2;
789 return(0);
790 }
791 }
792 else if (kw == "endif") {
793 list<char>::iterator dbit = tresit;
[1562]794 tresit--;
[2215]795 TestsStack.top().erase(dbit);
[1570]796 const char * npr = "Cmd> ";
[2215]797 if (TestsStack.top().size() > 1) {
798 curtestresult = true;
799 list<char>::iterator it;
800 for(it=TestsStack.top().begin(); it!=TestsStack.top().end(); it++) {
801 // Si on n'est pas ds le else et le if est faux
802 if ( !((*it)&2) && !((*it)&1) ) curtestresult = false;
803 // Si on est ds else et le if etait vrai !
804 if ( ((*it)&2) && ((*it)&1) ) curtestresult = false;
805 if (!curtestresult) break;
806 }
807
[1565]808 if (!((*tresit)&2))
809 npr = ((*tresit)&1) ? "if-T> " : "if-F> ";
810 else
811 npr = ((*tresit)&1) ? "else-F> " : "else-T> ";
812 }
[2215]813 else curtestresult = true;
[1565]814 mImgApp->GetConsole()->SetPrompt(npr);
[349]815 return(0);
816 }
[1565]817}
818else if ((kw == "else") || (kw == "endif")) {
819 cerr << "PIACmd::Interpret()/syntax error - else,endif outside if bloc \n"
820 << "line: " << s << endl;
821 return(1);
[1562]822}
[349]823
[1565]824bool fgcont = true;
[2215]825if (TestsStack.top().size() > 0) { // Resultat de if ou else
[1565]826 list<char>::iterator it;
[2215]827 for(it=TestsStack.top().begin(); it!=TestsStack.top().end(); it++) {
[1565]828 // Si on n'est pas ds le else et le if est faux
829 if ( !((*it)&2) && !((*it)&1) ) fgcont = false;
830 // Si on est ds else et le if etait vrai !
831 if ( ((*it)&2) && ((*it)&1) ) fgcont = false;
832 if (!fgcont) break;
833 }
834}
835
836if ((!fgcont) && (kw != "if")) return(0);
837
838
[2215]839// Les mots cles break et return peuvent de sortir de boucles/scripts/execfile
840if (kw == "break") return(77766);
841else if (kw == "return") return(77777);
842
[1262]843// Nous ne sommes donc pas dans un bloc .... Substitution de variables
[1276]844string s2;
845int rcs ;
[1262]846// Execution de code C++
847
[2236]848if (kw == "@@") {
[1262]849 CxxExecutor * cxxe = dynamic_cast<CxxExecutor *>(cxxexec);
850 if (cxxe == NULL) {
851 cerr << "PIACmd::Interpret() - BUG !!! Not a CxxExecutor " << endl;
852 return(99);
853 }
[2236]854 return(cxxe->ExecuteCXX(s.substr(2)));
[1262]855}
856
857
[1276]858rcs = SubstituteVars(s, s2);
859if (rcs) return(rcs);
[1262]860
861// >>>> Separating keyword and tokens
862vector<string> tokens;
[2236]863/*
[1262]864q = s2.find(' ');
865l = s2.length();
866if (q < l)
867 { kw = s2.substr(0,q); toks = s2.substr(q, l-q); }
868else { kw = s2; toks = ""; }
869
870q = 0;
871while (q < l) {
872 p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
873 if (p>=l) break;
[1276]874 if ( (toks[p] == '\'') || (toks[p] == '"') ) {
875 q = toks.find(toks[p],p+1);
876 if (q>=l) {
[1565]877 cerr << "PIACmd::Interpret()/Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl;
[1276]878 return(2);
879 }
880 p++;
881 }
882 else {
883 q = toks.find_first_of(" \t",p); // la fin du token;
884 }
[1262]885 string token = toks.substr(p,q-p);
886 tokens.push_back(token);
887 }
[2236]888*/
889/* decoupage en mots */
890LineToWords(s2, kw, tokens, toks, true);
[1562]891// Si c'est un for/foreach, on cree un nouveau bloc
892if ((kw == "foreach") || (kw == "for")) {
[1262]893 // cout << " *DBG* We got a foreach... " << endl;
[2215]894 PIACmdBloc* bloc = new PIACmdBloc(this, CmdBlks.top(), kw, tokens);
[1262]895 if (!bloc->CheckOK()) {
[1565]896 cerr << "PIACmd::Interpret() for/foreach syntax Error ! " << endl;
[1262]897 delete bloc;
[1565]898 return(1);
[1262]899 }
900 felevel++;
[2215]901 if (CmdBlks.top()) CmdBlks.top()->AddBloc(bloc);
[1562]902 else mImgApp->GetConsole()->SetPrompt("for...> ");
[2215]903 CmdBlks.top() = bloc;
[1262]904 // cout << " *DBG* New Bloc created ... " << endl;
905 return(0);
906 }
[1565]907else if (kw == "if") { // Un test if
908 bool restst = true;
909 int rct = EvaluateTest(tokens, s, restst);
910 if (rct) {
911 cerr << "PIACmd::Interpret() if syntax Error ! " << endl;
912 return(1);
913 }
914 char res_tst = (restst) ? 1 : 0;
[2215]915 TestsStack.top().push_back(res_tst);
916 if (TestsStack.top().size() == 1) tresit = TestsStack.top().begin();
[1562]917 else tresit++;
[1570]918 const char * npr = (restst) ? "if-T> " : "if-F> ";
[1565]919 mImgApp->GetConsole()->SetPrompt(npr);
[1562]920}
[2241]921else if ((tokens.size() > 0) && (tokens[0] == "=")) {
922 // x = RPNExpression (Evaluation d'expression RPN)
923 tokens[0] = kw;
924 int rcev = EvalRPNExpr(tokens, s);
[2236]925 if (rcev) {
[2241]926 cerr << "PIACmd::Interpret() evaluation (RPN) syntax Error ! " << endl;
[2236]927 return(1);
928 }
929 return(0);
930}
931else if (kw == "defscript") { // definition de script
[2275]932 if (tokens.size() > 0) {
933 if (tokens.size() < 2) tokens.push_back("");
934 curscript = new PIACmdScript(this, tokens[0], tokens[1]);
935 mImgApp->GetConsole()->SetPrompt("Script...> ");
936 return(0);
937 }
938 else {
939 cerr << "PIACmd::Interpret() No script name in defscript" << endl;
940 return(1);
941 }
[2236]942}
943else {
944 // Si c'est le nom d'un script
945 sit = mScripts.find(kw);
946 if (sit != mScripts.end()) {
947 bool ohv = histon;
948 histon = false;
949 PushStack(tokens);
950 (*sit).second->Execute(tokens);
951 PopStack(true);
952 histon = ohv;
953 }
954 // Execution de commandes
955 else rc = ExecuteCommandLine(kw, tokens, toks);
956 return(rc);
957}
[1262]958// cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl;
959// for(int ii=0; ii<tokens.size(); ii++)
960// cout << "arg[ " << ii << " ] : " << tokens[ii] << endl;
961
[2241]962return(0);
[1262]963}
964
[2236]965
[1262]966/* --Methode-- */
[2236]967int PIACmd::LineToWords(string& line, string& kw, vector<string>& tokens,
968 string& toks, bool uq)
969{
970if (line.length() < 1) return(0);
971int nw = 1;
972size_t p = line.find_first_not_of(" ");
973line = line.substr(p);
974p = 0;
975size_t q = line.find_first_of(" ");
976size_t l = line.length();
977
978if (q < l)
979 { kw = line.substr(p,q-p); toks = line.substr(q, l-q); }
980else { kw = line.substr(p,l-p); toks = ""; }
981
982q = 0;
983while (q < l) {
984 p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
985 if (p>=l) break;
986 if ( uq && ((toks[p] == '\'') || (toks[p] == '"')) ) {
987 q = toks.find(toks[p],p+1);
988 if (q>=l) {
989 cerr << "PIACmd::LineToWords/Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl;
990 return(-1);
991 }
992 p++;
993 }
994 else {
995 q = toks.find_first_of(" \t",p); // la fin du token;
996 }
997 string token = toks.substr(p,q-p);
998 tokens.push_back(token); nw++;
999 }
1000
1001return(nw);
1002}
1003
1004/* --Methode-- */
[1262]1005int PIACmd::SubstituteVars(string & s, string & s2)
1006// Variable substitution
1007{
[2214]1008NamedObjMgr& omg = *mObjMgr;
[1262]1009
[2215]1010int iarr = -1; // index d'element de tableau
1011size_t p,q,q2,q3,l;
[1262]1012
1013s2="";
[349]1014p = 0;
1015l = s.length();
[2214]1016string vn, vv;
[349]1017while (p < l) {
1018 q = s.find('$',p);
[1276]1019 if (q > l) break;
1020 q2 = s.find('\'',p);
1021 if ((q2 < l) && (q2 < q)) { // On saute la chaine delimitee par ' '
1022 q2 = s.find('\'',q2+1);
1023 if (q2 >= l) {
1024 cerr << " Syntax error - Unbalenced quotes !!! " << endl;
1025 return(1);
1026 }
1027 s2 += s.substr(p, q2-p+1);
1028 p = q2+1; continue;
1029 }
[349]1030 // cout << "DBG: " << s2 << " p= " << p << " q= " << q << " L= " << l << endl;
1031 if ((q>0) && (s[q-1] == '\\')) { // Escape character \$
1032 s2 += (s.substr(p,q-1-p) + '$') ; p = q+1;
1033 continue;
1034 }
1035 if (q >= l-1) {
[1276]1036 cerr << " Syntax error - line ending with $ !!! " << endl;
1037 return(2);
[349]1038 }
1039 vn = "";
1040 if ( s[q+1] == '{' ) { // Variable in the form ${name}
1041 q2 = s.find('}',q+1);
1042 if (q2 >= l) {
[1276]1043 cerr << " Syntax error - Unbalenced brace {} !!! " << endl;
1044 return(3);
[349]1045 }
1046 vn = s.substr(q+2,q2-q-2);
1047 q2++;
[2215]1048 }
1049 else if ( s[q+1] == '(' ) { // Variable in the form $(name)
1050 q2 = s.find(')',q+1);
1051 if (q2 >= l) {
1052 cerr << " Syntax error - Unbalenced parenthesis () !!! " << endl;
1053 return(3);
1054 }
1055 vn = s.substr(q+2,q2-q-2);
1056 q2++;
1057 }
[349]1058 else if ( s[q+1] == '[' ) { // Variable in the form $[varname] -> This is $$varname
1059 q2 = s.find(']',q+1);
1060 if (q2 >= l) {
[1276]1061 cerr << " Syntax error - Unbalenced brace [] !!! " << endl;
1062 return(4);
[349]1063 }
1064 vn = s.substr(q+2,q2-q-2);
[2214]1065 if (!GetVar(vn, vv)) return(5);
1066 vn = vv;
[349]1067 q2++;
1068 }
1069 else {
[1562]1070 q2 = s.find_first_of(" .:+-*/,[](){}&|!$\"'",q+1);
[349]1071 if (q2 > l) q2 = l;
[2215]1072 q3 = q2;
[349]1073 vn = s.substr(q+1, q2-q-1);
[2215]1074 // Si variable de type $varname[index] : element de tableau
1075 if ((q2 < l) && (s[q2] == '[') ) {
1076 q3 = s.find_first_of("]",q2+1);
1077 string sia = s.substr(q2+1, q3-q2-1);
[2218]1078 if (sia.length() < 1) {
1079 cerr << " Syntax error - in $varname[index] : $"
1080 << vn << "[" << sia <<"]" << endl;
1081 return(4);
1082 }
1083 if (isalpha(sia[0])) {
1084 string sia2;
1085 if (!GetVar(sia, sia2) || (sia2.length() < 1)) {
1086 cerr << " Syntax error - in $varname[index] : $"
1087 << vn << "[" << sia <<"]" << endl;
1088 return(4);
1089 }
1090 sia = sia2;
1091 }
[2215]1092 int rcdia = ctoi(sia.c_str(), &iarr);
1093 if (rcdia < 0) {
1094 cerr << " Syntax error - in $varname[iarr] : $"
1095 << vn << "[" << sia <<"]" << endl;
1096 return(4);
1097 }
[349]1098 }
[2215]1099 }
[2214]1100 if (!GetVar(vn, vv)) return(5);
[2215]1101 if (iarr < 0) {
1102 s2 += (s.substr(p, q-p) + vv);
1103 p = q2;
1104 }
1105 else {
1106 vector<string> vs;
1107 FillVStringFrString(vv, vs);
1108 if (iarr >= vs.size()) {
1109 cerr << " Substitution error - word index out of range in "
1110 << "$varname[iarr] : $" << vn << "[" << iarr <<"]" << endl;
1111 return(4);
1112 }
1113 else s2 += (s.substr(p, q-p) + vs[iarr]);
1114 p = q3+1;
1115 }
1116}
[349]1117if (p < l) s2 += s.substr(p);
1118
1119p = s2.find_first_not_of(" \t");
1120if (p < l) s2 = s2.substr(p);
1121
[1262]1122return(0);
1123}
[349]1124
[1262]1125/* --Methode-- */
[2214]1126bool PIACmd::GetVar(string & vn, string & vv)
1127{
1128NamedObjMgr& omg = *mObjMgr;
1129if (vn.length() < 1) {
1130 cerr << " PIACmd::SubstituteVar/Error: length(varname=" << vn << ")<1 !" << endl;
1131 vv = ""; return(false);
1132}
1133// Variable de type $# $0 $1 ... (argument de .pic ou de script)
1134int ka = 0;
1135if (vn == "#") {
1136 if (ArgsStack.empty()) {
1137 cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
1138 << " ($" << vn << ")" << endl;
[2218]1139 vv = ""; return(false);
[2214]1140 }
1141 char buff[32];
1142 long an = ArgsStack.top().size();
1143 sprintf(buff,"%ld", an);
[2218]1144 vv = buff; return(true);
[2214]1145}
1146else if (ctoi(vn.c_str(), &ka) > 0) { // $0 $1 $2 ...
1147 if (ArgsStack.empty()) {
1148 cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
1149 << " ($" << vn << ")" << endl;
1150 vv = ""; return(false);
1151 }
1152 if ( (ka < 0) || (ka >= ArgsStack.top().size()) ) {
1153 cerr << " PIACmd::SubstituteVar/Error: Undefined variable ! "
1154 << " ($" << vn << ")" << endl;
1155 vv = ""; return(false);
1156 }
[2218]1157 vv = ArgsStack.top()[ka]; return(true);
[2214]1158}
[2218]1159else if (vn[0] == '#') { // Variable de type $#vname --> size(vname)
1160 vn = vn.substr(1);
1161 if (!omg.HasVar(vn) ) {
1162 cerr << " PIACmd::SubstituteVarError: Undefined variable "
1163 << vn << " ! " << endl;
1164 vv = ""; return(false);
1165 }
1166 vn = omg.GetVar(vn);
1167 vector<string> vs;
1168 FillVStringFrString(vn, vs);
1169 char buff[32];
1170 sprintf(buff,"%d", (int)vs.size());
1171 vv = buff; return(true);
1172 }
[2214]1173else { // variable ordinaire geree par NamedObjMgr
1174 if ( (!omg.HasVar(vn)) ) {
1175 cerr << " PIACmd::SubstituteVarError: Undefined variable "
1176 << vn << " ! " << endl;
[2218]1177 vv = ""; return(false);
[2214]1178 }
[2218]1179 vv = omg.GetVar(vn); return(true);
[2214]1180}
1181
[2218]1182return(false);
[2214]1183}
1184
1185/* --Methode-- */
[1565]1186int PIACmd::EvaluateTest(vector<string> & args, string & line, bool & res)
[1562]1187{
[1565]1188 res = true;
[2215]1189 if ((args.size() != 6) || (args[5] != "then") ||
1190 (args[0] != "(") || (args[4] != ")") ) return(1);
1191 if (args[2] == "==") res = (args[1] == args[3]);
1192 else if (args[2] == "!=") res = (args[1] != args[3]);
1193 else if (args[2] == "<")
1194 res = (atof(args[1].c_str()) < atof(args[3].c_str()));
1195 else if (args[2] == ">")
1196 res = (atof(args[1].c_str()) > atof(args[3].c_str()));
1197 else if (args[2] == "<=")
1198 res = (atof(args[1].c_str()) <= atof(args[3].c_str()));
1199 else if (args[2] == ">=")
1200 res = (atof(args[1].c_str()) >= atof(args[3].c_str()));
[1565]1201 else return(2);
1202 return(0);
[1562]1203}
1204
[2241]1205/* Operations sur le stack RPN */
1206inline bool Check_myRPNStack_(stack<double>& s, double& x, string& line)
1207{
1208 if (s.empty()) {
1209 cerr << "PIACmd::EvalRPNExpr: syntax error / empty RPN stack " << line << endl;
1210 return true;
1211 }
1212 else x = s.top();
1213 return false;
1214}
1215inline bool Check_myRPNStack_(stack<double>& s, double& x, double& y, string& line)
1216{
1217 if (s.size() < 2) {
1218 cerr << "PIACmd::EvalRPNExpr: syntax error / RPN stack size < 2 " << line << endl;
1219 return true;
1220 }
1221 else {
1222 x = s.top(); s.pop(); y = s.top();
1223 }
1224 return false;
1225}
1226
1227inline void Print_myRPNStack_(stack<double> s)
1228{
1229 if (s.empty())
1230 cout << "PIACmd::EvalRPNExpr/PrintStack: Empty stack " << endl;
1231 else {
1232 int k = 0;
1233 cout << "PIACmd::EvalRPNExpr/PrintStack: Size()= " << s.size() << endl;
1234 while( !s.empty() ) {
1235 cout << " " << k << ": " << s.top() << " ";
1236 if (k == 0) cout << " (x) " << endl;
1237 else if (k == 1) cout << " (y) " << endl;
1238 else if (k == 2) cout << " (z) " << endl;
1239 else cout << endl;
1240 s.pop(); k++;
1241 }
1242 }
[2236]1243
[2241]1244}
1245
[2265]1246int Sum_RPNStack_(stack<double>& s, double& sx, double& sx2, string& line)
1247{
1248 sx = sx2 = 0.;
1249 int nn = 0;
1250 double x = 0.;
1251 while( !s.empty() ) {
1252 x = s.top(); s.pop();
1253 sx += x; sx2 += x*x;
1254 nn++;
1255 }
1256 return(nn);
1257}
1258
1259int Product_RPNStack_(stack<double>& s, double& px, string& line)
1260{
1261 px = 1.;
1262 int nn = 0;
1263 double x = 0.;
1264 while( !s.empty() ) {
1265 x = s.top(); s.pop();
1266 px *= x; nn++;
1267 }
1268 return(nn);
1269}
[2241]1270
[1562]1271/* --Methode-- */
[2241]1272int PIACmd::EvalRPNExpr(vector<string> & args, string & line)
[2236]1273{
[2241]1274 NamedObjMgr& omg = *mObjMgr;
1275
1276 if (args.size() < 2) {
1277 cerr << "PIACmd::EvalRPNExpr: syntax error / missing arguments " << line << endl;
[2236]1278 return(1);
1279 }
[2241]1280 else if (args.size() == 2) {
1281 omg.SetVar(args[0], args[1]);
1282 return(0);
1283 }
[2236]1284
[2241]1285 double x,y;
1286 x = y = 0.;
1287 stack<double> rpnstack; // Stack des operations en RPN
1288 for(int k=1; k<args.size(); k++) {
1289 // Les 4 operations de base + - * /
[2236]1290 if (args[k] == "+") {
[2241]1291 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1292 rpnstack.top() = y+x;
[2236]1293 }
1294 else if (args[k] == "-") {
[2241]1295 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1296 rpnstack.top() = y-x;
[2236]1297 }
1298 else if (args[k] == "*") {
[2241]1299 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1300 rpnstack.top() = y*x;
[2236]1301 }
1302 else if (args[k] == "/") {
[2241]1303 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1304 rpnstack.top() = y/x;
[2236]1305 }
[2241]1306 // Les constantes : e , pi
1307 else if (args[k] == "e") {
1308 rpnstack.push(M_E);
1309 }
1310 else if (args[k] == "pi") {
1311 rpnstack.push(M_PI);
1312 }
1313 // Les fonctions usuelles a 1 argument f(x)
1314 else if (args[k] == "cos") {
1315 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1316 rpnstack.top() = cos(x);
1317 }
1318 else if (args[k] == "sin") {
1319 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1320 rpnstack.top() = sin(x);
1321 }
1322 else if (args[k] == "tan") {
1323 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1324 rpnstack.top() = tan(x);
1325 }
1326 else if (args[k] == "acos") {
1327 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1328 rpnstack.top() = acos(x);
1329 }
1330 else if (args[k] == "asin") {
1331 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1332 rpnstack.top() = asin(x);
1333 }
1334 else if (args[k] == "atan") {
1335 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1336 rpnstack.top() = atan(x);
1337 }
1338 else if (args[k] == "log") {
1339 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1340 rpnstack.top() = log(x);
1341 }
1342 else if (args[k] == "log10") {
1343 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1344 rpnstack.top() = log10(x);
1345 }
1346 else if (args[k] == "exp") {
1347 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1348 rpnstack.top() = exp(x);
1349 }
1350 else if (args[k] == "deg2rad") {
1351 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1352 rpnstack.top() = x*M_PI/180.;
1353 }
1354 else if (args[k] == "rad2deg") {
1355 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1356 rpnstack.top() = x*180./M_PI;
1357 }
1358 // Les fonctions usuelles a 2 argument f(x,y)
1359 else if (args[k] == "pow") {
1360 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1361 rpnstack.top() = pow(y,x);
1362 }
1363 else if (args[k] == "atan2") {
1364 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1365 rpnstack.top() = atan2(x,y);
1366 }
[2265]1367 // Fonction a N arguments - Somme, produit, etc ...
1368 else if ((args[k] == "sum") || (args[k] == "mean") ||
1369 (args[k] == "sigma") || (args[k] == "sigma2") ) {
1370 double sx, sx2;
1371 int nn = Sum_RPNStack_(rpnstack, sx, sx2, line);
1372 if (args[k] == "sum") rpnstack.push(sx);
1373 else {
1374 if (nn == 0) {
1375 cerr << "PIACmd::EvalRPNExpr: mean/sigma error- RPN stack empty: "
1376 << line << endl;
1377 return(1);
1378 }
1379 double fnn = nn;
1380 if (args[k] == "mean") rpnstack.push(sx/fnn);
1381 else if (args[k] == "sigma2") rpnstack.push(sx2/fnn-(x*x/(fnn*fnn)));
1382 else rpnstack.push(sqrt(sx2/fnn-(x*x/(fnn*fnn))));
1383 }
1384 }
1385 else if (args[k] == "product") {
1386 double px;
1387 int nn = Product_RPNStack_(rpnstack, px, line);
1388 if (nn == 0) {
1389 cerr << "PIACmd::EvalRPNExpr: product error- RPN stack empty: "
1390 << line << endl;
1391 return(1);
1392 }
1393 rpnstack.push(px);
1394 }
[2241]1395 // Fonctions de manipulation de stack
1396 else if (args[k] == "print") {
1397 Print_myRPNStack_(rpnstack);
1398 }
1399 else if (args[k] == "x<>y") {
1400 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1401 rpnstack.top() = x; rpnstack.push(y);
1402 }
1403 // On met un nombre sur le stack
1404 else {
1405 if (ctof(args[k].c_str(),&x) < 0) {
1406 cerr << "PIACmd::EvalRPNExpr: syntax error near " << args[k]
1407 << " in expression: \n" << line << endl;
1408 return(2);
1409 }
1410 rpnstack.push(x);
1411 }
1412
[2236]1413 }
1414
[2241]1415 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
[2236]1416 char buff[64];
1417 sprintf(buff, "%g", x);
[2241]1418 string res = buff;
1419 omg.SetVar(args[0], res);
[2236]1420 return(0);
1421}
1422
1423/* --Methode-- */
[2215]1424void PIACmd::PushStack(vector<string>& args)
1425{
1426 // We push the argument list (args) on the stack
1427 ArgsStack.push(args);
1428 // We push also PIACmdBloc and testresult on the stack
1429 CmdBlks.push(NULL);
1430 list<char> xtx;
1431 TestsStack.push(xtx);
1432
1433}
1434
1435/* --Methode-- */
1436void PIACmd::PopStack(bool psta)
1437{
1438 // We remove the argument list (args) from the stack
1439 if (psta) ArgsStack.pop();
1440 // And PIACmdBloc and TestResult from the corresponding stacks
1441 PIACmdBloc* curb = CmdBlks.top();
1442 while (curb != NULL) {
1443 PIACmdBloc* parb = curb->Parent();
1444 delete curb; curb = parb;
1445 }
1446 CmdBlks.pop();
1447 TestsStack.pop();
1448}
1449
1450/* --Methode-- */
[1262]1451int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
1452{
1453int rc = 0;
1454NamedObjMgr omg;
[349]1455
[165]1456// >>>>>>>>>>> Commande d'interpreteur
[1262]1457if (kw == "helpwindow") ShowHelpWindow();
[293]1458else if (kw == "help") {
[330]1459 if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl;
[293]1460 else {
[330]1461 string kwh = "piacmd";
1462 cout << GetUsage(kwh) << endl;
[293]1463 }
[165]1464 }
1465
1466else if (kw == "set") {
[293]1467 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); }
[349]1468 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1469 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
1470 return(0);
1471 }
[1276]1472 // string xx = tokens[1];
1473 // for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk] );
1474 omg.SetVar(tokens[0], tokens[1]);
[165]1475 }
[349]1476
1477else if (kw == "getvar") {
1478 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: getvar newvarname varname" << endl; return(0); }
[1262]1479 if (!omg.HasVar(tokens[1])) {
[349]1480 cerr << "Error - No " << tokens[1] << " Variable " << endl;
1481 return(0);
1482 }
1483 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1484 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
1485 return(0);
1486 }
[1262]1487 omg.SetVar(tokens[0], omg.GetVar(tokens[1]) );
[349]1488 }
1489
1490else if (kw == "alias") {
1491 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: alias aliasname string" << endl; return(0); }
1492 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1493 cerr << "PIACmd::Interpret()/Error alias name should start with alphabetic" << endl;
1494 return(0);
1495 }
1496 string xx = tokens[1];
1497 for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk]);
1498 mAliases[tokens[0]] = xx;
1499 }
1500
[333]1501else if (kw == "setol") {
1502 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: setol varname objnamepattern" << endl; return(0); }
[349]1503 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1504 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
1505 return(0);
1506 }
[333]1507 vector<string> ol;
[349]1508 mObjMgr->GetObjList(tokens[1], ol);
1509 string vol;
1510 if (ol.size() < 1) vol = "";
1511 else {
1512 vol = ol[0];
1513 for (int kk=1; kk<ol.size(); kk++) vol += (' ' + ol[kk]);
1514 }
[1262]1515 omg.SetVar(tokens[0], vol);
[333]1516 }
[293]1517else if (kw == "unset") {
1518 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); }
[1262]1519 if (omg.HasVar(tokens[0])) omg.DeleteVar(tokens[0]) ;
[293]1520 else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl;
[165]1521 }
[2241]1522 else if (kw == "rpneval") { // Evaluation d'expression en notation polonaise inverse
1523 return(EvalRPNExpr(tokens, toks));
1524}
[333]1525else if (kw == "echo") {
[1276]1526 for (int ii=0; ii<tokens.size(); ii++)
1527 cout << tokens[ii] << " " ;
[333]1528 cout << endl;
[1276]1529 }
[353]1530else if (kw == "readstdin") {
1531 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: readstdin varname" << endl; return(0); }
1532 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1533 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
1534 return(0);
1535 }
[357]1536 mImgApp->GetConsole()->AddStr(">>> Reading From StdIn \n", PIVA_Magenta);
1537 cout << tokens[0] << " ? " << endl;
[1262]1538 omg.SetVar(tokens[0], GetStringFrStdin(this) );
[353]1539 }
1540
[165]1541else if (kw == "listvars") {
[293]1542 cout << "PIACmd::Interpret() Variable List , VarName = Value \n";
[1262]1543 DVList& varlist = omg.GetVarList();
1544 DVList::ValList::const_iterator it;
1545 string value;
1546 for(it = varlist.Begin(); it != varlist.End(); it++) {
[1291]1547#ifdef SANS_EVOLPLANCK
1548 MuTyV mtv = (*it).second;
1549 value = (string)(mtv);
1550#else
[1262]1551 value = (string)((*it).second.elval);
[1291]1552#endif
[1262]1553 cout << (*it).first << " = " << value << "\n";
1554 }
[165]1555 cout << endl;
1556 }
[353]1557else if (kw == "listalias") {
1558 cout << "PIACmd::Interpret() Alias List , AliasName = Value \n";
[2214]1559 CmdStrList::iterator it;
[353]1560 for(it = mAliases.begin(); it != mAliases.end(); it++)
1561 cout << (*it).first << " = " << (*it).second << "\n";
1562 cout << endl;
1563 }
1564else if (kw == "listcommands") {
[2236]1565 cout << "---- PIACmd::Interpret() Command List ----- \n";
[293]1566 CmdExmap::iterator it;
1567 int kc = 0;
1568 for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
1569 cout << (*it).first << " ";
1570 kc++;
1571 if (kc >= 5) { cout << "\n"; kc = 0; }
1572 }
1573 cout << endl;
1574 }
[2236]1575else if (kw == "listscripts") {
1576 cout << "---- PIACmd::Interpret() Script List ----- \n";
1577 for(ScriptList::iterator sit = mScripts.begin();
1578 sit != mScripts.end(); sit++)
1579 cout << " Script: " << (*sit).second->Name() << " - "
1580 << (*sit).second->Comment() << endl;
1581}
1582else if (kw == "clearscript") {
1583 if (tokens.size() < 1) {
1584 cout << "PIACmd::Interpret() Usage: clearscript scriptname" << endl;
1585 return(0);
1586 }
1587 ScriptList::iterator sit = mScripts.find(tokens[0]);
1588 if (sit == mScripts.end()) {
1589 cout << "PIACmd::Interpret() No script with name" << tokens[0] << endl;
1590 return(0);
1591 }
1592 else {
1593 delete (*sit).second;
1594 mScripts.erase(sit);
1595 cout << "PIACmd::Interpret() script " << tokens[0] << " cleared" << endl;
1596 return(0);
1597 }
1598}
[293]1599else if (kw == "traceon") { cout << "PIACmd::Interpret() -> Trace ON mode " << endl; trace = true; }
1600else if (kw == "traceoff") { cout << "PIACmd::Interpret() -> Trace OFF mode " << endl; trace = false; }
[165]1601else if (kw == "timingon") {
[293]1602 cout << "PIACmd::Interpret() -> Timing ON mode " << endl;
1603 if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true;
1604 }
[165]1605else if (kw == "timingoff") {
[293]1606 cout << "PIACmd::Interpret() -> Timing OFF mode " << endl;
1607 if (gltimer) delete gltimer; gltimer = NULL; timing = false;
1608 }
[165]1609else if (kw == "exec") {
[293]1610 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: exec filename" << endl; return(0); }
[349]1611 ExecFile(tokens[0], tokens);
[165]1612 }
1613else if (kw == "shell") {
[293]1614 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl; return(0); }
[1276]1615 string cmd;
1616 for (int ii=0; ii<tokens.size(); ii++)
1617 cmd += (tokens[ii] + ' ');
1618 system(cmd.c_str());
[165]1619 }
[2203]1620else if (kw == "cshell") {
1621 if(tokens.size()<1) {cout<<"PIACmd::Interpret() Usage: cshell cmdline"<<endl; return(0);}
1622 string cmd="";
1623 for(int ii=0;ii<tokens.size();ii++) cmd+=(tokens[ii]+' ');
1624 CShellExecute(cmd);
1625 }
[1276]1626
[293]1627// Execution d'une commande enregistree
[1268]1628else rc = ExecuteCommand(kw, tokens, toks);
[165]1629
1630if (timing) gltimer->Split();
[333]1631return(rc);
[165]1632}
1633
[333]1634/* --Methode-- */
[2236]1635int PIACmd::ParseLineExecute(string& line, bool qw)
1636 // Si qw == true, on decoupe entre '' ou "" ou espaces
[333]1637{
[1262]1638vector<string> tokens;
[2236]1639string kw, toks;
[333]1640if (line.length() < 1) return(0);
[2236]1641LineToWords(line, kw, tokens, toks, qw);
[1268]1642return(ExecuteCommand(kw, tokens, toks));
[333]1643}
1644
[165]1645/* --Methode-- */
[1268]1646int PIACmd::ExecuteCommand(string& keyw, vector<string>& args, string& toks)
[333]1647{
1648 int rc = -1;
1649 CmdExmap::iterator it = cmdexmap.find(keyw);
1650 if (it == cmdexmap.end()) cout << "No such command : " << keyw << " ! " << endl;
1651 else {
[1268]1652 if ((*it).second.cex) rc = (*it).second.cex->Execute(keyw, args, toks);
[333]1653 else cout << "Dont know how to execute " << keyw << " ? " << endl;
1654 }
1655 return(rc);
1656}
1657
1658/* --Methode-- */
[349]1659int PIACmd::ExecFile(string& file, vector<string>& args)
[165]1660{
[293]1661char line_buff[512];
1662FILE *fip;
[165]1663
[293]1664if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
[384]1665 if (file.find('.') >= file.length()) {
1666 cout << "PIACmd::Exec(): Error opening file " << file << endl;
1667 file += ".pic";
1668 cout << " Trying file " << file << endl;
1669 fip = fopen(file.c_str(),"r");
1670 }
1671 }
1672
1673if(fip == NULL) {
[293]1674 cerr << "PIACmd::Exec() Error opening file " << file << endl;
1675 hist << "##! PIACmd::Exec() Error opening file " << file << endl;
1676 return(0);
[165]1677 }
[349]1678
1679// hist << "### Executing commands from " << file << endl;
1680
[2215]1681PushStack(args);
[293]1682if (trace) {
1683 mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta);
1684 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
1685 mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta);
1686 }
[165]1687
[1562]1688bool ohv = histon;
[349]1689histon = false;
[293]1690while (fgets(line_buff,511,fip) != NULL)
1691 {
1692 if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta);
1693 line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */
1694 string line(line_buff);
[1565]1695 if (Interpret(line) == 77777) break;
[165]1696 }
[1562]1697histon = ohv;
[349]1698
1699// hist << "### End of Exec( " << file << " ) " << endl;
[293]1700if (trace) {
1701 mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta);
1702 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
1703 mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta);
[165]1704 }
1705
[2215]1706PopStack(true);
[2214]1707
[165]1708return(0);
1709}
1710
[2203]1711/* --Methode-- */
1712int PIACmd::CShellExecute(string cmd)
1713{
1714 if(cmd.size()<=0) return -1;
[293]1715
[2203]1716 NamedObjMgr omg;
1717 string fname = omg.GetTmpDir(); fname += "cshell_exec_pia.csh";
1718
1719 string cmdrm = "rm -f " + fname;
1720 system(cmdrm.c_str());
1721
1722 FILE *fip = fopen(fname.c_str(),"w");
1723 if(fip==NULL) {
1724 cout << "PIACmd/CShellExecute_Error: fopen("<<fname<<") failed"<<endl;
1725 return -2;
1726 }
1727 fprintf(fip,"#!/bin/csh\n\n");
1728 fprintf(fip,"%s\n",cmd.c_str());
1729 fprintf(fip,"\nexit 0\n");
1730 fclose(fip);
1731
1732 cmd = "csh "; cmd += fname;
1733 system(cmd.c_str());
1734
1735 system(cmdrm.c_str());
1736
1737 return 0;
1738}
1739
[293]1740static string* videstr = NULL;
1741/* --Methode-- */
1742string& PIACmd::GetUsage(const string& kw)
[165]1743{
[330]1744bool fndok = false;
[293]1745CmdExmap::iterator it = cmdexmap.find(kw);
[330]1746if (it == cmdexmap.end()) {
1747 it = helpexmap.find(kw);
1748 if (it != helpexmap.end()) fndok = true;
[165]1749 }
[330]1750 else fndok = true;
1751if (fndok) return( (*it).second.us );
1752// Keyword pas trouve
1753if (videstr == NULL) videstr = new string("");
1754*videstr = "Nothing known about " + kw + " ?? ";
1755return(*videstr);
1756
[165]1757}
1758
[293]1759/* --Methode-- */
1760void PIACmd::ShowHelpWindow()
[165]1761{
[293]1762helpwin->Show();
[165]1763}
[357]1764
[463]1765/* --Methode-- */
[1251]1766void PIACmd::ShowCxxOptionWindow()
1767{
1768cxxoptwin->Show();
1769}
1770
1771/* --Methode-- */
1772void PIACmd::ShowCxxExecWindow()
1773{
1774cxxexwin->Show();
1775}
1776
[2263]1777/* Les definitions suivantes doivent se trouver ds l'en-tete du fichier LaTeX
1778 \newcommand{\piacommand}[1]{
1779 \framebox{\bf \Large #1 } \index{#1} % (Command)
1780 }
1781
1782 \newcommand{\piahelpitem}[1]{
1783 \framebox{\bf \Large #1 } \index{#1} (Help item)
1784 }
1785
1786 \newcommand{\myppageref}[1]{ (p. \pageref{#1} ) }
1787*/
1788
[1251]1789/* --Methode-- */
[2263]1790void PIACmd::HelptoLaTeX(string const & fname)
[463]1791{
1792FILE *fip;
1793if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1794 cout << "PIACmd::HelptoLaTex_Error: fopen( " << fname << endl;
1795 return;
1796 }
[357]1797
[463]1798fputs("% ----- Liste des groupes de Help ----- \n",fip);
1799fputs("List of {\\bf piapp} on-line Help groups: \n", fip);
1800fputs("\\begin{itemize} \n",fip);
1801CmdHGroup::iterator it;
[2263]1802for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++) {
1803 if ((*it).first == "All") continue;
[484]1804 fprintf(fip,"\\item {\\bf %s } (p. \\pageref{%s}) \n",
1805 (*it).first.c_str(), (*it).first.c_str());
[2263]1806}
[463]1807
1808fputs("\\end{itemize} \n",fip);
1809
[2263]1810fputs("\\vspace*{10mm} \n",fip);
[484]1811
1812CmdExmap::iterator ite;
1813fputs("% ----- Liste de toutes les commandes ----- \n",fip);
1814fputs("\\begin{center} \n ", fip);
1815fputs("\\rule{2cm}{1mm} List of {\\bf piapp} Help items \\rule{2cm}{1mm} \n", fip);
1816fputs("\n \n \\vspace{5mm} \n",fip);
1817fputs("\\begin{tabular}{llllll} \n", fip);
1818int kt = 0;
1819for(ite = helpexmap.begin(); ite != helpexmap.end(); ite++) {
1820 fprintf(fip,"%s & p. \\pageref{%s} ", (*ite).first.c_str(), (*ite).first.c_str() );
1821 kt++;
1822 if (kt < 3) fputs(" & ", fip);
1823 else { fputs(" \\\\ \n", fip); kt = 0; }
1824 }
1825if (kt == 1) fputs(" & & & \\\\ \n", fip);
1826else if (kt == 2) fputs(" & \\\\ \n", fip);
1827fputs("\\end{tabular} \n", fip);
1828fputs("\\end{center} \n", fip);
[2263]1829fputs("\n \n \\newpage \\vspace{1cm} \n",fip);
[484]1830
1831fputs("\\begin{center} \n ", fip);
1832fputs("\\rule{2cm}{1mm} List of {\\bf piapp} Commands \\rule{2cm}{1mm} \n", fip);
1833fputs("\n \n \\vspace{5mm} \n",fip);
1834fputs("\\begin{tabular}{llllll} \n", fip);
1835kt = 0;
1836for(ite = cmdexmap.begin(); ite != cmdexmap.end(); ite++) {
1837 fprintf(fip,"%s & p. \\pageref{%s} ", (*ite).first.c_str(), (*ite).first.c_str() );
1838 kt++;
1839 if (kt < 3) fputs(" & ", fip);
1840 else { fputs(" \\\\ \n", fip); kt = 0; }
1841 }
1842if (kt == 1) fputs(" & & & \\\\ \n", fip);
1843else if (kt == 2) fputs(" & \\\\ \n", fip);
1844fputs("\\end{tabular} \n", fip);
1845fputs("\\end{center} \n", fip);
1846// fputs("\\newline \n",fip);
1847
[463]1848fputs("% ----- Liste des commandes dans chaque groupe ----- \n",fip);
1849fputs("\\newpage \n",fip);
1850int gid;
1851for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++) {
1852 gid = (*it).second;
1853 if (gid == 0) continue;
[484]1854 fprintf(fip,"\\subsection{%s} \\label{%s} \n",
1855 (*it).first.c_str(), (*it).first.c_str());
[2263]1856 fprintf(fip,"\\noindent \n");
[463]1857 for(ite = helpexmap.begin(); ite != helpexmap.end(); ite++) {
1858 if ((*ite).second.group != gid) continue;
[2263]1859 fprintf(fip,"\\piahelpitem{%s} \\label{%s} \n",
[484]1860 (*ite).first.c_str(), (*ite).first.c_str());
[463]1861 fputs("\\begin{verbatim} \n",fip);
1862 fprintf(fip,"%s\n", (*ite).second.us.c_str());
1863 fputs("\\end{verbatim} \n",fip);
1864 }
1865 for(ite = cmdexmap.begin(); ite != cmdexmap.end(); ite++) {
1866 if ((*ite).second.group != gid) continue;
[2263]1867 fprintf(fip,"\\piacommand{%s} \\label{%s} \n",
[484]1868 (*ite).first.c_str(), (*ite).first.c_str());
[463]1869 fputs("\\begin{verbatim} \n",fip);
1870 fprintf(fip,"%s\n", (*ite).second.us.c_str());
1871 fputs("\\end{verbatim} \n",fip);
1872 }
1873}
1874
1875fclose(fip);
1876return;
1877}
1878
1879
1880
Note: See TracBrowser for help on using the repository browser.