David Rose 25 лет назад
Родитель
Сommit
8cdfbeedcf

+ 4 - 3
dtool/src/dtoolutil/executionEnvironment.cxx

@@ -5,6 +5,8 @@
 
 #include "executionEnvironment.h"
 #include <assert.h>
+#include <errno.h>
+#include <stdio.h>  // for perror
 
 #ifdef WIN32_VC
 // Windows requires this for getcwd().
@@ -12,7 +14,6 @@
 #define getcwd _getcwd
 #endif
 
-#include <errno.h>
 
 // We define the symbol PREREAD_ENVIRONMENT if we cannot rely on
 // getenv() to read environment variables at static init time.  In
@@ -57,7 +58,7 @@ ExecutionEnvironment() {
 //       Access: Public, Static
 //  Description: Returns the name of the current working directory.
 ////////////////////////////////////////////////////////////////////
-string ExecutionEnvironment::
+Filename ExecutionEnvironment::
 get_cwd() {
   // getcwd() requires us to allocate a dynamic buffer and grow it on
   // demand.
@@ -79,7 +80,7 @@ get_cwd() {
     assert(buffer != (char *)NULL);
   }
 
-  return string(buffer);
+  return Filename::from_os_specific(buffer);
 }
 
 ////////////////////////////////////////////////////////////////////

+ 2 - 1
dtool/src/dtoolutil/executionEnvironment.h

@@ -9,6 +9,7 @@
 #include <dtoolbase.h>
 
 #include "vector_string.h"
+#include "filename.h"
 
 #include <map>
 
@@ -33,7 +34,7 @@ public:
   
   INLINE static string get_binary_name();
 
-  static string get_cwd();
+  static Filename get_cwd();
 
 private:
   bool ns_has_environment_variable(const string &var) const;

+ 48 - 3
dtool/src/dtoolutil/filename.cxx

@@ -14,6 +14,7 @@
 
 #include "filename.h"
 #include "dSearchPath.h"
+#include "executionEnvironment.h"
 
 #include <stdio.h>  // For rename()
 #include <sys/stat.h>
@@ -191,10 +192,13 @@ Filename::
 Filename(const Filename &dirname, const Filename &basename) {
   if (dirname.empty()) {
     (*this) = basename;
-  } else if (basename.empty()) {
-    (*this) = dirname;
   } else {
-    (*this) = dirname.get_fullpath() + "/" + basename.get_fullpath();
+    string dirpath = dirname.get_fullpath();
+    if (dirpath[dirpath.length() - 1] == '/') {
+      (*this) = dirpath + basename.get_fullpath();
+    } else {
+      (*this) = dirpath + "/" + basename.get_fullpath();
+    }
   }
   _flags = 0;
 }
@@ -474,6 +478,45 @@ standardize() {
   (*this) = result;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Filename::make_absolute
+//       Access: Public
+//  Description: Converts the filename to a fully-qualified pathname
+//               from the root (if it is a relative pathname), and
+//               then standardizes it (see standardize()).
+//
+//               This is sometimes a little problematic, since it may
+//               convert the file to its 'true' absolute pathname,
+//               which could be an ugly NFS-named file, irrespective
+//               of symbolic links
+//               (e.g. /.automount/dimbo/root/usr2/fit/people/drose
+//               instead of /fit/people/drose); besides being ugly,
+//               filenames like this may not be consistent across
+//               multiple different platforms.
+////////////////////////////////////////////////////////////////////
+void Filename::
+make_absolute() {
+  make_absolute(ExecutionEnvironment::get_cwd());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Filename::make_absolute
+//       Access: Public
+//  Description: Converts the filename to a fully-qualified filename
+//               from the root (if it is a relative filename), and
+//               then standardizes it (see standardize()).  This
+//               flavor accepts a specific starting directory that the
+//               filename is known to be relative to.
+////////////////////////////////////////////////////////////////////
+void Filename::
+make_absolute(const Filename &start_directory) {
+  if (is_local()) {
+    (*this) = Filename(start_directory, _filename);
+  }
+
+  standardize();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Filename::to_os_specific
 //       Access: Public
@@ -485,6 +528,8 @@ standardize() {
 //               instance).  Returns the string representing the
 //               converted filename, but does not change the Filename
 //               itself.
+//
+//               See also from_os_specific().
 ////////////////////////////////////////////////////////////////////
 string Filename::
 to_os_specific() const {

+ 2 - 0
dtool/src/dtoolutil/filename.h

@@ -116,6 +116,8 @@ public:
   // The following functions deal with the outside world.
 
   INLINE bool is_local() const;
+  void make_absolute();
+  void make_absolute(const Filename &start_directory);
 
   string to_os_specific() const;
 

+ 1 - 1
panda/src/framework/framework.cxx

@@ -900,7 +900,7 @@ int framework_main(int argc, char *argv[]) {
   for (int a = 1; a < argc; a++)
     if ((argv[a] != (char*)0L) && ((argv[a])[0] != '-') &&
 	((argv[a])[0] != '+') && ((argv[a])[0] != '#'))
-      files.push_back(argv[a]);
+      files.push_back(Filename::from_os_specific(argv[a]));
 
   // load display modules
   GraphicsPipe::resolve_modules();