Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TTabCom.h
Go to the documentation of this file.
1 // @(#)root/rint:$Id$
2 // Author: Christian Lacunza <lacunza@cdfsg6.lbl.gov> 27/04/99
3 
4 // Modified by Artur Szostak <artur@alice.phy.uct.ac.za> : 1 June 2003
5 // Added support for namespaces.
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #ifndef ROOT_TTabCom
16 #define ROOT_TTabCom
17 
18 
19 ////////////////////////////////////////////////////////////////////////////
20 // //
21 // TTabCom //
22 // //
23 // This class performs basic tab completion. //
24 // You should be able to hit [TAB] to complete a partially typed: //
25 // //
26 // username //
27 // environment variable //
28 // preprocessor directive //
29 // pragma //
30 // filename (with a context-sensitive path) //
31 // public member function or data member //
32 // global variable, function, or class name //
33 // //
34 // Also, something like gWhatever->Func([TAB] will print the appropriate //
35 // list of prototypes. For a list of some limitations see the source. //
36 // //
37 ////////////////////////////////////////////////////////////////////////////
38 
39 #include "TObjString.h"
40 #include "TRegexp.h"
41 
42 
43 #define MAX_LEN_PAT 1024 // maximum length of a pattern
44 #define dblquote(x) "\"" << x << "\""
45 
46 // forward declarations
47 class TList;
48 class TListIter;
49 class TSeqCollection;
50 class TClass;
51 
52 
53 class TTabCom {
54 
55 public: // constructors
56  TTabCom();
57  virtual ~TTabCom();
58 
59 public: // typedefs
60  typedef TList TContainer;
61  typedef TListIter TContIter;
62 
63 public: // member functions
64  Int_t Hook(char *buf, int *pLoc, std::ostream& out);
65 
66  const TSeqCollection* GetListOfClasses();
67  const TSeqCollection* GetListOfCppDirectives();
68  const TSeqCollection* GetListOfFilesInPath( const char path[] );
69  const TSeqCollection* GetListOfEnvVars();
70  TCollection* GetListOfGlobalFunctions();
71  const TSeqCollection* GetListOfGlobals();
72  const TSeqCollection* GetListOfPragmas();
73  const TSeqCollection* GetListOfSysIncFiles();
74  const TSeqCollection* GetListOfUsers();
75 
76  void ClearClasses();
77  void ClearCppDirectives();
78  void ClearEnvVars();
79  void ClearFiles();
80  void ClearGlobalFunctions();
81  void ClearGlobals();
82  void ClearPragmas();
83  void ClearSysIncFiles();
84  void ClearUsers();
85 
86  void ClearAll();
87 
88  void RehashClasses();
89  void RehashCppDirectives();
90  void RehashEnvVars();
91  void RehashFiles();
92  void RehashGlobalFunctions();
93  void RehashGlobals();
94  void RehashPragmas();
95  void RehashSysIncFiles();
96  void RehashUsers();
97 
98  void RehashAll();
99 
100 public: // static utility functions
101  static Char_t AllAgreeOnChar( int i, const TSeqCollection* pList, Int_t& nGoodStrings );
102  static void AppendListOfFilesInDirectory( const char dirName[], TSeqCollection* pList );
103  static TString DetermineClass( const char varName[] ); // TROOT
104  static Bool_t ExcludedByFignore( TString s );
105  static TString GetSysIncludePath(); // TROOT
106  static Bool_t IsDirectory( const char fileName[] ); // TSystem
107  static TSeqCollection* NewListOfFilesInPath( const char path[] );
108  static Bool_t PathIsSpecifiedInFileName( const TString& fileName );
109  static void NoMsg( Int_t errorLevel );
110 
111 public: // enums
112  enum {kDebug = 17}; // set gDebug==TTabCom::kDebug for debugging output
113 
114  enum EContext_t {
115  kUNKNOWN_CONTEXT=-1,
116  // first enum (not counting "kUNKNOWN_CONTEXT") must
117  // cast to zero because these enums will be used to
118  // index arrays of size "kNUM_PAT"
119  // ---------------
120 
121  // user names and environment variables should come first
122  kSYS_UserName,
123  kSYS_EnvVar, // environment variables
124 
125  // file descriptor redirection should almost come first
126  kCINT_stdout, // stdout
127  kCINT_stderr, // stderr
128  kCINT_stdin, // stdin
129 
130  // CINT "." instructions
131  // the position of these guys is irrelevant since each of
132  // these commands will always be the only command on the line.
133  kCINT_Edit, // .E
134  kCINT_Load, // .L
135  kCINT_Exec, // .x
136  kCINT_EXec, // .X
137 
138  // specific preprocessor directives.
139  kCINT_pragma,
140  kCINT_includeSYS, // system files
141  kCINT_includePWD, // local files
142 
143  // specific preprocessor directives
144  // must come before general preprocessor directives
145 
146  // general preprocessor directives
147  // must come after specific preprocessor directives
148  kCINT_cpp,
149 
150  // specific member accessing
151  // should come before general member accessing
152  kROOT_Load,
153 
154  // random files
155  /******************************************************************/
156  /* */
157  /* file names should come before member accessing */
158  /* */
159  /* (because otherwise "/tmp/a.cc" might look like you're trying */
160  /* to access member "cc" of some object "a") */
161  /* */
162  /* but after anything that requires a specific path. */
163  /* */
164  /******************************************************************/
165  kSYS_FileName,
166 
167  // time to print prototype
168  kCXX_NewProto, // kCXX_NewProto must come before kCXX_ConstructorProto
169  kCXX_ConstructorProto, // kCXX_ConstructorProto this must come before kCXX_GlobalProto
170  kCXX_ScopeProto,
171  kCXX_DirectProto,
172  kCXX_IndirectProto,
173 
174  // general member access
175  // should come after specific member access
176  kCXX_ScopeMember,
177  kCXX_DirectMember,
178  kCXX_IndirectMember,
179 
180  // arbitrary global identifiers
181  // should really come last
182  kCXX_Global,
183  kCXX_GlobalProto,
184 
185 
186  // ------- make additions above this line ---------
187  kNUM_PAT // kNUM_PAT must be last. (to fix array size)
188  };
189 
190 private: // member functions
191  TTabCom(const TTabCom &); //private and not implemented
192  TTabCom& operator=(const TTabCom&); //private and not implemented
193 
194  Int_t Complete(const TRegexp& re, const TSeqCollection* pListOfCandidates,
195  const char appendage[], std::ostream& out, TString::ECaseCompare cmp = TString::kExact);
196  void CopyMatch( char dest[], const char localName[], const char appendage[]=0, const char fullName[]=0 ) const;
197  EContext_t DetermineContext() const;
198  TString DeterminePath( const TString& fileName, const char defaultPath[] ) const;
199  TString ExtendPath( const char originalPath[], TString newBase ) const;
200  void InitPatterns();
201  TClass* MakeClassFromClassName( const char className[] ) const;
202  TClass* TryMakeClassFromClassName( const char className[] ) const;
203  TClass* MakeClassFromVarName( const char varName[], EContext_t& context,
204  int iter=0);
205  void SetPattern( EContext_t handle, const char regexp[] );
206  int ParseReverse(const char *var_str, int start);
207 
208 private: // data members
209  TSeqCollection* fpClasses;
210  ULong64_t fPrevInterpMarker;
211  TSeqCollection* fpDirectives;
212  TSeqCollection* fpEnvVars;
213  TSeqCollection* fpFiles;
214  TSeqCollection* fpGlobals;
215  TSeqCollection* fpPragmas;
216  TSeqCollection* fpSysIncFiles;
217  TSeqCollection* fpUsers;
218 
219  char* fBuf; // initialized by Hook()
220  int* fpLoc; // initialized by Hook()
221 
222  Pattern_t fPat[ kNUM_PAT ][ MAX_LEN_PAT ]; // array of patterns
223  const char* fRegExp[ kNUM_PAT ]; // corresponding regular expression plain text
224  Bool_t fVarIsPointer; // frodo: pointer or not flag
225  Int_t fLastIter; // frodo: iteration counter for recursive MakeClassFromVarName
226 
227  ClassDef(TTabCom,0) //Perform command line completion when hitting <TAB>
228 };
229 
230 R__EXTERN TTabCom *gTabCom;
231 
232 #endif