| [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> | 
|---|
| [165] | 14 | #include <map> | 
|---|
| [351] | 15 | #include <functional> | 
|---|
| [165] | 16 |  | 
|---|
|  | 17 | #include "dlftypes.h" | 
|---|
|  | 18 |  | 
|---|
| [293] | 19 |  | 
|---|
|  | 20 | // Classe definissant l'interface pour un executeur de commande | 
|---|
|  | 21 | class CmdExecutor { | 
|---|
|  | 22 | public: | 
|---|
|  | 23 | virtual       ~CmdExecutor() {} ; | 
|---|
|  | 24 | // keyw : Le mot cle associe , args: Arguments de la commande | 
|---|
|  | 25 | virtual int   Execute(string& keyw, vector<string>& args)=0; | 
|---|
|  | 26 | }; | 
|---|
|  | 27 |  | 
|---|
|  | 28 | // Classe definissant l'interface pour un interpreteur de commande | 
|---|
|  | 29 | class CmdInterpreter { | 
|---|
|  | 30 | public: | 
|---|
|  | 31 | virtual               ~CmdInterpreter() {} ; | 
|---|
|  | 32 | virtual string        Name()=0; | 
|---|
|  | 33 | virtual int           Interpret(string& line)=0; | 
|---|
|  | 34 | }; | 
|---|
|  | 35 |  | 
|---|
|  | 36 |  | 
|---|
|  | 37 |  | 
|---|
|  | 38 | // Forward declaration of some classes ... | 
|---|
| [165] | 39 | class NamedObjMgr; | 
|---|
|  | 40 | class PIStdImgApp; | 
|---|
| [293] | 41 | class Timer; | 
|---|
|  | 42 | class PDynLinkMgr; | 
|---|
| [165] | 43 |  | 
|---|
| [349] | 44 | class PIAHelpWind; // Fenetre d'aide en ligne | 
|---|
|  | 45 | class PIACmdBloc; | 
|---|
|  | 46 |  | 
|---|
| [293] | 47 | // --------------------------------------------------------------------- | 
|---|
|  | 48 | // Classe Interpreteur de commande, gestionnaire de module chargeable, | 
|---|
|  | 49 | // et de fonctions dynamiquement linke pour PIStdImgApp | 
|---|
|  | 50 | // Permet de gerer plusieurs Interpreter differents | 
|---|
|  | 51 | // --------------------------------------------------------------------- | 
|---|
| [165] | 52 |  | 
|---|
| [330] | 53 |  | 
|---|
| [293] | 54 | class PIACmd : public CmdInterpreter  { | 
|---|
| [165] | 55 | public: | 
|---|
| [293] | 56 | static PIACmd*        GetInterpreter(); | 
|---|
| [165] | 57 |  | 
|---|
| [293] | 58 | PIACmd(NamedObjMgr* omg, PIStdImgApp* app); | 
|---|
|  | 59 | virtual               ~PIACmd(); | 
|---|
|  | 60 | virtual string        Name(); | 
|---|
|  | 61 |  | 
|---|
| [330] | 62 | virtual void          RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, | 
|---|
|  | 63 | string grp="Command"); | 
|---|
|  | 64 | virtual void          RegisterHelp(string& keyw, string& usage, string& grp); | 
|---|
| [293] | 65 | virtual void          LoadModule(string& fnameso, string& name); | 
|---|
|  | 66 |  | 
|---|
|  | 67 | virtual void          AddInterpreter(CmdInterpreter * cl); | 
|---|
|  | 68 | virtual void          SelInterpreter(string& name); | 
|---|
|  | 69 |  | 
|---|
|  | 70 | virtual int           Interpret(string& line); | 
|---|
| [333] | 71 | virtual int           ExecuteCommandLine(string& line); | 
|---|
|  | 72 | virtual int           ExecuteCommand(string& keyw, vector<string>& args); | 
|---|
| [349] | 73 | virtual int           ExecFile(string& file, vector<string>& args); | 
|---|
| [293] | 74 |  | 
|---|
|  | 75 | virtual string&       GetUsage(const string& kw); | 
|---|
|  | 76 | virtual void          ShowHelpWindow(); | 
|---|
|  | 77 |  | 
|---|
|  | 78 | inline  CmdInterpreter* CurrentInterpreter() { return(curcmdi); } | 
|---|
|  | 79 | inline  CmdExecutor*    BaseExecutor()  { return(basexec); } | 
|---|
|  | 80 | inline  PIStdImgApp*    GetImgApp() { return(mImgApp); } | 
|---|
|  | 81 |  | 
|---|
| [330] | 82 | //   Pour utilisation par PIAHelpWind uniquement | 
|---|
|  | 83 | virtual void          UpdateHelpList(PIAHelpWind* hw, int gid); | 
|---|
|  | 84 |  | 
|---|
| [293] | 85 | protected: | 
|---|
| [330] | 86 | virtual int           CheckHelpGrp(string& grp); | 
|---|
|  | 87 |  | 
|---|
| [165] | 88 | NamedObjMgr* mObjMgr; | 
|---|
|  | 89 | PIStdImgApp* mImgApp; | 
|---|
|  | 90 |  | 
|---|
| [293] | 91 | CmdInterpreter* curcmdi; | 
|---|
|  | 92 | CmdExecutor* basexec; | 
|---|
| [361] | 93 | CmdExecutor* fitexec; | 
|---|
| [293] | 94 |  | 
|---|
| [330] | 95 | // Pour enregistrer la liste de commandes et leurs executeurs et le help | 
|---|
|  | 96 | struct cmdex {int group; string us; CmdExecutor * cex; } ; | 
|---|
|  | 97 | typedef map<string, int, less<string> > CmdHGroup;   // Liste des groupes de commandes | 
|---|
|  | 98 | CmdHGroup cmdhgrp; | 
|---|
|  | 99 | int cmdgrpid;                                     // Numero de groupe courant | 
|---|
| [293] | 100 | typedef map<string, cmdex, less<string> > CmdExmap; | 
|---|
|  | 101 | CmdExmap cmdexmap; | 
|---|
| [330] | 102 | CmdExmap helpexmap;                               // Pour les helps sans commande | 
|---|
| [293] | 103 |  | 
|---|
|  | 104 | // Pour garder la liste des modules | 
|---|
|  | 105 | typedef map<string, PDynLinkMgr* , less<string> > Modmap; | 
|---|
|  | 106 | Modmap modmap; | 
|---|
|  | 107 |  | 
|---|
|  | 108 | // Pour garder la liste des interpreteur | 
|---|
|  | 109 | typedef map<string, CmdInterpreter*, less<string> > InterpMap; | 
|---|
|  | 110 | InterpMap interpmap; | 
|---|
|  | 111 |  | 
|---|
| [165] | 112 | //  Pour stocker les variables definies par l'interpreteur | 
|---|
| [293] | 113 | typedef map<string, string, less<string> > CmdVarList; | 
|---|
| [349] | 114 | CmdVarList mVars;     // Liste des variables | 
|---|
|  | 115 | CmdVarList mAliases;  // Liste des alias | 
|---|
|  | 116 |  | 
|---|
|  | 117 | PIACmdBloc * curblk;  // Bloc de commande courant (foreach, ...) | 
|---|
|  | 118 | int felevel;          // foreah level | 
|---|
|  | 119 |  | 
|---|
| [165] | 120 | ofstream hist;       //  History file | 
|---|
| [349] | 121 | bool histon;        //  True ->  history file | 
|---|
| [165] | 122 | bool trace;          // Trace flag | 
|---|
|  | 123 | bool timing;         // Display CPU Time | 
|---|
|  | 124 | Timer* gltimer;      // pour Display CPU Time | 
|---|
|  | 125 |  | 
|---|
| [293] | 126 | // Fenetre d'aide interactive | 
|---|
|  | 127 | PIAHelpWind* helpwin; | 
|---|
| [165] | 128 |  | 
|---|
|  | 129 | }; | 
|---|
|  | 130 |  | 
|---|
| [293] | 131 |  | 
|---|
|  | 132 |  | 
|---|
| [165] | 133 | #endif | 
|---|