68#include "RConfigure.h"
133 while ((
c = fgetc(
fIfp)) != EOF) {
138 if (
name.Length() > 0) {
181 if (
c !=
' ' &&
c !=
'\t')
194 state = (
c ==
':') ? 3 : 4;
198 state = (
c ==
')') ? 6 : 5;
217 if (
name.Length() > 0) {
301 "duplicate entry <%s=%s> for level %d; ignored",
fName.Data(),
v,
l);
337 char *
v, *vorg =
StrDup(value);
342 while ((
s1 = (
char*)strstr(
v,
"$("))) {
344 s2 = (
char*)strchr(
s1,
')');
351 if (vv) len += strlen(vv);
362 int nch = strlen(
v) + len;
363 char *nv =
new char[nch];
366 while ((
s1 = (
char*)strstr(
v,
"$("))) {
371 s2 = (
char*)strchr(
s1,
')');
374 if (vv) strlcat(nv, vv,nch);
379 if (*
v) strlcat(nv,
v,nch);
420 if (!
gSystem->Getenv(
"ROOTENV_NO_HOME")) {
421 if (
const auto rootrcPath =
gSystem->Getenv(
"ROOTENV_USER_PATH")) {
423 const char *
s1 =
gSystem->PrependPathName(rootrcPath, temp);
430 if (strcmp(
gSystem->HomeDirectory(),
gSystem->WorkingDirectory())) {
457 haveProgName =
kTRUE;
463 aname +=
"."; aname +=
name;
467 aname =
gSystem->GetName(); aname +=
"."; aname +=
gROOT->GetName();
468 aname +=
"."; aname +=
name;
471 if (er ==
nullptr &&
gSystem) {
472 aname =
gSystem->GetName(); aname +=
".*."; aname +=
name;
475 if (er ==
nullptr && haveProgName &&
gProgName) {
479 if (er ==
nullptr &&
gROOT) {
480 aname =
gROOT->GetName(); aname +=
"."; aname +=
name;
484 aname =
"*.*."; aname +=
name;
488 aname =
"*."; aname +=
name;
507 char buf2[512], *cp2 = buf2;
509 while (isspace((
int)*cp))
513 if (isdigit((
int)*cp) || *cp ==
'-' || *cp ==
'+')
515 while (isalpha((
int)*cp))
516 *cp2++ = toupper((
int)*cp++);
519 if (strcmp(buf2, bt->
fName) == 0)
536 if (val == 0.0 && cp == endptr)
561 if (!
fTable)
return nullptr;
570 if (!opt || !opt[0]) {
575 if (!strcmp(opt,
"global"))
577 if (!strcmp(opt,
"user"))
579 if (!strcmp(opt,
"local"))
592 static const char *lc[] = {
"Global",
"User",
"Local",
"Changed",
"All" };
594 while ((er = (
TEnvRec*) next()))
606 if (!fname || !fname[0]) {
607 Error(
"ReadFile",
"no file name specified");
612 if ((ifp = fopen(fname,
"r"))) {
631 if (!fname || !fname[0]) {
632 Error(
"WriteFile",
"no file name specified");
637 Error(
"WriteFile",
"TEnv table is empty");
642 if ((ofp = fopen(fname,
"w"))) {
645 while ((er = (
TEnvRec*) next()))
653 Error(
"WriteFile",
"cannot open %s for writing", fname);
664 Error(
"Save",
"no resource file name specified");
679 Error(
"SaveLevel",
"no resource file name specified");
684 Error(
"SaveLevel",
"TEnv table is empty");
704 ifp = fopen(rootrcdir.
Data(),
"r");
705 if (ifp ==
nullptr) {
706 ifp = fopen(rootrcdir.
Data(),
"w");
712 if (ifp || (ifp = fopen(rootrcdir.
Data(),
"r"))) {
718 while ((er = (
TEnvRec*) next())) {
723 if (er->
fLevel == level) {
738 Error(
"SaveLevel",
"cannot write to file %s", rootrcdir.
Data());
750 const char *nam =
name;
752 if (
name[0] ==
'+') {
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char).
static struct BoolNameTable_t gBoolNames[]
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
char * StrDup(const char *str)
Duplicate the string str.
externconst char * gProgName
void Parse()
Parse a line of the env file and create an entry in the resource dictionary (i.e.
TEnvParser(TEnv *e, FILE *f)
virtual void KeyValue(const TString &, const TString &, const TString &)
void ChangeValue(const char *v, const char *t, EEnvLevel l, Bool_t append=kFALSE, Bool_t ignoredup=kFALSE)
Change the value of a resource.
TEnvRec(const char *n, const char *v, const char *t, EEnvLevel l)
Ctor of a single resource.
TString ExpandValue(const char *v)
Replace all strings by the value defined in the shell (obtained via TSystem::Getenv()).
~TEnvRec()
TNamed destructor.
Int_t Compare(const TObject *obj) const override
Comparison function for resources.
The TEnv class reads config files, by default named .rootrc.
void Print(Option_t *option="") const override
Print all resources or the global, user or local resources separately.
virtual void PrintEnv(EEnvLevel level=kEnvAll) const
Print all resources for a certain level (global, user, local, changed).
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
virtual Int_t WriteFile(const char *fname, EEnvLevel level=kEnvAll)
Write resource records to file fname for a certain level.
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 SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.
virtual TEnvRec * Lookup(const char *n) const
Loop over all resource records and return the one with name.
virtual void Save()
Write the resource files for each level.
const char * Getvalue(const char *name) const
Returns the character value for a named resource.
virtual void SaveLevel(EEnvLevel level)
Write the resource file for a certain level.
virtual ~TEnv()
Delete the resource table.
TEnv(const TEnv &)=delete
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TObject()
TObject constructor.
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
void KeyValue(const TString &name, const TString &value, const TString &type) override
TReadEnvParser(TEnv *e, FILE *f, EEnvLevel l)
void Clear()
Clear string without changing its capacity.
const char * Data() const
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
void KeyValue(const TString &name, const TString &value, const TString &type) override
Write resources out to a new file.
void Char(Int_t c) override
TWriteEnvParser(TEnv *e, FILE *f, FILE *of)
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.