Logo ROOT  
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 "TString.h"
40 #include "TRegexp.h"
41 
42 #define MAX_LEN_PAT 1024 // maximum length of a pattern
43 #define dblquote(x) "\"" << x << "\""
44 
45 // forward declarations
46 class TList;
47 class TListIter;
48 class TSeqCollection;
49 class TClass;
50 
51 
52 class TTabCom {
53 
54 public: // constructors
55  TTabCom();
56  virtual ~TTabCom();
57 
58 public: // typedefs
59  typedef TList TContainer;
61 
62 public: // member functions
63  Int_t Hook(char *buf, int *pLoc, std::ostream& out);
64 
67  const TSeqCollection* GetListOfFilesInPath( const char path[] );
74 
75  void ClearClasses();
76  void ClearCppDirectives();
77  void ClearEnvVars();
78  void ClearFiles();
79  void ClearGlobalFunctions();
80  void ClearGlobals();
81  void ClearPragmas();
82  void ClearSysIncFiles();
83  void ClearUsers();
84 
85  void ClearAll();
86 
87  void RehashClasses();
88  void RehashCppDirectives();
89  void RehashEnvVars();
90  void RehashFiles();
91  void RehashGlobalFunctions();
92  void RehashGlobals();
93  void RehashPragmas();
94  void RehashSysIncFiles();
95  void RehashUsers();
96 
97  void RehashAll();
98 
99 public: // static utility functions
100  static Char_t AllAgreeOnChar( int i, const TSeqCollection* pList, Int_t& nGoodStrings );
101  static void AppendListOfFilesInDirectory( const char dirName[], TSeqCollection* pList );
102  static TString DetermineClass( const char varName[] ); // TROOT
103  static Bool_t ExcludedByFignore( TString s );
104  static TString GetSysIncludePath(); // TROOT
105  static Bool_t IsDirectory( const char fileName[] ); // TSystem
106  static TSeqCollection* NewListOfFilesInPath( const char path[] );
107  static Bool_t PathIsSpecifiedInFileName( const TString& fileName );
108  static void NoMsg( Int_t errorLevel );
109 
110 public: // enums
111  enum {kDebug = 17}; // set gDebug==TTabCom::kDebug for debugging output
112 
113  enum EContext_t {
115  // first enum (not counting "kUNKNOWN_CONTEXT") must
116  // cast to zero because these enums will be used to
117  // index arrays of size "kNUM_PAT"
118  // ---------------
119 
120  // user names and environment variables should come first
122  kSYS_EnvVar, // environment variables
123 
124  // file descriptor redirection should almost come first
125  kCINT_stdout, // stdout
126  kCINT_stderr, // stderr
127  kCINT_stdin, // stdin
128 
129  // CINT "." instructions
130  // the position of these guys is irrelevant since each of
131  // these commands will always be the only command on the line.
132  kCINT_Edit, // .E
133  kCINT_Load, // .L
134  kCINT_Exec, // .x
135  kCINT_EXec, // .X
136 
137  // specific preprocessor directives.
139  kCINT_includeSYS, // system files
140  kCINT_includePWD, // local files
141 
142  // specific preprocessor directives
143  // must come before general preprocessor directives
144 
145  // general preprocessor directives
146  // must come after specific preprocessor directives
148 
149  // specific member accessing
150  // should come before general member accessing
152 
153  // random files
154  /******************************************************************/
155  /* */
156  /* file names should come before member accessing */
157  /* */
158  /* (because otherwise "/tmp/a.cc" might look like you're trying */
159  /* to access member "cc" of some object "a") */
160  /* */
161  /* but after anything that requires a specific path. */
162  /* */
163  /******************************************************************/
165 
166  // time to print prototype
167  kCXX_NewProto, // kCXX_NewProto must come before kCXX_ConstructorProto
168  kCXX_ConstructorProto, // kCXX_ConstructorProto this must come before kCXX_GlobalProto
172 
173  // general member access
174  // should come after specific member access
178 
179  // arbitrary global identifiers
180  // should really come last
183 
184 
185  // ------- make additions above this line ---------
186  kNUM_PAT // kNUM_PAT must be last. (to fix array size)
187  };
188 
189 private: // member functions
190  TTabCom(const TTabCom &); //private and not implemented
191  TTabCom& operator=(const TTabCom&); //private and not implemented
192 
193  Int_t Complete(const TRegexp& re, const TSeqCollection* pListOfCandidates,
194  const char appendage[], std::ostream& out, TString::ECaseCompare cmp = TString::kExact);
195  void CopyMatch( char dest[], const char localName[], const char appendage[]=0, const char fullName[]=0 ) const;
197  TString DeterminePath( const TString& fileName, const char defaultPath[] ) const;
198  TString ExtendPath( const char originalPath[], TString newBase ) const;
199  void InitPatterns();
200  TClass* MakeClassFromClassName( const char className[] ) const;
201  TClass* TryMakeClassFromClassName( const char className[] ) const;
202  TClass* MakeClassFromVarName( const char varName[], EContext_t& context,
203  int iter=0);
204  void SetPattern( EContext_t handle, const char regexp[] );
205  int ParseReverse(const char *var_str, int start);
206 
207 private: // data members
217 
218  char* fBuf; // initialized by Hook()
219  int* fpLoc; // initialized by Hook()
220 
221  Pattern_t fPat[ kNUM_PAT ][ MAX_LEN_PAT ]; // array of patterns
222  const char* fRegExp[ kNUM_PAT ]; // corresponding regular expression plain text
223  Bool_t fVarIsPointer; // frodo: pointer or not flag
224  Int_t fLastIter; // frodo: iteration counter for recursive MakeClassFromVarName
225 
226  ClassDef(TTabCom,0) //Perform command line completion when hitting <TAB>
227 };
228 
230 
231 #endif
TTabCom::RehashEnvVars
void RehashEnvVars()
Environemnt variables rehashing.
Definition: TTabCom.cxx:353
TTabCom::InitPatterns
void InitPatterns()
[private]
Definition: TTabCom.cxx:2132
TTabCom::ExtendPath
TString ExtendPath(const char originalPath[], TString newBase) const
[private]
Definition: TTabCom.cxx:1528
TTabCom::fVarIsPointer
Bool_t fVarIsPointer
Definition: TTabCom.h:223
TTabCom::TContIter
TListIter TContIter
Definition: TTabCom.h:60
TTabCom::NewListOfFilesInPath
static TSeqCollection * NewListOfFilesInPath(const char path[])
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:1044
TTabCom::kCINT_Load
@ kCINT_Load
Definition: TTabCom.h:133
TTabCom::GetListOfFilesInPath
const TSeqCollection * GetListOfFilesInPath(const char path[])
"path" should be initialized with a colon separated list of system directories
Definition: TTabCom.cxx:503
TTabCom::fpDirectives
TSeqCollection * fpDirectives
Definition: TTabCom.h:210
TTabCom::ClearUsers
void ClearUsers()
Forget all user seen so far.
Definition: TTabCom.cxx:306
TTabCom::kROOT_Load
@ kROOT_Load
Definition: TTabCom.h:151
TTabCom::kCXX_DirectProto
@ kCXX_DirectProto
Definition: TTabCom.h:170
TTabCom::ParseReverse
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:2558
TTabCom::kCXX_IndirectMember
@ kCXX_IndirectMember
Definition: TTabCom.h:177
dest
#define dest(otri, vertexptr)
Definition: triangle.c:1040
TTabCom::RehashAll
void RehashAll()
clears and then rebuilds all lists except for user names and system include files.
Definition: TTabCom.cxx:415
TTabCom::fRegExp
const char * fRegExp[kNUM_PAT]
Definition: TTabCom.h:222
TTabCom::ClearCppDirectives
void ClearCppDirectives()
Forget all Cpp directives seen so far.
Definition: TTabCom.cxx:230
TTabCom::GetListOfClasses
const TSeqCollection * GetListOfClasses()
Return the list of classes.
Definition: TTabCom.cxx:431
TTabCom::kCXX_ConstructorProto
@ kCXX_ConstructorProto
Definition: TTabCom.h:168
TTabCom::RehashGlobals
void RehashGlobals()
Reload globals.
Definition: TTabCom.cxx:378
TTabCom::GetSysIncludePath
static TString GetSysIncludePath()
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:923
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
TTabCom::kSYS_UserName
@ kSYS_UserName
Definition: TTabCom.h:121
Int_t
int Int_t
Definition: RtypesCore.h:45
Pattern_t
unsigned short Pattern_t
Definition: Match.h:26
TTabCom::kCXX_Global
@ kCXX_Global
Definition: TTabCom.h:181
TTabCom::fPat
Pattern_t fPat[kNUM_PAT][MAX_LEN_PAT]
Definition: TTabCom.h:221
TTabCom::GetListOfEnvVars
const TSeqCollection * GetListOfEnvVars()
Uses "env" (Unix) or "set" (Windows) to get list of environment variables.
Definition: TTabCom.cxx:522
TTabCom::ClearPragmas
void ClearPragmas()
Forget all pragmas seen so far.
Definition: TTabCom.cxx:282
TString::kExact
@ kExact
Definition: TString.h:268
TTabCom::kNUM_PAT
@ kNUM_PAT
Definition: TTabCom.h:186
TTabCom::ClearGlobalFunctions
void ClearGlobalFunctions()
Forget all global functions seen so far.
Definition: TTabCom.cxx:267
TTabCom::kCINT_Edit
@ kCINT_Edit
Definition: TTabCom.h:132
TTabCom::fpFiles
TSeqCollection * fpFiles
Definition: TTabCom.h:212
TTabCom::~TTabCom
virtual ~TTabCom()
Definition: TTabCom.cxx:200
TString
Definition: TString.h:136
TTabCom::ClearAll
void ClearAll()
clears all lists except for user names and system include files.
Definition: TTabCom.cxx:319
TTabCom::RehashClasses
void RehashClasses()
Do the class rehash.
Definition: TTabCom.cxx:335
TTabCom::fpClasses
TSeqCollection * fpClasses
Definition: TTabCom.h:208
TTabCom::operator=
TTabCom & operator=(const TTabCom &)
TString.h
TTabCom::SetPattern
void SetPattern(EContext_t handle, const char regexp[])
[private]
Definition: TTabCom.cxx:2536
bool
TListIter
Definition: TList.h:197
TTabCom::DetermineContext
EContext_t DetermineContext() const
[private]
Definition: TTabCom.cxx:1461
TTabCom::MakeClassFromClassName
TClass * MakeClassFromClassName(const char className[]) const
private returns a new'd TClass given the name of a class.
Definition: TTabCom.cxx:2199
TTabCom::GetListOfUsers
const TSeqCollection * GetListOfUsers()
reads from "/etc/passwd"
Definition: TTabCom.cxx:634
TTabCom::fpUsers
TSeqCollection * fpUsers
Definition: TTabCom.h:216
TTabCom::GetListOfSysIncFiles
const TSeqCollection * GetListOfSysIncFiles()
Return the list of system include files.
Definition: TTabCom.cxx:622
TTabCom::MakeClassFromVarName
TClass * MakeClassFromVarName(const char varName[], EContext_t &context, int iter=0)
private returns a new'd TClass given the name of a variable.
Definition: TTabCom.cxx:2248
TTabCom::kCINT_EXec
@ kCINT_EXec
Definition: TTabCom.h:135
MAX_LEN_PAT
#define MAX_LEN_PAT
Definition: TTabCom.h:42
TTabCom::TryMakeClassFromClassName
TClass * TryMakeClassFromClassName(const char className[]) const
Same as above but does not print the error message.
Definition: TTabCom.cxx:2228
TTabCom::kCINT_stdin
@ kCINT_stdin
Definition: TTabCom.h:127
TTabCom::kCINT_includeSYS
@ kCINT_includeSYS
Definition: TTabCom.h:139
TRegexp.h
TTabCom::GetListOfGlobals
const TSeqCollection * GetListOfGlobals()
Return the list of globals.
Definition: TTabCom.cxx:575
TString::ECaseCompare
ECaseCompare
Definition: TString.h:268
TTabCom::PathIsSpecifiedInFileName
static Bool_t PathIsSpecifiedInFileName(const TString &fileName)
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:1083
TTabCom::kCXX_IndirectProto
@ kCXX_IndirectProto
Definition: TTabCom.h:171
TTabCom::GetListOfGlobalFunctions
TCollection * GetListOfGlobalFunctions()
Return the list of global functions.
Definition: TTabCom.cxx:583
TTabCom::AppendListOfFilesInDirectory
static void AppendListOfFilesInDirectory(const char dirName[], TSeqCollection *pList)
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:745
TTabCom::TContainer
TList TContainer
Definition: TTabCom.h:59
TTabCom::Hook
Int_t Hook(char *buf, int *pLoc, std::ostream &out)
[private]
Definition: TTabCom.cxx:1560
TTabCom::ClearClasses
void ClearClasses()
Clear classes and namespace collections.
Definition: TTabCom.cxx:218
TTabCom::fpSysIncFiles
TSeqCollection * fpSysIncFiles
Definition: TTabCom.h:215
TTabCom::RehashPragmas
void RehashPragmas()
Reload pragmas.
Definition: TTabCom.cxx:387
TTabCom::fpLoc
int * fpLoc
Definition: TTabCom.h:219
TTabCom::kUNKNOWN_CONTEXT
@ kUNKNOWN_CONTEXT
Definition: TTabCom.h:114
TTabCom::ClearSysIncFiles
void ClearSysIncFiles()
Close system files.
Definition: TTabCom.cxx:294
TTabCom::kCINT_pragma
@ kCINT_pragma
Definition: TTabCom.h:138
TTabCom::kCINT_stdout
@ kCINT_stdout
Definition: TTabCom.h:125
TTabCom::kCXX_NewProto
@ kCXX_NewProto
Definition: TTabCom.h:167
TTabCom::RehashCppDirectives
void RehashCppDirectives()
Cpp rehashing.
Definition: TTabCom.cxx:344
TTabCom::fLastIter
Int_t fLastIter
Definition: TTabCom.h:224
TTabCom::fPrevInterpMarker
ULong64_t fPrevInterpMarker
Definition: TTabCom.h:209
TTabCom::RehashFiles
void RehashFiles()
Close files.
Definition: TTabCom.cxx:362
TRegexp
Definition: TRegexp.h:31
TTabCom::RehashUsers
void RehashUsers()
Reload users.
Definition: TTabCom.cxx:405
TSeqCollection
Definition: TSeqCollection.h:28
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
TTabCom::GetListOfCppDirectives
const TSeqCollection * GetListOfCppDirectives()
Return the list of CPP directives.
Definition: TTabCom.cxx:477
TTabCom::AllAgreeOnChar
static Char_t AllAgreeOnChar(int i, const TSeqCollection *pList, Int_t &nGoodStrings)
[static utility function]///////////////////////////////////////////
Definition: TTabCom.cxx:680
TTabCom::DeterminePath
TString DeterminePath(const TString &fileName, const char defaultPath[]) const
[private]
Definition: TTabCom.cxx:1485
TTabCom
Definition: TTabCom.h:52
TTabCom::kCXX_ScopeMember
@ kCXX_ScopeMember
Definition: TTabCom.h:175
TTabCom::fpGlobals
TSeqCollection * fpGlobals
Definition: TTabCom.h:213
TTabCom::kCINT_includePWD
@ kCINT_includePWD
Definition: TTabCom.h:140
TTabCom::EContext_t
EContext_t
Definition: TTabCom.h:113
TClass
Definition: TClass.h:80
TTabCom::IsDirectory
static Bool_t IsDirectory(const char fileName[])
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:1024
TTabCom::RehashGlobalFunctions
void RehashGlobalFunctions()
Reload global functions.
Definition: TTabCom.cxx:370
TTabCom::NoMsg
static void NoMsg(Int_t errorLevel)
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:1103
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TTabCom::DetermineClass
static TString DetermineClass(const char varName[])
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:794
TTabCom::kCINT_stderr
@ kCINT_stderr
Definition: TTabCom.h:126
TTabCom::kSYS_FileName
@ kSYS_FileName
Definition: TTabCom.h:164
TTabCom::kCXX_GlobalProto
@ kCXX_GlobalProto
Definition: TTabCom.h:182
TTabCom::CopyMatch
void CopyMatch(char dest[], const char localName[], const char appendage[]=0, const char fullName[]=0) const
[private]
Definition: TTabCom.cxx:1409
TTabCom::kCXX_DirectMember
@ kCXX_DirectMember
Definition: TTabCom.h:176
TTabCom::fBuf
char * fBuf
Definition: TTabCom.h:218
R__EXTERN
#define R__EXTERN
Definition: DllImport.h:27
TTabCom::ClearEnvVars
void ClearEnvVars()
Forget all environment variables seen so far.
Definition: TTabCom.cxx:242
TTabCom::kCINT_cpp
@ kCINT_cpp
Definition: TTabCom.h:147
TTabCom::fpEnvVars
TSeqCollection * fpEnvVars
Definition: TTabCom.h:211
TCollection
Definition: TCollection.h:63
TTabCom::kCXX_ScopeProto
@ kCXX_ScopeProto
Definition: TTabCom.h:169
TTabCom::RehashSysIncFiles
void RehashSysIncFiles()
Reload system include files.
Definition: TTabCom.cxx:396
TTabCom::kDebug
@ kDebug
Definition: TTabCom.h:111
TTabCom::ClearGlobals
void ClearGlobals()
Forget all global variables seen so far.
Definition: TTabCom.cxx:275
TTabCom::GetListOfPragmas
const TSeqCollection * GetListOfPragmas()
Return the list of pragmas.
Definition: TTabCom.cxx:591
TTabCom::ExcludedByFignore
static Bool_t ExcludedByFignore(TString s)
[static utility function]/////////////////////////////
Definition: TTabCom.cxx:887
TTabCom::Complete
Int_t Complete(const TRegexp &re, const TSeqCollection *pListOfCandidates, const char appendage[], std::ostream &out, TString::ECaseCompare cmp=TString::kExact)
[private]
Definition: TTabCom.cxx:1158
Char_t
char Char_t
Definition: RtypesCore.h:33
TTabCom::kSYS_EnvVar
@ kSYS_EnvVar
Definition: TTabCom.h:122
TTabCom::ClearFiles
void ClearFiles()
Close all files.
Definition: TTabCom.cxx:254
TList
Definition: TList.h:44
gTabCom
R__EXTERN TTabCom * gTabCom
Definition: TTabCom.h:229
TTabCom::TTabCom
TTabCom()
Default constructor.
Definition: TTabCom.cxx:177
TTabCom::kCINT_Exec
@ kCINT_Exec
Definition: TTabCom.h:134
TTabCom::fpPragmas
TSeqCollection * fpPragmas
Definition: TTabCom.h:214
int