Logo ROOT   6.10/09
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 #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;
62 
63 public: // member functions
64  Int_t Hook(char *buf, int *pLoc, std::ostream& out);
65 
68  const TSeqCollection* GetListOfFilesInPath( const char path[] );
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 {
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
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.
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
149 
150  // specific member accessing
151  // should come before general member accessing
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  /******************************************************************/
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
173 
174  // general member access
175  // should come after specific member access
179 
180  // arbitrary global identifiers
181  // should really come last
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;
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
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 
231 
232 #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:2244
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:2224
TSeqCollection * fpEnvVars
Definition: TTabCom.h:212
Regular expression class.
Definition: TRegexp.h:31
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:129
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:215
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:183
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:219
TSeqCollection * fpUsers
Definition: TTabCom.h:217
Sequenceable collection abstract base class.
#define ClassDef(name, id)
Definition: Rtypes.h:297
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:2554
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:60
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:43
ECaseCompare
Definition: TString.h:249
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:43
void SetPattern(EContext_t handle, const char regexp[])
[private]
Definition: TTabCom.cxx:2532
unsigned short Pattern_t
Definition: Match.h:26
void RehashGlobalFunctions()
Reload global functions.
Definition: TTabCom.cxx:365
TListIter TContIter
Definition: TTabCom.h:61
Collection abstract base class.
Definition: TCollection.h:42
TSeqCollection * fpSysIncFiles
Definition: TTabCom.h:216
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:71
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:213
void ClearFiles()
Close all files.
Definition: TTabCom.cxx:249
virtual ~TTabCom()
Definition: TTabCom.cxx:195
TSeqCollection * fpClasses
Definition: TTabCom.h:209
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:210
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:2195
EContext_t
Definition: TTabCom.h:114
const char * fRegExp[kNUM_PAT]
Definition: TTabCom.h:223
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:214
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:220
const TSeqCollection * GetListOfCppDirectives()
Return the list of CPP directives.
Definition: TTabCom.cxx:472
void InitPatterns()
[private]
Definition: TTabCom.cxx:2128
Bool_t fVarIsPointer
Definition: TTabCom.h:224
Int_t fLastIter
Definition: TTabCom.h:225
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:230
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:211
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:222