Logo Search packages:      
Sourcecode: odyssey version File versions

ConfigFile::ConfigFile ( const char *  usercfg,
const char *  progid = NULL,
const char *  syscfg = NULL 
)

Create a ConfigFile object and read in the configuration file(s). If the CONFIG environment variable is set, the usercfg file will be opened/created in the directory specified by that variable. Otherwise it will be opened/created in the user's HOME directory. The reread() method is then called to read in the configuration variables.

Parameters:
usercfg The name of the user's configuration file.
progid If this is not NULL, the config file will be located under a subdirectory with this name.
syscfg The name of an optional global system-wide config file.
Exceptions:
bad_alloc If there is insufficient memory.

Definition at line 29 of file ConfigFile.cxx.

References Util::mkdir_p(), reread(), sysfilename, and userfilename.

                                                                                  {
      char *dir;
      int userfilenamelen;
      bool dot=false;

      dir = getenv("CONFIG");
      if(dir == NULL) {
            dot = true;
            dir = getenv("HOME");
            if(dir == NULL)
                  dir = ".";
      }

      if(syscfg != NULL) {
            this->sysfilename = new char[strlen(syscfg)+2];
            if(this->sysfilename == NULL)
                  throw bad_alloc();
            strcpy(this->sysfilename, syscfg);
      } else {
            this->sysfilename = NULL;
      }

      userfilenamelen = strlen(dir) + strlen(usercfg) + 4;
      if(progid != NULL) userfilenamelen += (strlen(progid) + 2);
      this->userfilename=new char[userfilenamelen];
      if(this->userfilename == NULL) throw bad_alloc();

      if(progid != NULL) {
            sprintf(this->userfilename, "%s/%s%s", dir, (dot ? "." : ""), progid);
            Util::mkdir_p(this->userfilename);
            sprintf(this->userfilename, "%s/%s%s/%s", dir, (dot ? "." : ""), progid, usercfg);
      } else {
            sprintf(this->userfilename, "%s/%s%s", dir, (dot ? "." : ""), usercfg);
      }
      reread();
}


Generated by  Doxygen 1.6.0   Back to index