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