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