| [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" | 
|---|
|  | 10 | #include <iostream.h> | 
|---|
| [165] | 11 | #include <fstream.h> | 
|---|
|  | 12 | #include <string> | 
|---|
| [293] | 13 | #include <vector> | 
|---|
| [1262] | 14 | #include <list> | 
|---|
| [165] | 15 | #include <map> | 
|---|
| [351] | 16 | #include <functional> | 
|---|
| [165] | 17 |  | 
|---|
|  | 18 | #include "dlftypes.h" | 
|---|
| [912] | 19 | #include "pdlmgr.h" | 
|---|
| [165] | 20 |  | 
|---|
| [293] | 21 |  | 
|---|
|  | 22 | // Classe definissant l'interface pour un executeur de commande | 
|---|
|  | 23 | class CmdExecutor { | 
|---|
|  | 24 | public: | 
|---|
|  | 25 | virtual       ~CmdExecutor() {} ; | 
|---|
|  | 26 | // keyw : Le mot cle associe , args: Arguments de la commande | 
|---|
| [1268] | 27 | virtual int   Execute(string& keyw, vector<string>& args, string& toks)=0; | 
|---|
| [293] | 28 | }; | 
|---|
|  | 29 |  | 
|---|
|  | 30 | // Classe definissant l'interface pour un interpreteur de commande | 
|---|
|  | 31 | class CmdInterpreter { | 
|---|
|  | 32 | public: | 
|---|
|  | 33 | virtual               ~CmdInterpreter() {} ; | 
|---|
|  | 34 | virtual string        Name()=0; | 
|---|
|  | 35 | virtual int           Interpret(string& line)=0; | 
|---|
|  | 36 | }; | 
|---|
|  | 37 |  | 
|---|
|  | 38 |  | 
|---|
|  | 39 |  | 
|---|
|  | 40 | // Forward declaration of some classes ... | 
|---|
| [165] | 41 | class NamedObjMgr; | 
|---|
|  | 42 | class PIStdImgApp; | 
|---|
| [897] | 43 | #ifdef SANS_EVOLPLANCK | 
|---|
| [293] | 44 | class Timer; | 
|---|
| [897] | 45 | #else | 
|---|
|  | 46 | namespace SOPHYA { | 
|---|
|  | 47 | class Timer; | 
|---|
|  | 48 | } | 
|---|
|  | 49 | #endif | 
|---|
| [1251] | 50 |  | 
|---|
|  | 51 | class PIAHelpWind;   // Fenetre d'aide en ligne | 
|---|
|  | 52 | class CxxExecWind;   // Fenetre pour CxxExecutor | 
|---|
|  | 53 | class CxxOptionWind; // Option de CxxExecutor | 
|---|
|  | 54 |  | 
|---|
| [349] | 55 | class PIACmdBloc; | 
|---|
|  | 56 |  | 
|---|
| [293] | 57 | // --------------------------------------------------------------------- | 
|---|
|  | 58 | // Classe Interpreteur de commande, gestionnaire de module chargeable, | 
|---|
|  | 59 | // et de fonctions dynamiquement linke pour PIStdImgApp | 
|---|
|  | 60 | // Permet de gerer plusieurs Interpreter differents | 
|---|
|  | 61 | // --------------------------------------------------------------------- | 
|---|
| [165] | 62 |  | 
|---|
| [330] | 63 |  | 
|---|
| [293] | 64 | class PIACmd : public CmdInterpreter  { | 
|---|
| [165] | 65 | public: | 
|---|
| [293] | 66 | static PIACmd*        GetInterpreter(); | 
|---|
| [165] | 67 |  | 
|---|
| [293] | 68 | PIACmd(NamedObjMgr* omg, PIStdImgApp* app); | 
|---|
|  | 69 | virtual               ~PIACmd(); | 
|---|
|  | 70 | virtual string        Name(); | 
|---|
|  | 71 |  | 
|---|
| [330] | 72 | virtual void          RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, | 
|---|
| [484] | 73 | string grp="Commands"); | 
|---|
| [330] | 74 | virtual void          RegisterHelp(string& keyw, string& usage, string& grp); | 
|---|
| [293] | 75 | virtual void          LoadModule(string& fnameso, string& name); | 
|---|
|  | 76 |  | 
|---|
|  | 77 | virtual void          AddInterpreter(CmdInterpreter * cl); | 
|---|
|  | 78 | virtual void          SelInterpreter(string& name); | 
|---|
|  | 79 |  | 
|---|
|  | 80 | virtual int           Interpret(string& line); | 
|---|
| [1262] | 81 | virtual int           ParseLineExecute(string& line); | 
|---|
| [1268] | 82 | virtual int           ExecuteCommand(string& keyw, vector<string>& args, string& toks); | 
|---|
| [349] | 83 | virtual int           ExecFile(string& file, vector<string>& args); | 
|---|
| [293] | 84 |  | 
|---|
|  | 85 | virtual string&       GetUsage(const string& kw); | 
|---|
|  | 86 |  | 
|---|
| [1251] | 87 | void          ShowHelpWindow(); | 
|---|
|  | 88 | void          ShowCxxOptionWindow(); | 
|---|
|  | 89 | void          ShowCxxExecWindow(); | 
|---|
|  | 90 |  | 
|---|
| [463] | 91 | virtual void          HelptoLaTex(string const & flnm); | 
|---|
|  | 92 |  | 
|---|
| [293] | 93 | inline  CmdInterpreter* CurrentInterpreter() { return(curcmdi); } | 
|---|
|  | 94 | inline  CmdExecutor*    BaseExecutor()  { return(basexec); } | 
|---|
|  | 95 | inline  PIStdImgApp*    GetImgApp() { return(mImgApp); } | 
|---|
|  | 96 |  | 
|---|
| [330] | 97 | //   Pour utilisation par PIAHelpWind uniquement | 
|---|
|  | 98 | virtual void          UpdateHelpList(PIAHelpWind* hw, int gid); | 
|---|
|  | 99 |  | 
|---|
| [293] | 100 | protected: | 
|---|
| [330] | 101 | virtual int           CheckHelpGrp(string& grp); | 
|---|
| [1262] | 102 | int           ExecuteCommandLine(string & keyw, vector<string> & args, | 
|---|
|  | 103 | string & toks); | 
|---|
| [330] | 104 |  | 
|---|
| [1262] | 105 | int           SubstituteVars(string & s, string & s2); | 
|---|
| [1565] | 106 | int           EvaluateTest(vector<string> & args, | 
|---|
|  | 107 | string & line, bool & res); | 
|---|
| [1262] | 108 |  | 
|---|
| [165] | 109 | NamedObjMgr* mObjMgr; | 
|---|
|  | 110 | PIStdImgApp* mImgApp; | 
|---|
|  | 111 |  | 
|---|
| [293] | 112 | CmdInterpreter* curcmdi; | 
|---|
| [1224] | 113 | CmdExecutor* basexec;  // basic command executor | 
|---|
|  | 114 | CmdExecutor* fitexec;  // Fit command executor | 
|---|
|  | 115 | CmdExecutor* pawexec;  // paw-like command executor | 
|---|
|  | 116 | CmdExecutor* cxxexec;  // on-line c++ compile/execution command executor | 
|---|
| [293] | 117 |  | 
|---|
| [330] | 118 | // Pour enregistrer la liste de commandes et leurs executeurs et le help | 
|---|
|  | 119 | struct cmdex {int group; string us; CmdExecutor * cex; } ; | 
|---|
|  | 120 | typedef map<string, int, less<string> > CmdHGroup;   // Liste des groupes de commandes | 
|---|
|  | 121 | CmdHGroup cmdhgrp; | 
|---|
|  | 122 | int cmdgrpid;                                     // Numero de groupe courant | 
|---|
| [293] | 123 | typedef map<string, cmdex, less<string> > CmdExmap; | 
|---|
|  | 124 | CmdExmap cmdexmap; | 
|---|
| [330] | 125 | CmdExmap helpexmap;                               // Pour les helps sans commande | 
|---|
| [293] | 126 |  | 
|---|
|  | 127 | // Pour garder la liste des modules | 
|---|
|  | 128 | typedef map<string, PDynLinkMgr* , less<string> > Modmap; | 
|---|
|  | 129 | Modmap modmap; | 
|---|
|  | 130 |  | 
|---|
|  | 131 | // Pour garder la liste des interpreteur | 
|---|
|  | 132 | typedef map<string, CmdInterpreter*, less<string> > InterpMap; | 
|---|
|  | 133 | InterpMap interpmap; | 
|---|
|  | 134 |  | 
|---|
| [165] | 135 | //  Pour stocker les variables definies par l'interpreteur | 
|---|
| [293] | 136 | typedef map<string, string, less<string> > CmdVarList; | 
|---|
| [349] | 137 | CmdVarList mAliases;  // Liste des alias | 
|---|
|  | 138 |  | 
|---|
|  | 139 | PIACmdBloc * curblk;  // Bloc de commande courant (foreach, ...) | 
|---|
|  | 140 | int felevel;          // foreah level | 
|---|
| [1565] | 141 | list<char> testresult;    // Resultat des test if | 
|---|
|  | 142 | list<char>::iterator tresit;       // Test courant | 
|---|
| [1276] | 143 | bool mulinefg;            // Bloc multi-lignes (ligne suite) | 
|---|
|  | 144 | string mulinecmd;         // Commande multi-lignes | 
|---|
| [349] | 145 |  | 
|---|
| [165] | 146 | ofstream hist;       //  History file | 
|---|
| [349] | 147 | bool histon;        //  True ->  history file | 
|---|
| [165] | 148 | bool trace;          // Trace flag | 
|---|
|  | 149 | bool timing;         // Display CPU Time | 
|---|
|  | 150 | Timer* gltimer;      // pour Display CPU Time | 
|---|
|  | 151 |  | 
|---|
| [293] | 152 | // Fenetre d'aide interactive | 
|---|
|  | 153 | PIAHelpWind* helpwin; | 
|---|
| [1251] | 154 | CxxExecWind* cxxexwin; | 
|---|
|  | 155 | CxxOptionWind* cxxoptwin; | 
|---|
| [165] | 156 | }; | 
|---|
|  | 157 |  | 
|---|
| [293] | 158 |  | 
|---|
|  | 159 |  | 
|---|
| [165] | 160 | #endif | 
|---|