Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
f075f7311d

+ 7 - 0
direct/src/showbase/showBase.cxx

@@ -35,11 +35,18 @@
 #include <orthoProjection.h>
 #include <appTraverser.h>
 #include <collisionTraverser.h>
+#include <get_config_path.h>
 
 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

+ 3 - 0
direct/src/showbase/showBase.h

@@ -16,6 +16,7 @@
 #include <pointerTo.h>
 #include <nodePath.h>
 #include <dconfig.h>
+#include <dSearchPath.h>
 
 ConfigureDecl(config_showbase, EXPCL_DIRECT, EXPTP_DIRECT);
 typedef Config::Config<ConfigureGetConfig_config_showbase> 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, 

+ 60 - 0
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

+ 2 - 0
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);
   

+ 4 - 2
panda/src/express/get_config_path.cxx

@@ -6,6 +6,8 @@
 #include "get_config_path.h"
 #include "config_express.h"
 
+#include <executionEnvironment.h>
+
 
 ////////////////////////////////////////////////////////////////////
 //     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;
       }
     }