Logo ROOT   6.08/07
Reference Guide
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 #ifndef ROOT_TObjString
40 #include "TObjString.h"
41 #endif
42 #ifndef ROOT_TRegExp
43 #include "TRegexp.h"
44 #endif
45 #ifndef ROOT_Riosfwd
46 #include "Riosfwd.h"
47 #endif
48 
49 
50 #define MAX_LEN_PAT 1024 // maximum length of a pattern
51 #define dblquote(x) "\"" << x << "\""
52 
53 // forward declarations
54 class TList;
55 class TListIter;
56 class TSeqCollection;
57 class TClass;
58 
59 
60 class TTabCom {
61 
62 public: // constructors
63  TTabCom();
64  virtual ~TTabCom();
65 
66 public: // typedefs
67  typedef TList TContainer;
69 
70 public: // member functions
71  Int_t Hook(char *buf, int *pLoc, std::ostream& out);
72 
75  const TSeqCollection* GetListOfFilesInPath( const char path[] );
82 
83  void ClearClasses();
84  void ClearCppDirectives();
85  void ClearEnvVars();
86  void ClearFiles();
87  void ClearGlobalFunctions();
88  void ClearGlobals();
89  void ClearPragmas();
90  void ClearSysIncFiles();
91  void ClearUsers();
92 
93  void ClearAll();
94 
95  void RehashClasses();
96  void RehashCppDirectives();
97  void RehashEnvVars();
98  void RehashFiles();
99  void RehashGlobalFunctions();
100  void RehashGlobals();
101  void RehashPragmas();
102  void RehashSysIncFiles();
103  void RehashUsers();
104 
105  void RehashAll();
106 
107 public: // static utility functions
108  static Char_t AllAgreeOnChar( int i, const TSeqCollection* pList, Int_t& nGoodStrings );
109  static void AppendListOfFilesInDirectory( const char dirName[], TSeqCollection* pList );
110  static TString DetermineClass( const char varName[] ); // TROOT
111  static Bool_t ExcludedByFignore( TString s );
112  static TString GetSysIncludePath(); // TROOT
113  static Bool_t IsDirectory( const char fileName[] ); // TSystem
114  static TSeqCollection* NewListOfFilesInPath( const char path[] );
115  static Bool_t PathIsSpecifiedInFileName( const TString& fileName );
116  static void NoMsg( Int_t errorLevel );
117 
118 public: // enums
119  enum {kDebug = 17}; // set gDebug==TTabCom::kDebug for debugging output
120 
121  enum EContext_t {
123  // first enum (not counting "kUNKNOWN_CONTEXT") must
124  // cast to zero because these enums will be used to
125  // index arrays of size "kNUM_PAT"
126  // ---------------
127 
128  // user names and environment variables should come first
130  kSYS_EnvVar, // environment variables
131 
132  // file descriptor redirection should almost come first
133  kCINT_stdout, // stdout
134  kCINT_stderr, // stderr
135  kCINT_stdin, // stdin
136 
137  // CINT "." instructions
138  // the position of these guys is irrelevant since each of
139  // these commands will always be the only command on the line.
140  kCINT_Edit, // .E
141  kCINT_Load, // .L
142  kCINT_Exec, // .x
143  kCINT_EXec, // .X
144 
145  // specific preprocessor directives.
147  kCINT_includeSYS, // system files
148  kCINT_includePWD, // local files
149 
150  // specific preprocessor directives
151  // must come before general preprocessor directives
152 
153  // general preprocessor directives
154  // must come after specific preprocessor directives
156 
157  // specific member accessing
158  // should come before general member accessing
160 
161  // random files
162  /******************************************************************/
163  /* */
164  /* file names should come before member accessing */
165  /* */
166  /* (because otherwise "/tmp/a.cc" might look like you're trying */
167  /* to access member "cc" of some object "a") */
168  /* */
169  /* but after anything that requires a specific path. */
170  /* */
171  /******************************************************************/
173 
174  // time to print prototype
175  kCXX_NewProto, // kCXX_NewProto must come before kCXX_ConstructorProto
176  kCXX_ConstructorProto, // kCXX_ConstructorProto this must come before kCXX_GlobalProto
180 
181  // general member access
182  // should come after specific member access
186 
187  // arbitrary global identifiers
188  // should really come last
191 
192 
193  // ------- make additions above this line ---------
194  kNUM_PAT // kNUM_PAT must be last. (to fix array size)
195  };
196 
197 private: // member functions
198  TTabCom(const TTabCom &); //private and not implemented
199  TTabCom& operator=(const TTabCom&); //private and not implemented
200 
201  Int_t Complete(const TRegexp& re, const TSeqCollection* pListOfCandidates,
202  const char appendage[], std::ostream& out, TString::ECaseCompare cmp = TString::kExact);
203  void CopyMatch( char dest[], const char localName[], const char appendage[]=0, const char fullName[]=0 ) const;
205  TString DeterminePath( const TString& fileName, const char defaultPath[] ) const;
206  TString ExtendPath( const char originalPath[], TString newBase ) const;
207  void InitPatterns();
208  TClass* MakeClassFromClassName( const char className[] ) const;
209  TClass* TryMakeClassFromClassName( const char className[] ) const;
210  TClass* MakeClassFromVarName( const char varName[], EContext_t& context,
211  int iter=0);
212  void SetPattern( EContext_t handle, const char regexp[] );
213  int ParseReverse(const char *var_str, int start);
214 
215 private: // data members
225 
226  char* fBuf; // initialized by Hook()
227  int* fpLoc; // initialized by Hook()
228 
229  Pattern_t fPat[ kNUM_PAT ][ MAX_LEN_PAT ]; // array of patterns
230  const char* fRegExp[ kNUM_PAT ]; // corresponding regular expression plain text
231  Bool_t fVarIsPointer; // frodo: pointer or not flag
232  Int_t fLastIter; // frodo: iteration counter for recursive MakeClassFromVarName
233 
234  ClassDef(TTabCom,0) //Perform command line completion when hitting <TAB>
235 };
236 
238 
239 #endif
static void AppendListOfFilesInDirectory(const char dirName[], TSeqCollection *pList)
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:740
void ClearGlobals()
Forget all global variables seen so far.
Definition: TTabCom.cxx:270
static Char_t AllAgreeOnChar(int i, const TSeqCollection *pList, Int_t &nGoodStrings)
[static utility function]///////////////////////////////////////////
Definition: TTabCom.cxx:675
void ClearSysIncFiles()
Close system files.
Definition: TTabCom.cxx:289
void RehashGlobals()
Reload globals.
Definition: TTabCom.cxx:373
const TSeqCollection * GetListOfUsers()
reads from "/etc/passwd"
Definition: TTabCom.cxx:629
void CopyMatch(char dest[], const char localName[], const char appendage[]=0, const char fullName[]=0) const
[private]
Definition: TTabCom.cxx:1404
TClass * MakeClassFromVarName(const char varName[], EContext_t &context, int iter=0)
private returns a new&#39;d TClass given the name of a variable.
Definition: TTabCom.cxx:2245
void ClearEnvVars()
Forget all environment variables seen so far.
Definition: TTabCom.cxx:237
TClass * TryMakeClassFromClassName(const char className[]) const
Same as above but does not print the error message.
Definition: TTabCom.cxx:2225
TSeqCollection * fpEnvVars
Definition: TTabCom.h:219
Regular expression class.
Definition: TRegexp.h:35
static TSeqCollection * NewListOfFilesInPath(const char path[])
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:1039
const TSeqCollection * GetListOfClasses()
Return the list of classes.
Definition: TTabCom.cxx:426
Basic string class.
Definition: TString.h:137
void RehashSysIncFiles()
Reload system include files.
Definition: TTabCom.cxx:391
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TSeqCollection * fpPragmas
Definition: TTabCom.h:222
void ClearCppDirectives()
Forget all Cpp directives seen so far.
Definition: TTabCom.cxx:225
TTabCom & operator=(const TTabCom &)
void RehashPragmas()
Reload pragmas.
Definition: TTabCom.cxx:382
Iterator of linked list.
Definition: TList.h:187
static TString DetermineClass(const char varName[])
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:789
TTabCom()
Default constructor.
Definition: TTabCom.cxx:172
char * fBuf
Definition: TTabCom.h:226
TSeqCollection * fpUsers
Definition: TTabCom.h:224
Sequenceable collection abstract base class.
#define ClassDef(name, id)
Definition: Rtypes.h:254
void ClearPragmas()
Forget all pragmas seen so far.
Definition: TTabCom.cxx:277
int ParseReverse(const char *var_str, int start)
Returns the place in the string where to put the \0, starting the search from "start".
Definition: TTabCom.cxx:2555
const TSeqCollection * GetListOfFilesInPath(const char path[])
"path" should be initialized with a colon separated list of system directories
Definition: TTabCom.cxx:498
void ClearGlobalFunctions()
Forget all global functions seen so far.
Definition: TTabCom.cxx:262
TList TContainer
Definition: TTabCom.h:67
void RehashCppDirectives()
Cpp rehashing.
Definition: TTabCom.cxx:339
Int_t Hook(char *buf, int *pLoc, std::ostream &out)
[private]
Definition: TTabCom.cxx:1556
#define MAX_LEN_PAT
Definition: TTabCom.h:50
ECaseCompare
Definition: TString.h:257
void RehashClasses()
Do the class rehash.
Definition: TTabCom.cxx:330
void ClearAll()
clears all lists except for user names and system include files.
Definition: TTabCom.cxx:314
static void NoMsg(Int_t errorLevel)
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:1098
A doubly linked list.
Definition: TList.h:47
void SetPattern(EContext_t handle, const char regexp[])
[private]
Definition: TTabCom.cxx:2533
unsigned short Pattern_t
Definition: Match.h:26
void RehashGlobalFunctions()
Reload global functions.
Definition: TTabCom.cxx:365
TListIter TContIter
Definition: TTabCom.h:68
Collection abstract base class.
Definition: TCollection.h:48
TSeqCollection * fpSysIncFiles
Definition: TTabCom.h:223
void ClearUsers()
Forget all user seen so far.
Definition: TTabCom.cxx:301
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
void RehashAll()
clears and then rebuilds all lists except for user names and system include files.
Definition: TTabCom.cxx:410
TSeqCollection * fpFiles
Definition: TTabCom.h:220
void ClearFiles()
Close all files.
Definition: TTabCom.cxx:249
virtual ~TTabCom()
Definition: TTabCom.cxx:195
TSeqCollection * fpClasses
Definition: TTabCom.h:216
TString DeterminePath(const TString &fileName, const char defaultPath[]) const
[private]
Definition: TTabCom.cxx:1480
void RehashEnvVars()
Environemnt variables rehashing.
Definition: TTabCom.cxx:348
const TSeqCollection * GetListOfSysIncFiles()
Return the list of system include files.
Definition: TTabCom.cxx:617
EContext_t DetermineContext() const
[private]
Definition: TTabCom.cxx:1456
static Bool_t PathIsSpecifiedInFileName(const TString &fileName)
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:1078
TString ExtendPath(const char originalPath[], TString newBase) const
[private]
Definition: TTabCom.cxx:1524
unsigned long long ULong64_t
Definition: RtypesCore.h:70
ULong64_t fPrevInterpMarker
Definition: TTabCom.h:217
const TSeqCollection * GetListOfPragmas()
Return the list of pragmas.
Definition: TTabCom.cxx:586
void ClearClasses()
Clear classes and namespace collections.
Definition: TTabCom.cxx:213
#define R__EXTERN
Definition: DllImport.h:27
char Char_t
Definition: RtypesCore.h:29
#define dest(otri, vertexptr)
Definition: triangle.c:1040
TClass * MakeClassFromClassName(const char className[]) const
private returns a new&#39;d TClass given the name of a class.
Definition: TTabCom.cxx:2196
EContext_t
Definition: TTabCom.h:121
const char * fRegExp[kNUM_PAT]
Definition: TTabCom.h:230
Int_t Complete(const TRegexp &re, const TSeqCollection *pListOfCandidates, const char appendage[], std::ostream &out, TString::ECaseCompare cmp=TString::kExact)
[private]
Definition: TTabCom.cxx:1153
TSeqCollection * fpGlobals
Definition: TTabCom.h:221
static Bool_t ExcludedByFignore(TString s)
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:882
static TString GetSysIncludePath()
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:918
static Bool_t IsDirectory(const char fileName[])
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:1019
int * fpLoc
Definition: TTabCom.h:227
const TSeqCollection * GetListOfCppDirectives()
Return the list of CPP directives.
Definition: TTabCom.cxx:472
void InitPatterns()
[private]
Definition: TTabCom.cxx:2129
Bool_t fVarIsPointer
Definition: TTabCom.h:231
Int_t fLastIter
Definition: TTabCom.h:232
const TSeqCollection * GetListOfEnvVars()
Uses "env" (Unix) or "set" (Windows) to get list of environment variables.
Definition: TTabCom.cxx:517
R__EXTERN TTabCom * gTabCom
Definition: TTabCom.h:237
TCollection * GetListOfGlobalFunctions()
Return the list of global functions.
Definition: TTabCom.cxx:578
const TSeqCollection * GetListOfGlobals()
Return the list of globals.
Definition: TTabCom.cxx:570
TSeqCollection * fpDirectives
Definition: TTabCom.h:218
void RehashUsers()
Reload users.
Definition: TTabCom.cxx:400
void RehashFiles()
Close files.
Definition: TTabCom.cxx:357
Pattern_t fPat[kNUM_PAT][MAX_LEN_PAT]
Definition: TTabCom.h:229