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