ROOT  6.06/08
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 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 
376 ClassImp(TEnv)
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  char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
403  ReadFile(s, kEnvGlobal);
404  delete [] s;
405  if (!gSystem->Getenv("ROOTENV_NO_HOME")) {
407  ReadFile(s, kEnvUser);
408  delete [] s;
409  if (strcmp(gSystem->HomeDirectory(), gSystem->WorkingDirectory()))
410  ReadFile(name, kEnvLocal);
411  } else
412  ReadFile(name, kEnvLocal);
413  }
414 }
415 
416 ////////////////////////////////////////////////////////////////////////////////
417 /// Delete the resource table.
418 
420 {
421  if (fTable) {
422  fTable->Delete();
423  SafeDelete(fTable);
424  }
425 }
426 
427 ////////////////////////////////////////////////////////////////////////////////
428 /// Returns the character value for a named resource.
429 
430 const char *TEnv::Getvalue(const char *name)
431 {
432  Bool_t haveProgName = kFALSE;
433  if (gProgName && strlen(gProgName) > 0)
434  haveProgName = kTRUE;
435 
436  TString aname;
437  TEnvRec *er = 0;
438  if (haveProgName && gSystem && gProgName) {
439  aname = gSystem->GetName(); aname += "."; aname += gProgName;
440  aname += "."; aname += name;
441  er = Lookup(aname);
442  }
443  if (er == 0 && gSystem && gROOT) {
444  aname = gSystem->GetName(); aname += "."; aname += gROOT->GetName();
445  aname += "."; aname += name;
446  er = Lookup(aname);
447  }
448  if (er == 0 && gSystem) {
449  aname = gSystem->GetName(); aname += ".*."; aname += name;
450  er = Lookup(aname);
451  }
452  if (er == 0 && haveProgName && gProgName) {
453  aname = gProgName; aname += "."; aname += name;
454  er = Lookup(aname);
455  }
456  if (er == 0 && gROOT) {
457  aname = gROOT->GetName(); aname += "."; aname += name;
458  er = Lookup(aname);
459  }
460  if (er == 0) {
461  aname = "*.*."; aname += name;
462  er = Lookup(aname);
463  }
464  if (er == 0) {
465  aname = "*."; aname += name;
466  er = Lookup(aname);
467  }
468  if (er == 0) {
469  er = Lookup(name);
470  }
471  if (er == 0)
472  return 0;
473  return er->fValue;
474 }
475 
476 ////////////////////////////////////////////////////////////////////////////////
477 /// Returns the integer value for a resource. If the resource is not found
478 /// return the default value.
479 
480 Int_t TEnv::GetValue(const char *name, Int_t dflt)
481 {
482  const char *cp = TEnv::Getvalue(name);
483  if (cp) {
484  char buf2[512], *cp2 = buf2;
485 
486  while (isspace((int)*cp))
487  cp++;
488  if (*cp) {
489  BoolNameTable_t *bt;
490  if (isdigit((int)*cp) || *cp == '-' || *cp == '+')
491  return atoi(cp);
492  while (isalpha((int)*cp))
493  *cp2++ = toupper((int)*cp++);
494  *cp2 = 0;
495  for (bt = gBoolNames; bt->fName; bt++)
496  if (strcmp(buf2, bt->fName) == 0)
497  return bt->fValue;
498  }
499  }
500  return dflt;
501 }
502 
503 ////////////////////////////////////////////////////////////////////////////////
504 /// Returns the double value for a resource. If the resource is not found
505 /// return the default value.
506 
507 Double_t TEnv::GetValue(const char *name, Double_t dflt)
508 {
509  const char *cp = TEnv::Getvalue(name);
510  if (cp) {
511  char *endptr;
512  Double_t val = strtod(cp, &endptr);
513  if (val == 0.0 && cp == endptr)
514  return dflt;
515  return val;
516  }
517  return dflt;
518 }
519 
520 ////////////////////////////////////////////////////////////////////////////////
521 /// Returns the character value for a named resource. If the resource is
522 /// not found the default value is returned.
523 
524 const char *TEnv::GetValue(const char *name, const char *dflt)
525 {
526  const char *cp = TEnv::Getvalue(name);
527  if (cp)
528  return cp;
529  return dflt;
530 }
531 
532 ////////////////////////////////////////////////////////////////////////////////
533 /// Loop over all resource records and return the one with name.
534 /// Return 0 in case name is not in the resource table.
535 
536 TEnvRec *TEnv::Lookup(const char *name)
537 {
538  if (!fTable) return 0;
539  return (TEnvRec*) fTable->FindObject(name);
540 }
541 
542 ////////////////////////////////////////////////////////////////////////////////
543 /// Print all resources or the global, user or local resources separately.
544 
545 void TEnv::Print(Option_t *opt) const
546 {
547  if (!opt || !opt[0]) {
548  PrintEnv();
549  return;
550  }
551 
552  if (!strcmp(opt, "global"))
553  PrintEnv(kEnvGlobal);
554  if (!strcmp(opt, "user"))
555  PrintEnv(kEnvUser);
556  if (!strcmp(opt, "local"))
557  PrintEnv(kEnvLocal);
558 }
559 
560 ////////////////////////////////////////////////////////////////////////////////
561 /// Print all resources for a certain level (global, user, local, changed).
562 
563 void TEnv::PrintEnv(EEnvLevel level) const
564 {
565  if (!fTable) return;
566 
567  TIter next(fTable);
568  TEnvRec *er;
569  static const char *lc[] = { "Global", "User", "Local", "Changed", "All" };
570 
571  while ((er = (TEnvRec*) next()))
572  if (er->fLevel == level || level == kEnvAll)
573  Printf("%-25s %-30s [%s]", Form("%s:", er->fName.Data()),
574  er->fValue.Data(), lc[er->fLevel]);
575 }
576 
577 ////////////////////////////////////////////////////////////////////////////////
578 /// Read and parse the resource file for a certain level.
579 /// Returns -1 on case of error, 0 in case of success.
580 
581 Int_t TEnv::ReadFile(const char *fname, EEnvLevel level)
582 {
583  if (!fname || !fname[0]) {
584  Error("ReadFile", "no file name specified");
585  return -1;
586  }
587 
588  FILE *ifp;
589  if ((ifp = fopen(fname, "r"))) {
590  TReadEnvParser rp(this, ifp, level);
591  rp.Parse();
592  fclose(ifp);
593  return 0;
594  }
595 
596  // no Error() here since we are allowed to try to read from a non-existing
597  // file (like ./.rootrc, $HOME/.rootrc, etc.)
598  return -1;
599 }
600 
601 ////////////////////////////////////////////////////////////////////////////////
602 /// Write resource records to file fname for a certain level. Use
603 /// level kEnvAll to write all resources. Returns -1 on case of error,
604 /// 0 in case of success.
605 
606 Int_t TEnv::WriteFile(const char *fname, EEnvLevel level)
607 {
608  if (!fname || !fname[0]) {
609  Error("WriteFile", "no file name specified");
610  return -1;
611  }
612 
613  if (!fTable) {
614  Error("WriteFile", "TEnv table is empty");
615  return -1;
616  }
617 
618  FILE *ofp;
619  if ((ofp = fopen(fname, "w"))) {
620  TIter next(fTable);
621  TEnvRec *er;
622  while ((er = (TEnvRec*) next()))
623  if (er->fLevel == level || level == kEnvAll)
624  fprintf(ofp, "%-40s %s\n", Form("%s:", er->fName.Data()),
625  er->fValue.Data());
626  fclose(ofp);
627  return 0;
628  }
629 
630  Error("WriteFile", "cannot open %s for writing", fname);
631  return -1;
632 }
633 
634 ////////////////////////////////////////////////////////////////////////////////
635 /// Write the resource files for each level. The new files have the same
636 /// name as the original files. The old files are renamed to *.bak.
637 
639 {
640  if (fRcName == "") {
641  Error("Save", "no resource file name specified");
642  return;
643  }
644 
645  SaveLevel(kEnvLocal); // Be default, new items will be put into Local.
646  SaveLevel(kEnvUser);
647  SaveLevel(kEnvGlobal);
648 }
649 
650 ////////////////////////////////////////////////////////////////////////////////
651 /// Write the resource file for a certain level.
652 
654 {
655  if (fRcName == "") {
656  Error("SaveLevel", "no resource file name specified");
657  return;
658  }
659 
660  if (!fTable) {
661  Error("SaveLevel", "TEnv table is empty");
662  return;
663  }
664 
665  TString rootrcdir;
666  FILE *ifp, *ofp;
667 
668  if (level == kEnvGlobal) {
669 
670  TString sname = "system";
671  sname += fRcName;
672  char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
673  rootrcdir = s;
674  delete [] s;
675  } else if (level == kEnvUser) {
676  char *s = gSystem->ConcatFileName(gSystem->HomeDirectory(), fRcName);
677  rootrcdir = s;
678  delete [] s;
679  } else if (level == kEnvLocal)
680  rootrcdir = fRcName;
681  else
682  return;
683 
684  if ((ofp = fopen(Form("%s.new", rootrcdir.Data()), "w"))) {
685  ifp = fopen(rootrcdir.Data(), "r");
686  if (ifp == 0) { // try to create file
687  ifp = fopen(rootrcdir.Data(), "w");
688  if (ifp) {
689  fclose(ifp);
690  ifp = 0;
691  }
692  }
693  if (ifp || (ifp = fopen(rootrcdir.Data(), "r"))) {
694  TWriteEnvParser wp(this, ifp, ofp);
695  wp.Parse();
696 
697  TIter next(fTable);
698  TEnvRec *er;
699  while ((er = (TEnvRec*) next())) {
700  if (er->fModified) {
701 
702  // If it doesn't have a level yet, make it this one.
703  if (er->fLevel == kEnvChange) er->fLevel = level;
704  if (er->fLevel == level) {
705  er->fModified = kFALSE;
706  fprintf(ofp, "%-40s %s\n", Form("%s:", er->fName.Data()),
707  er->fValue.Data());
708  }
709  }
710  }
711  fclose(ifp);
712  fclose(ofp);
713  gSystem->Rename(rootrcdir.Data(), Form("%s.bak", rootrcdir.Data()));
714  gSystem->Rename(Form("%s.new", rootrcdir.Data()), rootrcdir.Data());
715  return;
716  }
717  fclose(ofp);
718  } else
719  Error("SaveLevel", "cannot write to file %s", rootrcdir.Data());
720 }
721 
722 ////////////////////////////////////////////////////////////////////////////////
723 /// Set the value of a resource or create a new resource.
724 
725 void TEnv::SetValue(const char *name, const char *value, EEnvLevel level,
726  const char *type)
727 {
728  if (!fTable)
729  fTable = new THashList(1000);
730 
731  const char *nam = name;
732  Bool_t append = kFALSE;
733  if (name[0] == '+') {
734  nam = &name[1];
735  append = kTRUE;
736  }
737 
738  TEnvRec *er = Lookup(nam);
739  if (er)
740  er->ChangeValue(value, type, level, append, fIgnoreDup);
741  else
742  fTable->Add(new TEnvRec(nam, value, type, level));
743 }
744 
745 ////////////////////////////////////////////////////////////////////////////////
746 /// Set the value of a resource or create a new resource.
747 /// Use this method to set a resource like, "name=val".
748 /// If just "name" is given it will be interpreted as "name=1".
749 
750 void TEnv::SetValue(const char *name, EEnvLevel level)
751 {
752  TString buf = name;
753  int l = buf.Index("=");
754  if (l > 0) {
755  TString nm = buf(0, l);
756  TString val = buf(l+1, buf.Length());
757  SetValue(nm, val, level);
758  } else
759  SetValue(name, "1", level);
760 }
761 
762 ////////////////////////////////////////////////////////////////////////////////
763 /// Set or create an integer resource value.
764 
765 void TEnv::SetValue(const char *name, Int_t value)
766 {
767  SetValue(name, Form("%d", value));
768 }
769 
770 ////////////////////////////////////////////////////////////////////////////////
771 /// Set or create a double resource value.
772 
773 void TEnv::SetValue(const char *name, double value)
774 {
775  SetValue(name, Form("%g", value));
776 }
777 
778 ////////////////////////////////////////////////////////////////////////////////
779 /// If set to true, no warnings in case of duplicates are issued.
780 /// Returns previous value.
781 
783 {
784  Bool_t ret = fIgnoreDup;
785  fIgnoreDup = ignore;
786  return ret;
787 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
TEnvRec()
Definition: TEnv.h:112
const char * Getvalue(const char *name)
Returns the character value for a named resource.
Definition: TEnv.cxx:430
Definition: TEnv.h:76
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:881
#define gROOT
Definition: TROOT.h:352
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
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
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:725
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition: TSystem.cxx:1318
#define SafeDelete(p)
Definition: RConfig.h:449
virtual ~TEnv()
Delete the resource table.
Definition: TEnv.cxx:419
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
virtual void PrintEnv(EEnvLevel level=kEnvAll) const
Print all resources for a certain level (global, user, local, changed).
Definition: TEnv.cxx:563
virtual Int_t WriteFile(const char *fname, EEnvLevel level=kEnvAll)
Write resource records to file fname for a certain level.
Definition: TEnv.cxx:606
TString fName
Definition: TEnv.h:99
void Clear()
Clear string without changing its capacity.
Definition: TString.cxx:1139
virtual const char * Getenv(const char *env)
Get environment variable.
Definition: TSystem.cxx:1626
TString & Append(const char *cs)
Definition: TString.h:492
Bool_t IgnoreDuplicates(Bool_t ignore)
If set to true, no warnings in case of duplicates are issued.
Definition: TEnv.cxx:782
virtual void Print(Option_t *option="") const
Print all resources or the global, user or local resources separately.
Definition: TEnv.cxx:545
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:581
virtual void Save()
Write the resource files for each level.
Definition: TEnv.cxx:638
R__EXTERN const char * gProgName
Definition: TSystem.h:234
Definition: TEnv.h:91
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:379
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
SVector< double, 2 > v
Definition: Dict.h:5
friend class TWriteEnvParser
Definition: TEnv.h:96
PyObject * fValue
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:480
virtual TEnvRec * Lookup(const char *n)
Loop over all resource records and return the one with name.
Definition: TEnv.cxx:536
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
char * Form(const char *fmt,...)
Ssiz_t Length() const
Definition: TString.h:390
TLine * l
Definition: textangle.C:4
const std::string sname
Definition: testIO.cxx:45
Definition: TEnv.h:77
#define Printf
Definition: TGeoToOCC.h:18
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2513
PyObject * fType
Definition: TEnv.h:79
TEnv * gEnv
Definition: TEnv.cxx:80
Int_t Compare(const TObject *obj) const
Comparison function for resources.
Definition: TEnv.cxx:313
#define ClassImp(name)
Definition: Rtypes.h:279
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:322
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:2601
friend class TReadEnvParser
Definition: TEnv.h:95
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:385
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual void SaveLevel(EEnvLevel level)
Write the resource file for a certain level.
Definition: TEnv.cxx:653
Mother of all ROOT objects.
Definition: TObject.h:58
TString fValue
Definition: TEnv.h:101
EEnvLevel fLevel
Definition: TEnv.h:102
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:1044
const Int_t n
Definition: legend1.C:16
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904
const char * Data() const
Definition: TString.h:349