ROOT logo
// @(#)root/rint:$Id: TTabCom.h 30215 2009-09-17 10:25:41Z rdm $
// Author: Christian Lacunza <lacunza@cdfsg6.lbl.gov>   27/04/99

// Modified by Artur Szostak <artur@alice.phy.uct.ac.za> : 1 June 2003
//   Added support for namespaces.

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TTabCom
#define ROOT_TTabCom


////////////////////////////////////////////////////////////////////////////
//                                                                        //
// TTabCom                                                                //
//                                                                        //
// This class performs basic tab completion.                              //
// You should be able to hit [TAB] to complete a partially typed:         //
//                                                                        //
//   username                                                             //
//   environment variable                                                 //
//   preprocessor directive                                               //
//   pragma                                                               //
//   filename (with a context-sensitive path)                             //
//   public member function or data member                                //
//   global variable, function, or class name                             //
//                                                                        //
// Also, something like gWhatever->Func([TAB] will print the appropriate  //
// list of prototypes. For a list of some limitations see the source.     //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObjString
#include "TObjString.h"
#endif
#ifndef ROOT_TRegExp
#include "TRegexp.h"
#endif


#define MAX_LEN_PAT 1024               // maximum length of a pattern
#define dblquote(x) "\"" << x << "\""

// forward declarations
class TList;
class TListIter;
class TSeqCollection;
class TClass;


class TTabCom {

public: // constructors
   TTabCom();
   virtual ~TTabCom();

public: // typedefs
   typedef TList     TContainer;
   typedef TListIter TContIter;

public: // member functions
   Int_t Hook(char *buf, int *pLoc);

   const TSeqCollection* GetListOfClasses();
   const TSeqCollection* GetListOfCppDirectives();
   const TSeqCollection* GetListOfFilesInPath( const char path[] );
   const TSeqCollection* GetListOfEnvVars();
   const TSeqCollection* GetListOfGlobalFunctions();
   const TSeqCollection* GetListOfGlobals();
   const TSeqCollection* GetListOfPragmas();
   const TSeqCollection* GetListOfSysIncFiles();
   const TSeqCollection* GetListOfUsers();

   void ClearClasses();
   void ClearCppDirectives();
   void ClearEnvVars();
   void ClearFiles();
   void ClearGlobalFunctions();
   void ClearGlobals();
   void ClearPragmas();
   void ClearSysIncFiles();
   void ClearUsers();

   void ClearAll();

   void RehashClasses();
   void RehashCppDirectives();
   void RehashEnvVars();
   void RehashFiles();
   void RehashGlobalFunctions();
   void RehashGlobals();
   void RehashPragmas();
   void RehashSysIncFiles();
   void RehashUsers();

   void RehashAll();

public: // static utility functions
   static Char_t   AllAgreeOnChar( int i, const TSeqCollection* pList, Int_t& nGoodStrings );
   static void     AppendListOfFilesInDirectory( const char dirName[], TSeqCollection* pList );
   static TString  DetermineClass( const char varName[] ); // TROOT
   static Bool_t   ExcludedByFignore( TString s );
   static TString  GetSysIncludePath(); // TROOT
   static Bool_t   IsDirectory( const char fileName[] ); // TSystem
   static TSeqCollection* NewListOfFilesInPath( const char path[] );
   static Bool_t   PathIsSpecifiedInFileName( const TString& fileName );
   static void     NoMsg( Int_t errorLevel );

public: // enums
   enum {kDebug = 17}; // set gDebug==TTabCom::kDebug for debugging output

   enum EContext_t {
      kUNKNOWN_CONTEXT=-1,
      // first enum (not counting "kUNKNOWN_CONTEXT") must
      // cast to zero because these enums will be used to
      // index arrays of size "kNUM_PAT"
      // ---------------

      // user names and environment variables should come first
      kSYS_UserName,
      kSYS_EnvVar, // environment variables

      // file descriptor redirection should almost come first
      kCINT_stdout,  // stdout
      kCINT_stderr,  // stderr
      kCINT_stdin,   // stdin

      // CINT "." instructions
      // the position of these guys is irrelevant since each of
      // these commands will always be the only command on the line.
      kCINT_Edit,  // .E
      kCINT_Load,  // .L
      kCINT_Exec,  // .x
      kCINT_EXec,  // .X

      // specific preprocessor directives.
      kCINT_pragma,
      kCINT_includeSYS,  // system files
      kCINT_includePWD,  // local files

      // specific preprocessor directives
      // must come before general preprocessor directives

      // general preprocessor directives
      // must come after specific preprocessor directives
      kCINT_cpp,

      // specific member accessing
      // should come before general member accessing
      kROOT_Load,

