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>
|
---|
11 | #include <fstream>
|
---|
12 | #include <string>
|
---|
13 | #include <vector>
|
---|
14 | #include <list>
|
---|
15 | #include <stack>
|
---|
16 | #include <map>
|
---|
17 | #include <functional>
|
---|
18 |
|
---|
19 | #include "dlftypes.h"
|
---|
20 | #include "pdlmgr.h"
|
---|
21 | #include "ctimer.h"
|
---|
22 |
|
---|
23 | // Classe definissant l'interface pour un executeur de commande
|
---|
24 | class CmdExecutor {
|
---|
25 | public:
|
---|
26 | virtual ~CmdExecutor() {} ;
|
---|
27 | // keyw : Le mot cle associe , args: Arguments de la commande
|
---|
28 | virtual int Execute(string& keyw, vector<string>& args, string& toks)=0;
|
---|
29 | };
|
---|
30 |
|
---|
31 | // Classe definissant l'interface pour un interpreteur de commande
|
---|
32 | class CmdInterpreter {
|
---|
33 | public:
|
---|
34 | virtual ~CmdInterpreter() {} ;
|
---|
35 | virtual string Name()=0;
|
---|
36 | virtual int Interpret(string& line)=0;
|
---|
37 | };
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | // Forward declaration of some classes ...
|
---|
42 | class NamedObjMgr;
|
---|
43 | class PIStdImgApp;
|
---|
44 | #ifdef SANS_EVOLPLANCK
|
---|
45 | class Timer;
|
---|
46 | #else
|
---|
47 | namespace SOPHYA {
|
---|
48 | class Timer;
|
---|
49 | }
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | class PIAHelpWind; // Fenetre d'aide en ligne
|
---|
53 | class CxxExecWind; // Fenetre pour CxxExecutor
|
---|
54 | class CxxOptionWind; // Option de CxxExecutor
|
---|
55 |
|
---|
56 | class PIACmdBloc; // Bloc de type foreach / for de l'interpreteur PIACmd
|
---|
57 | class PIACmdScript; // Script de commandes defini ds l'interpreteur PIACmd
|
---|
58 |
|
---|
59 | // ---------------------------------------------------------------------
|
---|
60 | // Classe Interpreteur de commande, gestionnaire de module chargeable,
|
---|
61 | // et de fonctions dynamiquement linke pour PIStdImgApp
|
---|
62 | // Permet de gerer plusieurs Interpreter differents
|
---|
63 | // ---------------------------------------------------------------------
|
---|
64 |
|
---|
65 |
|
---|
66 | class PIACmd : public CmdInterpreter {
|
---|
67 | public:
|
---|
68 | static PIACmd* GetInterpreter();
|
---|
69 |
|
---|
70 | PIACmd(NamedObjMgr* omg, PIStdImgApp* app);
|
---|
71 | virtual ~PIACmd();
|
---|
72 | virtual string Name();
|
---|
73 |
|
---|
74 | virtual void RegisterCommand(string& keyw, string& usage, CmdExecutor * ce,
|
---|
75 | string grp="Commands");
|
---|
76 | virtual void RegisterHelp(string& keyw, string& usage, string& grp);
|
---|
77 | virtual void LoadModule(string& fnameso, string& name);
|
---|
78 |
|
---|
79 | virtual void AddInterpreter(CmdInterpreter * cl);
|
---|
80 | virtual void SelInterpreter(string& name);
|
---|
81 |
|
---|
82 | virtual int Interpret(string& line);
|
---|
83 | virtual int ParseLineExecute(string& line, bool qw=true);
|
---|
84 | virtual int ExecuteCommand(string& keyw, vector<string>& args, string& toks);
|
---|
85 | virtual int ExecFile(string& file, vector<string>& args);
|
---|
86 | virtual int CShellExecute(string cmd);
|
---|
87 | virtual string& GetUsage(const string& kw);
|
---|
88 |
|
---|
89 | void ShowHelpWindow();
|
---|
90 | void ShowCxxOptionWindow();
|
---|
91 | void ShowCxxExecWindow();
|
---|
92 |
|
---|
93 | virtual void HelptoLaTeX(string const & flnm);
|
---|
94 |
|
---|
95 | inline CmdInterpreter* CurrentInterpreter() { return(curcmdi); }
|
---|
96 | inline CmdExecutor* BaseExecutor() { return(basexec); }
|
---|
97 | inline CmdExecutor* ContExecutor() { return(cntexec); } //_OP_
|
---|
98 | inline PIStdImgApp* GetImgApp() { return(mImgApp); }
|
---|
99 |
|
---|
100 | // Pour utilisation par PIAHelpWind uniquement
|
---|
101 | virtual void UpdateHelpList(PIAHelpWind* hw, int gid);
|
---|
102 |
|
---|
103 | // Utilitaire pour decoupage en mot
|
---|
104 | static int LineToWords(string& line, string& kw, vector<string>& tokens,
|
---|
105 | string& toks, bool uq=true);
|
---|
106 | protected:
|
---|
107 | virtual int CheckHelpGrp(string& grp);
|
---|
108 | int ExecuteCommandLine(string & keyw, vector<string> & args,
|
---|
109 | string & toks);
|
---|
110 |
|
---|
111 | int SubstituteVars(string & s, string & s2);
|
---|
112 | int EvaluateTest(vector<string> & args,
|
---|
113 | string & line, bool & res);
|
---|
114 | int EvalRPNExpr(vector<string> & args, string & line);
|
---|
115 |
|
---|
116 | bool GetVar(string & vn, string & vv);
|
---|
117 | void PushStack(vector<string> & args);
|
---|
118 | void PopStack(bool psta=true);
|
---|
119 |
|
---|
120 | NamedObjMgr* mObjMgr;
|
---|
121 | PIStdImgApp* mImgApp;
|
---|
122 |
|
---|
123 | CmdInterpreter* curcmdi;
|
---|
124 | CmdExecutor* basexec; // basic command executor
|
---|
125 | CmdExecutor* fitexec; // Fit command executor
|
---|
126 | CmdExecutor* pawexec; // paw-like command executor
|
---|
127 | CmdExecutor* cxxexec; // on-line c++ compile/execution command executor
|
---|
128 |
|
---|
129 | CmdExecutor *cntexec; // contour executor _OP_
|
---|
130 | CmdExecutor *flwexec; // flow chart executor _OP_
|
---|
131 |
|
---|
132 | // Pour enregistrer la liste de commandes et leurs executeurs et le help
|
---|
133 | struct cmdex {int group; string us; CmdExecutor * cex; } ;
|
---|
134 | typedef map<string, int, less<string> > CmdHGroup; // Liste des groupes de commandes
|
---|
135 | CmdHGroup cmdhgrp;
|
---|
136 | int cmdgrpid; // Numero de groupe courant
|
---|
137 | typedef map<string, cmdex, less<string> > CmdExmap;
|
---|
138 | CmdExmap cmdexmap;
|
---|
139 | CmdExmap helpexmap; // Pour les helps sans commande
|
---|
140 |
|
---|
141 | // Pour garder la liste des modules
|
---|
142 | typedef map<string, PDynLinkMgr* , less<string> > Modmap;
|
---|
143 | Modmap modmap;
|
---|
144 |
|
---|
145 | // Pour garder la liste des interpreteur
|
---|
146 | typedef map<string, CmdInterpreter*, less<string> > InterpMap;
|
---|
147 | InterpMap interpmap;
|
---|
148 |
|
---|
149 | // Pour stocker les scripts definis ds l'interpreteur
|
---|
150 | typedef map<string, PIACmdScript*, less<string> > ScriptList;
|
---|
151 | ScriptList mScripts; // Liste des scripts
|
---|
152 | PIACmdScript* curscript; // Script en cours de definition
|
---|
153 |
|
---|
154 | // Pour stocker les alias definies par l'interpreteur
|
---|
155 | typedef map<string, string, less<string> > CmdStrList;
|
---|
156 | CmdStrList mAliases; // Liste des alias
|
---|
157 |
|
---|
158 | // Le stack pour les arguments des .pic et des scripts
|
---|
159 | stack< vector<string> > ArgsStack;
|
---|
160 |
|
---|
161 | stack< PIACmdBloc * > CmdBlks; // Bloc de commande courant (foreach, ...)
|
---|
162 | int felevel; // foreach-for level
|
---|
163 | stack< list<char> > TestsStack; // Stack des resultats de test
|
---|
164 | list<char>::iterator tresit; // Test courant
|
---|
165 | bool curtestresult; // Resultat courant des tests
|
---|
166 |
|
---|
167 | bool mulinefg; // Bloc multi-lignes (ligne suite)
|
---|
168 | string mulinecmd; // Commande multi-lignes
|
---|
169 | string spromptmul; // Prompt console avant multi-ligne
|
---|
170 |
|
---|
171 | ofstream hist; // History file
|
---|
172 | bool histon; // True -> history file
|
---|
173 | bool trace; // Trace flag
|
---|
174 | bool timing; // Display CPU Time
|
---|
175 | Timer* gltimer; // pour Display CPU Time
|
---|
176 |
|
---|
177 | // Fenetre d'aide interactive
|
---|
178 | PIAHelpWind* helpwin;
|
---|
179 | CxxExecWind* cxxexwin;
|
---|
180 | CxxOptionWind* cxxoptwin;
|
---|
181 | };
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 | #endif
|
---|