//#if defined(_WIN32) && !defined(WITHOUT_GUI) //int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) //#else int main(int argc, char *argv[]) //#endif { int iRet = 0; #ifdef ENABLE_MPI initScilabMPI(); #endif ScilabEngineInfo* pSEI = InitScilabEngineInfo(); #ifdef WITHOUT_GUI /* Building Scilab-cli-bin. We won't ever had the gui nor the jvm */ pSEI->iConsoleMode = 1; pSEI->iNoJvm = 1; setScilabMode(SCILAB_NWNI); #else setScilabMode(SCILAB_STD); #endif //#if defined(_WIN32) && !defined(WITHOUT_GUI) // { // LPSTR my_argv[256]; // int nArgs = 0; // LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); // if (szArglist) // { // for (int i = 0; i < nArgs; i++) // { // my_argv[i] = wide_string_to_UTF8(szArglist[i]); // } // LocalFree(szArglist); // } // get_option(nArgs, my_argv, pSEI); // } //#else get_option(argc, argv, pSEI); //#endif // if WITHOUT_GUI is defined // force Terminal IO -> Terminal IO + StartScilabEngine // WITHOUT_GUI (All Platform) => Terminal IO + StartScilabEngine // GUI (MacOSX) => [no option] -> Console IO + InitMacOSXEnv // | [-nwni] -> Terminal IO + StartScilabEngine // | [-nw] -> Terminal IO + InitMacOSXEnv #ifndef WITHOUT_GUI if (pSEI->iConsoleMode) { setScilabMode(SCILAB_NW); setScilabInputMethod(&getCmdLine); setScilabOutputMethod(&TermPrintf); #if defined(__APPLE__) if (pSEI->iNoJvm == 0) { return initMacOSXEnv(pSEI); } #endif // !defined(__APPLE__) } else { setScilabMode(SCILAB_STD); setScilabInputMethod(&ConsoleRead); setScilabOutputMethod(&ConsolePrintf); #if defined(__APPLE__) return initMacOSXEnv(pSEI); #endif // !defined(__APPLE__) } #else setScilabMode(SCILAB_NWNI); setScilabInputMethod(&getCmdLine); setScilabOutputMethod(&TermPrintf); #endif // defined(WITHOUT_GUI) if (pSEI->iShowVersion == 1) { disp_scilab_version(); exit(0); } int val = setjmp(ScilabJmpEnv); if (!val) { StartScilabEngine(pSEI); iRet = RunScilabEngine(pSEI); StopScilabEngine(pSEI); FREE(pSEI); return iRet; } else { // We probably had a segfault so print error std::wcerr << getLastErrorMessage() << std::endl; return val; } }
/** * Actually launch Scilab under Mac OS X. Need to be in a specific thread. * See http://wiki.scilab.org/Compiling_Scilab_5.x_under_MacOSX * @param param The structure containing the missing argument mandatory for realmain * @return the result of the operation (0 if OK ...) */ static int launchMacOSXEnv(ScilabEngineInfo* _pSEI) { #undef JVM_DETECTION #ifdef JVM_DETECTION int ret = -1; { CFStringRef targetJVM = CFSTR("1.5"); CFBundleRef JavaVMBundle; CFURLRef JavaVMBundleURL; CFURLRef JavaVMBundlerVersionsDirURL; CFURLRef TargetJavaVM; UInt8 pathToTargetJVM [PATH_MAX] = "\0"; struct stat sbuf; /* * This piece of code is mandatory because Mac OS X implementation of Java has a bug here. * Cocoa does not know how to handle the new window created this way. * See: http://lists.apple.com/archives/Java-dev/2009/Jan/msg00062.html * Or Mac Os X bug #6484319 * Thanks to Mike Swingler */ ProcessSerialNumber psn; GetCurrentProcess(&psn); TransformProcessType(&psn, kProcessTransformToForegroundApplication); /* End of the workaround */ // Look for the JavaVM bundle using its identifier JavaVMBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.JavaVM") ); if (JavaVMBundle != NULL) { // Get a path for the JavaVM bundle JavaVMBundleURL = CFBundleCopyBundleURL(JavaVMBundle); CFRelease(JavaVMBundle); if (JavaVMBundleURL != NULL) { // Append to the path the Versions Component JavaVMBundlerVersionsDirURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, JavaVMBundleURL, CFSTR("Versions"), true); CFRelease(JavaVMBundleURL); if (JavaVMBundlerVersionsDirURL != NULL) { // Append to the path the target JVM's Version TargetJavaVM = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, JavaVMBundlerVersionsDirURL, targetJVM, true); CFRelease(JavaVMBundlerVersionsDirURL); if (TargetJavaVM != NULL) { if (CFURLGetFileSystemRepresentation (TargetJavaVM, true, pathToTargetJVM, PATH_MAX )) { // Check to see if the directory, or a sym link for the target JVM directory exists, and if so set the // environment variable JAVA_JVM_VERSION to the target JVM. if (stat((char*)pathToTargetJVM, &sbuf) == 0) { // Ok, the directory exists, so now we need to set the environment var JAVA_JVM_VERSION to the CFSTR targetJVM // We can reuse the pathToTargetJVM buffer to set the environement var. if (CFStringGetCString(targetJVM, (char*)pathToTargetJVM, PATH_MAX, kCFStringEncodingUTF8)) { setenv("JAVA_JVM_VERSION", (char*)pathToTargetJVM, 1); ret = 0; } else { fprintf(stderr, "Could not get the path to the target JVM.\n"); } } else { fprintf(stderr, "Error checking symlink for the target jvm.\n"); } } else { fprintf(stderr, "Error getting file system representation for bundle url.\n"); CFRelease(TargetJavaVM); } } else { fprintf(stderr, "Error appending version component to bundle url.\n"); } } else { fprintf(stderr, "Error appending path component to bundle url.\n"); } } else { fprintf(stderr, "Error copying bundle url.\n"); } } else { fprintf(stderr, "Error: cant find bundle: com.apple.JavaVM.\n"); } } #else int ret = 0; /* * This piece of code is mandatory because Mac OS X implementation of Java has a bug here. * Cocoa does not know how to handle the new window created this way. * See: http://lists.apple.com/archives/Java-dev/2009/Jan/msg00062.html * Or Mac Os X bug #6484319 * Thanks to Mike Swingler */ ProcessSerialNumber psn; GetCurrentProcess(&psn); TransformProcessType(&psn, kProcessTransformToForegroundApplication); /* End of the workaround */ #endif if (ret == 0) { StartScilabEngine(_pSEI); ret = RunScilabEngine(_pSEI); StopScilabEngine(_pSEI); exit(ret); } return ret; }