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