Forráskód Böngészése

Various fixes to p3dWrapper

rdb 16 éve
szülő
commit
b1866def94
1 módosított fájl, 38 hozzáadás és 18 törlés
  1. 38 18
      direct/src/p3d/p3dWrapper.c

+ 38 - 18
direct/src/p3d/p3dWrapper.c

@@ -14,7 +14,7 @@
 
 
 /* p3dWrapper is a small wrapper executable that locates a .p3d file
 /* p3dWrapper is a small wrapper executable that locates a .p3d file
    on the PATH that has the same basename as the executable, and runs
    on the PATH that has the same basename as the executable, and runs
-   it with panda3d.exe that is also located on the PATH.  */
+   it with panda3d(.exe) that is also located on the PATH.  */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
@@ -28,46 +28,66 @@ const char delims[] = ":";
 #endif
 #endif
 
 
 int main (int argc, char* argv[]) {
 int main (int argc, char* argv[]) {
+  char havep3dfile = 0;
+  char havepanda3d = 0;
   char* p3dname = strdup (argv [0]);
   char* p3dname = strdup (argv [0]);
   strcat (p3dname, ".p3d");
   strcat (p3dname, ".p3d");
+  if (access (p3dname, R_OK) == 0) {
+    havep3dfile = 1;
+  } else {
+    // Make sure that p3dname contains a basename only.
+    int c;
+    for (c = strlen(p3dname) - 1; c >= 0; --c) {
+      if (p3dname[c] == '/' || p3dname[c] == '\\') {
+        p3dname += c + 1;
+        break;
+      }
+    }
+  }
   
   
   char* p3dfile = NULL;
   char* p3dfile = NULL;
   char* panda3d = NULL;
   char* panda3d = NULL;
   char* path = getenv ("PATH");
   char* path = getenv ("PATH");
   if (path) {
   if (path) {
     // Locate the .p3d file and panda3d(.exe) on PATH.
     // Locate the .p3d file and panda3d(.exe) on PATH.
-    char* pathtok = strtok(path, delims);
+    char* pathtok = NULL;
+    pathtok = strtok (path, delims);
     while (pathtok != NULL) {
     while (pathtok != NULL) {
-      p3dfile = strdup (pathtok);
+      // Check if the p3d file is in this directory.
+      if (!havep3dfile) {
+        p3dfile = strdup (pathtok);
 #ifdef _WIN32
 #ifdef _WIN32
-      strcat (p3dfile, "\\");
+        strcat (p3dfile, "\\");
 #else
 #else
-      strcat (p3dfile, "/");
+        strcat (p3dfile, "/");
 #endif
 #endif
-      strcat (p3dfile, p3dname);
-      if (access (p3dfile, R_OK) == 0) {
-        break;
-      } else {
-        p3dfile = NULL;
+        strcat (p3dfile, p3dname);
+        if (access (p3dfile, R_OK) == 0) {
+          havep3dfile = 1;
+        }
       }
       }
-      panda3d = strdup (pathtok);
+      // Check if panda3d(.exe) is in this directory.
+      if (!havepanda3d) {
+        panda3d = strdup (pathtok);
 #ifdef _WIN32
 #ifdef _WIN32
-      strcat (panda3d, "\\panda3d.exe");
+        strcat (panda3d, "\\panda3d.exe");
 #else
 #else
-      strcat (panda3d, "/panda3d");
+        strcat (panda3d, "/panda3d");
 #endif
 #endif
-      if (access (panda3d, X_OK) == 0) {
+        if (access (panda3d, X_OK) == 0) {
+          havepanda3d = 1;
+        }
+      }
+      if (havep3dfile && havepanda3d) {
         break;
         break;
-      } else {
-        panda3d = NULL;
       }
       }
       pathtok = strtok(NULL, delims);
       pathtok = strtok(NULL, delims);
     }
     }
   }
   }
-  if (p3dfile == NULL) {
+  if (havep3dfile == 0 || p3dfile == NULL) {
     p3dfile = p3dname;
     p3dfile = p3dname;
   }
   }
-  if (panda3d == NULL) {
+  if (havepanda3d == 0 || panda3d == NULL) {
 #ifdef _WIN32
 #ifdef _WIN32
     panda3d = "panda3d.exe";
     panda3d = "panda3d.exe";
 #else
 #else