      // random files
      /******************************************************************/
      /*                                                                */
      /* file names should come before member accessing                 */
      /*                                                                */
      /* (because otherwise "/tmp/a.cc" might look like you're trying   */
      /* to access member "cc" of some object "a")                      */
      /*                                                                */
      /* but after anything that requires a specific path.              */
      /*                                                                */
      /******************************************************************/
      kSYS_FileName,

      // time to print prototype
      kCXX_NewProto, // kCXX_NewProto must come before kCXX_ConstructorProto
      kCXX_ConstructorProto, // kCXX_ConstructorProto this must come before kCXX_GlobalProto
      kCXX_ScopeProto,
      kCXX_DirectProto,
      kCXX_IndirectProto,

      // general member access
      // should come after specific member access
      kCXX_ScopeMember,
      kCXX_DirectMember,
      kCXX_IndirectMember,

      // arbitrary global identifiers
      // should really come last
      kCXX_Global,
      kCXX_GlobalProto,


      // ------- make additions above this line ---------
      kNUM_PAT // kNUM_PAT must be last. (to fix array size)
   };

private: // member functions
   TTabCom(const TTabCom &);           //private and not implemented
   TTabCom& operator=(const TTabCom&); //private and not implemented

   Int_t      Complete( const TRegexp& re, const TSeqCollection* pListOfCandidates, const char appendage[], TString::ECaseCompare cmp = TString::kExact);
   void       CopyMatch( char dest[], const char localName[], const char appendage[]=0, const char fullName[]=0 ) const;
   EContext_t DetermineContext() const;
   TString    DeterminePath( const TString& fileName, const char defaultPath[] ) const;
   TString    ExtendPath( const char originalPath[], TString newBase ) const;
   void       InitPatterns();
   TClass*    MakeClassFromClassName( const char className[] ) const;
   TClass*    TryMakeClassFromClassName( const char className[] ) const;
   TClass*    MakeClassFromVarName( const char varName[], EContext_t& context, 
                  int iter=0);
   void       SetPattern( EContext_t handle, const char regexp[] );
   int        ParseReverse(const char *var_str, int start);

private: // data members
   TSeqCollection* fpClasses;
   TSeqCollection* fpNamespaces;  // Contains the names of namespaces registered in CINT.
   TSeqCollection* fpDirectives;
   TSeqCollection* fpEnvVars;
   TSeqCollection* fpFiles;
   TSeqCollection* fpGlobals;
   TSeqCollection* fpGlobalFuncs;
   TSeqCollection* fpPragmas;
   TSeqCollection* fpSysIncFiles;
   TSeqCollection* fpUsers;

   char* fBuf;  // initialized by Hook()
   int*  fpLoc; // initialized by Hook()

   Pattern_t   fPat[ kNUM_PAT ][ MAX_LEN_PAT ];  // array of patterns
   const char* fRegExp[ kNUM_PAT ];              // corresponding regular expression plain text
   Bool_t fVarIsPointer;                         // frodo: pointer or not flag
   Int_t  fLastIter;                             // frodo: iteration counter for recursive MakeClassFromVarName

   ClassDef(TTabCom,0)  //Perform comand line completion when hitting <TAB>
};

extern TTabCom *gTabCom;

