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