1    	// @(#)root/base:$Id$
2    	// Author: Fons Rademakers   22/09/95
3    	
4    	/*************************************************************************
5    	 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
6    	 * All rights reserved.                                                  *
7    	 *                                                                       *
8    	 * For the licensing terms see $ROOTSYS/LICENSE.                         *
9    	 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
10   	 *************************************************************************/
11   	
12   	#ifndef ROOT_TEnv
13   	#define ROOT_TEnv
14   	
15   	
16   	//////////////////////////////////////////////////////////////////////////
17   	//                                                                      //
18   	// TEnv                                                                 //
19   	//                                                                      //
20   	// The TEnv class reads config files, by default named .rootrc. Three   //
21   	// types of config files are read: global, user and local files. The    //
22   	// global file is $ROOTSYS/etc/system<name> (or ROOTETCDIR/system<name>)//
23   	// the user file is $HOME/<name> and the local file is ./<name>.        //
24   	// By setting the shell variable ROOTENV_NO_HOME=1 the reading of       //
25   	// the $HOME/<name> resource file will be skipped. This might be useful //
26   	// in case the home directory resides on an automounted remote file     //
27   	// system and one wants to avoid this file system from being mounted.   //
28   	//                                                                      //
29   	// The format of the .rootrc file is similar to the .Xdefaults format:  //
30   	//                                                                      //
31   	//   [+]<SystemName>.<RootName|ProgName>.<name>[(type)]:  <value>       //
32   	//                                                                      //
33   	// Where <SystemName> is either Unix, WinNT, MacOS or Vms,              //
34   	// <RootName> the name as given in the TApplication ctor (or "RootApp"  //
35   	// in case no explicit TApplication derived object was created),        //
36   	// <ProgName> the current program name and <name> the resource name,    //
37   	// with optionally a type specification. <value> can be either a        //
38   	// string, an integer, a float/double or a boolean with the values      //
39   	// TRUE, FALSE, ON, OFF, YES, NO, OK, NOT. Booleans will be returned as //
40   	// an integer 0 or 1. The options [+] allows the concatenation of       //
41   	// values to the same resouce name.                                     //
42   	//                                                                      //
43   	// E.g.:                                                                //
44   	//                                                                      //
45   	//   Unix.Rint.Root.DynamicPath: .:$ROOTSYS/lib:~/lib                   //
46   	//   myapp.Root.Debug:  FALSE                                           //
47   	//   TH.Root.Debug: YES                                                 //
48   	//   *.Root.MemStat: 1                                                  //
49   	//                                                                      //
50   	// <SystemName> and <ProgName> or <RootName> may be the wildcard "*".   //
51   	// A # in the first column starts comment line.                         //
52   	//                                                                      //
53   	// For the currently defined resources (and their default values) see   //
54   	// $ROOTSYS/etc/system.rootrc.                                          //
55   	//                                                                      //
56   	// Note that the .rootrc config files contain the config for all ROOT   //
57   	// based applications.                                                  //
58   	//                                                                      //
59   	//////////////////////////////////////////////////////////////////////////
60   	
61   	#ifndef ROOT_TObject
62   	#include "TObject.h"
63   	#endif
64   	#ifndef ROOT_TString
65   	#include "TString.h"
66   	#endif
67   	
68   	class THashList;
69   	class TEnv;
70   	class TEnvParser;
71   	class TReadEnvParser;
72   	class TWriteEnvParser;
73   	
74   	enum EEnvLevel {
75   	   kEnvGlobal,
76   	   kEnvUser,
77   	   kEnvLocal,
78   	   kEnvChange,
79   	   kEnvAll
80   	};
81   	
82   	
83   	//////////////////////////////////////////////////////////////////////////
84   	//                                                                      //
85   	// TEnvRec                                                              //
86   	//                                                                      //
87   	// Individual TEnv records.                                             //
88   	//                                                                      //
89   	//////////////////////////////////////////////////////////////////////////
90   	
91   	class TEnvRec : public TObject {
92   	
93   	friend class  TEnv;
94   	friend class  TEnvParser;
95   	friend class  TReadEnvParser;
96   	friend class  TWriteEnvParser;
97   	
98   	private:
99   	   TString     fName;       // env rec key name
100  	   TString     fType;       // env rec type
101  	   TString     fValue;      // env rec value
102  	   EEnvLevel   fLevel;      // env rec level
103  	   Bool_t      fModified;   // if env rec has been modified
104  	
105  	   TEnvRec(const char *n, const char *v, const char *t, EEnvLevel l);
106  	   Int_t    Compare(const TObject *obj) const;
107  	   void     ChangeValue(const char *v, const char *t, EEnvLevel l,
108  	                        Bool_t append = kFALSE, Bool_t ignoredup = kFALSE);
109  	   TString  ExpandValue(const char *v);
110  	
111  	public:
112  	   TEnvRec(): fName(), fType(), fValue(), fLevel(kEnvAll), fModified(kTRUE) { }
113  	   const char *GetName() const { return fName; }
114  	   const char *GetValue() const { return fValue; }
115  	   const char *GetType() const { return fType; }
116  	   EEnvLevel   GetLevel() const { return fLevel; }
117  	   ULong_t     Hash() const { return fName.Hash(); }
118  	
119  	   ClassDef(TEnvRec,2)  // Individual TEnv records
120  	};
121  	
122  	//////////////////////////////////////////////////////////////////////////
123  	//                                                                      //
124  	// TEnv                                                                 //
125  	//                                                                      //
126  	//////////////////////////////////////////////////////////////////////////
127  	
128  	class TEnv : public TObject {
129  	
130  	private:
131  	   THashList        *fTable;     // hash table containing env records
132  	   TString           fRcName;    // resource file base name
133  	   Bool_t            fIgnoreDup; // ignore duplicates, don't issue warning
134  	
135  	   TEnv(const TEnv&);            // not implemented
136  	   TEnv& operator=(const TEnv&); // not implemented
137  	
138  	   const char       *Getvalue(const char *name);
139  	
140  	public:
141  	   TEnv(const char *name="");
142  	   virtual ~TEnv();
143  	
144  	   THashList          *GetTable() const { return fTable; }
145  	   Bool_t              Defined(const char *name)
146  	                                    { return Getvalue(name) != 0; }
147  	
148  	   virtual const char *GetRcName() const { return fRcName; }
149  	   virtual void        SetRcName(const char *name) { fRcName = name; }
150  	
151  	   virtual Int_t       GetValue(const char *name, Int_t dflt);
152  	   virtual Double_t    GetValue(const char *name, Double_t dflt);
153  	   virtual const char *GetValue(const char *name, const char *dflt);
154  	
155  	   virtual void        SetValue(const char *name, const char *value,
156  	                                EEnvLevel level = kEnvChange,
157  	                                const char *type = 0);
158  	   virtual void        SetValue(const char *name, EEnvLevel level = kEnvChange);
159  	   virtual void        SetValue(const char *name, Int_t value);
160  	   virtual void        SetValue(const char *name, Double_t value);
161  	
162  	   virtual TEnvRec    *Lookup(const char *n);
163  	   virtual Int_t       ReadFile(const char *fname, EEnvLevel level);
164  	   virtual Int_t       WriteFile(const char *fname, EEnvLevel level = kEnvAll);
165  	   virtual void        Save();
166  	   virtual void        SaveLevel(EEnvLevel level);
167  	   virtual void        Print(Option_t *option="") const;
168  	   virtual void        PrintEnv(EEnvLevel level = kEnvAll) const;
169  	   Bool_t              IgnoreDuplicates(Bool_t ignore);
170  	
171  	   ClassDef(TEnv,2)  // Handle ROOT configuration resources
172  	};
173  	
174  	R__EXTERN TEnv *gEnv;
175  	
176  	#endif
177