diff --git a/direct/src/showbase/showBase.cxx b/direct/src/showbase/showBase.cxx index e085f8daf6..47100209d0 100644 --- a/direct/src/showbase/showBase.cxx +++ b/direct/src/showbase/showBase.cxx @@ -35,11 +35,18 @@ #include #include #include +#include ConfigureDef(config_showbase); ConfigureFn(config_showbase) { } +DSearchPath & +get_particle_path() { + static DSearchPath *particle_path = NULL; + return get_config_path("particle-path", particle_path); +} + static CollisionTraverser *collision_traverser = NULL; // Default channel config diff --git a/direct/src/showbase/showBase.h b/direct/src/showbase/showBase.h index 15ff1aea78..4785846385 100644 --- a/direct/src/showbase/showBase.h +++ b/direct/src/showbase/showBase.h @@ -16,6 +16,7 @@ #include #include #include +#include ConfigureDecl(config_showbase, EXPCL_DIRECT, EXPTP_DIRECT); typedef Config::Config ConfigShowbase; @@ -25,6 +26,8 @@ class Camera; BEGIN_PUBLISH +EXPCL_DIRECT DSearchPath &get_particle_path(); + EXPCL_DIRECT PT(GraphicsPipe) make_graphics_pipe(); EXPCL_DIRECT PT(GraphicsWindow) make_graphics_window(GraphicsPipe *pipe, diff --git a/dtool/src/dtoolutil/executionEnvironment.cxx b/dtool/src/dtoolutil/executionEnvironment.cxx index c6502519cc..15574a990f 100644 --- a/dtool/src/dtoolutil/executionEnvironment.cxx +++ b/dtool/src/dtoolutil/executionEnvironment.cxx @@ -53,6 +53,66 @@ ExecutionEnvironment() { read_args(); } +//////////////////////////////////////////////////////////////////// +// Function: ExecutionEnviroment::expand_string +// Access: Public, Static +// Description: Reads the string, looking for environment variable +// names marked by a $. Expands all such variable +// names. A repeated dollar sign ($$) is mapped to a +// single dollar sign. +// +// Returns the expanded string. +//////////////////////////////////////////////////////////////////// +string ExecutionEnvironment:: +expand_string(const string &str) { + string result; + + size_t last = 0; + size_t dollar = str.find('$'); + while (dollar != string::npos && dollar + 1 < str.length()) { + size_t start = dollar + 1; + + if (str[start] == '$') { + // A double dollar sign maps to a single dollar sign. + result += str.substr(last, start - last); + last = start + 1; + + } else { + string varname; + size_t end = start; + + if (str[start] == '{') { + // Curly braces delimit the variable name explicitly. + end = str.find('}', start + 1); + if (end != string::npos) { + varname = str.substr(start + 1, end - (start + 1)); + end++; + } + } + + if (end == start) { + // Scan for the end of the variable name. + while (end < str.length() && (isalnum(str[end]) || str[end] == '_')) { + end++; + } + varname = str.substr(start, end - start); + } + + string subst = + result += str.substr(last, dollar - last); + result += get_environment_variable(varname); + last = end; + } + + dollar = str.find('$', last); + } + + result += str.substr(last); + + cerr << "Expanding " << str << " to " << result << "\n"; + return result; +} + //////////////////////////////////////////////////////////////////// // Function: ExecutionEnviroment::get_cwd // Access: Public, Static diff --git a/dtool/src/dtoolutil/executionEnvironment.h b/dtool/src/dtoolutil/executionEnvironment.h index d7ec220626..fc1869b72d 100644 --- a/dtool/src/dtoolutil/executionEnvironment.h +++ b/dtool/src/dtoolutil/executionEnvironment.h @@ -29,6 +29,8 @@ public: INLINE static bool has_environment_variable(const string &var); INLINE static string get_environment_variable(const string &var); + static string expand_string(const string &str); + INLINE static int get_num_args(); INLINE static string get_arg(int n); diff --git a/panda/src/express/get_config_path.cxx b/panda/src/express/get_config_path.cxx index 4ee4d64108..2feeec7298 100644 --- a/panda/src/express/get_config_path.cxx +++ b/panda/src/express/get_config_path.cxx @@ -6,6 +6,8 @@ #include "get_config_path.h" #include "config_express.h" +#include + //////////////////////////////////////////////////////////////////// // Function: get_config_path @@ -35,10 +37,10 @@ get_config_path(const string &config_var_name, DSearchPath *&static_ptr) { if (!all_defs.empty()) { Config::ConfigTable::Symbol::reverse_iterator si = all_defs.rbegin(); - (*static_ptr).append_path((*si).Val()); + (*static_ptr).append_path(ExecutionEnvironment::expand_string((*si).Val())); ++si; while (si != all_defs.rend()) { - (*static_ptr).append_path((*si).Val()); + (*static_ptr).append_path(ExecutionEnvironment::expand_string((*si).Val())); ++si; } }