mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
Various fixes to p3dWrapper
This commit is contained in:
parent
f4a06bca9f
commit
b1866def94
@ -14,7 +14,7 @@
|
||||
|
||||
/* p3dWrapper is a small wrapper executable that locates a .p3d file
|
||||
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 <string.h>
|
||||
@ -28,46 +28,66 @@ const char delims[] = ":";
|
||||
#endif
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
char havep3dfile = 0;
|
||||
char havepanda3d = 0;
|
||||
char* p3dname = strdup (argv [0]);
|
||||
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* panda3d = NULL;
|
||||
char* path = getenv ("PATH");
|
||||
if (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) {
|
||||
p3dfile = strdup (pathtok);
|
||||
// Check if the p3d file is in this directory.
|
||||
if (!havep3dfile) {
|
||||
p3dfile = strdup (pathtok);
|
||||
#ifdef _WIN32
|
||||
strcat (p3dfile, "\\");
|
||||
strcat (p3dfile, "\\");
|
||||
#else
|
||||
strcat (p3dfile, "/");
|
||||
strcat (p3dfile, "/");
|
||||
#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
|
||||
strcat (panda3d, "\\panda3d.exe");
|
||||
strcat (panda3d, "\\panda3d.exe");
|
||||
#else
|
||||
strcat (panda3d, "/panda3d");
|
||||
strcat (panda3d, "/panda3d");
|
||||
#endif
|
||||
if (access (panda3d, X_OK) == 0) {
|
||||
if (access (panda3d, X_OK) == 0) {
|
||||
havepanda3d = 1;
|
||||
}
|
||||
}
|
||||
if (havep3dfile && havepanda3d) {
|
||||
break;
|
||||
} else {
|
||||
panda3d = NULL;
|
||||
}
|
||||
pathtok = strtok(NULL, delims);
|
||||
}
|
||||
}
|
||||
if (p3dfile == NULL) {
|
||||
if (havep3dfile == 0 || p3dfile == NULL) {
|
||||
p3dfile = p3dname;
|
||||
}
|
||||
if (panda3d == NULL) {
|
||||
if (havepanda3d == 0 || panda3d == NULL) {
|
||||
#ifdef _WIN32
|
||||
panda3d = "panda3d.exe";
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user