Example #1
0
//#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;
    }
}
Example #2
0
/*--------------------------------------------------------------------------*/ 
int Console_Main(int argc, char **argv)
{
    int iExitCode = 0;
    int argcount = 0, lpath = 0;
    InitScriptType pathtype = SCILAB_SCRIPT;
    char *path = NULL;
    char *ScilabDirectory = NULL;
    int i=0;

    my_argc = -1;

    forbiddenToUseScilab();

    setScilabMode(SCILAB_NW);

    setCommandLineArgs(argv, argc);

    for (i=0;i<argc;i++)
    {
        my_argv[i] = argv[i];
    }
    my_argc = argc;

    ScilabDirectory = getScilabDirectory(FALSE);

    if (ScilabDirectory == NULL)
    {
        // This message must never occur, but ...
        MessageBox (NULL, "ERROR" , "Cannot determine the Scilab directory (SCI).", MB_ICONSTOP | MB_OK);
        exit(1);
    }
    else
    {
        FREE(ScilabDirectory);
        ScilabDirectory = NULL;
    }

    argcount = my_argc;
    while (argcount > 0)
    {
        argcount--;
        if (_stricmp (my_argv[argcount], "-NS") == 0) startupf = 1;
        else if ( _stricmp(my_argv[argcount],"-NB") == 0) { sci_show_banner = 0; }
        else if (_stricmp (my_argv[argcount], "-NWNI") == 0)
        {
            setScilabMode(SCILAB_NWNI);
        }
        else if (_stricmp (my_argv[argcount], "-F") == 0 && argcount + 1 < my_argc)
        {
            path = my_argv[argcount + 1];
            lpath = (int) strlen (my_argv[argcount + 1]);
        }
        else if (_stricmp (my_argv[argcount], "-E") == 0 && argcount + 1 < my_argc)
        {
            path = my_argv[argcount + 1];
            lpath = (int) strlen (my_argv[argcount + 1]);
            pathtype = SCILAB_CODE;
        }
        else if ( _stricmp(my_argv[argcount],"-MEM") == 0 && argcount + 1 < my_argc)
        {
            memory = Max(atoi( my_argv[argcount + 1]),MIN_STACKSIZE );
        } 
        else if ( _stricmp(my_argv[argcount],"-TEXMACS") == 0 )
        {
            setScilabMode(SCILAB_NWNI);
            settexmacs();
        }
        else if ( _stricmp(my_argv[argcount],"-NOGUI") == 0 )
        {
            setScilabMode(SCILAB_NWNI);
        }
        else if ( (_stricmp (my_argv[argcount],"-VERSION")==0) ||
            (_stricmp (my_argv[argcount],"-VER")==0) )
        {
            disp_scilab_version();
            exit(1);
        }
        else if ( _stricmp(my_argv[argcount],"-L") == 0 && argcount + 1 < my_argc)
        {
            char *language = my_argv[argcount + 1];
            setLanguageFromCommandLine(language);
        }
        else if ( (_stricmp (my_argv[argcount],"-H")==0) ||
            (_stricmp (my_argv[argcount],"-?")==0) ||
            (_stricmp (my_argv[argcount],"-HELP")==0) )
        {
            printf("scilex <Options> : run Scilab.\n");
            printf("Arguments : passes Arguments to Scilab, This Arguments can be retreived\n  by the Scilab function sciargs.\n"); 
            printf("-e Instruction : execute the scilab instruction given in Instruction argument.\n"); 
            printf("-f File : execute the scilab script given in File argument.\n"); 
            printf("  '-e' and '-f' options are mutually exclusive.\n\n"); 
            printf("-l lang : it fixes the user language.\n\n" ); 
            printf("-mem N : set the initial stacksize.\n"); 
            printf("-ns : if this option is present the startup file scilab.start is not executed.\n"); 
            printf("-nb : if this option is present then scilab welcome banner is not displayed.\n"); 
            printf("-nouserstartup : don't execute user startup files SCIHOME/.scilab or SCIHOME/scilab.ini.\n"); 
            printf("-nw : start Scilab without specialized Scilab Window.\n"); 
            printf("-nwni : start Scilab without user interaction (batch mode).\n"); 
            printf("-nogui : start Scilab without GUI,tcl/tk and user interaction (batch mode).\n"); 
            printf("-texmacs : reserved for WinTeXMacs.\n"); 
            printf("-version : print product version and exit.\n"); 
            printf("\n");
            exit(1);
        }
    }

    if (!with_module("jvm")) 
    {
        /* no module jvm then we force NWNI mode */
        setScilabMode(SCILAB_NWNI);
    }

    if (getScilabMode() != SCILAB_NWNI) CreateScilabHiddenWndThread();

    if ( (getScilabMode() == SCILAB_NWNI) || (getScilabMode() == SCILAB_NW) )
    {
        SaveConsoleColors();
        if (getScilabMode() == SCILAB_NW)
        {
            RenameConsole();
            UpdateConsoleColors();
        }

        iExitCode = sci_windows_main (&startupf, path, (InitScriptType)pathtype, &lpath,memory);

    }
    else
    {
        MessageBox(NULL,"-nw or -nwni not found","ERROR",MB_ICONWARNING);
        iExitCode = 1;
    }
    return iExitCode;
}