From a11c7a4828da73f665815b2d05fe879539caa998 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 4 Jun 2004 06:44:04 +0000 Subject: [PATCH] use CONFIGRC_DIR and DEFAULT_CONFIGRC_DIR --- dtool/Config.pp | 9 +++++++ dtool/LocalSetup.pp | 8 ++++++ dtool/src/dconfig/configTable.cxx | 42 +++++++++++++++++++++++++++---- dtool/src/dconfig/configTable.h | 1 + 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/dtool/Config.pp b/dtool/Config.pp index ffd37f9d21..22c93e3add 100644 --- a/dtool/Config.pp +++ b/dtool/Config.pp @@ -98,6 +98,15 @@ // #define INSTALL_LIB_DIR /usr/lib/python2.2/site-packages +// The Configrc file is used by Panda for runtime configuration. +// Panda will look for it in the directory specified by the +// CONFIGRC_DIR environment variable, or in the directory named here +// if that environment variable is undefined. By default, we specify +// a dot, to indicate the current directory; you may redefine this if +// you have someplace in particular you'd rather put it. +#define DEFAULT_CONFIGRC_DIR . + + // What level of compiler optimization/debug symbols should we build? // The various optimize levels are defined as follows: // diff --git a/dtool/LocalSetup.pp b/dtool/LocalSetup.pp index acf5184cc8..2586383d11 100644 --- a/dtool/LocalSetup.pp +++ b/dtool/LocalSetup.pp @@ -183,6 +183,14 @@ $[cdefine LINK_IN_GL] /* Define if we are linking PANDAPHYSICS in with PANDA. */ $[cdefine LINK_IN_PHYSICS] +/* The compiled-in default directory to look for the Configrc file, in + the absence of the CONFIGRC_DIR environment variable set, and in + the absence of anything specified via the configpath directive. */ +# define DEFAULT_CONFIGRC_DIR "$[DEFAULT_CONFIGRC_DIR]" + + + + /* Define if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ $[cdefine WORDS_BIGENDIAN] diff --git a/dtool/src/dconfig/configTable.cxx b/dtool/src/dconfig/configTable.cxx index 6c7bdbb7d7..e081923605 100644 --- a/dtool/src/dconfig/configTable.cxx +++ b/dtool/src/dconfig/configTable.cxx @@ -141,17 +141,33 @@ void ConfigTable::ReadConfigFile() { int i = configpath.find_first_of(" "); ConfigString stmp = configpath.substr(0, i); if (ExecutionEnvironment::has_environment_variable(stmp)) { - Filename next_path = Filename::from_os_specific(ExecutionEnvironment::get_environment_variable(stmp)); - config_search.append_path(next_path); + string next_path = ExecutionEnvironment::get_environment_variable(stmp); + + while (!next_path.empty()) { + int j = next_path.find_first_of(" "); + Filename dir = Filename::from_os_specific(next_path.substr(0, j)); + config_search.append_directory(dir); + next_path.erase(0, j); + CropString(next_path); + } } configpath.erase(0, i); CropString(configpath); } + // If the configpath is empty, use the configdir string instead. If + // the configdir string is empty, it gets its value from the + // CONFIGRC_DIR environment variable, or from the compiled-in + // default. if (config_search.is_empty()) { - // If we still have no directories on the search path, then at - // least search the current directory. - config_search.append_directory("."); + if (configdir.empty()) { + configdir = ExecutionEnvironment::get_environment_variable("CONFIGRC_DIR"); + if (configdir.empty()) { + configdir = DEFAULT_CONFIGRC_DIR; + } + } + + config_search.append_directory(Filename::from_os_specific(configdir)); } if (microconfig_cat->is_spam()) { @@ -361,6 +377,7 @@ void ConfigTable::MicroConfig() { bool csuff = false; bool cargs = false; bool cpath = false; + bool cdir = false; bool ccmt = false; bool asuff = false; bool cstub = false; @@ -467,6 +484,14 @@ void ConfigTable::MicroConfig() { << endl; } cpath = true; + } else if (tok == "configdir") { + configdir = rest; + if (microconfig_cat->is_spam()) + microconfig_cat->spam() + << "got a microconfig configdir directive, " + << "setting the configdir to '" << configdir << "'" + << endl; + cdir = true; } else if (tok == "configcmt") { configcmt = rest; ccmt = true; @@ -576,6 +601,13 @@ void ConfigTable::MicroConfig() { << "setting to default '" << configpath << "'" << endl; } + if (!cdir) { + ConfigPathDefault(); + if (microconfig_cat->is_spam()) + microconfig_cat->spam() << "no microconfig for configdir, " + << "setting to default '" << configdir + << "'" << endl; + } if (!ccmt) { ConfigCmtDefault(); if (microconfig_cat->is_spam()) diff --git a/dtool/src/dconfig/configTable.h b/dtool/src/dconfig/configTable.h index 0c5116ced2..466a6a4e29 100644 --- a/dtool/src/dconfig/configTable.h +++ b/dtool/src/dconfig/configTable.h @@ -53,6 +53,7 @@ private: ConfigString configsuffix; ConfigString configargs; ConfigString configpath; + ConfigString configdir; ConfigString configcmt; ConfigString argsuffix; ConfigString commandstub;