66 #include "RConfigure.h"
83 static struct BoolNameTable_t {
112 TEnvParser(
TEnv *e, FILE *
f) : fIfp(f), fEnv(e) { }
113 virtual ~TEnvParser() { }
123 void TEnvParser::Parse()
130 while ((c = fgetc(fIfp)) != EOF) {
136 KeyValue(name, value,
type);
178 if (c !=
' ' && c !=
'\t')
191 state = (c ==
':') ? 3 : 4;
195 state = (c ==
')') ? 6 : 5;
215 KeyValue(name, value,
type);
225 class TReadEnvParser :
public TEnvParser {
231 TReadEnvParser(
TEnv *e, FILE *
f,
EEnvLevel l) : TEnvParser(e, f), fLevel(l) { }
233 { fEnv->SetValue(name, value, fLevel, type); }
239 class TWriteEnvParser :
public TEnvParser {
245 TWriteEnvParser(
TEnv *e, FILE *
f, FILE *of) : TEnvParser(e, f), fOfp(of) { }
253 void TWriteEnvParser::KeyValue(
const TString &name,
const TString &value,
256 TEnvRec *er = fEnv->Lookup(name);
261 fprintf(fOfp,
"%s", value.
Data());
272 : fName(n),
fType(t), fLevel(l)
287 if (
fValue != v && !ignoredup)
289 "duplicate entry <%s=%s> for level %d; ignored",
fName.
Data(),
v,
l);
325 char *
v, *vorg =
StrDup(value);
330 while ((s1 = (
char*)strstr(v,
"$("))) {
332 s2 = (
char*)strchr(s1,
')');
339 if (vv) len += strlen(vv);
350 int nch = strlen(v) + len;
351 char *nv =
new char[nch];
354 while ((s1 = (
char*)strstr(v,
"$("))) {
359 s2 = (
char*)strchr(s1,
')');
362 if (vv) strlcat(nv, vv,nch);
367 if (*v) strlcat(nv, v,nch);
394 if (!name || !name[0] || !
gSystem)
411 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
448 haveProgName =
kTRUE;
454 aname +=
"."; aname +=
name;
459 aname +=
"."; aname +=
name;
466 if (er == 0 && haveProgName &&
gProgName) {
470 if (er == 0 &&
gROOT) {
471 aname =
gROOT->GetName(); aname +=
"."; aname +=
name;
475 aname =
"*.*."; aname +=
name;
479 aname =
"*."; aname +=
name;
498 char buf2[512], *cp2 = buf2;
500 while (isspace((
int)*cp))
504 if (isdigit((
int)*cp) || *cp ==
'-' || *cp ==
'+')
506 while (isalpha((
int)*cp))
507 *cp2++ = toupper((
int)*cp++);
510 if (strcmp(buf2, bt->fName) == 0)
527 if (val == 0.0 && cp == endptr)
561 if (!opt || !opt[0]) {
566 if (!strcmp(opt,
"global"))
568 if (!strcmp(opt,
"user"))
570 if (!strcmp(opt,
"local"))
583 static const char *lc[] = {
"Global",
"User",
"Local",
"Changed",
"All" };
597 if (!fname || !fname[0]) {
598 Error(
"ReadFile",
"no file name specified");
603 if ((ifp = fopen(fname,
"r"))) {
604 TReadEnvParser rp(
this, ifp, level);
622 if (!fname || !fname[0]) {
623 Error(
"WriteFile",
"no file name specified");
628 Error(
"WriteFile",
"TEnv table is empty");
633 if ((ofp = fopen(fname,
"w"))) {
644 Error(
"WriteFile",
"cannot open %s for writing", fname);
655 Error(
"Save",
"no resource file name specified");
670 Error(
"SaveLevel",
"no resource file name specified");
675 Error(
"SaveLevel",
"TEnv table is empty");
708 if ((ofp = fopen(
Form(
"%s.new", rootrcdir.
Data()),
"w"))) {
709 ifp = fopen(rootrcdir.
Data(),
"r");
711 ifp = fopen(rootrcdir.
Data(),
"w");
717 if (ifp || (ifp = fopen(rootrcdir.
Data(),
"r"))) {
718 TWriteEnvParser wp(
this, ifp, ofp);
728 if (er->
fLevel == level) {
743 Error(
"SaveLevel",
"cannot write to file %s", rootrcdir.
Data());
755 const char *nam =
name;
757 if (name[0] ==
'+') {
ClassImp(TEnv) TEnv
Create a resource table and read the (possibly) three resource files, i.e $ROOTSYS/etc/system<name> (...
virtual const char * WorkingDirectory()
Return working directory.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
const char * Getvalue(const char *name)
Returns the character value for a named resource.
TObject * FindObject(const char *name) const
Find object using its name.
static struct BoolNameTable_t gBoolNames[]
virtual void Print(Option_t *option="") const
Print all resources or the global, user or local resources separately.
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
The TEnv class reads config files, by default named .rootrc.
void ChangeValue(const char *v, const char *t, EEnvLevel l, Bool_t append=kFALSE, Bool_t ignoredup=kFALSE)
Change the value of a resource.
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
virtual int Rename(const char *from, const char *to)
Rename a file.
const char * Data() const
Int_t Compare(const TObject *obj) const
Comparison function for resources.
virtual ~TEnv()
Delete the resource table.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
virtual Int_t WriteFile(const char *fname, EEnvLevel level=kEnvAll)
Write resource records to file fname for a certain level.
void Clear()
Clear string without changing its capacity.
virtual const char * Getenv(const char *env)
Get environment variable.
TString & Append(const char *cs)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Bool_t IgnoreDuplicates(Bool_t ignore)
If set to true, no warnings in case of duplicates are issued.
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
Read and parse the resource file for a certain level.
virtual void Save()
Write the resource files for each level.
R__EXTERN const char * gProgName
R__EXTERN TSystem * gSystem
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
virtual TEnvRec * Lookup(const char *n)
Loop over all resource records and return the one with name.
char * Form(const char *fmt,...)
virtual const char * GetName() const
Returns name of object.
virtual void PrintEnv(EEnvLevel level=kEnvAll) const
Print all resources for a certain level (global, user, local, changed).
char * StrDup(const char *str)
Duplicate the string str.
TString ExpandValue(const char *v)
Replace all strings by the value defined in the shell (obtained via TSystem::Getenv()).
virtual void SaveLevel(EEnvLevel level)
Write the resource file for a certain level.
Mother of all ROOT objects.
virtual void Add(TObject *obj)
R__EXTERN const char * gRootDir
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.