TTabCom.h

Go to the documentation of this file.
00001 // @(#)root/rint:$Id: TTabCom.h 30215 2009-09-17 10:25:41Z rdm $
00002 // Author: Christian Lacunza <lacunza@cdfsg6.lbl.gov>   27/04/99
00003 
00004 // Modified by Artur Szostak <artur@alice.phy.uct.ac.za> : 1 June 2003
00005 //   Added support for namespaces.
00006 
00007 /*************************************************************************
00008  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00009  * All rights reserved.                                                  *
00010  *                                                                       *
00011  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00012  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00013  *************************************************************************/
00014 
00015 #ifndef ROOT_TTabCom
00016 #define ROOT_TTabCom
00017 
00018 
00019 ////////////////////////////////////////////////////////////////////////////
00020 //                                                                        //
00021 // TTabCom                                                                //
00022 //                                                                        //
00023 // This class performs basic tab completion.                              //
00024 // You should be able to hit [TAB] to complete a partially typed:         //
00025 //                                                                        //
00026 //   username                                                             //
00027 //   environment variable                                                 //
00028 //   preprocessor directive                                               //
00029 //   pragma                                                               //
00030 //   filename (with a context-sensitive path)                             //
00031 //   public member function or data member                                //
00032 //   global variable, function, or class name                             //
00033 //                                                                        //
00034 // Also, something like gWhatever->Func([TAB] will print the appropriate  //
00035 // list of prototypes. For a list of some limitations see the source.     //
00036 //                                                                        //
00037 ////////////////////////////////////////////////////////////////////////////
00038 
00039 #ifndef ROOT_TObjString
00040 #include "TObjString.h"
00041 #endif
00042 #ifndef ROOT_TRegExp
00043 #include "TRegexp.h"
00044 #endif
00045 
00046 
00047 #define MAX_LEN_PAT 1024               // maximum length of a pattern
00048 #define dblquote(x) "\"" << x << "\""
00049 
00050 // forward declarations
00051 class TList;
00052 class TListIter;
00053 class TSeqCollection;
00054 class TClass;
00055 
00056 
00057 class TTabCom {
00058 
00059 public: // constructors
00060    TTabCom();
00061    virtual ~TTabCom();
00062 
00063 public: // typedefs
00064    typedef TList     TContainer;
00065    typedef TListIter TContIter;
00066 
00067 public: // member functions
00068    Int_t Hook(char *buf, int *pLoc);
00069 
00070    const TSeqCollection* GetListOfClasses();
00071    const TSeqCollection* GetListOfCppDirectives();
00072    const TSeqCollection* GetListOfFilesInPath( const char path[] );
00073    const TSeqCollection* GetListOfEnvVars();
00074    const TSeqCollection* GetListOfGlobalFunctions();
00075    const TSeqCollection* GetListOfGlobals();
00076    const TSeqCollection* GetListOfPragmas();
00077    const TSeqCollection* GetListOfSysIncFiles();
00078    const TSeqCollection* GetListOfUsers();
00079 
00080    void ClearClasses();
00081    void ClearCppDirectives();
00082    void ClearEnvVars();
00083    void ClearFiles();
00084    void ClearGlobalFunctions();
00085    void ClearGlobals();
00086    void ClearPragmas();
00087    void ClearSysIncFiles();
00088    void ClearUsers();
00089 
00090    void ClearAll();
00091 
00092    void RehashClasses();
00093    void RehashCppDirectives();
00094    void RehashEnvVars();
00095    void RehashFiles();
00096    void RehashGlobalFunctions();
00097    void RehashGlobals();
00098    void RehashPragmas();
00099    void RehashSysIncFiles();
00100    void RehashUsers();
00101 
00102    void RehashAll();
00103 
00104 public: // static utility functions
00105    static Char_t   AllAgreeOnChar( int i, const TSeqCollection* pList, Int_t& nGoodStrings );
00106    static void     AppendListOfFilesInDirectory( const char dirName[], TSeqCollection* pList );
00107    static TString  DetermineClass( const char varName[] ); // TROOT
00108    static Bool_t   ExcludedByFignore( TString s );
00109    static TString  GetSysIncludePath(); // TROOT
00110    static Bool_t   IsDirectory( const char fileName[] ); // TSystem
00111    static TSeqCollection* NewListOfFilesInPath( const char path[] );
00112    static Bool_t   PathIsSpecifiedInFileName( const TString& fileName );
00113    static void     NoMsg( Int_t errorLevel );
00114 
00115 public: // enums
00116    enum {kDebug = 17}; // set gDebug==TTabCom::kDebug for debugging output
00117 
00118    enum EContext_t {
00119       kUNKNOWN_CONTEXT=-1,
00120       // first enum (not counting "kUNKNOWN_CONTEXT") must
00121       // cast to zero because these enums will be used to
00122       // index arrays of size "kNUM_PAT"
00123       // ---------------
00124 
00125       // user names and environment variables should come first
00126       kSYS_UserName,
00127       kSYS_EnvVar, // environment variables
00128 
00129       // file descriptor redirection should almost come first
00130       kCINT_stdout,  // stdout
00131       kCINT_stderr,  // stderr
00132       kCINT_stdin,   // stdin
00133 
00134       // CINT "." instructions
00135       // the position of these guys is irrelevant since each of
00136       // these commands will always be the only command on the line.
00137       kCINT_Edit,  // .E
00138       kCINT_Load,  // .L
00139       kCINT_Exec,  // .x
00140       kCINT_EXec,  // .X
00141 
00142       // specific preprocessor directives.
00143       kCINT_pragma,
00144       kCINT_includeSYS,  // system files
00145       kCINT_includePWD,  // local files
00146 
00147       // specific preprocessor directives
00148       // must come before general preprocessor directives
00149 
00150       // general preprocessor directives
00151       // must come after specific preprocessor directives
00152       kCINT_cpp,
00153 
00154       // specific member accessing
00155       // should come before general member accessing
00156       kROOT_Load,
00157 
00158       // random files
00159       /******************************************************************/
00160       /*                                                                */
00161       /* file names should come before member accessing                 */
00162       /*                                                                */
00163       /* (because otherwise "/tmp/a.cc" might look like you're trying   */
00164       /* to access member "cc" of some object "a")                      */
00165       /*                                                                */
00166       /* but after anything that requires a specific path.              */
00167       /*                                                                */
00168       /******************************************************************/
00169       kSYS_FileName,
00170 
00171       // time to print prototype
00172       kCXX_NewProto, // kCXX_NewProto must come before kCXX_ConstructorProto
00173       kCXX_ConstructorProto, // kCXX_ConstructorProto this must come before kCXX_GlobalProto
00174       kCXX_ScopeProto,
00175       kCXX_DirectProto,
00176       kCXX_IndirectProto,
00177 
00178       // general member access
00179       // should come after specific member access
00180       kCXX_ScopeMember,
00181       kCXX_DirectMember,
00182       kCXX_IndirectMember,
00183 
00184       // arbitrary global identifiers
00185       // should really come last
00186       kCXX_Global,
00187       kCXX_GlobalProto,
00188 
00189 
00190       // ------- make additions above this line ---------
00191       kNUM_PAT // kNUM_PAT must be last. (to fix array size)
00192    };
00193 
00194 private: // member functions
00195    TTabCom(const TTabCom &);           //private and not implemented
00196    TTabCom& operator=(const TTabCom&); //private and not implemented
00197 
00198    Int_t      Complete( const TRegexp& re, const TSeqCollection* pListOfCandidates, const char appendage[], TString::ECaseCompare cmp = TString::kExact);
00199    void       CopyMatch( char dest[], const char localName[], const char appendage[]=0, const char fullName[]=0 ) const;
00200    EContext_t DetermineContext() const;
00201    TString    DeterminePath( const TString& fileName, const char defaultPath[] ) const;
00202    TString    ExtendPath( const char originalPath[], TString newBase ) const;
00203    void       InitPatterns();
00204    TClass*    MakeClassFromClassName( const char className[] ) const;
00205    TClass*    TryMakeClassFromClassName( const char className[] ) const;
00206    TClass*    MakeClassFromVarName( const char varName[], EContext_t& context, 
00207                   int iter=0);
00208    void       SetPattern( EContext_t handle, const char regexp[] );
00209    int        ParseReverse(const char *var_str, int start);
00210 
00211 private: // data members
00212    TSeqCollection* fpClasses;
00213    TSeqCollection* fpNamespaces;  // Contains the names of namespaces registered in CINT.
00214    TSeqCollection* fpDirectives;
00215    TSeqCollection* fpEnvVars;
00216    TSeqCollection* fpFiles;
00217    TSeqCollection* fpGlobals;
00218    TSeqCollection* fpGlobalFuncs;
00219    TSeqCollection* fpPragmas;
00220    TSeqCollection* fpSysIncFiles;
00221    TSeqCollection* fpUsers;
00222 
00223    char* fBuf;  // initialized by Hook()
00224    int*  fpLoc; // initialized by Hook()
00225 
00226    Pattern_t   fPat[ kNUM_PAT ][ MAX_LEN_PAT ];  // array of patterns
00227    const char* fRegExp[ kNUM_PAT ];              // corresponding regular expression plain text
00228    Bool_t fVarIsPointer;                         // frodo: pointer or not flag
00229    Int_t  fLastIter;                             // frodo: iteration counter for recursive MakeClassFromVarName
00230 
00231    ClassDef(TTabCom,0)  //Perform comand line completion when hitting <TAB>
00232 };
00233 
00234 extern TTabCom *gTabCom;
00235 
00236 #endif

Generated on Tue Jul 5 14:11:58 2011 for ROOT_528-00b_version by  doxygen 1.5.1