ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TEnv.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id: 0daf41ec24086ee7af29fdc2f9f2f848b150dcc8 $
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 /** \class TEnv
13 The TEnv class reads config files, by default named `.rootrc`.
14 Three types of config files are read: global, user and local files. The
15 global file is `$ROOTSYS/etc/system<name>` (or `ROOTETCDIR/system<name>`)
16 the user file is `$HOME/<name>` and the local file is `./<name>`.
17 By setting the shell variable `ROOTENV_NO_HOME=1` the reading of
18 the `$HOME/<name>` resource file will be skipped. This might be useful
19 in case the home directory resides on an auto-mounted remote file
20 system and one wants to avoid this file system from being mounted.
21 
22 The format of the `.rootrc` file is similar to the `.Xdefaults` format:
23 ~~~ {.cpp}
24  [+]<SystemName>.<RootName|ProgName>.<name>[(type)]: <value>
25 ~~~
26 Where `<SystemName>` is either Unix, WinNT, MacOS or Vms,
27 `<RootName>` the name as given in the TApplication ctor (or "RootApp"
28 in case no explicit TApplication derived object was created),
29 `<ProgName>` the current program name and `<name>` the resource name,
30 with optionally a type specification. `<value>` can be either a
31 string, an integer, a float/double or a boolean with the values
32 TRUE, FALSE, ON, OFF, YES, NO, OK, NOT. Booleans will be returned as
33 an integer 0 or 1. The options [+] allows the concatenation of
34 values to the same resource name.
35 
36 E.g.:
37 ~~~ {.cpp}
38  Unix.Rint.Root.DynamicPath: .:$(ROOTSYS)/lib:~/lib
39  myapp.Root.Debug: FALSE
40  TH.Root.Debug: YES
41  *.Root.MemStat: 1
42 ~~~
43 `<SystemName>` and `<ProgName>` or `<RootName>` may be the wildcard "*".
44 A # in the first column starts comment line.
45 
46 Note that the environment variables (like $ROOTSYS) need to be
47 surrounded in parentheses in order to be expanded.
48 
49 For the currently defined resources (and their default values) see
50 `$ROOTSYS/etc/system.rootrc`.
51 
52 Note that the .rootrc config files contain the config for all ROOT
53 based applications.
54 
55 To add new entries to a TEnv:
56 ~~~ {.cpp}
57 TEnv env(".myfile");
58 env.SetValue("myname","value");
59 env.SaveLevel(kEnvLocal);
60 ~~~
61 All new entries will be saved in the file corresponding to the
62 first SaveLevel() command. If Save() is used, new entries go
63 into the local file by default.
64 */
65 
66 #include "RConfigure.h"
67 
68 #include <string.h>
69 #include <stdio.h>
70 #include <stdlib.h>
71 #include <ctype.h>
72 
73 #include "TEnv.h"
74 #include "TROOT.h"
75 #include "TSystem.h"
76 #include "THashList.h"
77 #include "TError.h"
78 
79 
80 TEnv *gEnv; // main environment created in TROOT
81 
82 
83 static struct BoolNameTable_t {
84  const char *fName;
85  Int_t fValue;
86 } gBoolNames[]= {
87  { "TRUE", 1 },
88  { "FALSE", 0 },
89  { "ON", 1 },
90  { "OFF", 0 },
91  { "YES", 1 },
92  { "NO", 0 },
93  { "OK", 1 },
94  { "NOT", 0 },
95  { 0, 0 }
96 };
97 
98 
99 /** \class TEnvParser
100 TEnv Parser.
101 */
102 
103 class TEnvParser {
104 
105 private:
106  FILE *fIfp;
107 
108 protected:
109  TEnv *fEnv;
110 
111 public:
112  TEnvParser(TEnv *e, FILE *f) : fIfp(f), fEnv(e) { }
113  virtual ~TEnvParser() { }
114  virtual void KeyValue(const TString&, const TString&, const TString&) { }
115  virtual void Char(Int_t) { }
116  void Parse();
117 };
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Parse a line of the env file and create an entry in the resource
121 /// dictionary (i.e. add a KeyValue pair).
122 
123 void TEnvParser::Parse()
124 {
125  TString name(1024);
126  TString type(1024);
127  TString value(1024);
128  int c, state = 0;
129 
130  while ((c = fgetc(fIfp)) != EOF) {
131  if (c == 13) // ignore CR
132  continue;
133  if (c == '\n') {
134  state = 0;
135  if (name.Length() > 0) {
136  KeyValue(name, value, type);
137  name.Clear();
138  value.Clear();
139  type.Clear();
140  }
141  Char(c);
142  continue;
143  }
144  switch (state) {
145  case 0: // start of line
146  switch (c) {
147  case ' ':
148  case '\t':
149  break;
150  case '#':
151  state = 1;
152  break;
153  default:
154  state = 2;
155  break;
156  }
157  break;
158 
159  case 1: // comment
160  break;
161 
162  case 2: // name
163  switch (c) {
164  case ' ':
165  case '\t':
166  case ':':
167  state = 3;
168  break;
169  case '(':
170  state = 7;
171  break;
172  default:
173  break;
174  }
175  break;
176 
177  case 3: // ws before value
178  if (c != ' ' && c != '\t')
179  state = 4;
180  break;
181 
182  case 4: // value
183  break;
184 
185  case 5: // type
186  if (c == ')')
187  state = 6;
188  break;
189 
190  case 6: // optional ':'
191  state = (c == ':') ? 3 : 4;
192  break;
193 
194  case 7:
195  state = (c == ')') ? 6 : 5;
196  break;
197 
198  }
199  switch (state) {
200  case 2:
201  name.Append(c);
202  break;
203  case 4:
204  value.Append(c);
205  break;
206  case 5:
207  type.Append(c);
208  break;
209  }
210  if (state != 4)
211  Char(c);
212  }
213  // In case EOF is reach before '\n'
214  if (name.Length() > 0) {
215  KeyValue(name, value, type);
216  name.Clear();
217  value.Clear();
218  type.Clear();
219  }
220 }
221 
222 /** \class TReadEnvParser
223 */
224 
225 class TReadEnvParser : public TEnvParser {
226 
227 private:
228  EEnvLevel fLevel;
229 
230 public:
231  TReadEnvParser(TEnv *e, FILE *f, EEnvLevel l) : TEnvParser(e, f), fLevel(l) { }
232  void KeyValue(const TString &name, const TString &value, const TString &type)
233  { fEnv->SetValue(name, value, fLevel, type); }
234 };
235 
236 /** \class TWriteEnvParser
237 */
238 
239 class TWriteEnvParser : public TEnvParser {
240 
241 private:
242  FILE *fOfp;
243 
244 public:
245  TWriteEnvParser(TEnv *e, FILE *f, FILE *of) : TEnvParser(e, f), fOfp(of) { }
246  void KeyValue(const TString &name, const TString &value, const TString &type);
247  void Char(Int_t c) { fputc(c, fOfp); }
248 };
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Write resources out to a new file.
252 
253 void TWriteEnvParser::KeyValue(const TString &name, const TString &value,
254  const TString &)
255 {
256  TEnvRec *er = fEnv->Lookup(name);
257  if (er && er->fModified) {
258  er->fModified = kFALSE;
259  fprintf(fOfp, "%s", er->fValue.Data());
260  } else
261  fprintf(fOfp, "%s", value.Data());
262 }
263 
264 
265 /** \class TEnvRec
266 */
267 
268 ////////////////////////////////////////////////////////////////////////////////
269 /// Ctor of a single resource.
270 
271 TEnvRec::TEnvRec(const char *n, const char *v, const char *t, EEnvLevel l)
272  : fName(n), fType(t), fLevel(l)
273 {
274  fValue = ExpandValue(v);
275  fModified = (l == kEnvChange);
276 }
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Change the value of a resource.
280 
281 void TEnvRec::ChangeValue(const char *v, const char *, EEnvLevel l,
282  Bool_t append, Bool_t ignoredup)
283 {
284  if (l != kEnvChange && fLevel == l && !append) {
285  // use global Warning() since interpreter might not yet be initialized
286  // at this stage (called from TROOT ctor)
287  if (fValue != v && !ignoredup)
288  ::Warning("TEnvRec::ChangeValue",
289  "duplicate entry <%s=%s> for level %d; ignored", fName.Data(), v, l);
290  return;
291  }
292  if (!append) {
293  if (fValue != v) {
294  if (l == kEnvChange)
295  fModified = kTRUE;
296  else
297  fModified = kFALSE;
298  fLevel = l;
299  fValue = ExpandValue(v);
300  }
301  } else {
302  if (l == kEnvChange)
303  fModified = kTRUE;
304  fLevel = l;
305  fValue += " ";
306  fValue += ExpandValue(v);
307  }
308 }
309 
310 ////////////////////////////////////////////////////////////////////////////////
311 /// Comparison function for resources.
312 
314 {
315  return fName.CompareTo(((TEnvRec*)op)->fName);
316 }
317 
318 ////////////////////////////////////////////////////////////////////////////////
319 /// Replace all $(XXX) strings by the value defined in the shell
320 /// (obtained via TSystem::Getenv()).
321 
322 TString TEnvRec::ExpandValue(const char *value)
323 {
324  const char *vv;
325  char *v, *vorg = StrDup(value);
326  v = vorg;
327 
328  char *s1, *s2;
329  int len = 0;
330  while ((s1 = (char*)strstr(v, "$("))) {
331  s1 += 2;
332  s2 = (char*)strchr(s1, ')');
333  if (!s2) {
334  len = 0;
335  break;
336  }
337  *s2 = 0;
338  vv = gSystem->Getenv(s1);
339  if (vv) len += strlen(vv);
340  *s2 = ')';
341  v = s2 + 1;
342  }
343 
344  if (!len) {
345  delete [] vorg;
346  return TString(value);
347  }
348 
349  v = vorg;
350  int nch = strlen(v) + len;
351  char *nv = new char[nch];
352  *nv = 0;
353 
354  while ((s1 = (char*)strstr(v, "$("))) {
355  *s1 = 0;
356  strlcat(nv, v,nch);
357  *s1 = '$';
358  s1 += 2;
359  s2 = (char*)strchr(s1, ')');
360  *s2 = 0;
361  vv = gSystem->Getenv(s1);
362  if (vv) strlcat(nv, vv,nch);
363  *s2 = ')';
364  v = s2 + 1;
365  }
366 
367  if (*v) strlcat(nv, v,nch);
368 
369  TString val = nv;
370  delete [] nv;
371  delete [] vorg;
372 
373  return val;
374 }
375 
377 
378 ////////////////////////////////////////////////////////////////////////////////
379 /// Create a resource table and read the (possibly) three resource files, i.e
380 /// `$ROOTSYS/etc/system``<name>` (or `ROOTETCDIR/system``<name>`),
381 /// `$HOME/``<name>` and
382 /// `./``<name>`.
383 /// ROOT always reads ".rootrc" (in TROOT::InitSystem()). You can
384 /// read additional user defined resource files by creating additional TEnv
385 /// objects. By setting the shell variable ROOTENV_NO_HOME=1 the reading of
386 /// the `$HOME/<name>` resource file will be skipped. This might be useful in
387 /// case the home directory resides on an auto-mounted remote file system
388 /// and one wants to avoid the file system from being mounted.
389 
390 TEnv::TEnv(const char *name)
391 {
392  fIgnoreDup = kFALSE;
393 
394  if (!name || !name[0] || !gSystem)
395  fTable = 0;
396  else {
397  fTable = new THashList(1000);
398  fRcName = name;
399 
400  TString sname = "system";
401  sname += name;
402 #ifdef ROOTETCDIR
403  char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
404 #else
405  TString etc = gRootDir;
406 #ifdef WIN32
407  etc += "\\etc";
408 #else
409  etc += "/etc";
410 #endif
411 #if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
412  // on iOS etc does not exist and system<name> resides in $ROOTSYS
413  etc = gRootDir;
414 #endif
415  char *s = gSystem->ConcatFileName(etc, sname);
416 #endif
417  ReadFile(s, kEnvGlobal);
418  delete [] s;
419  if (!gSystem->Getenv("ROOTENV_NO_HOME")) {
421  ReadFile(s, kEnvUser);
422  delete [] s;
423  if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory()))
424  ReadFile(name, kEnvLocal);
425  } else
426  ReadFile(name, kEnvLocal);
427  }
428 }
429 
430 ////////////////////////////////////////////////////////////////////////////////
431 /// Delete the resource table.
432 
434 {
435  if (fTable) {
436  fTable->Delete();
438  }
439 }
440 
441 ////////////////////////////////////////////////////////////////////////////////
442 /// Returns the character value for a named resource.
443 
444 const char *TEnv::Getvalue(const char *name)
445 {
446  Bool_t haveProgName = kFALSE;
447  if (gProgName && strlen(gProgName) > 0)
448  haveProgName = kTRUE;
449 
450  TString aname;
451  TEnvRec *er = 0;
452  if (haveProgName && gSystem && gProgName) {
453  aname = gSystem->GetName(); aname += "."; aname += gProgName;
454  aname += "."; aname += name;
455  er = Lookup(aname);
456  }
457  if (er == 0 && gSystem && gROOT) {
458  aname = gSystem->GetName(); aname += "."; aname += gROOT->GetName();
459  aname += "."; aname += name;
460  er = Lookup(aname);
461  }
462  if (er == 0 && gSystem) {
463  aname = gSystem->GetName(); aname += ".*."; aname += name;
464  er = Lookup(aname);
465  }
466  if (er == 0 && haveProgName && gProgName) {
467  aname = gProgName; aname += "."; aname += name;
468  er = Lookup(aname);
469  }
470  if (er == 0 && gROOT) {
471  aname = gROOT->GetName(); aname += "."; aname += name;
472  er = Lookup(aname);
473  }
474  if (er == 0) {
475  aname = "*.*."; aname += name;
476  er = Lookup(aname);
477  }
478  if (er == 0) {
479  aname = "*."; aname += name;
480  er = Lookup(aname);
481  }
482  if (er == 0) {
483  er = Lookup(name);
484  }
485  if (er == 0)
486  return 0;
487  return er->fValue;
488 }
489 
490 ////////////////////////////////////////////////////////////////////////////////
491 /// Returns the integer value for a resource. If the resource is not found
492 /// return the default value.
493 
494 Int_t TEnv::GetValue(const char *name, Int_t dflt)
495 {
496  const char *cp = TEnv::Getvalue(name);
497  if (cp) {
498  char buf2[512], *cp2 = buf2;
499 
500  while (isspace((int)*cp))
501  cp++;
502  if (*cp) {
503  BoolNameTable_t *bt;
504  if (isdigit((int)*cp) || *cp == '-' || *cp == '+')
505  return atoi(cp);
506  while (isalpha((int)*cp))
507  *cp2++ = toupper((int)*cp++);
508  *cp2 = 0;
509  for (bt = gBoolNames; bt->fName; bt++)
510  if (strcmp(buf2, bt->fName) == 0)
511  return bt->fValue;
512  }
513  }
514  return dflt;
515 }
516 
517 ////////////////////////////////////////////////////////////////////////////////
518 /// Returns the double value for a resource. If the resource is not found
519 /// return the default value.
520 
521 Double_t TEnv::GetValue(const char *name, Double_t dflt)
522 {
523  const char *cp = TEnv::Getvalue(name);
524  if (cp) {
525  char *endptr;
526  Double_t val = strtod(cp, &endptr);
527  if (val == 0.0 && cp == endptr)
528  return dflt;
529  return val;
530  }
531  return dflt;
532 }
533 
534 ////////////////////////////////////////////////////////////////////////////////
535 /// Returns the character value for a named resource. If the resource is
536 /// not found the default value is returned.
537 
538 const char *TEnv::GetValue(const char *name, const char *dflt)
539 {
540  const char *cp = TEnv::Getvalue(name);
541  if (cp)
542  return cp;
543  return dflt;
544 }
545 
546 ////////////////////////////////////////////////////////////////////////////////
547 /// Loop over all resource records and return the one with name.
548 /// Return 0 in case name is not in the resource table.
549 
550 TEnvRec *TEnv::Lookup(const char *name)
551 {
552  if (!fTable) return 0;
553  return (TEnvRec*) fTable->FindObject(name);
554 }
555 
556 ////////////////////////////////////////////////////////////////////////////////
557 /// Print all resources or the global, user or local resources separately.
558 
559 void TEnv::Print(Option_t *opt) const
560 {
561  if (!opt || !opt[0]) {
562  PrintEnv();
563  return;
564  }
565 
566  if (!strcmp(opt, "global"))
568  if (!strcmp(opt, "user"))
570  if (!strcmp(opt, "local"))
572 }
573 
574 ////////////////////////////////////////////////////////////////////////////////
575 /// Print all resources for a certain level (global, user, local, changed).
576 
577 void TEnv::PrintEnv(EEnvLevel level) const
578 {
579  if (!fTable) return;
580 
581  TIter next(fTable);
582  TEnvRec *er;
583  static const char *lc[] = { "Global", "User", "Local", "Changed", "All" };
584 
585  while ((er = (TEnvRec*) next()))
586  if (er->fLevel == level || level == kEnvAll)
587  Printf("%-25s %-30s [%s]", Form("%s:", er->fName.Data()),
588  er->fValue.Data(), lc[er->fLevel]);
589 }
590 
591 ////////////////////////////////////////////////////////////////////////////////
592 /// Read and parse the resource file for a certain level.
593 /// Returns -1 on case of error, 0 in case of success.
594 
595 Int_t TEnv::ReadFile(const char *fname, EEnvLevel level)
596 {
597  if (!fname || !fname[0]) {
598  Error("ReadFile", "no file name specified");
599  return -1;
600  }
601 
602  FILE *ifp;
603  if ((ifp = fopen(fname, "r"))) {
604  TReadEnvParser rp(this, ifp, level);
605  rp.Parse();
606  fclose(ifp);
607  return 0;
608  }
609 
610  // no Error() here since we are allowed to try to read from a non-existing
611  // file (like ./.rootrc, $HOME/.rootrc, etc.)
612  return -1;
613 }
614 
615 ////////////////////////////////////////////////////////////////////////////////
616 /// Write resource records to file fname for a certain level. Use
617 /// level kEnvAll to write all resources. Returns -1 on case of error,
618 /// 0 in case of success.
619 
620 Int_t TEnv::WriteFile(const char *fname, EEnvLevel level)
621 {
622  if (!fname || !fname[0]) {
623  Error("WriteFile", "no file name specified");
624  return -1;
625  }
626 
627  if (!fTable) {
628  Error("WriteFile", "TEnv table is empty");
629  return -1;
630  }
631 
632  FILE *ofp;
633  if ((ofp = fopen(fname, "w"))) {
634  TIter next(fTable);
635  TEnvRec *er;
636  while ((er = (TEnvRec*) next()))
637  if (er->fLevel == level || level == kEnvAll)
638  fprintf(ofp, "%-40s %s\n", Form("%s:", er->fName.Data()),
639  er->fValue.Data());
640  fclose(ofp);
641  return 0;
642  }
643 
644  Error("WriteFile", "cannot open %s for writing", fname);
645  return -1;
646 }
647 
648 ////////////////////////////////////////////////////////////////////////////////
649 /// Write the resource files for each level. The new files have the same
650 /// name as the original files. The old files are renamed to *.bak.
651 
653 {
654  if (fRcName == "") {
655  Error("Save", "no resource file name specified");
656  return;
657  }
658 
659  SaveLevel(kEnvLocal); // Be default, new items will be put into Local.
662 }
663 
664 ////////////////////////////////////////////////////////////////////////////////
665 /// Write the resource file for a certain level.
666 
668 {
669  if (fRcName == "") {
670  Error("SaveLevel", "no resource file name specified");
671  return;
672  }
673 
674  if (!fTable) {
675  Error("SaveLevel", "TEnv table is empty");
676  return;
677  }
678 
679  TString rootrcdir;
680  FILE *ifp, *ofp;
681 
682  if (level == kEnvGlobal) {
683 
684  TString sname = "system";
685  sname += fRcName;
686 #ifdef ROOTETCDIR
687  char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
688 #else
689  TString etc = gRootDir;
690 #ifdef WIN32
691  etc += "\\etc";
692 #else
693  etc += "/etc";
694 #endif
695  char *s = gSystem->ConcatFileName(etc, sname);
696 #endif
697  rootrcdir = s;
698  delete [] s;
699  } else if (level == kEnvUser) {
701  rootrcdir = s;
702  delete [] s;
703  } else if (level == kEnvLocal)
704  rootrcdir = fRcName;
705  else
706  return;
707 
708  if ((ofp = fopen(Form("%s.new", rootrcdir.Data()), "w"))) {
709  ifp = fopen(rootrcdir.Data(), "r");
710  if (ifp == 0) { // try to create file
711  ifp = fopen(rootrcdir.Data(), "w");
712  if (ifp) {
713  fclose(ifp);
714  ifp = 0;
715  }
716  }
717  if (ifp || (ifp = fopen(rootrcdir.Data(), "r"))) {
718  TWriteEnvParser wp(this, ifp, ofp);
719  wp.Parse();
720 
721  TIter next(fTable);
722  TEnvRec *er;
723  while ((er = (TEnvRec*) next())) {
724  if (er->fModified) {
725 
726  // If it doesn't have a level yet, make it this one.
727  if (er->fLevel == kEnvChange) er->fLevel = level;
728  if (er->fLevel == level) {
729  er->fModified = kFALSE;
730  fprintf(ofp, "%-40s %s\n", Form("%s:", er->fName.Data()),
731  er->fValue.Data());
732  }
733  }
734  }
735  fclose(ifp);
736  fclose(ofp);
737  gSystem->Rename(rootrcdir.Data(), Form("%s.bak", rootrcdir.Data()));
738  gSystem->Rename(Form("%s.new", rootrcdir.Data()), rootrcdir.Data());
739  return;
740  }
741  fclose(ofp);
742  } else
743  Error("SaveLevel", "cannot write to file %s", rootrcdir.Data());
744 }
745 
746 ////////////////////////////////////////////////////////////////////////////////
747 /// Set the value of a resource or create a new resource.
748 
749 void TEnv::SetValue(const char *name, const char *value, EEnvLevel level,
750  const char *type)
751 {
752  if (!fTable)
753  fTable = new THashList(1000);
754 
755  const char *nam = name;
756  Bool_t append = kFALSE;
757  if (name[0] == '+') {
758  nam = &name[1];
759  append = kTRUE;
760  }
761 
762  TEnvRec *er = Lookup(nam);
763  if (er)
764  er->ChangeValue(value, type, level, append, fIgnoreDup);
765  else
766  fTable->Add(new TEnvRec(nam, value, type, level));
767 }
768 
769 ////////////////////////////////////////////////////////////////////////////////
770 /// Set the value of a resource or create a new resource.
771 /// Use this method to set a resource like, "name=val".
772 /// If just "name" is given it will be interpreted as "name=1".
773 
774 void TEnv::SetValue(const char *name, EEnvLevel level)
775 {
776  TString buf = name;
777  int l = buf.Index("=");
778  if (l > 0) {
779  TString nm = buf(0, l);
780  TString val = buf(l+1, buf.Length());
781  SetValue(nm, val, level);
782  } else
783  SetValue(name, "1", level);
784 }
785 
786 ////////////////////////////////////////////////////////////////////////////////
787 /// Set or create an integer resource value.
788 
789 void TEnv::SetValue(const char *name, Int_t value)
790 {
791  SetValue(name, Form("%d", value));
792 }
793 
794 ////////////////////////////////////////////////////////////////////////////////
795 /// Set or create a double resource value.
796 
797 void TEnv::SetValue(const char *name, double value)
798 {
799  SetValue(name, Form("%g", value));
800 }
801 
802 ////////////////////////////////////////////////////////////////////////////////
803 /// If set to true, no warnings in case of duplicates are issued.
804 /// Returns previous value.
805 
807 {
808  Bool_t ret = fIgnoreDup;
809  fIgnoreDup = ignore;
810  return ret;
811 }
Bool_t fIgnoreDup
Definition: TEnv.h:133
ClassImp(TEnv) TEnv
Create a resource table and read the (possibly) three resource files, i.e $ROOTSYS/etc/system<name> (...
Definition: TEnv.cxx:376
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Ssiz_t Length() const
Definition: TString.h:390
TEnvRec()
Definition: TEnv.h:112
const char * Getvalue(const char *name)
Returns the character value for a named resource.
Definition: TEnv.cxx:444
Definition: TEnv.h:76
return c
const char Option_t
Definition: RtypesCore.h:62
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:213
static struct BoolNameTable_t gBoolNames[]
virtual void Print(Option_t *option="") const
Print all resources or the global, user or local resources separately.
Definition: TEnv.cxx:559
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
Definition: TSystem.cxx:873
void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: THashList.cxx:184
#define gROOT
Definition: TROOT.h:344
The TEnv class reads config files, by default named .rootrc.
Definition: TEnv.h:128
Basic string class.
Definition: TString.h:137
void ChangeValue(const char *v, const char *t, EEnvLevel l, Bool_t append=kFALSE, Bool_t ignoredup=kFALSE)
Change the value of a resource.
Definition: TEnv.cxx:281
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
const char * Char
TFile * f
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.
Definition: TEnv.cxx:749
TSocket * s1
Definition: hserv2.C:36
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition: TSystem.cxx:1267
const char * Data() const
Definition: TString.h:349
#define SafeDelete(p)
Definition: RConfig.h:436
Int_t Compare(const TObject *obj) const
Comparison function for resources.
Definition: TEnv.cxx:313
virtual ~TEnv()
Delete the resource table.
Definition: TEnv.cxx:433
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
virtual Int_t WriteFile(const char *fname, EEnvLevel level=kEnvAll)
Write resource records to file fname for a certain level.
Definition: TEnv.cxx:620
TString fName
Definition: TEnv.h:99
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1126
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1575
TString & Append(const char *cs)
Definition: TString.h:492
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
Bool_t IgnoreDuplicates(Bool_t ignore)
If set to true, no warnings in case of duplicates are issued.
Definition: TEnv.cxx:806
Bool_t fModified
Definition: TEnv.h:103
EEnvLevel
Definition: TEnv.h:74
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
Read and parse the resource file for a certain level.
Definition: TEnv.cxx:595
virtual void Save()
Write the resource files for each level.
Definition: TEnv.cxx:652
R__EXTERN const char * gProgName
Definition: TSystem.h:234
Definition: TEnv.h:91
TThread * t[5]
Definition: threadsh1.C:13
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
SVector< double, 2 > v
Definition: Dict.h:5
PyObject * fValue
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
virtual TEnvRec * Lookup(const char *n)
Loop over all resource records and return the one with name.
Definition: TEnv.cxx:550
char * Form(const char *fmt,...)
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
const std::string sname
Definition: testIO.cxx:45
Definition: TEnv.h:77
#define Printf
Definition: TGeoToOCC.h:18
virtual void PrintEnv(EEnvLevel level=kEnvAll) const
Print all resources for a certain level (global, user, local, changed).
Definition: TEnv.cxx:577
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2500
PyObject * fType
Definition: TEnv.h:79
TEnv * gEnv
Definition: TEnv.cxx:80
THashList * fTable
Definition: TEnv.h:131
TH1F * s2
Definition: threadsh2.C:15
TString ExpandValue(const char *v)
Replace all strings by the value defined in the shell (obtained via TSystem::Getenv()).
Definition: TEnv.cxx:322
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void SaveLevel(EEnvLevel level)
Write the resource file for a certain level.
Definition: TEnv.cxx:667
Mother of all ROOT objects.
Definition: TObject.h:58
virtual void Add(TObject *obj)
Definition: TList.h:81
R__EXTERN const char * gRootDir
Definition: TSystem.h:233
TString fValue
Definition: TEnv.h:101
EEnvLevel fLevel
Definition: TEnv.h:102
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
const Bool_t kTRUE
Definition: Rtypes.h:91
float value
Definition: math.cpp:443
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
Definition: TSystem.cxx:1028
const Int_t n
Definition: legend1.C:16
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:372
TString fRcName
Definition: TEnv.h:132
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904