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

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

Correction changement prompt du console piapp - Reza 17/11/2002

File size: 52.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"
[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();
643if (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 ...
[1276]654 mulinefg = true;
[1539]655 mulinecmd += s.substr(0,lnb);
[2274]656 spromptmul = mImgApp->GetConsole()->GetPrompt();
[1276]657 mImgApp->GetConsole()->SetPrompt("...? ");
658 return(0);
659}
[165]660
[1276]661if (mulinefg) { // Il y avait des lignes suite
662 s = mulinecmd + s;
663 mulinecmd = "";
664 mulinefg = false;
[2274]665 mImgApp->GetConsole()->SetPrompt(spromptmul);
[1276]666}
667
[1262]668// Removing leading blanks
[1276]669size_t p,q;
[1262]670
671p=s.find_first_not_of(" \t");
672if (p < l) s = s.substr(p);
673
[349]674// >>>> Substitution d'alias (1er mot)
[2214]675CmdStrList::iterator it;
[449]676p = 0;
677q = s.find_first_of(" \t");
678l = s.length();
679string w1 = (q < l) ? s.substr(p,q-p) : s.substr(p);
680it = mAliases.find(w1);
681if (it != mAliases.end()) {
682 s = (q < l) ? ((*it).second + s.substr(q)) : (*it).second ;
683 l = s.length();
684 p=s.find_first_not_of(" \t");
685 if (p < l) s = s.substr(p);
[349]686 p = 0;
687 q = s.find_first_of(" ");
688 }
689
690// >>>> Separating keyword
[1262]691string toks,kw;
[165]692if (q < l)
693 { kw = s.substr(p,q-p); toks = s.substr(q, l-q); }
694else { kw = s.substr(p,l-p); toks = ""; }
695
[1562]696// les mot-cle end else endif doivent etre le seul mot de la ligne
[2236]697if ( (kw == "end") || (kw == "else") || (kw == "endif") || (kw == "endscript") ) {
[1562]698 size_t ltk = toks.length();
699 if (toks.find_first_not_of(" \t") < ltk) {
[2236]700 cerr << "PIACmd::Interpret()/syntax error near end else endif endscript \n"
[1562]701 << "line: " << s << endl;
702 return(1);
703 }
704}
705
[2236]706// On verifie si on est en train de definir un script
707if (curscript) {
708 if (kw == "endscript") {
709 if (curscript->CheckScript()) {
710 sit = mScripts.find(curscript->Name());
711 if (sit != mScripts.end()) {
712 cout << "PIACmd::Interpret() replacing script "
713 << curscript->Name() << endl;
714 PIACmdScript* scr = mScripts[curscript->Name()];
715 mScripts.erase(sit);
716 delete scr;
717 }
718 cout << "PIACmd::Interpret() Script " << curscript->Name()
719 << " defined successfully" << endl;
720 mScripts[curscript->Name()] = curscript;
721 mImgApp->GetConsole()->SetPrompt("Cmd> ");
722 curscript = NULL;
723 return(0);
724 }
725 else {
726 cout << "PIACmd::Interpret() Error in Script " << curscript->Name()
727 << " definition " << endl;
728 mImgApp->GetConsole()->SetPrompt("Cmd> ");
729 curscript = NULL;
730 return(2);
731 }
732 }
733 else curscript->AddLine(s, kw);
734 return(0);
735}
[1562]736// On verifie si nous sommes dans un bloc (for , foreach)
[2215]737if (CmdBlks.top() != NULL) { // On est dans un bloc
[1562]738 if ( (kw == "for") || (kw == "foreach")) felevel++;
739 else if (kw == "end") felevel--;
740 if (felevel == 0) { // Il faut executer le bloc
[2215]741 PIACmdBloc* curb = CmdBlks.top();
742 CmdBlks.top() = curb->Parent();
[1562]743 mImgApp->GetConsole()->SetPrompt("Cmd> ");
[2236]744 if (!curb->CheckBloc()) {
[2215]745 cerr << "PIACmd::Interpret()/syntax error - unbalenced if ... endif"
746 << " within for/foreach bloc ! " << endl;
747 delete curb;
748 return(2);
749 }
[349]750 // cout << " *DBG* Executing bloc " << endl;
[1562]751 bool ohv = histon;
752 histon = false;
[2215]753 if (curtestresult) {
754 // We push also PIACmdBloc and testresult on the stack
755 CmdBlks.push(NULL);
756 list<char> xtx;
757 TestsStack.push(xtx);
758 curb->Execute();
759 // And PIACmdBloc and TestResult from the corresponding stacks
760 PopStack(false);
761 }
762 delete curb;
[1562]763 histon = ohv;
764 }
[2215]765 else CmdBlks.top()->AddLine(s, kw);
[1562]766 return(0);
767}
[1565]768else if (kw == "end") {
769 cerr << "PIACmd::Interpret()/syntax error - end outside for/foreach bloc \n"
770 << "line: " << s << endl;
771 return(1);
772}
[1562]773
774// Sommes-nous dans un bloc de test if then else
[2215]775if (TestsStack.top().size() > 0) { // Nous sommes ds un bloc if
[1565]776 if (kw == "else") {
777 if ((*tresit) & 2) {
778 cerr << "PIACmd::Interpret()/syntax error - multiple else in if bloc \n"
779 << "line: " << s << endl;
780 return(1);
781 }
782 else {
[1570]783 const char * npr = ((*tresit)&1) ? "else-F> " : "else-T> ";
[2215]784 if ((*tresit)&1) curtestresult = false;
[1565]785 mImgApp->GetConsole()->SetPrompt(npr);
786 (*tresit) |= 2;
787 return(0);
788 }
789 }
790 else if (kw == "endif") {
791 list<char>::iterator dbit = tresit;
[1562]792 tresit--;
[2215]793 TestsStack.top().erase(dbit);
[1570]794 const char * npr = "Cmd> ";
[2215]795 if (TestsStack.top().size() > 1) {
796 curtestresult = true;
797 list<char>::iterator it;
798 for(it=TestsStack.top().begin(); it!=TestsStack.top().end(); it++) {
799 // Si on n'est pas ds le else et le if est faux
800 if ( !((*it)&2) && !((*it)&1) ) curtestresult = false;
801 // Si on est ds else et le if etait vrai !
802 if ( ((*it)&2) && ((*it)&1) ) curtestresult = false;
803 if (!curtestresult) break;
804 }
805
[1565]806 if (!((*tresit)&2))
807 npr = ((*tresit)&1) ? "if-T> " : "if-F> ";
808 else
809 npr = ((*tresit)&1) ? "else-F> " : "else-T> ";
810 }
[2215]811 else curtestresult = true;
[1565]812 mImgApp->GetConsole()->SetPrompt(npr);
[349]813 return(0);
814 }
[1565]815}
816else if ((kw == "else") || (kw == "endif")) {
817 cerr << "PIACmd::Interpret()/syntax error - else,endif outside if bloc \n"
818 << "line: " << s << endl;
819 return(1);
[1562]820}
[349]821
[1565]822bool fgcont = true;
[2215]823if (TestsStack.top().size() > 0) { // Resultat de if ou else
[1565]824 list<char>::iterator it;
[2215]825 for(it=TestsStack.top().begin(); it!=TestsStack.top().end(); it++) {
[1565]826 // Si on n'est pas ds le else et le if est faux
827 if ( !((*it)&2) && !((*it)&1) ) fgcont = false;
828 // Si on est ds else et le if etait vrai !
829 if ( ((*it)&2) && ((*it)&1) ) fgcont = false;
830 if (!fgcont) break;
831 }
832}
833
834if ((!fgcont) && (kw != "if")) return(0);
835
836
[2215]837// Les mots cles break et return peuvent de sortir de boucles/scripts/execfile
838if (kw == "break") return(77766);
839else if (kw == "return") return(77777);
840
[1262]841// Nous ne sommes donc pas dans un bloc .... Substitution de variables
[1276]842string s2;
843int rcs ;
[1262]844// Execution de code C++
845
[2236]846if (kw == "@@") {
[1262]847 CxxExecutor * cxxe = dynamic_cast<CxxExecutor *>(cxxexec);
848 if (cxxe == NULL) {
849 cerr << "PIACmd::Interpret() - BUG !!! Not a CxxExecutor " << endl;
850 return(99);
851 }
[2236]852 return(cxxe->ExecuteCXX(s.substr(2)));
[1262]853}
854
855
[1276]856rcs = SubstituteVars(s, s2);
857if (rcs) return(rcs);
[1262]858
859// >>>> Separating keyword and tokens
860vector<string> tokens;
[2236]861/*
[1262]862q = s2.find(' ');
863l = s2.length();
864if (q < l)
865 { kw = s2.substr(0,q); toks = s2.substr(q, l-q); }
866else { kw = s2; toks = ""; }
867
868q = 0;
869while (q < l) {
870 p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
871 if (p>=l) break;
[1276]872 if ( (toks[p] == '\'') || (toks[p] == '"') ) {
873 q = toks.find(toks[p],p+1);
874 if (q>=l) {
[1565]875 cerr << "PIACmd::Interpret()/Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl;
[1276]876 return(2);
877 }
878 p++;
879 }
880 else {
881 q = toks.find_first_of(" \t",p); // la fin du token;
882 }
[1262]883 string token = toks.substr(p,q-p);
884 tokens.push_back(token);
885 }
[2236]886*/
887/* decoupage en mots */
888LineToWords(s2, kw, tokens, toks, true);
[1562]889// Si c'est un for/foreach, on cree un nouveau bloc
890if ((kw == "foreach") || (kw == "for")) {
[1262]891 // cout << " *DBG* We got a foreach... " << endl;
[2215]892 PIACmdBloc* bloc = new PIACmdBloc(this, CmdBlks.top(), kw, tokens);
[1262]893 if (!bloc->CheckOK()) {
[1565]894 cerr << "PIACmd::Interpret() for/foreach syntax Error ! " << endl;
[1262]895 delete bloc;
[1565]896 return(1);
[1262]897 }
898 felevel++;
[2215]899 if (CmdBlks.top()) CmdBlks.top()->AddBloc(bloc);
[1562]900 else mImgApp->GetConsole()->SetPrompt("for...> ");
[2215]901 CmdBlks.top() = bloc;
[1262]902 // cout << " *DBG* New Bloc created ... " << endl;
903 return(0);
904 }
[1565]905else if (kw == "if") { // Un test if
906 bool restst = true;
907 int rct = EvaluateTest(tokens, s, restst);
908 if (rct) {
909 cerr << "PIACmd::Interpret() if syntax Error ! " << endl;
910 return(1);
911 }
912 char res_tst = (restst) ? 1 : 0;
[2215]913 TestsStack.top().push_back(res_tst);
914 if (TestsStack.top().size() == 1) tresit = TestsStack.top().begin();
[1562]915 else tresit++;
[1570]916 const char * npr = (restst) ? "if-T> " : "if-F> ";
[1565]917 mImgApp->GetConsole()->SetPrompt(npr);
[1562]918}
[2241]919else if ((tokens.size() > 0) && (tokens[0] == "=")) {
920 // x = RPNExpression (Evaluation d'expression RPN)
921 tokens[0] = kw;
922 int rcev = EvalRPNExpr(tokens, s);
[2236]923 if (rcev) {
[2241]924 cerr << "PIACmd::Interpret() evaluation (RPN) syntax Error ! " << endl;
[2236]925 return(1);
926 }
927 return(0);
928}
929else if (kw == "defscript") { // definition de script
930 curscript = new PIACmdScript(this, tokens[0], tokens[1]);
931 mImgApp->GetConsole()->SetPrompt("Script...> ");
932 return(0);
933}
934else {
935 // Si c'est le nom d'un script
936 sit = mScripts.find(kw);
937 if (sit != mScripts.end()) {
938 bool ohv = histon;
939 histon = false;
940 PushStack(tokens);
941 (*sit).second->Execute(tokens);
942 PopStack(true);
943 histon = ohv;
944 }
945 // Execution de commandes
946 else rc = ExecuteCommandLine(kw, tokens, toks);
947 return(rc);
948}
[1262]949// cout << "PIACmd::Do() DBG KeyW= " << kw << " NbArgs= " << tokens.size() << endl;
950// for(int ii=0; ii<tokens.size(); ii++)
951// cout << "arg[ " << ii << " ] : " << tokens[ii] << endl;
952
[2241]953return(0);
[1262]954}
955
[2236]956
[1262]957/* --Methode-- */
[2236]958int PIACmd::LineToWords(string& line, string& kw, vector<string>& tokens,
959 string& toks, bool uq)
960{
961if (line.length() < 1) return(0);
962int nw = 1;
963size_t p = line.find_first_not_of(" ");
964line = line.substr(p);
965p = 0;
966size_t q = line.find_first_of(" ");
967size_t l = line.length();
968
969if (q < l)
970 { kw = line.substr(p,q-p); toks = line.substr(q, l-q); }
971else { kw = line.substr(p,l-p); toks = ""; }
972
973q = 0;
974while (q < l) {
975 p = toks.find_first_not_of(" \t",q+1); // au debut d'un token
976 if (p>=l) break;
977 if ( uq && ((toks[p] == '\'') || (toks[p] == '"')) ) {
978 q = toks.find(toks[p],p+1);
979 if (q>=l) {
980 cerr << "PIACmd::LineToWords/Syntax Error - Unbalenced quotes " << toks[p] << '.' << endl;
981 return(-1);
982 }
983 p++;
984 }
985 else {
986 q = toks.find_first_of(" \t",p); // la fin du token;
987 }
988 string token = toks.substr(p,q-p);
989 tokens.push_back(token); nw++;
990 }
991
992return(nw);
993}
994
995/* --Methode-- */
[1262]996int PIACmd::SubstituteVars(string & s, string & s2)
997// Variable substitution
998{
[2214]999NamedObjMgr& omg = *mObjMgr;
[1262]1000
[2215]1001int iarr = -1; // index d'element de tableau
1002size_t p,q,q2,q3,l;
[1262]1003
1004s2="";
[349]1005p = 0;
1006l = s.length();
[2214]1007string vn, vv;
[349]1008while (p < l) {
1009 q = s.find('$',p);
[1276]1010 if (q > l) break;
1011 q2 = s.find('\'',p);
1012 if ((q2 < l) && (q2 < q)) { // On saute la chaine delimitee par ' '
1013 q2 = s.find('\'',q2+1);
1014 if (q2 >= l) {
1015 cerr << " Syntax error - Unbalenced quotes !!! " << endl;
1016 return(1);
1017 }
1018 s2 += s.substr(p, q2-p+1);
1019 p = q2+1; continue;
1020 }
[349]1021 // cout << "DBG: " << s2 << " p= " << p << " q= " << q << " L= " << l << endl;
1022 if ((q>0) && (s[q-1] == '\\')) { // Escape character \$
1023 s2 += (s.substr(p,q-1-p) + '$') ; p = q+1;
1024 continue;
1025 }
1026 if (q >= l-1) {
[1276]1027 cerr << " Syntax error - line ending with $ !!! " << endl;
1028 return(2);
[349]1029 }
1030 vn = "";
1031 if ( s[q+1] == '{' ) { // Variable in the form ${name}
1032 q2 = s.find('}',q+1);
1033 if (q2 >= l) {
[1276]1034 cerr << " Syntax error - Unbalenced brace {} !!! " << endl;
1035 return(3);
[349]1036 }
1037 vn = s.substr(q+2,q2-q-2);
1038 q2++;
[2215]1039 }
1040 else if ( s[q+1] == '(' ) { // Variable in the form $(name)
1041 q2 = s.find(')',q+1);
1042 if (q2 >= l) {
1043 cerr << " Syntax error - Unbalenced parenthesis () !!! " << endl;
1044 return(3);
1045 }
1046 vn = s.substr(q+2,q2-q-2);
1047 q2++;
1048 }
[349]1049 else if ( s[q+1] == '[' ) { // Variable in the form $[varname] -> This is $$varname
1050 q2 = s.find(']',q+1);
1051 if (q2 >= l) {
[1276]1052 cerr << " Syntax error - Unbalenced brace [] !!! " << endl;
1053 return(4);
[349]1054 }
1055 vn = s.substr(q+2,q2-q-2);
[2214]1056 if (!GetVar(vn, vv)) return(5);
1057 vn = vv;
[349]1058 q2++;
1059 }
1060 else {
[1562]1061 q2 = s.find_first_of(" .:+-*/,[](){}&|!$\"'",q+1);
[349]1062 if (q2 > l) q2 = l;
[2215]1063 q3 = q2;
[349]1064 vn = s.substr(q+1, q2-q-1);
[2215]1065 // Si variable de type $varname[index] : element de tableau
1066 if ((q2 < l) && (s[q2] == '[') ) {
1067 q3 = s.find_first_of("]",q2+1);
1068 string sia = s.substr(q2+1, q3-q2-1);
[2218]1069 if (sia.length() < 1) {
1070 cerr << " Syntax error - in $varname[index] : $"
1071 << vn << "[" << sia <<"]" << endl;
1072 return(4);
1073 }
1074 if (isalpha(sia[0])) {
1075 string sia2;
1076 if (!GetVar(sia, sia2) || (sia2.length() < 1)) {
1077 cerr << " Syntax error - in $varname[index] : $"
1078 << vn << "[" << sia <<"]" << endl;
1079 return(4);
1080 }
1081 sia = sia2;
1082 }
[2215]1083 int rcdia = ctoi(sia.c_str(), &iarr);
1084 if (rcdia < 0) {
1085 cerr << " Syntax error - in $varname[iarr] : $"
1086 << vn << "[" << sia <<"]" << endl;
1087 return(4);
1088 }
[349]1089 }
[2215]1090 }
[2214]1091 if (!GetVar(vn, vv)) return(5);
[2215]1092 if (iarr < 0) {
1093 s2 += (s.substr(p, q-p) + vv);
1094 p = q2;
1095 }
1096 else {
1097 vector<string> vs;
1098 FillVStringFrString(vv, vs);
1099 if (iarr >= vs.size()) {
1100 cerr << " Substitution error - word index out of range in "
1101 << "$varname[iarr] : $" << vn << "[" << iarr <<"]" << endl;
1102 return(4);
1103 }
1104 else s2 += (s.substr(p, q-p) + vs[iarr]);
1105 p = q3+1;
1106 }
1107}
[349]1108if (p < l) s2 += s.substr(p);
1109
1110p = s2.find_first_not_of(" \t");
1111if (p < l) s2 = s2.substr(p);
1112
[1262]1113return(0);
1114}
[349]1115
[1262]1116/* --Methode-- */
[2214]1117bool PIACmd::GetVar(string & vn, string & vv)
1118{
1119NamedObjMgr& omg = *mObjMgr;
1120if (vn.length() < 1) {
1121 cerr << " PIACmd::SubstituteVar/Error: length(varname=" << vn << ")<1 !" << endl;
1122 vv = ""; return(false);
1123}
1124// Variable de type $# $0 $1 ... (argument de .pic ou de script)
1125int ka = 0;
1126if (vn == "#") {
1127 if (ArgsStack.empty()) {
1128 cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
1129 << " ($" << vn << ")" << endl;
[2218]1130 vv = ""; return(false);
[2214]1131 }
1132 char buff[32];
1133 long an = ArgsStack.top().size();
1134 sprintf(buff,"%ld", an);
[2218]1135 vv = buff; return(true);
[2214]1136}
1137else if (ctoi(vn.c_str(), &ka) > 0) { // $0 $1 $2 ...
1138 if (ArgsStack.empty()) {
1139 cerr << " PIACmd::SubstituteVar/Error: ArgsStack empty ! "
1140 << " ($" << vn << ")" << endl;
1141 vv = ""; return(false);
1142 }
1143 if ( (ka < 0) || (ka >= ArgsStack.top().size()) ) {
1144 cerr << " PIACmd::SubstituteVar/Error: Undefined variable ! "
1145 << " ($" << vn << ")" << endl;
1146 vv = ""; return(false);
1147 }
[2218]1148 vv = ArgsStack.top()[ka]; return(true);
[2214]1149}
[2218]1150else if (vn[0] == '#') { // Variable de type $#vname --> size(vname)
1151 vn = vn.substr(1);
1152 if (!omg.HasVar(vn) ) {
1153 cerr << " PIACmd::SubstituteVarError: Undefined variable "
1154 << vn << " ! " << endl;
1155 vv = ""; return(false);
1156 }
1157 vn = omg.GetVar(vn);
1158 vector<string> vs;
1159 FillVStringFrString(vn, vs);
1160 char buff[32];
1161 sprintf(buff,"%d", (int)vs.size());
1162 vv = buff; return(true);
1163 }
[2214]1164else { // variable ordinaire geree par NamedObjMgr
1165 if ( (!omg.HasVar(vn)) ) {
1166 cerr << " PIACmd::SubstituteVarError: Undefined variable "
1167 << vn << " ! " << endl;
[2218]1168 vv = ""; return(false);
[2214]1169 }
[2218]1170 vv = omg.GetVar(vn); return(true);
[2214]1171}
1172
[2218]1173return(false);
[2214]1174}
1175
1176/* --Methode-- */
[1565]1177int PIACmd::EvaluateTest(vector<string> & args, string & line, bool & res)
[1562]1178{
[1565]1179 res = true;
[2215]1180 if ((args.size() != 6) || (args[5] != "then") ||
1181 (args[0] != "(") || (args[4] != ")") ) return(1);
1182 if (args[2] == "==") res = (args[1] == args[3]);
1183 else if (args[2] == "!=") res = (args[1] != args[3]);
1184 else if (args[2] == "<")
1185 res = (atof(args[1].c_str()) < atof(args[3].c_str()));
1186 else if (args[2] == ">")
1187 res = (atof(args[1].c_str()) > atof(args[3].c_str()));
1188 else if (args[2] == "<=")
1189 res = (atof(args[1].c_str()) <= atof(args[3].c_str()));
1190 else if (args[2] == ">=")
1191 res = (atof(args[1].c_str()) >= atof(args[3].c_str()));
[1565]1192 else return(2);
1193 return(0);
[1562]1194}
1195
[2241]1196/* Operations sur le stack RPN */
1197inline bool Check_myRPNStack_(stack<double>& s, double& x, string& line)
1198{
1199 if (s.empty()) {
1200 cerr << "PIACmd::EvalRPNExpr: syntax error / empty RPN stack " << line << endl;
1201 return true;
1202 }
1203 else x = s.top();
1204 return false;
1205}
1206inline bool Check_myRPNStack_(stack<double>& s, double& x, double& y, string& line)
1207{
1208 if (s.size() < 2) {
1209 cerr << "PIACmd::EvalRPNExpr: syntax error / RPN stack size < 2 " << line << endl;
1210 return true;
1211 }
1212 else {
1213 x = s.top(); s.pop(); y = s.top();
1214 }
1215 return false;
1216}
1217
1218inline void Print_myRPNStack_(stack<double> s)
1219{
1220 if (s.empty())
1221 cout << "PIACmd::EvalRPNExpr/PrintStack: Empty stack " << endl;
1222 else {
1223 int k = 0;
1224 cout << "PIACmd::EvalRPNExpr/PrintStack: Size()= " << s.size() << endl;
1225 while( !s.empty() ) {
1226 cout << " " << k << ": " << s.top() << " ";
1227 if (k == 0) cout << " (x) " << endl;
1228 else if (k == 1) cout << " (y) " << endl;
1229 else if (k == 2) cout << " (z) " << endl;
1230 else cout << endl;
1231 s.pop(); k++;
1232 }
1233 }
[2236]1234
[2241]1235}
1236
[2265]1237int Sum_RPNStack_(stack<double>& s, double& sx, double& sx2, string& line)
1238{
1239 sx = sx2 = 0.;
1240 int nn = 0;
1241 double x = 0.;
1242 while( !s.empty() ) {
1243 x = s.top(); s.pop();
1244 sx += x; sx2 += x*x;
1245 nn++;
1246 }
1247 return(nn);
1248}
1249
1250int Product_RPNStack_(stack<double>& s, double& px, string& line)
1251{
1252 px = 1.;
1253 int nn = 0;
1254 double x = 0.;
1255 while( !s.empty() ) {
1256 x = s.top(); s.pop();
1257 px *= x; nn++;
1258 }
1259 return(nn);
1260}
[2241]1261
[1562]1262/* --Methode-- */
[2241]1263int PIACmd::EvalRPNExpr(vector<string> & args, string & line)
[2236]1264{
[2241]1265 NamedObjMgr& omg = *mObjMgr;
1266
1267 if (args.size() < 2) {
1268 cerr << "PIACmd::EvalRPNExpr: syntax error / missing arguments " << line << endl;
[2236]1269 return(1);
1270 }
[2241]1271 else if (args.size() == 2) {
1272 omg.SetVar(args[0], args[1]);
1273 return(0);
1274 }
[2236]1275
[2241]1276 double x,y;
1277 x = y = 0.;
1278 stack<double> rpnstack; // Stack des operations en RPN
1279 for(int k=1; k<args.size(); k++) {
1280 // Les 4 operations de base + - * /
[2236]1281 if (args[k] == "+") {
[2241]1282 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1283 rpnstack.top() = y+x;
[2236]1284 }
1285 else if (args[k] == "-") {
[2241]1286 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1287 rpnstack.top() = y-x;
[2236]1288 }
1289 else if (args[k] == "*") {
[2241]1290 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1291 rpnstack.top() = y*x;
[2236]1292 }
1293 else if (args[k] == "/") {
[2241]1294 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1295 rpnstack.top() = y/x;
[2236]1296 }
[2241]1297 // Les constantes : e , pi
1298 else if (args[k] == "e") {
1299 rpnstack.push(M_E);
1300 }
1301 else if (args[k] == "pi") {
1302 rpnstack.push(M_PI);
1303 }
1304 // Les fonctions usuelles a 1 argument f(x)
1305 else if (args[k] == "cos") {
1306 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1307 rpnstack.top() = cos(x);
1308 }
1309 else if (args[k] == "sin") {
1310 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1311 rpnstack.top() = sin(x);
1312 }
1313 else if (args[k] == "tan") {
1314 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1315 rpnstack.top() = tan(x);
1316 }
1317 else if (args[k] == "acos") {
1318 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1319 rpnstack.top() = acos(x);
1320 }
1321 else if (args[k] == "asin") {
1322 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1323 rpnstack.top() = asin(x);
1324 }
1325 else if (args[k] == "atan") {
1326 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1327 rpnstack.top() = atan(x);
1328 }
1329 else if (args[k] == "log") {
1330 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1331 rpnstack.top() = log(x);
1332 }
1333 else if (args[k] == "log10") {
1334 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1335 rpnstack.top() = log10(x);
1336 }
1337 else if (args[k] == "exp") {
1338 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1339 rpnstack.top() = exp(x);
1340 }
1341 else if (args[k] == "deg2rad") {
1342 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1343 rpnstack.top() = x*M_PI/180.;
1344 }
1345 else if (args[k] == "rad2deg") {
1346 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
1347 rpnstack.top() = x*180./M_PI;
1348 }
1349 // Les fonctions usuelles a 2 argument f(x,y)
1350 else if (args[k] == "pow") {
1351 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1352 rpnstack.top() = pow(y,x);
1353 }
1354 else if (args[k] == "atan2") {
1355 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1356 rpnstack.top() = atan2(x,y);
1357 }
[2265]1358 // Fonction a N arguments - Somme, produit, etc ...
1359 else if ((args[k] == "sum") || (args[k] == "mean") ||
1360 (args[k] == "sigma") || (args[k] == "sigma2") ) {
1361 double sx, sx2;
1362 int nn = Sum_RPNStack_(rpnstack, sx, sx2, line);
1363 if (args[k] == "sum") rpnstack.push(sx);
1364 else {
1365 if (nn == 0) {
1366 cerr << "PIACmd::EvalRPNExpr: mean/sigma error- RPN stack empty: "
1367 << line << endl;
1368 return(1);
1369 }
1370 double fnn = nn;
1371 if (args[k] == "mean") rpnstack.push(sx/fnn);
1372 else if (args[k] == "sigma2") rpnstack.push(sx2/fnn-(x*x/(fnn*fnn)));
1373 else rpnstack.push(sqrt(sx2/fnn-(x*x/(fnn*fnn))));
1374 }
1375 }
1376 else if (args[k] == "product") {
1377 double px;
1378 int nn = Product_RPNStack_(rpnstack, px, line);
1379 if (nn == 0) {
1380 cerr << "PIACmd::EvalRPNExpr: product error- RPN stack empty: "
1381 << line << endl;
1382 return(1);
1383 }
1384 rpnstack.push(px);
1385 }
[2241]1386 // Fonctions de manipulation de stack
1387 else if (args[k] == "print") {
1388 Print_myRPNStack_(rpnstack);
1389 }
1390 else if (args[k] == "x<>y") {
1391 if ( Check_myRPNStack_(rpnstack, x, y, line) ) return(1);
1392 rpnstack.top() = x; rpnstack.push(y);
1393 }
1394 // On met un nombre sur le stack
1395 else {
1396 if (ctof(args[k].c_str(),&x) < 0) {
1397 cerr << "PIACmd::EvalRPNExpr: syntax error near " << args[k]
1398 << " in expression: \n" << line << endl;
1399 return(2);
1400 }
1401 rpnstack.push(x);
1402 }
1403
[2236]1404 }
1405
[2241]1406 if ( Check_myRPNStack_(rpnstack, x, line) ) return(1);
[2236]1407 char buff[64];
1408 sprintf(buff, "%g", x);
[2241]1409 string res = buff;
1410 omg.SetVar(args[0], res);
[2236]1411 return(0);
1412}
1413
1414/* --Methode-- */
[2215]1415void PIACmd::PushStack(vector<string>& args)
1416{
1417 // We push the argument list (args) on the stack
1418 ArgsStack.push(args);
1419 // We push also PIACmdBloc and testresult on the stack
1420 CmdBlks.push(NULL);
1421 list<char> xtx;
1422 TestsStack.push(xtx);
1423
1424}
1425
1426/* --Methode-- */
1427void PIACmd::PopStack(bool psta)
1428{
1429 // We remove the argument list (args) from the stack
1430 if (psta) ArgsStack.pop();
1431 // And PIACmdBloc and TestResult from the corresponding stacks
1432 PIACmdBloc* curb = CmdBlks.top();
1433 while (curb != NULL) {
1434 PIACmdBloc* parb = curb->Parent();
1435 delete curb; curb = parb;
1436 }
1437 CmdBlks.pop();
1438 TestsStack.pop();
1439}
1440
1441/* --Methode-- */
[1262]1442int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
1443{
1444int rc = 0;
1445NamedObjMgr omg;
[349]1446
[165]1447// >>>>>>>>>>> Commande d'interpreteur
[1262]1448if (kw == "helpwindow") ShowHelpWindow();
[293]1449else if (kw == "help") {
[330]1450 if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl;
[293]1451 else {
[330]1452 string kwh = "piacmd";
1453 cout << GetUsage(kwh) << endl;
[293]1454 }
[165]1455 }
1456
1457else if (kw == "set") {
[293]1458 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: set varname string" << endl; return(0); }
[349]1459 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1460 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
1461 return(0);
1462 }
[1276]1463 // string xx = tokens[1];
1464 // for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk] );
1465 omg.SetVar(tokens[0], tokens[1]);
[165]1466 }
[349]1467
1468else if (kw == "getvar") {
1469 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: getvar newvarname varname" << endl; return(0); }
[1262]1470 if (!omg.HasVar(tokens[1])) {
[349]1471 cerr << "Error - No " << tokens[1] << " Variable " << endl;
1472 return(0);
1473 }
1474 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1475 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
1476 return(0);
1477 }
[1262]1478 omg.SetVar(tokens[0], omg.GetVar(tokens[1]) );
[349]1479 }
1480
1481else if (kw == "alias") {
1482 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: alias aliasname string" << endl; return(0); }
1483 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1484 cerr << "PIACmd::Interpret()/Error alias name should start with alphabetic" << endl;
1485 return(0);
1486 }
1487 string xx = tokens[1];
1488 for (int kk=2; kk<tokens.size(); kk++) xx += (' ' + tokens[kk]);
1489 mAliases[tokens[0]] = xx;
1490 }
1491
[333]1492else if (kw == "setol") {
1493 if (tokens.size() < 2) { cout << "PIACmd::Interpret() Usage: setol varname objnamepattern" << endl; return(0); }
[349]1494 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1495 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
1496 return(0);
1497 }
[333]1498 vector<string> ol;
[349]1499 mObjMgr->GetObjList(tokens[1], ol);
1500 string vol;
1501 if (ol.size() < 1) vol = "";
1502 else {
1503 vol = ol[0];
1504 for (int kk=1; kk<ol.size(); kk++) vol += (' ' + ol[kk]);
1505 }
[1262]1506 omg.SetVar(tokens[0], vol);
[333]1507 }
[293]1508else if (kw == "unset") {
1509 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: unset varname" << endl; return(0); }
[1262]1510 if (omg.HasVar(tokens[0])) omg.DeleteVar(tokens[0]) ;
[293]1511 else cerr << "PIACmd::Interpret() No variable with name " << tokens[0] << endl;
[165]1512 }
[2241]1513 else if (kw == "rpneval") { // Evaluation d'expression en notation polonaise inverse
1514 return(EvalRPNExpr(tokens, toks));
1515}
[333]1516else if (kw == "echo") {
[1276]1517 for (int ii=0; ii<tokens.size(); ii++)
1518 cout << tokens[ii] << " " ;
[333]1519 cout << endl;
[1276]1520 }
[353]1521else if (kw == "readstdin") {
1522 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: readstdin varname" << endl; return(0); }
1523 if ((tokens[0].length() < 1) || !isalpha((int)tokens[0][0]) ) {
1524 cerr << "PIACmd::Interpret()/Error Variable name should start with alphabetic" << endl;
1525 return(0);
1526 }
[357]1527 mImgApp->GetConsole()->AddStr(">>> Reading From StdIn \n", PIVA_Magenta);
1528 cout << tokens[0] << " ? " << endl;
[1262]1529 omg.SetVar(tokens[0], GetStringFrStdin(this) );
[353]1530 }
1531
[165]1532else if (kw == "listvars") {
[293]1533 cout << "PIACmd::Interpret() Variable List , VarName = Value \n";
[1262]1534 DVList& varlist = omg.GetVarList();
1535 DVList::ValList::const_iterator it;
1536 string value;
1537 for(it = varlist.Begin(); it != varlist.End(); it++) {
[1291]1538#ifdef SANS_EVOLPLANCK
1539 MuTyV mtv = (*it).second;
1540 value = (string)(mtv);
1541#else
[1262]1542 value = (string)((*it).second.elval);
[1291]1543#endif
[1262]1544 cout << (*it).first << " = " << value << "\n";
1545 }
[165]1546 cout << endl;
1547 }
[353]1548else if (kw == "listalias") {
1549 cout << "PIACmd::Interpret() Alias List , AliasName = Value \n";
[2214]1550 CmdStrList::iterator it;
[353]1551 for(it = mAliases.begin(); it != mAliases.end(); it++)
1552 cout << (*it).first << " = " << (*it).second << "\n";
1553 cout << endl;
1554 }
1555else if (kw == "listcommands") {
[2236]1556 cout << "---- PIACmd::Interpret() Command List ----- \n";
[293]1557 CmdExmap::iterator it;
1558 int kc = 0;
1559 for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
1560 cout << (*it).first << " ";
1561 kc++;
1562 if (kc >= 5) { cout << "\n"; kc = 0; }
1563 }
1564 cout << endl;
1565 }
[2236]1566else if (kw == "listscripts") {
1567 cout << "---- PIACmd::Interpret() Script List ----- \n";
1568 for(ScriptList::iterator sit = mScripts.begin();
1569 sit != mScripts.end(); sit++)
1570 cout << " Script: " << (*sit).second->Name() << " - "
1571 << (*sit).second->Comment() << endl;
1572}
1573else if (kw == "clearscript") {
1574 if (tokens.size() < 1) {
1575 cout << "PIACmd::Interpret() Usage: clearscript scriptname" << endl;
1576 return(0);
1577 }
1578 ScriptList::iterator sit = mScripts.find(tokens[0]);
1579 if (sit == mScripts.end()) {
1580 cout << "PIACmd::Interpret() No script with name" << tokens[0] << endl;
1581 return(0);
1582 }
1583 else {
1584 delete (*sit).second;
1585 mScripts.erase(sit);
1586 cout << "PIACmd::Interpret() script " << tokens[0] << " cleared" << endl;
1587 return(0);
1588 }
1589}
[293]1590else if (kw == "traceon") { cout << "PIACmd::Interpret() -> Trace ON mode " << endl; trace = true; }
1591else if (kw == "traceoff") { cout << "PIACmd::Interpret() -> Trace OFF mode " << endl; trace = false; }
[165]1592else if (kw == "timingon") {
[293]1593 cout << "PIACmd::Interpret() -> Timing ON mode " << endl;
1594 if (gltimer) delete gltimer; gltimer = new Timer("PIA-CmdInterpreter "); timing = true;
1595 }
[165]1596else if (kw == "timingoff") {
[293]1597 cout << "PIACmd::Interpret() -> Timing OFF mode " << endl;
1598 if (gltimer) delete gltimer; gltimer = NULL; timing = false;
1599 }
[165]1600else if (kw == "exec") {
[293]1601 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: exec filename" << endl; return(0); }
[349]1602 ExecFile(tokens[0], tokens);
[165]1603 }
1604else if (kw == "shell") {
[293]1605 if (tokens.size() < 1) { cout << "PIACmd::Interpret() Usage: shell cmdline" << endl; return(0); }
[1276]1606 string cmd;
1607 for (int ii=0; ii<tokens.size(); ii++)
1608 cmd += (tokens[ii] + ' ');
1609 system(cmd.c_str());
[165]1610 }
[2203]1611else if (kw == "cshell") {
1612 if(tokens.size()<1) {cout<<"PIACmd::Interpret() Usage: cshell cmdline"<<endl; return(0);}
1613 string cmd="";
1614 for(int ii=0;ii<tokens.size();ii++) cmd+=(tokens[ii]+' ');
1615 CShellExecute(cmd);
1616 }
[1276]1617
[293]1618// Execution d'une commande enregistree
[1268]1619else rc = ExecuteCommand(kw, tokens, toks);
[165]1620
1621if (timing) gltimer->Split();
[333]1622return(rc);
[165]1623}
1624
[333]1625/* --Methode-- */
[2236]1626int PIACmd::ParseLineExecute(string& line, bool qw)
1627 // Si qw == true, on decoupe entre '' ou "" ou espaces
[333]1628{
[1262]1629vector<string> tokens;
[2236]1630string kw, toks;
[333]1631if (line.length() < 1) return(0);
[2236]1632LineToWords(line, kw, tokens, toks, qw);
[1268]1633return(ExecuteCommand(kw, tokens, toks));
[333]1634}
1635
[165]1636/* --Methode-- */
[1268]1637int PIACmd::ExecuteCommand(string& keyw, vector<string>& args, string& toks)
[333]1638{
1639 int rc = -1;
1640 CmdExmap::iterator it = cmdexmap.find(keyw);
1641 if (it == cmdexmap.end()) cout << "No such command : " << keyw << " ! " << endl;
1642 else {
[1268]1643 if ((*it).second.cex) rc = (*it).second.cex->Execute(keyw, args, toks);
[333]1644 else cout << "Dont know how to execute " << keyw << " ? " << endl;
1645 }
1646 return(rc);
1647}
1648
1649/* --Methode-- */
[349]1650int PIACmd::ExecFile(string& file, vector<string>& args)
[165]1651{
[293]1652char line_buff[512];
1653FILE *fip;
[165]1654
[293]1655if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
[384]1656 if (file.find('.') >= file.length()) {
1657 cout << "PIACmd::Exec(): Error opening file " << file << endl;
1658 file += ".pic";
1659 cout << " Trying file " << file << endl;
1660 fip = fopen(file.c_str(),"r");
1661 }
1662 }
1663
1664if(fip == NULL) {
[293]1665 cerr << "PIACmd::Exec() Error opening file " << file << endl;
1666 hist << "##! PIACmd::Exec() Error opening file " << file << endl;
1667 return(0);
[165]1668 }
[349]1669
1670// hist << "### Executing commands from " << file << endl;
1671
[2215]1672PushStack(args);
[293]1673if (trace) {
1674 mImgApp->GetConsole()->AddStr("### Executing commands from ", PIVA_Magenta);
1675 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
1676 mImgApp->GetConsole()->AddStr("\n", PIVA_Magenta);
1677 }
[165]1678
[1562]1679bool ohv = histon;
[349]1680histon = false;
[293]1681while (fgets(line_buff,511,fip) != NULL)
1682 {
1683 if (trace) mImgApp->GetConsole()->AddStr(line_buff, PIVA_Magenta);
1684 line_buff[strlen(line_buff)-1] = '\0'; /* LF/CR de la fin */
1685 string line(line_buff);
[1565]1686 if (Interpret(line) == 77777) break;
[165]1687 }
[1562]1688histon = ohv;
[349]1689
1690// hist << "### End of Exec( " << file << " ) " << endl;
[293]1691if (trace) {
1692 mImgApp->GetConsole()->AddStr("### End of Exec( ", PIVA_Magenta);
1693 mImgApp->GetConsole()->AddStr(file.c_str(), PIVA_Magenta);
1694 mImgApp->GetConsole()->AddStr(" ) \n", PIVA_Magenta);
[165]1695 }
1696
[2215]1697PopStack(true);
[2214]1698
[165]1699return(0);
1700}
1701
[2203]1702/* --Methode-- */
1703int PIACmd::CShellExecute(string cmd)
1704{
1705 if(cmd.size()<=0) return -1;
[293]1706
[2203]1707 NamedObjMgr omg;
1708 string fname = omg.GetTmpDir(); fname += "cshell_exec_pia.csh";
1709
1710 string cmdrm = "rm -f " + fname;
1711 system(cmdrm.c_str());
1712
1713 FILE *fip = fopen(fname.c_str(),"w");
1714 if(fip==NULL) {
1715 cout << "PIACmd/CShellExecute_Error: fopen("<<fname<<") failed"<<endl;
1716 return -2;
1717 }
1718 fprintf(fip,"#!/bin/csh\n\n");
1719 fprintf(fip,"%s\n",cmd.c_str());
1720 fprintf(fip,"\nexit 0\n");
1721 fclose(fip);
1722
1723 cmd = "csh "; cmd += fname;
1724 system(cmd.c_str());
1725
1726 system(cmdrm.c_str());
1727
1728 return 0;
1729}
1730
[293]1731static string* videstr = NULL;
1732/* --Methode-- */
1733string& PIACmd::GetUsage(const string& kw)
[165]1734{
[330]1735bool fndok = false;
[293]1736CmdExmap::iterator it = cmdexmap.find(kw);
[330]1737if (it == cmdexmap.end()) {
1738 it = helpexmap.find(kw);
1739 if (it != helpexmap.end()) fndok = true;
[165]1740 }
[330]1741 else fndok = true;
1742if (fndok) return( (*it).second.us );
1743// Keyword pas trouve
1744if (videstr == NULL) videstr = new string("");
1745*videstr = "Nothing known about " + kw + " ?? ";
1746return(*videstr);
1747
[165]1748}
1749
[293]1750/* --Methode-- */
1751void PIACmd::ShowHelpWindow()
[165]1752{
[293]1753helpwin->Show();
[165]1754}
[357]1755
[463]1756/* --Methode-- */
[1251]1757void PIACmd::ShowCxxOptionWindow()
1758{
1759cxxoptwin->Show();
1760}
1761
1762/* --Methode-- */
1763void PIACmd::ShowCxxExecWindow()
1764{
1765cxxexwin->Show();
1766}
1767
[2263]1768/* Les definitions suivantes doivent se trouver ds l'en-tete du fichier LaTeX
1769 \newcommand{\piacommand}[1]{
1770 \framebox{\bf \Large #1 } \index{#1} % (Command)
1771 }
1772
1773 \newcommand{\piahelpitem}[1]{
1774 \framebox{\bf \Large #1 } \index{#1} (Help item)
1775 }
1776
1777 \newcommand{\myppageref}[1]{ (p. \pageref{#1} ) }
1778*/
1779
[1251]1780/* --Methode-- */
[2263]1781void PIACmd::HelptoLaTeX(string const & fname)
[463]1782{
1783FILE *fip;
1784if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1785 cout << "PIACmd::HelptoLaTex_Error: fopen( " << fname << endl;
1786 return;
1787 }
[357]1788
[463]1789fputs("% ----- Liste des groupes de Help ----- \n",fip);
1790fputs("List of {\\bf piapp} on-line Help groups: \n", fip);
1791fputs("\\begin{itemize} \n",fip);
1792CmdHGroup::iterator it;
[2263]1793for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++) {
1794 if ((*it).first == "All") continue;
[484]1795 fprintf(fip,"\\item {\\bf %s } (p. \\pageref{%s}) \n",
1796 (*it).first.c_str(), (*it).first.c_str());
[2263]1797}
[463]1798
1799fputs("\\end{itemize} \n",fip);
1800
[2263]1801fputs("\\vspace*{10mm} \n",fip);
[484]1802
1803CmdExmap::iterator ite;
1804fputs("% ----- Liste de toutes les commandes ----- \n",fip);
1805fputs("\\begin{center} \n ", fip);
1806fputs("\\rule{2cm}{1mm} List of {\\bf piapp} Help items \\rule{2cm}{1mm} \n", fip);
1807fputs("\n \n \\vspace{5mm} \n",fip);
1808fputs("\\begin{tabular}{llllll} \n", fip);
1809int kt = 0;
1810for(ite = helpexmap.begin(); ite != helpexmap.end(); ite++) {
1811 fprintf(fip,"%s & p. \\pageref{%s} ", (*ite).first.c_str(), (*ite).first.c_str() );
1812 kt++;
1813 if (kt < 3) fputs(" & ", fip);
1814 else { fputs(" \\\\ \n", fip); kt = 0; }
1815 }
1816if (kt == 1) fputs(" & & & \\\\ \n", fip);
1817else if (kt == 2) fputs(" & \\\\ \n", fip);
1818fputs("\\end{tabular} \n", fip);
1819fputs("\\end{center} \n", fip);
[2263]1820fputs("\n \n \\newpage \\vspace{1cm} \n",fip);
[484]1821
1822fputs("\\begin{center} \n ", fip);
1823fputs("\\rule{2cm}{1mm} List of {\\bf piapp} Commands \\rule{2cm}{1mm} \n", fip);
1824fputs("\n \n \\vspace{5mm} \n",fip);
1825fputs("\\begin{tabular}{llllll} \n", fip);
1826kt = 0;
1827for(ite = cmdexmap.begin(); ite != cmdexmap.end(); ite++) {
1828 fprintf(fip,"%s & p. \\pageref{%s} ", (*ite).first.c_str(), (*ite).first.c_str() );
1829 kt++;
1830 if (kt < 3) fputs(" & ", fip);
1831 else { fputs(" \\\\ \n", fip); kt = 0; }
1832 }
1833if (kt == 1) fputs(" & & & \\\\ \n", fip);
1834else if (kt == 2) fputs(" & \\\\ \n", fip);
1835fputs("\\end{tabular} \n", fip);
1836fputs("\\end{center} \n", fip);
1837// fputs("\\newline \n",fip);
1838
[463]1839fputs("% ----- Liste des commandes dans chaque groupe ----- \n",fip);
1840fputs("\\newpage \n",fip);
1841int gid;
1842for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++) {
1843 gid = (*it).second;
1844 if (gid == 0) continue;
[484]1845 fprintf(fip,"\\subsection{%s} \\label{%s} \n",
1846 (*it).first.c_str(), (*it).first.c_str());
[2263]1847 fprintf(fip,"\\noindent \n");
[463]1848 for(ite = helpexmap.begin(); ite != helpexmap.end(); ite++) {
1849 if ((*ite).second.group != gid) continue;
[2263]1850 fprintf(fip,"\\piahelpitem{%s} \\label{%s} \n",
[484]1851 (*ite).first.c_str(), (*ite).first.c_str());
[463]1852 fputs("\\begin{verbatim} \n",fip);
1853 fprintf(fip,"%s\n", (*ite).second.us.c_str());
1854 fputs("\\end{verbatim} \n",fip);
1855 }
1856 for(ite = cmdexmap.begin(); ite != cmdexmap.end(); ite++) {
1857 if ((*ite).second.group != gid) continue;
[2263]1858 fprintf(fip,"\\piacommand{%s} \\label{%s} \n",
[484]1859 (*ite).first.c_str(), (*ite).first.c_str());
[463]1860 fputs("\\begin{verbatim} \n",fip);
1861 fprintf(fip,"%s\n", (*ite).second.us.c_str());
1862 fputs("\\end{verbatim} \n",fip);
1863 }
1864}
1865
1866fclose(fip);
1867return;
1868}
1869
1870
1871
Note: See TracBrowser for help on using the repository browser.