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