#endif
 TTabCom.h:1
 TTabCom.h:2
 TTabCom.h:3
 TTabCom.h:4
 TTabCom.h:5
 TTabCom.h:6
 TTabCom.h:7
 TTabCom.h:8
 TTabCom.h:9
 TTabCom.h:10
 TTabCom.h:11
 TTabCom.h:12
 TTabCom.h:13
 TTabCom.h:14
 TTabCom.h:15
 TTabCom.h:16
 TTabCom.h:17
 TTabCom.h:18
 TTabCom.h:19
 TTabCom.h:20
 TTabCom.h:21
 TTabCom.h:22
 TTabCom.h:23
 TTabCom.h:24
 TTabCom.h:25
 TTabCom.h:26
 TTabCom.h:27
 TTabCom.h:28
 TTabCom.h:29
 TTabCom.h:30
 TTabCom.h:31
 TTabCom.h:32
 TTabCom.h:33
 TTabCom.h:34
 TTabCom.h:35
 TTabCom.h:36
 TTabCom.h:37
 TTabCom.h:38
 TTabCom.h:39
 TTabCom.h:40
 TTabCom.h:41
 TTabCom.h:42
 TTabCom.h:43
 TTabCom.h:44
 TTabCom.h:45
 TTabCom.h:46
 TTabCom.h:47
 TTabCom.h:48
 TTabCom.h:49
 TTabCom.h:50
 TTabCom.h:51
 TTabCom.h:52
 TTabCom.h:53
 TTabCom.h:54
 TTabCom.h:55
 TTabCom.h:56
 TTabCom.h:57
 TTabCom.h:58
 TTabCom.h:59
 TTabCom.h:60
 TTabCom.h:61
 TTabCom.h:62
 TTabCom.h:63
 TTabCom.h:64
 TTabCom.h:65
 TTabCom.h:66
 TTabCom.h:67
 TTabCom.h:68
 TTabCom.h:69
 TTabCom.h:70
 TTabCom.h:71
 TTabCom.h:72
 TTabCom.h:73
 TTabCom.h:74
 TTabCom.h:75
 TTabCom.h:76
 TTabCom.h:77
 TTabCom.h:78
 TTabCom.h:79
 TTabCom.h:80
 TTabCom.h:81
 TTabCom.h:82
 TTabCom.h:83
 TTabCom.h:84
 TTabCom.h:85
 TTabCom.h:86
 TTabCom.h:87
 TTabCom.h:88
 TTabCom.h:89
 TTabCom.h:90
 TTabCom.h:91
 TTabCom.h:92
 TTabCom.h:93
 TTabCom.h:94
 TTabCom.h:95
 TTabCom.h:96
 TTabCom.h:97
 TTabCom.h:98
 TTabCom.h:99
 TTabCom.h:100
 TTabCom.h:101
 TTabCom.h:102
 TTabCom.h:103
 TTabCom.h:104
 TTabCom.h:105
 TTabCom.h:106
 TTabCom.h:107
 TTabCom.h:108
 TTabCom.h:109
 TTabCom.h:110
 TTabCom.h:111
 TTabCom.h:112
 TTabCom.h:113
 TTabCom.h:114
 TTabCom.h:115
 TTabCom.h:116
 TTabCom.h:117
 TTabCom.h:118
 TTabCom.h:119
 TTabCom.h:120
 TTabCom.h:121
 TTabCom.h:122
 TTabCom.h:123
 TTabCom.h:124
 TTabCom.h:125
 TTabCom.h:126
 TTabCom.h:127
 TTabCom.h:128
 TTabCom.h:129
 TTabCom.h:130
 TTabCom.h:131
 TTabCom.h:132
 TTabCom.h:133
 TTabCom.h:134
 TTabCom.h:135
 TTabCom.h:136
 TTabCom.h:137
 TTabCom.h:138
 TTabCom.h:139
 TTabCom.h:140
 TTabCom.h:141
 TTabCom.h:142
 TTabCom.h:143
 TTabCom.h:144
 TTabCom.h:145
 TTabCom.h:146
 TTabCom.h:147
 TTabCom.h:148
 TTabCom.h:149
 TTabCom.h:150
 TTabCom.h:151
 TTabCom.h:152
 TTabCom.h:153
 TTabCom.h:154
 TTabCom.h:155
 TTabCom.h:156
 TTabCom.h:157
 TTabCom.h:158
 TTabCom.h:159
 TTabCom.h:160
 TTabCom.h:161
 TTabCom.h:162
 TTabCom.h:163
 TTabCom.h:164
 TTabCom.h:165
 TTabCom.h:166
 TTabCom.h:167
 TTabCom.h:168
 TTabCom.h:169
 TTabCom.h:170
 TTabCom.h:171
 TTabCom.h:172
 TTabCom.h:173
 TTabCom.h:174
 TTabCom.h:175
 TTabCom.h:176
 TTabCom.h:177
 TTabCom.h:178
 TTabCom.h:179
 TTabCom.h:180
 TTabCom.h:181
 TTabCom.h:182
 TTabCom.h:183
 TTabCom.h:184
 TTabCom.h:185
 TTabCom.h:186
 TTabCom.h:187
 TTabCom.h:188
 TTabCom.h:189
 TTabCom.h:190
 TTabCom.h:191
 TTabCom.h:192
 TTabCom.h:193
 TTabCom.h:194
 TTabCom.h:195
 TTabCom.h:196
 TTabCom.h:197
 TTabCom.h:198
 TTabCom.h:199
 TTabCom.h:200
 TTabCom.h:201
 TTabCom.h:202
 TTabCom.h:203
 TTabCom.h:204
 TTabCom.h:205
 TTabCom.h:206
 TTabCom.h:207
 TTabCom.h:208
 TTabCom.h:209
 TTabCom.h:210
 TTabCom.h:211
 TTabCom.h:212
 TTabCom.h:213
 TTabCom.h:214
 TTabCom.h:215
 TTabCom.h:216
 TTabCom.h:217
 TTabCom.h:218
 TTabCom.h:219
 TTabCom.h:220
 TTabCom.h:221
 TTabCom.h:222
 TTabCom.h:223
 TTabCom.h:224
 TTabCom.h:225
 TTabCom.h:226
 TTabCom.h:227
 TTabCom.h:228
 TTabCom.h:229
 TTabCom.h:230
 TTabCom.h:231
 TTabCom.h:232
 TTabCom.h:233
 TTabCom.h:234
 TTabCom.h:235
 TTabCom.h:236