| [165] | 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
|  | 2 | // Classe interpreteur de commande pour piapp | 
|---|
|  | 3 | // Reza      Aout 97 , Juillet,Aout 98 | 
|---|
|  | 4 | // LAL-IN2P3/CNRS | 
|---|
|  | 5 |  | 
|---|
|  | 6 | #ifndef PIACMD_H_SEEN | 
|---|
|  | 7 | #define PIACMD_H_SEEN | 
|---|
|  | 8 |  | 
|---|
| [293] | 9 | #include "machdefs.h" | 
|---|
| [2322] | 10 | #include <iostream> | 
|---|
|  | 11 | #include <fstream> | 
|---|
| [165] | 12 | #include <string> | 
|---|
| [293] | 13 | #include <vector> | 
|---|
| [1262] | 14 | #include <list> | 
|---|
| [2214] | 15 | #include <stack> | 
|---|
| [165] | 16 | #include <map> | 
|---|
| [351] | 17 | #include <functional> | 
|---|
| [165] | 18 |  | 
|---|
|  | 19 | #include "dlftypes.h" | 
|---|
| [912] | 20 | #include "pdlmgr.h" | 
|---|
| [1920] | 21 | #include "ctimer.h" | 
|---|
| [165] | 22 |  | 
|---|
| [293] | 23 | // Classe definissant l'interface pour un executeur de commande | 
|---|
|  | 24 | class CmdExecutor { | 
|---|
|  | 25 | public: | 
|---|
|  | 26 | virtual       ~CmdExecutor() {} ; | 
|---|
|  | 27 | // keyw : Le mot cle associe , args: Arguments de la commande | 
|---|
| [1268] | 28 | virtual int   Execute(string& keyw, vector<string>& args, string& toks)=0; | 
|---|
| [293] | 29 | }; | 
|---|
|  | 30 |  | 
|---|
|  | 31 | // Classe definissant l'interface pour un interpreteur de commande | 
|---|
|  | 32 | class CmdInterpreter { | 
|---|
|  | 33 | public: | 
|---|
|  | 34 | virtual               ~CmdInterpreter() {} ; | 
|---|
|  | 35 | virtual string        Name()=0; | 
|---|
|  | 36 | virtual int           Interpret(string& line)=0; | 
|---|
|  | 37 | }; | 
|---|
|  | 38 |  | 
|---|
|  | 39 |  | 
|---|
|  | 40 |  | 
|---|
|  | 41 | // Forward declaration of some classes ... | 
|---|
| [165] | 42 | class NamedObjMgr; | 
|---|
|  | 43 | class PIStdImgApp; | 
|---|
| [897] | 44 | #ifdef SANS_EVOLPLANCK | 
|---|
| [293] | 45 | class Timer; | 
|---|
| [897] | 46 | #else | 
|---|
|  | 47 | namespace SOPHYA { | 
|---|
|  | 48 | class Timer; | 
|---|
|  | 49 | } | 
|---|
|  | 50 | #endif | 
|---|
| [1251] | 51 |  | 
|---|
|  | 52 | class PIAHelpWind;   // Fenetre d'aide en ligne | 
|---|
|  | 53 | class CxxExecWind;   // Fenetre pour CxxExecutor | 
|---|
|  | 54 | class CxxOptionWind; // Option de CxxExecutor | 
|---|
|  | 55 |  | 
|---|
| [2214] | 56 | class PIACmdBloc;    // Bloc de type foreach / for de l'interpreteur PIACmd | 
|---|
|  | 57 | class PIACmdScript;  // Script de commandes defini ds l'interpreteur PIACmd | 
|---|
| [349] | 58 |  | 
|---|
| [293] | 59 | // --------------------------------------------------------------------- | 
|---|
|  | 60 | // Classe Interpreteur de commande, gestionnaire de module chargeable, | 
|---|
|  | 61 | // et de fonctions dynamiquement linke pour PIStdImgApp | 
|---|
|  | 62 | // Permet de gerer plusieurs Interpreter differents | 
|---|
|  | 63 | // --------------------------------------------------------------------- | 
|---|
| [165] | 64 |  | 
|---|
| [330] | 65 |  | 
|---|
| [293] | 66 | class PIACmd : public CmdInterpreter  { | 
|---|
| [165] | 67 | public: | 
|---|
| [293] | 68 | static PIACmd*        GetInterpreter(); | 
|---|
| [165] | 69 |  | 
|---|
| [293] | 70 | PIACmd(NamedObjMgr* omg, PIStdImgApp* app); | 
|---|
|  | 71 | virtual               ~PIACmd(); | 
|---|
|  | 72 | virtual string        Name(); | 
|---|
|  | 73 |  | 
|---|
| [330] | 74 | virtual void          RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, | 
|---|
| [484] | 75 | string grp="Commands"); | 
|---|
| [330] | 76 | virtual void          RegisterHelp(string& keyw, string& usage, string& grp); | 
|---|
| [293] | 77 | virtual void          LoadModule(string& fnameso, string& name); | 
|---|
|  | 78 |  | 
|---|
|  | 79 | virtual void          AddInterpreter(CmdInterpreter * cl); | 
|---|
|  | 80 | virtual void          SelInterpreter(string& name); | 
|---|
|  | 81 |  | 
|---|
|  | 82 | virtual int           Interpret(string& line); | 
|---|
| [2236] | 83 | virtual int           ParseLineExecute(string& line, bool qw=true); | 
|---|
| [1268] | 84 | virtual int           ExecuteCommand(string& keyw, vector<string>& args, string& toks); | 
|---|
| [349] | 85 | virtual int           ExecFile(string& file, vector<string>& args); | 
|---|
| [2203] | 86 | virtual int           CShellExecute(string cmd); | 
|---|
| [293] | 87 | virtual string&       GetUsage(const string& kw); | 
|---|
|  | 88 |  | 
|---|
| [1251] | 89 | void          ShowHelpWindow(); | 
|---|
|  | 90 | void          ShowCxxOptionWindow(); | 
|---|
|  | 91 | void          ShowCxxExecWindow(); | 
|---|
|  | 92 |  | 
|---|
| [2263] | 93 | virtual void          HelptoLaTeX(string const & flnm); | 
|---|
| [463] | 94 |  | 
|---|
| [293] | 95 | inline  CmdInterpreter* CurrentInterpreter() { return(curcmdi); } | 
|---|
|  | 96 | inline  CmdExecutor*    BaseExecutor()  { return(basexec); } | 
|---|
| [1828] | 97 | inline  CmdExecutor*    ContExecutor()  { return(cntexec); } //_OP_ | 
|---|
| [293] | 98 | inline  PIStdImgApp*    GetImgApp() { return(mImgApp); } | 
|---|
|  | 99 |  | 
|---|
| [330] | 100 | //   Pour utilisation par PIAHelpWind uniquement | 
|---|
|  | 101 | virtual void          UpdateHelpList(PIAHelpWind* hw, int gid); | 
|---|
|  | 102 |  | 
|---|
| [2236] | 103 | //   Utilitaire pour decoupage en mot | 
|---|
|  | 104 | static  int   LineToWords(string& line, string& kw, vector<string>& tokens, | 
|---|
|  | 105 | string& toks, bool uq=true); | 
|---|
| [293] | 106 | protected: | 
|---|
| [2215] | 107 | virtual int   CheckHelpGrp(string& grp); | 
|---|
| [1262] | 108 | int           ExecuteCommandLine(string & keyw, vector<string> & args, | 
|---|
|  | 109 | string & toks); | 
|---|
| [330] | 110 |  | 
|---|
| [1262] | 111 | int           SubstituteVars(string & s, string & s2); | 
|---|
| [1565] | 112 | int           EvaluateTest(vector<string> & args, | 
|---|
|  | 113 | string & line, bool & res); | 
|---|
| [2241] | 114 | int           EvalRPNExpr(vector<string> & args, string & line); | 
|---|
| [2236] | 115 |  | 
|---|
| [2214] | 116 | bool          GetVar(string & vn, string & vv); | 
|---|
| [2215] | 117 | void          PushStack(vector<string> & args); | 
|---|
|  | 118 | void          PopStack(bool psta=true); | 
|---|
| [1262] | 119 |  | 
|---|
| [165] | 120 | NamedObjMgr* mObjMgr; | 
|---|
|  | 121 | PIStdImgApp* mImgApp; | 
|---|
|  | 122 |  | 
|---|
| [293] | 123 | CmdInterpreter* curcmdi; | 
|---|
| [1224] | 124 | CmdExecutor* basexec;  // basic command executor | 
|---|
|  | 125 | CmdExecutor* fitexec;  // Fit command executor | 
|---|
|  | 126 | CmdExecutor* pawexec;  // paw-like command executor | 
|---|
|  | 127 | CmdExecutor* cxxexec;  // on-line c++ compile/execution command executor | 
|---|
| [293] | 128 |  | 
|---|
| [1828] | 129 | CmdExecutor *cntexec; // contour executor _OP_ | 
|---|
| [1920] | 130 | CmdExecutor *flwexec; // flow chart executor _OP_ | 
|---|
| [1828] | 131 |  | 
|---|
| [330] | 132 | // Pour enregistrer la liste de commandes et leurs executeurs et le help | 
|---|
|  | 133 | struct cmdex {int group; string us; CmdExecutor * cex; } ; | 
|---|
|  | 134 | typedef map<string, int, less<string> > CmdHGroup;   // Liste des groupes de commandes | 
|---|
|  | 135 | CmdHGroup cmdhgrp; | 
|---|
|  | 136 | int cmdgrpid;                                     // Numero de groupe courant | 
|---|
| [293] | 137 | typedef map<string, cmdex, less<string> > CmdExmap; | 
|---|
|  | 138 | CmdExmap cmdexmap; | 
|---|
| [330] | 139 | CmdExmap helpexmap;                               // Pour les helps sans commande | 
|---|
| [293] | 140 |  | 
|---|
|  | 141 | // Pour garder la liste des modules | 
|---|
|  | 142 | typedef map<string, PDynLinkMgr* , less<string> > Modmap; | 
|---|
|  | 143 | Modmap modmap; | 
|---|
|  | 144 |  | 
|---|
|  | 145 | // Pour garder la liste des interpreteur | 
|---|
|  | 146 | typedef map<string, CmdInterpreter*, less<string> > InterpMap; | 
|---|
|  | 147 | InterpMap interpmap; | 
|---|
|  | 148 |  | 
|---|
| [2214] | 149 | //  Pour stocker les scripts definis ds l'interpreteur | 
|---|
|  | 150 | typedef map<string, PIACmdScript*, less<string> > ScriptList; | 
|---|
|  | 151 | ScriptList mScripts;  // Liste des scripts | 
|---|
| [2236] | 152 | PIACmdScript* curscript; // Script en cours de definition | 
|---|
| [349] | 153 |  | 
|---|
| [2214] | 154 | //  Pour stocker les alias definies par l'interpreteur | 
|---|
|  | 155 | typedef map<string, string, less<string> > CmdStrList; | 
|---|
|  | 156 | CmdStrList mAliases;  // Liste des alias | 
|---|
|  | 157 |  | 
|---|
|  | 158 | // Le stack pour les arguments des .pic et des scripts | 
|---|
|  | 159 | stack< vector<string> > ArgsStack; | 
|---|
|  | 160 |  | 
|---|
| [2215] | 161 | stack< PIACmdBloc * > CmdBlks;  // Bloc de commande courant (foreach, ...) | 
|---|
|  | 162 | int felevel;                    // foreach-for level | 
|---|
|  | 163 | stack< list<char> > TestsStack; // Stack des resultats de test | 
|---|
| [1565] | 164 | list<char>::iterator tresit;       // Test courant | 
|---|
| [2215] | 165 | bool curtestresult;             // Resultat courant des tests | 
|---|
|  | 166 |  | 
|---|
| [1276] | 167 | bool mulinefg;            // Bloc multi-lignes (ligne suite) | 
|---|
|  | 168 | string mulinecmd;         // Commande multi-lignes | 
|---|
| [2274] | 169 | string spromptmul;        // Prompt console avant multi-ligne | 
|---|
| [349] | 170 |  | 
|---|
| [165] | 171 | ofstream hist;       //  History file | 
|---|
| [349] | 172 | bool histon;        //  True ->  history file | 
|---|
| [165] | 173 | bool trace;          // Trace flag | 
|---|
|  | 174 | bool timing;         // Display CPU Time | 
|---|
|  | 175 | Timer* gltimer;      // pour Display CPU Time | 
|---|
|  | 176 |  | 
|---|
| [293] | 177 | // Fenetre d'aide interactive | 
|---|
|  | 178 | PIAHelpWind* helpwin; | 
|---|
| [1251] | 179 | CxxExecWind* cxxexwin; | 
|---|
|  | 180 | CxxOptionWind* cxxoptwin; | 
|---|
| [165] | 181 | }; | 
|---|
|  | 182 |  | 
|---|
| [293] | 183 |  | 
|---|
|  | 184 |  | 
|---|
| [165] | 185 | #endif | 
|---|