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