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 |
|
---|
9 | #include "machdefs.h"
|
---|
10 | #include <iostream.h>
|
---|
11 | #include <fstream.h>
|
---|
12 | #include <string>
|
---|
13 | #include <vector>
|
---|
14 | #include <list>
|
---|
15 | #include <map>
|
---|
16 | #include <functional>
|
---|
17 |
|
---|
18 | #include "dlftypes.h"
|
---|
19 | #include "pdlmgr.h"
|
---|
20 | #include "ctimer.h"
|
---|
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
|
---|
27 | virtual int Execute(string& keyw, vector<string>& args, string& toks)=0;
|
---|
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 ...
|
---|
41 | class NamedObjMgr;
|
---|
42 | class PIStdImgApp;
|
---|
43 | #ifdef SANS_EVOLPLANCK
|
---|
44 | class Timer;
|
---|
45 | #else
|
---|
46 | namespace SOPHYA {
|
---|
47 | class Timer;
|
---|
48 | }
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | class PIAHelpWind; // Fenetre d'aide en ligne
|
---|
52 | class CxxExecWind; // Fenetre pour CxxExecutor
|
---|
53 | class CxxOptionWind; // Option de CxxExecutor
|
---|
54 |
|
---|
55 | class PIACmdBloc;
|
---|
56 |
|
---|
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 | // ---------------------------------------------------------------------
|
---|
62 |
|
---|
63 |
|
---|
64 | class PIACmd : public CmdInterpreter {
|
---|
65 | public:
|
---|
66 | static PIACmd* GetInterpreter();
|
---|
67 |
|
---|
68 | PIACmd(NamedObjMgr* omg, PIStdImgApp* app);
|
---|
69 | virtual ~PIACmd();
|
---|
70 | virtual string Name();
|
---|
71 |
|
---|
72 | virtual void RegisterCommand(string& keyw, string& usage, CmdExecutor * ce,
|
---|
73 | string grp="Commands");
|
---|
74 | virtual void RegisterHelp(string& keyw, string& usage, string& grp);
|
---|
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);
|
---|
81 | virtual int ParseLineExecute(string& line);
|
---|
82 | virtual int ExecuteCommand(string& keyw, vector<string>& args, string& toks);
|
---|
83 | virtual int ExecFile(string& file, vector<string>& args);
|
---|
84 |
|
---|
85 | virtual string& GetUsage(const string& kw);
|
---|
86 |
|
---|
87 | void ShowHelpWindow();
|
---|
88 | void ShowCxxOptionWindow();
|
---|
89 | void ShowCxxExecWindow();
|
---|
90 |
|
---|
91 | virtual void HelptoLaTex(string const & flnm);
|
---|
92 |
|
---|
93 | inline CmdInterpreter* CurrentInterpreter() { return(curcmdi); }
|
---|
94 | inline CmdExecutor* BaseExecutor() { return(basexec); }
|
---|
95 | inline CmdExecutor* ContExecutor() { return(cntexec); } //_OP_
|
---|
96 | inline PIStdImgApp* GetImgApp() { return(mImgApp); }
|
---|
97 |
|
---|
98 | // Pour utilisation par PIAHelpWind uniquement
|
---|
99 | virtual void UpdateHelpList(PIAHelpWind* hw, int gid);
|
---|
100 |
|
---|
101 | protected:
|
---|
102 | virtual int CheckHelpGrp(string& grp);
|
---|
103 | int ExecuteCommandLine(string & keyw, vector<string> & args,
|
---|
104 | string & toks);
|
---|
105 |
|
---|
106 | int SubstituteVars(string & s, string & s2);
|
---|
107 | int EvaluateTest(vector<string> & args,
|
---|
108 | string & line, bool & res);
|
---|
109 |
|
---|
110 | NamedObjMgr* mObjMgr;
|
---|
111 | PIStdImgApp* mImgApp;
|
---|
112 |
|
---|
113 | CmdInterpreter* curcmdi;
|
---|
114 | CmdExecutor* basexec; // basic command executor
|
---|
115 | CmdExecutor* fitexec; // Fit command executor
|
---|
116 | CmdExecutor* pawexec; // paw-like command executor
|
---|
117 | CmdExecutor* cxxexec; // on-line c++ compile/execution command executor
|
---|
118 |
|
---|
119 | CmdExecutor *cntexec; // contour executor _OP_
|
---|
120 | CmdExecutor *flwexec; // flow chart executor _OP_
|
---|
121 |
|
---|
122 | // Pour enregistrer la liste de commandes et leurs executeurs et le help
|
---|
123 | struct cmdex {int group; string us; CmdExecutor * cex; } ;
|
---|
124 | typedef map<string, int, less<string> > CmdHGroup; // Liste des groupes de commandes
|
---|
125 | CmdHGroup cmdhgrp;
|
---|
126 | int cmdgrpid; // Numero de groupe courant
|
---|
127 | typedef map<string, cmdex, less<string> > CmdExmap;
|
---|
128 | CmdExmap cmdexmap;
|
---|
129 | CmdExmap helpexmap; // Pour les helps sans commande
|
---|
130 |
|
---|
131 | // Pour garder la liste des modules
|
---|
132 | typedef map<string, PDynLinkMgr* , less<string> > Modmap;
|
---|
133 | Modmap modmap;
|
---|
134 |
|
---|
135 | // Pour garder la liste des interpreteur
|
---|
136 | typedef map<string, CmdInterpreter*, less<string> > InterpMap;
|
---|
137 | InterpMap interpmap;
|
---|
138 |
|
---|
139 | // Pour stocker les variables definies par l'interpreteur
|
---|
140 | typedef map<string, string, less<string> > CmdVarList;
|
---|
141 | CmdVarList mAliases; // Liste des alias
|
---|
142 |
|
---|
143 | PIACmdBloc * curblk; // Bloc de commande courant (foreach, ...)
|
---|
144 | int felevel; // foreah level
|
---|
145 | list<char> testresult; // Resultat des test if
|
---|
146 | list<char>::iterator tresit; // Test courant
|
---|
147 | bool mulinefg; // Bloc multi-lignes (ligne suite)
|
---|
148 | string mulinecmd; // Commande multi-lignes
|
---|
149 |
|
---|
150 | ofstream hist; // History file
|
---|
151 | bool histon; // True -> history file
|
---|
152 | bool trace; // Trace flag
|
---|
153 | bool timing; // Display CPU Time
|
---|
154 | Timer* gltimer; // pour Display CPU Time
|
---|
155 |
|
---|
156 | // Fenetre d'aide interactive
|
---|
157 | PIAHelpWind* helpwin;
|
---|
158 | CxxExecWind* cxxexwin;
|
---|
159 | CxxOptionWind* cxxoptwin;
|
---|
160 | };
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 | #endif
|
---|