source: Sophya/trunk/SophyaPI/PIext/piacmd.h@ 2214

Last change on this file since 2214 was 2214, checked in by ansari, 23 years ago

Gestion des arguments des .pic (-tcsh ...) dans un stack , separe de la liste des variables , Reza 17/10/02

File size: 5.6 KB
Line 
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 <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
24class CmdExecutor {
25public:
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
32class CmdInterpreter {
33public:
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 ...
42class NamedObjMgr;
43class PIStdImgApp;
44#ifdef SANS_EVOLPLANCK
45class Timer;
46#else
47namespace SOPHYA {
48class Timer;
49}
50#endif
51
52class PIAHelpWind; // Fenetre d'aide en ligne
53class CxxExecWind; // Fenetre pour CxxExecutor
54class CxxOptionWind; // Option de CxxExecutor
55
56class PIACmdBloc; // Bloc de type foreach / for de l'interpreteur PIACmd
57class 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
66class PIACmd : public CmdInterpreter {
67public:
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);
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
103protected:
104 virtual int CheckHelpGrp(string& grp);
105 int ExecuteCommandLine(string & keyw, vector<string> & args,
106 string & toks);
107
108 int SubstituteVars(string & s, string & s2);
109 int EvaluateTest(vector<string> & args,
110 string & line, bool & res);
111 bool GetVar(string & vn, string & vv);
112
113 NamedObjMgr* mObjMgr;
114 PIStdImgApp* mImgApp;
115
116 CmdInterpreter* curcmdi;
117 CmdExecutor* basexec; // basic command executor
118 CmdExecutor* fitexec; // Fit command executor
119 CmdExecutor* pawexec; // paw-like command executor
120 CmdExecutor* cxxexec; // on-line c++ compile/execution command executor
121
122 CmdExecutor *cntexec; // contour executor _OP_
123 CmdExecutor *flwexec; // flow chart executor _OP_
124
125// Pour enregistrer la liste de commandes et leurs executeurs et le help
126 struct cmdex {int group; string us; CmdExecutor * cex; } ;
127 typedef map<string, int, less<string> > CmdHGroup; // Liste des groupes de commandes
128 CmdHGroup cmdhgrp;
129 int cmdgrpid; // Numero de groupe courant
130 typedef map<string, cmdex, less<string> > CmdExmap;
131 CmdExmap cmdexmap;
132 CmdExmap helpexmap; // Pour les helps sans commande
133
134// Pour garder la liste des modules
135 typedef map<string, PDynLinkMgr* , less<string> > Modmap;
136 Modmap modmap;
137
138// Pour garder la liste des interpreteur
139 typedef map<string, CmdInterpreter*, less<string> > InterpMap;
140 InterpMap interpmap;
141
142// Pour stocker les scripts definis ds l'interpreteur
143 typedef map<string, PIACmdScript*, less<string> > ScriptList;
144 ScriptList mScripts; // Liste des scripts
145
146// Pour stocker les alias definies par l'interpreteur
147 typedef map<string, string, less<string> > CmdStrList;
148 CmdStrList mAliases; // Liste des alias
149
150// Le stack pour les arguments des .pic et des scripts
151 stack< vector<string> > ArgsStack;
152
153 PIACmdBloc * curblk; // Bloc de commande courant (foreach, ...)
154 int felevel; // foreah level
155 list<char> testresult; // Resultat des test if
156 list<char>::iterator tresit; // Test courant
157 bool mulinefg; // Bloc multi-lignes (ligne suite)
158 string mulinecmd; // Commande multi-lignes
159
160 ofstream hist; // History file
161 bool histon; // True -> history file
162 bool trace; // Trace flag
163 bool timing; // Display CPU Time
164 Timer* gltimer; // pour Display CPU Time
165
166// Fenetre d'aide interactive
167 PIAHelpWind* helpwin;
168 CxxExecWind* cxxexwin;
169 CxxOptionWind* cxxoptwin;
170};
171
172
173
174#endif
Note: See TracBrowser for help on using the repository browser.