// used when seperate startup (for shell) is needed int main(int argc, char **argv) { #else // called by VMD main program int win32vmdstart(void) { #endif int i, j, len; char *str, *str2, *vmddir; char tmp[MAX_PATH + 8192]; char buffer[MAX_PATH +1]; int usedregistry; #if defined(VMDSEPARATESTARTUP) int rc; #endif /* XXX debugging hacks to be sure the compiler mode is set correctly */ #ifdef _WIN64 printf("TEST: Windows x64 VMD test build.\n"); printf("TEST: sizeof(int): %d sizeof(long): %d sizeof(void *): %d\n", sizeof(int), sizeof(long), sizeof(void *)); #endif vmddir = NULL; // initialize to NULL for safety usedregistry = 1; // change this to 0 if we fail vmddir = vmd_get_vmddir(); // search Windows registry first if (vmddir == NULL) { #if 1 // get full pathname to VMD executable GetModuleFileName(NULL, buffer, sizeof(buffer)); usedregistry = 0; // registry failed, we had to guess, using exe path vmddir = buffer; // get from the Win32 API vmd.exe path #elif defined(VMDSEPARATESTARTUP) // desparate attempt to get VMDDIR from argv[0], which only works if // we were started from the explorer shell usedregistry = 0; // registry failed, we had to guess, using exe path vmddir = argv[0]; // get from the explorer shell vmd.exe path #else return -1; // fail and exit #endif } len = strlen(vmddir); str = (char *) malloc(len); str2 = (char *) malloc(len); strcpy(str, vmddir); strcpy(str2, vmddir); j=len; for (i=0; i<len; i++) { if (str[i] == '\\') { str2[i] = '/'; j=i; } } if (usedregistry) { free(vmddir); // free memory allocated by the vmd_get_vmddir() function vmddir = NULL; // make sure we don't accidentally use it again } else { // If we didn't use the registry, we need to strip off everything after // and including the last "\" character. // If we did use the registry, no string truncation is required. str[j] = '\0'; str2[j] = '\0'; } strcpy(tmp, "VMDDIR="); strcat(tmp, str2); putenv(tmp); strcpy(tmp, "TCL_LIBRARY="); strcat(tmp, str2); strcat(tmp, "/scripts/tcl"); putenv(tmp); strcpy(tmp, "TK_LIBRARY="); strcat(tmp, str2); strcat(tmp, "/scripts/tk"); putenv(tmp); if (!getenv("PYTHONPATH")) { strcpy(tmp, "PYTHONPATH="); strcat(tmp, str2); strcat(tmp, "/scripts/python"); putenv(tmp); } else { strcpy(tmp, getenv("PYTHONPATH")); strcat(tmp, ":"); strcat(tmp, str2); strcat(tmp, "/scripts/python"); putenv(tmp); } strcpy(tmp, "VMDBABELBIN="); strcat(tmp, str); strcat(tmp, "\\babel\\babel.exe"); putenv(tmp); strcpy(tmp, "BABEL_DIR="); strcat(tmp, str); strcat(tmp, "\\babel"); putenv(tmp); strcpy(tmp, "STRIDE_BIN=\""); strcat(tmp, str); strcat(tmp, "\\stride_WIN32.exe\""); putenv(tmp); strcpy(tmp, "SURF_BIN="); strcat(tmp, str); strcat(tmp, "\\surf_WIN32.exe"); putenv(tmp); strcpy(tmp, "TACHYON_BIN="); strcat(tmp, str); strcat(tmp, "\\tachyon_WIN32.exe"); putenv(tmp); #if defined(VMDSEPARATESTARTUP) strcpy(tmp, str); strcat(tmp, "\\winvmd.exe"); // Add all of the command line options we may have had to the // invocation of the real program. strcat(tmp, " "); for(i=1; i<argc; i++) { strcat(tmp, argv[i]); strcat(tmp, " "); } // Run the program! rc = WinExec(tmp, SW_SHOW); if (!rc) { printf("failed to start program %s\n", tmp); Sleep(10000); } #endif return 0; }
static char * vmd_get_vmddir(void) { FSSpec spec; FSRef ref; UInt8 * path; OSErr rc; char *bundledir; char *vmddir; char *tmp; bundledir = (char *) malloc(2048 * sizeof(UInt8)); memset(bundledir, 0, 2048 * sizeof(UInt8)); #if 0 if (!(rc = GetApplicationPackageFSSpecFromBundle(&spec))) { #else if (!(rc = GetApplicationBundleFSSpec(&spec))) { #endif rc = FSpMakeFSRef(&spec, &ref); if (rc) printf("makefsref OSErr: %d\n", rc); rc = FSRefMakePath(&ref,(UInt8 *) bundledir, 2048); if (rc) printf("makepath OSErr: %d\n", rc); } else { printf("getappbundlepath OSErr: %d\n", rc); } if (rc) { free(bundledir); return NULL; } // truncate bundle path to parent bundle directory if ((tmp = strrchr(bundledir, '/')) != NULL) { tmp[0] = '\0'; } if ((tmp = strrchr(bundledir, '/')) != NULL) { tmp[0] = '\0'; } // add "/vmd" to parent bundle directory vmddir = (char *) malloc(strlen(bundledir) + 1 + strlen("/vmd")); strcpy(vmddir, bundledir); strcat(vmddir, "/vmd"); free(bundledir); return (char *) vmddir; } #if 1 int macosxvmdstart(int argc, char **argv) { #else int main(int argc, char **argv) { #endif char tmp[8192]; char * vmddir; int i; vmddir = vmd_get_vmddir(); if (vmddir == NULL) { return -1; // fail and exit } #if 0 if (!getenv("MACOSXVMDSTARTUP")) { int startterminal=1; // be default, we start one... setenv("MACOSXVMDSTARTUP", "1", 1); // check for -dispdev text, in which case we don't start a terminal... for (i=0; i < argc; i++) { if (!strupcmp(argv[i], "-dispdev")) { if (argc > i+1) { if (!strupcmp(argv[i+1], "text")) { startterminal=0; } } } } if (startterminal) { char cmdbuf[16384]; sprintf(cmdbuf, "\"%s/vmd_MACOSX\"", vmddir); if (argc > 1) { for (i=1; i < argc; i++) { strcat(cmdbuf, " "); strcat(cmdbuf, argv[i]); } } strcat(cmdbuf, " &"); printf("Executing VMD startup command: %s\n", cmdbuf); exit(system(cmdbuf)); } } #endif if (!getenv("VMDDIR")) { setenv("VMDDIR", vmddir, 1); } if (!getenv("TCL_LIBRARY")) { strcpy(tmp, vmddir); strcat(tmp, "/scripts/tcl"); setenv("TCL_LIBRARY", tmp, 1); } if (!getenv("TK_LIBRARY")) { strcpy(tmp, vmddir); strcat(tmp, "/scripts/tk"); setenv("TK_LIBRARY", tmp, 1); } if (!getenv("PYTHONPATH")) { strcpy(tmp, vmddir); strcat(tmp, "/scripts/python"); setenv("PYTHONPATH", tmp, 1); } else { strcpy(tmp, getenv("PYTHONPATH")); strcat(tmp, ":"); strcat(tmp, vmddir); strcat(tmp, "/scripts/python"); setenv("PYTHONPATH", tmp, 1); } if (!getenv("STRIDE_BIN")) { strcpy(tmp, vmddir); #if defined(ARCH_MACOSXX86) strcat(tmp, "/stride_MACOSXX86"); #else strcat(tmp, "/stride_MACOSX"); #endif setenv("STRIDE_BIN", tmp, 1); } if (!getenv("SURF_BIN")) { strcpy(tmp, vmddir); #if defined(ARCH_MACOSXX86) strcat(tmp, "/surf_MACOSXX86"); #else strcat(tmp, "/surf_MACOSX"); #endif setenv("SURF_BIN", tmp, 1); } if (!getenv("TACHYON_BIN")) { strcpy(tmp, vmddir); #if defined(ARCH_MACOSXX86) strcat(tmp, "/tachyon_MACOSXX86"); #else strcat(tmp, "/tachyon_MACOSX"); #endif setenv("TACHYON_BIN", tmp, 1); } return 0; }
static char * vmd_get_vmddir(void) { OSErr rc = 0; FSSpec spec; FSRef ref; UInt8 *path = NULL; char *bundledir = NULL; char *vmddir = NULL; char *tmp = NULL; bundledir = (char *) malloc(2048 * sizeof(UInt8)); memset(bundledir, 0, 2048 * sizeof(UInt8)); #if defined(ARCH_MACOSXX86_64) // // CoreFoundation/Cocoa-based application bundle path query code // CFBundleRef mainbundle = CFBundleGetMainBundle(); if (mainbundle != NULL) { #if 1 CFURLRef appurl = CFBundleCopyBundleURL(mainbundle); #else CFURLRef appurl = CFBundleCopyExecutableURL(mainbundle); #endif CFStringRef cfpath = CFURLCopyFileSystemPath(appurl, kCFURLPOSIXPathStyle); if (CFStringGetFileSystemRepresentation(cfpath, bundledir, 2048 * sizeof(UInt8) - 1) == true) { // printf("MacOS X Bundle path: %s\n", bundledir); // Truncate bundle path to parent bundle directory, // if needed, when the executable is launched by double clicking // the application bundle in the GUI. When the application // is launched directly via scripts etc, the main bundle path // returned from the previous calls already points to the parent // directory of the VMD executable. if (strstr(bundledir, "/Contents/Resources/VMD.app")) { if ((tmp = strrchr(bundledir, '/')) != NULL) { tmp[0] = '\0'; } if ((tmp = strrchr(bundledir, '/')) != NULL) { tmp[0] = '\0'; } if ((tmp = strrchr(bundledir, '/')) != NULL) { tmp[0] = '\0'; } // add path to main VMD directory from the outermost bundle container strcat(bundledir, "/Contents/vmd"); } vmddir = (char *) malloc(strlen(bundledir) + 1 + strlen("/vmd")); strcpy(vmddir, bundledir); } free(bundledir); CFRelease(appurl); CFRelease(cfpath); } if (!vmddir) { printf("WARNING: Failed to get path for main VMD application bundle...\n"); vmddir = getenv("VMDDIR"); } #else // // Carbon-based application bundle path query code // #if 0 if (!(rc = GetApplicationPackageFSSpecFromBundle(&spec))) { #else if (!(rc = GetApplicationBundleFSSpec(&spec))) { #endif rc = FSpMakeFSRef(&spec, &ref); if (rc) printf("makefsref OSErr: %d\n", rc); rc = FSRefMakePath(&ref,(UInt8 *) bundledir, 2048); if (rc) printf("makepath OSErr: %d\n", rc); } else { printf("getappbundlepath OSErr: %d\n", rc); } if (rc) { free(bundledir); return NULL; } // truncate bundle path to parent bundle directory if ((tmp = strrchr(bundledir, '/')) != NULL) { tmp[0] = '\0'; } if ((tmp = strrchr(bundledir, '/')) != NULL) { tmp[0] = '\0'; } // add "/vmd" to parent bundle directory vmddir = (char *) malloc(strlen(bundledir) + 1 + strlen("/vmd")); strcpy(vmddir, bundledir); strcat(vmddir, "/vmd"); free(bundledir); #endif return (char *) vmddir; } #if 1 int macosxvmdstart(int argc, char **argv) { #else int main(int argc, char **argv) { #endif char tmp[8192]; char * vmddir; int i; vmddir = vmd_get_vmddir(); if (vmddir == NULL) { return -1; // fail and exit } #if 0 if (!getenv("MACOSXVMDSTARTUP")) { int startterminal=1; // be default, we start one... setenv("MACOSXVMDSTARTUP", "1", 1); // check for -dispdev text, in which case we don't start a terminal... for (i=0; i < argc; i++) { if (!strupcmp(argv[i], "-dispdev")) { if (argc > i+1) { if (!strupcmp(argv[i+1], "text")) { startterminal=0; } } } } if (startterminal) { char cmdbuf[16384]; sprintf(cmdbuf, "\"%s/vmd_MACOSX\"", vmddir); if (argc > 1) { for (i=1; i < argc; i++) { strcat(cmdbuf, " "); strcat(cmdbuf, argv[i]); } } strcat(cmdbuf, " &"); printf("Executing VMD startup command: %s\n", cmdbuf); exit(system(cmdbuf)); } } #endif if (!getenv("VMDDIR")) { setenv("VMDDIR", vmddir, 1); } if (!getenv("TCL_LIBRARY")) { strcpy(tmp, vmddir); strcat(tmp, "/scripts/tcl"); setenv("TCL_LIBRARY", tmp, 1); } if (!getenv("TK_LIBRARY")) { strcpy(tmp, vmddir); strcat(tmp, "/scripts/tk"); setenv("TK_LIBRARY", tmp, 1); } if (!getenv("PYTHONPATH")) { strcpy(tmp, vmddir); strcat(tmp, "/scripts/python"); setenv("PYTHONPATH", tmp, 1); } else { strcpy(tmp, getenv("PYTHONPATH")); strcat(tmp, ":"); strcat(tmp, vmddir); strcat(tmp, "/scripts/python"); setenv("PYTHONPATH", tmp, 1); } if (!getenv("STRIDE_BIN")) { strcpy(tmp, vmddir); #if defined(ARCH_MACOSXX86_64) strcat(tmp, "/stride_MACOSXX86_64"); #elif defined(ARCH_MACOSXX86) strcat(tmp, "/stride_MACOSXX86"); #else strcat(tmp, "/stride_MACOSX"); #endif setenv("STRIDE_BIN", tmp, 1); } if (!getenv("SURF_BIN")) { strcpy(tmp, vmddir); #if defined(ARCH_MACOSXX86_64) strcat(tmp, "/surf_MACOSXX86_64"); #elif defined(ARCH_MACOSXX86) strcat(tmp, "/surf_MACOSXX86"); #else strcat(tmp, "/surf_MACOSX"); #endif setenv("SURF_BIN", tmp, 1); } if (!getenv("TACHYON_BIN")) { strcpy(tmp, vmddir); #if defined(ARCH_MACOSXX86_64) strcat(tmp, "/tachyon_MACOSXX86_64"); #elif defined(ARCH_MACOSXX86) strcat(tmp, "/tachyon_MACOSXX86"); #else strcat(tmp, "/tachyon_MACOSX"); #endif setenv("TACHYON_BIN", tmp, 1); } return 0; }