/*--------------------------------------------------------------------------*/
SCILAB_WINDOWS_IMPEXP void setFocusOnConsole(void)
{
    if ( (getScilabMode() == SCILAB_NW) || (getScilabMode() == SCILAB_NWNI) )
    {
        HWND hWndConsole = GetConsoleWindow();
        if (hWndConsole)
        {
            SetForegroundWindow(hWndConsole);
            SetActiveWindow(hWndConsole);
        }
    }
}
Exemple #2
0
/*
** This function is threaded and watch for a signal.
** sent when StoreCommand is performed.
*/
static void initAll(void)
{
    /* Set console mode to raw */
#ifndef _MSC_VER
    if (getScilabMode() == SCILAB_NWNI || getScilabMode() == SCILAB_NW)
    {
        initConsoleMode(RAW);
    }
#endif
    initialized = TRUE;
    pReadyForLaunch = mmap(0, sizeof(__threadSignalLock), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
    atexit(release);
    __InitSignal(&TimeToWork);
    __InitSignalLock(pReadyForLaunch);
}
/*--------------------------------------------------------------------------*/
BOOL TerminateWindows_tools(void)
{
    BOOL bOK = FALSE;
    int scilabMode = getScilabMode();

    switch (scilabMode)
    {
        case SCILAB_STD:
        {
            //Since Scilab 6 All scilab mode are launch in console mode
            //So we cannot close owner console
            //CloseScilabConsole();
            closeInnosetupMutex();
            bOK = TRUE;
        }
        break;

        case SCILAB_NW:
        {
            RestoreConsoleColors();
            RestoreExitButton();
            bOK = TRUE;
        }
        break;

        default:
            break;
    }

    return bOK;
}
/*--------------------------------------------------------------------------*/
int sci_iswaitingforinput(char *fname, unsigned long fname_len)
{
    BOOL res = FALSE;
    int un = 1, outIndex = 0;

    Rhs = Max(Rhs, 0);
    CheckRhs(0, 1);
    CheckLhs(0, 1);

    if (getScilabMode() == SCILAB_STD)
    {
        res = ConsoleIsWaitingForInput();
    }
    else
    {
        sciprint(_("%s: Not implemented in this mode.\n"), fname);
    }

    CreateVar(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &un, &un, &outIndex);
    *istk(outIndex) = res;

    LhsVar(1) = Rhs + 1;
    PutLhsVar();
    return 0;
}
Exemple #5
0
/*--------------------------------------------------------------------------*/
int gw_xcos(void)
{
    Rhs = Max(0, Rhs);

    if (getScilabMode() == SCILAB_NWNI)
    {
        Scierror(999, _("Scilab '%s' module disabled in -nogui or -nwni mode.\n"), "xcos");
        return 0;
    }

    if (!loadedDep              // never reload
            && Tab[Fin - 1].f != sci_closeXcosFromScilab)   // do not load on close
    {
        loadOnUseClassPath("Xcos");
        loadedDep = TRUE;
    }


    if (pvApiCtx == NULL)
    {
        pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
    }

    pvApiCtx->pstName = (char*)Tab[Fin - 1].name;
    callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
    return 0;
}
Exemple #6
0
/***********************************************************************
 * line editor
 **********************************************************************/
static void getCommandLine(void)
{
    tmpPrompt = GetTemporaryPrompt();
    GetCurrentPrompt(Sci_Prompt);

    if (__CommandLine)
    {
        FREE(__CommandLine);
        __CommandLine = NULL;
    }

    if (getScilabMode() == SCILAB_STD)
    {
        /* Send new prompt to Java Console, do not display it */
        if (tmpPrompt != NULL)
        {
            SetConsolePrompt(tmpPrompt);
        }
        else
        {
            SetConsolePrompt(Sci_Prompt);
        }
        setSearchedTokenInScilabHistory(NULL);
        /* Call Java Console to get a string */
        __CommandLine = strdup(ConsoleRead());
    }
    else
    {
        /* Call Term Management for NW and NWNI to get a string */
        __CommandLine = getCmdLine();

    }
}
Exemple #7
0
/*--------------------------------------------------------------------------*/
int gw_ui_data(void)
{
	Rhs = Max(0, Rhs);

	if ( getScilabMode() == SCILAB_NWNI)
	{
		Scierror(999,_("Scilab '%s' module disabled in -nogui or -nwni mode.\n"), "ui_data");
		return 0;
	}

/*	if (!loadedDep)
	{
		loadOnUseClassPath("ui_data");
		loadedDep = TRUE;
	}
*/

    if(pvApiCtx == NULL)
	{
		pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
	}

	pvApiCtx->pstName = (char*)Tab[Fin-1].name;
	callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
	return 0;
}
Exemple #8
0
/*--------------------------------------------------------------------------*/ 
static void printf_scilab(char *buffer)
{
	if (buffer)
	{
		wchar_t *wcBuffer = NULL;
		if (getScilabMode() == SCILAB_STD)
		{
			ConsolePrintf(buffer);
		}
		else
		{
			#ifdef _MSC_VER
			TermPrintf_Windows(buffer);
			#else
			printf("%s",buffer);
			#endif
		}

		wcBuffer = to_wide_string(buffer);
		if (wcBuffer)
		{
			diaryWrite(wcBuffer, FALSE);
			FREE(wcBuffer);
			wcBuffer = NULL;
		}
	}
}
Exemple #9
0
/*--------------------------------------------------------------------------*/
int C2F(sci_havewindow)(char *fname, unsigned long fname_len)
{
    static int n1, m1;
    int *Status = NULL;

    CheckRhs(0, 1);
    CheckLhs(1, 1);

    Status = (int*)MALLOC(sizeof(int));
    *Status = (int) ( getScilabMode() == SCILAB_STD );

    m1 = 1;
    n1 = 1;
    CreateVarFromPtr(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &Status);
    LhsVar(1) = Rhs + 1;

    if (Status)
    {
        FREE(Status);
        Status = NULL;
    }

    PutLhsVar();

    return 0;
}
Exemple #10
0
/*--------------------------------------------------------------------------*/
int scilinesdefault(void)
{
#ifndef _MSC_VER

    char tc_buf[1024];       /* holds termcap buffer */
    if (tgetent(tc_buf, getenv("TERM")) == 1)
    {
        setConsoleLines(tgetnum("li")); /* retrieve from the term info the number
										of lines */
        setConsoleWidth(tgetnum("co")); /* And the number of columns */
    }
    else
    {
        /* Haven't been able to detect the terminal */
        setConsoleLines(DEFAULT_NUMBERS_LINES);
        setConsoleWidth(DEFAULT_NUMBERS_COLUMNS);
    }

#else
    if ( (getScilabMode() != SCILAB_STD) && (getScilabMode() != SCILAB_API) )
    {
        /* -NW or -NWNI mode */
        int X = getXConsoleScreenSize();
        int Y = getYConsoleScreenSize();

        if (X < DEFAULT_NUMBERS_COLUMNS)
        {
            X = DEFAULT_NUMBERS_COLUMNS;
        }
        if (Y < DEFAULT_NUMBERS_LINES)
        {
            Y = DEFAULT_NUMBERS_LINES;
        }
        setConsoleWidth(X);
        setConsoleLines(Y);
    }
    else
    {
        setConsoleLines(DEFAULT_NUMBERS_LINES);
        setConsoleWidth(DEFAULT_NUMBERS_COLUMNS);
    }
#endif
    return 0;
}
/*--------------------------------------------------------------------------*/
BOOL InitializeTclTk(void)
{
    if ( getScilabMode() != SCILAB_NWNI )
    {
        setTkStarted(TRUE);
        if ( OpenTCLsci() != 0 )
        {
            setTkStarted(FALSE);
        }
    }
    return isTkStarted();
}
Exemple #12
0
/*--------------------------------------------------------------------------*/
void disp_scilab_version(void)
{
    if ( (getScilabMode() == SCILAB_NWNI) || (getScilabMode() == SCILAB_NW) || (getScilabMode() == SCILAB_API) )
    {
        printf(_("Scilab version \"%d.%d.%d.%d\"\n"), SCI_VERSION_MAJOR, SCI_VERSION_MINOR, SCI_VERSION_MAINTENANCE, SCI_VERSION_TIMESTAMP);
        printf("%s\n\n", SCI_VERSION_STRING);
    }
    else
    {
#ifdef _MSC_VER
        {
            char msg[1024];
            wsprintf(msg, gettext("Scilab version \"%d.%d.%d.%d\"\n%s\n"), SCI_VERSION_MAJOR, SCI_VERSION_MINOR, SCI_VERSION_MAINTENANCE, SCI_VERSION_TIMESTAMP, SCI_VERSION_STRING);
            MessageBox(NULL, msg, gettext("Scilab Version Info."), MB_ICONINFORMATION);
        }
#else
        printf(_("Scilab version \"%d.%d.%d.%d\"\n"), SCI_VERSION_MAJOR, SCI_VERSION_MINOR, SCI_VERSION_MAINTENANCE, SCI_VERSION_TIMESTAMP);
        printf("%s\n\n", SCI_VERSION_STRING);
#endif
    }
}
Exemple #13
0
/*--------------------------------------------------------------------------*/
int gw_xcos(void)
{
    if (getScilabMode() == SCILAB_NWNI)
    {
        Scierror(999, _("Scilab '%s' module disabled in -nogui or -nwni mode.\n"), "xcos");
    }
    else
    {
        Scierror(999, _("Scilab '%s' module not installed.\n"), "xcos");
    }
    return 0;
}
/*--------------------------------------------------------------------------*/
int gw_graphic_objects(void)
{
	Rhs = Max(0, Rhs);

	if ( getScilabMode() == SCILAB_NWNI)
	{
		Scierror(999,_("Scilab '%s' module disabled in -nogui or -nwni mode.\n"), "graphic_objects");
		return 0;
	}

	callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
	return 0;
}
/*--------------------------------------------------------------------------*/
int gw_graphic_export(void)
{
#ifndef _MSC_VER
	if (getScilabMode() == SCILAB_NWNI)
    {
        Scierror(999, _("Scilab '%s' module disabled in -nogui or -nwni mode.\n"), "graphic_export");
    }
    else
#endif
    {
        Scierror(999, _("Scilab '%s' module not installed.\n"), "graphic_export");
    }
    return 0;
}
Exemple #16
0
/*--------------------------------------------------------------------------*/
int sci_oemtochar(char *fname, unsigned long l)
{
    int l1 = 0, n1 = 0, m1 = 0;
    char *Output = NULL;

    if (getWarningMode())
    {
        sciprint(_("%s: Feature %s is obsolete.\n"), _("Warning"), fname);
        sciprint(_("%s: This feature will be permanently removed in Scilab %s\n\n"), _("Warning"), "5.4.1");
    }

    CheckRhs(1, 1);
    CheckLhs(0, 1);

    if (GetType(1) == sci_strings)
    {
        char *OEMstring = NULL;

        GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1);
        OEMstring = cstk(l1);

        Output = (char*)MALLOC((strlen(OEMstring) + 1) * sizeof(char));
        if (getScilabMode() == SCILAB_STD)
        {
            OemToChar(OEMstring, Output);
        }
        else
        {
            wsprintf(Output, "%s", OEMstring);
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
        return 0;
    }

    n1 = 1;
    m1 = (int)strlen(Output);
    CreateVarFromPtr(Rhs + 1, STRING_DATATYPE, &m1, &n1, &Output);
    if (Output)
    {
        FREE(Output);
        Output = NULL;
    }

    LhsVar(1) = Rhs + 1;
    PutLhsVar();
    return 0;
}
Exemple #17
0
/*--------------------------------------------------------------------------*/
BOOL CloseTCLsci(void)
{
    if ( getScilabMode() != SCILAB_NWNI )
    {
        if (isTkStarted())
        {
            setTkStarted(FALSE);
            __WaitThreadDie(TclThread);
            deleteTclInterp();
            TKmainWindow = NULL;
            return TRUE;
        }
    }
    return FALSE;
}
/*--------------------------------------------------------------------------*/
BOOL InitializeGUI(void)
{
    if (getScilabMode() == SCILAB_STD)
    {

        // TODO why this line since already done above
        // createSwingView();
#ifdef _MSC_VER
        WindowShow();
#endif
    }
    else
    {
        return TRUE;
    }

    return FALSE;
}
Exemple #19
0
/*--------------------------------------------------------------------------*/
int gw_jvm(void)
{  
	Rhs = Max(0, Rhs);

    if(pvApiCtx == NULL)
	{
		pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
	}

	pvApiCtx->pstName = (char*)Tab[Fin-1].name;
	if ( (getScilabMode() != SCILAB_NWNI) )
	{
		callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));	
	}
	else
	{
		Scierror(999,_("JVM interface disabled in -nogui or -nwni modes.\n"));
	}

	return 0;
}
Exemple #20
0
/*--------------------------------------------------------------------------*/
int C2F(sci_getscilabmode)(char *fname, unsigned long fname_len)
{
    int n1 = 0, m1 = 0;
    char *output = NULL ;
    int iRet = 0;
    SciErr sciErr;

    CheckInputArgument(pvApiCtx, 0, 0) ;
    CheckOutputArgument(pvApiCtx, 1, 1) ;

    switch (getScilabMode())
    {
        case SCILAB_API:
        default :
            output = strdup("API");
            break;
        case SCILAB_STD:
            output = strdup("STD");
            break;
        case SCILAB_NW:
            output = strdup("NW");
            break;
        case SCILAB_NWNI:
            output = strdup("NWNI");
            break;
    }

    /* Create the string matrix as return of the function */
    iRet = createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, output);
    free(output); // Data have been copied into Scilab memory
    if (iRet)
    {
        freeAllocatedSingleString(output);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return 0;
}
const char * getScilabModeString(void)
{
    scilabMode smMode = getScilabMode();
    switch (smMode)
    {
        case SCILAB_API:
            return "API";
            break;
        case SCILAB_STD:
            return "STD";
            break;
        case SCILAB_NW:
            return "NW";
            break;
        case SCILAB_NWNI:
            return "NWNI";
            break;
        default:
            return "STD";
            break;
    }
}
Exemple #22
0
int ScicosModule::Load()
{
    std::wstring wstModuleName = L"scicos";
    const wchar_t* wstLibName = wstModuleName.c_str();
    if (getScilabMode() == SCILAB_NWNI)
    {
        wstLibName = L"scicos-cli";
    }
#ifdef _MSC_VER
    wchar_t* pwstLibName = buildModuleDynLibraryNameW(wstLibName, DYNLIB_NAME_FORMAT_1);
#else
    wchar_t* pwstLibName = buildModuleDynLibraryNameW(wstLibName, DYNLIB_NAME_FORMAT_3);
#endif
    vectGateway vect = loadGatewaysName(wstModuleName);

    for (int i = 0 ; i < (int)vect.size() ; i++)
    {
        symbol::Context::getInstance()->addFunction(types::Function::createFunction(vect[i].wstFunction, vect[i].wstName, pwstLibName, vect[i].iType, NULL, wstModuleName));
    }

    FREE(pwstLibName);
    return 1;
}
Exemple #23
0
/* interface for the previous function Table */
int gw_graphics(void)
{
    nbInputArgument(pvApiCtx) = Max(0, nbInputArgument(pvApiCtx));

    if (pvApiCtx == NULL)
    {
        pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
    }

    pvApiCtx->pstName = (char*)Tab[Fin - 1].name;
    if (getScilabMode() != SCILAB_NWNI)
    {
        if (!loadedDep)
        {
            loadOnUseClassPath("graphics");
            loadedDep = TRUE;
        }
        callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
    }
    else
    {
        if ((strcmp(Tab[Fin - 1].name, "set") == 0 ||
                strcmp(Tab[Fin - 1].name, "delete") == 0 ||
                strcmp(Tab[Fin - 1].name, "get") == 0) &&
                (getInputArgumentType(pvApiCtx, 1) == sci_tlist || getInputArgumentType(pvApiCtx, 1) == sci_mlist))
        {
            callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
            return 0;
        }
        else
        {
            Scierror(999, _("Scilab '%s' module disabled in -nogui or -nwni mode.\n"), "graphics");
        }
    }

    return 0;
}
Exemple #24
0
int StaticRunner::launch()
{
    //set execution thread in java
    if (!initialJavaHooks && getScilabMode() != SCILAB_NWNI)
    {
        initialJavaHooks = true;
        // Execute the initial hooks registered in Scilab.java
        ExecuteInitialHooks();
    }

    int iRet = 0;
    // get the runner to execute
    std::unique_ptr<Runner> runMe(getRunner());
    // set if the current comment is interruptible
    setInterruptibleCommand(runMe->isInterruptible());
    debugger::DebuggerMagager* manager = debugger::DebuggerMagager::getInstance();

    ConfigVariable::resetExecutionBreak();

    int oldMode = ConfigVariable::getPromptMode();
    symbol::Context* pCtx = symbol::Context::getInstance();
    int scope = pCtx->getScopeLevel();

    // a TCL command display nothing
    int iOldPromptMode = 0;
    if (runMe->getCommandOrigin() == TCLSCI)
    {
        iOldPromptMode = ConfigVariable::getPromptMode();
        ConfigVariable::setPromptMode(-1);
    }

    try
    {
        int level = ConfigVariable::getRecursionLevel();
        try
        {
            runMe->getProgram()->accept(*(runMe->getVisitor()));
        }
        catch (const ast::RecursionException& re)
        {
            // management of pause
            if (ConfigVariable::getPauseLevel())
            {
                ConfigVariable::DecreasePauseLevel();
                throw re;
            }

            //close opened scope during try
            while (pCtx->getScopeLevel() > scope)
            {
                pCtx->scope_end();
            }

            //decrease recursion to init value and close where
            while (ConfigVariable::getRecursionLevel() > level)
            {
                ConfigVariable::where_end();
                ConfigVariable::decreaseRecursion();
            }

            ConfigVariable::resetWhereError();
            ConfigVariable::setPromptMode(oldMode);

            //print msg about recursion limit and trigger an error
            wchar_t sz[1024];
            os_swprintf(sz, 1024, _W("Recursion limit reached (%d).\n").data(), ConfigVariable::getRecursionLimit());
            throw ast::InternalError(sz);
        }
    }
    catch (const ast::InternalError& se)
    {
        if (runMe->getCommandOrigin() == TCLSCI)
        {
            ConfigVariable::setPromptMode(iOldPromptMode);
        }

        std::wostringstream ostr;
        ConfigVariable::whereErrorToString(ostr);
        scilabErrorW(ostr.str().c_str());
        scilabErrorW(se.GetErrorMessage().c_str());
        ConfigVariable::resetWhereError();
        iRet = 1;
    }
    catch (const ast::InternalAbort& ia)
    {
        if (runMe->getCommandOrigin() == TCLSCI)
        {
            ConfigVariable::setPromptMode(iOldPromptMode);
        }

        // management of pause
        if (ConfigVariable::getPauseLevel())
        {
            ConfigVariable::DecreasePauseLevel();
            throw ia;
        }

        // close all scope before return to console scope
        symbol::Context* pCtx = symbol::Context::getInstance();
        while (pCtx->getScopeLevel() > scope)
        {
            pCtx->scope_end();
        }

        // send the good signal about the end of execution
        sendExecDoneSignal(runMe.get());

        //clean debugger step flag if debugger is not interrupted ( end of debug )
        manager->resetStep();
        throw ia;
    }

    if (runMe->getCommandOrigin() == TCLSCI)
    {
        ConfigVariable::setPromptMode(iOldPromptMode);
    }

    if (getScilabMode() != SCILAB_NWNI && getScilabMode() != SCILAB_API)
    {
        char *cwd = NULL;
        int err = 0;

        UpdateBrowseVar();
        cwd = scigetcwd(&err);
        if (cwd)
        {
            FileBrowserChDir(cwd);
            FREE(cwd);
        }
    }

    // reset error state when new prompt occurs
    ConfigVariable::resetError();

    // send the good signal about the end of execution
    sendExecDoneSignal(runMe.get());

    //clean debugger step flag if debugger is not interrupted ( end of debug )
    manager->resetStep();
    return iRet;
}
Exemple #25
0
/*--------------------------------------------------------------------------*/
int sci_toolbar(char *fname, unsigned long l)
{
    SciErr sciErr;

    int* piAddr1 = NULL;
    int* piStkAdr = NULL;
    int* piAddrstkAdr = NULL;
    long long* stkAdr = NULL;
    int* piAddrparam = NULL;

    int nbCol = 0;
    int nbRow = 0;

    char *Output = NULL;
    char **param = NULL;
    int figNum = -2;

    int iIsVisible = 0;
    int *piIsVisible = NULL;

    int iParentUID = 0;
    int iParentType = -1;
    int *piParentType = &iParentType;

    CheckInputArgument(pvApiCtx, 1, 2);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* Figure number */
    if (checkInputArgumentType(pvApiCtx, 1, sci_matrix))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr1, &nbRow, &nbCol, &piStkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 1);
            return 1;
        }

        if (nbRow * nbCol != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1);
            return FALSE;
        }
        figNum = *piStkAdr;

        if (figNum < -1)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: Must be > %d expected.\n"), fname, 1, -1);
            return FALSE;
        }

        if (figNum != -1)       /* Check that the figure exists */
        {
            if (getFigureFromIndex(figNum) == 0)
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: 'Graphic Window Number %d' does not exist.\n"), fname, 1, figNum);
                return FALSE;
            }
        }

        if (figNum == -1)
        {
            iParentUID = getConsoleIdentifier();
        }
        else
        {
            iParentUID = getFigureFromIndex(figNum);
        }
    }
    else if (checkInputArgumentType(pvApiCtx, 1, sci_handles))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of handle at position 1.
        sciErr = getMatrixOfHandle(pvApiCtx, piAddrstkAdr, &nbRow, &nbCol, &stkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
            return 1;
        }

        if (nbRow * nbCol != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
            return FALSE;
        }

        iParentUID = getObjectFromHandle((long) * stkAdr);

        if (iParentUID == 0)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: this handle does not exist.\n"), fname, 1);
            return FALSE;
        }

        getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
        if (iParentType != __GO_FIGURE__)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real or a Figure handle expected.\n"), fname, 1);
            return FALSE;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A real or a Figure handle expected.\n"), fname, 1);
        return FALSE;
    }

    if (nbInputArgument(pvApiCtx) == 2)               /* New status */
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrparam);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrparam, &nbRow, &nbCol, &param))
            {
                Scierror(202, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, param);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
                return FALSE;
            }

            if ((strcmp(param[0], "off") == 0) || (strcmp(param[0], "on") == 0))
            {
                iIsVisible = strcmp(param[0], "on") == 0;
                if (iParentUID != getConsoleIdentifier() || getScilabMode() == SCILAB_STD)
                {
                    setGraphicObjectProperty(iParentUID, __GO_TOOLBAR_VISIBLE__, &iIsVisible, jni_bool, 1);
                }
                freeAllocatedMatrixOfString(nbRow, nbCol, param);
            }
            else
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, param);
                Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "on", "off");
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
            return FALSE;
        }
    }

    /* Returned value */
    piIsVisible = &iIsVisible;
    getGraphicObjectProperty(iParentUID, __GO_TOOLBAR_VISIBLE__, jni_bool, (void **)&piIsVisible);
    if (iIsVisible)
    {
        Output = strdup("on");
    }
    else
    {
        Output = strdup("off");
    }

    nbCol = 1;
    nbRow = (int)strlen(Output);
    if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, Output))
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;

    if (Output)
    {
        FREE(Output);
        Output = NULL;
    }

    ReturnArguments(pvApiCtx);
    return TRUE;
}
types::Function::ReturnValue sci_consolebox(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    if (in.size() < 0 || in.size() > 1)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d or %d expected.\n"), "consolebox", 0, 1);
        return types::Function::Error;
    }

    if (getScilabMode() != SCILAB_STD)
    {
        sciprint(_("Only on Windows Mode, not in Console Mode.\n"));
        out.push_back(new types::String(L"off"));
        return types::Function::OK;
    }


    //request mode
    if (in.size() == 0)
    {
        if (GetConsoleState())
        {
            out.push_back(new types::String(L"on"));
        }
        else
        {
            out.push_back(new types::String(L"off"));
        }
        return types::Function::OK;
    }

    types::InternalType* pIT1 = in[0];

    if (pIT1->isString() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), "consolebox", 1);
        return types::Function::Error;
    }

    types::String* pS1 = pIT1->getAs<types::String>();
    if (pS1->isScalar() == false)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "consolebox", 1);
        return types::Function::Error;
    }

    std::wstring wcsAction(pS1->get(0));

    if (wcsAction == L"on")
    {
        SetConsoleState(1);
        ShowScilex();
    }
    else if (wcsAction == L"off")
    {
        SetConsoleState(0);
        HideScilex();
    }
    else if (wcsAction == L"toggle")
    {
        SwitchConsole();
    }
    else
    {
        Scierror(999, ("%s: Wrong input argument: '%s', '%s' or '%s' expected.\n"), "consolebox", "on", "off", "toggle");
        return types::Function::Error;
    }

    if (GetConsoleState())
    {
        out.push_back(new types::String(L"on"));
    }
    else
    {
        out.push_back(new types::String(L"off"));
    }

    return types::Function::OK;
}
Exemple #27
0
/*--------------------------------------------------------------------------*/
int sci_consolebox(char *fname,unsigned long l)
{
	static int l1,n1,m1;
	char *Output=NULL;

	Rhs=Max(Rhs,0);
	CheckRhs(0,1);
	CheckLhs(0,1);

	Output=(char*)MALLOC(4*sizeof(char));

	if (Rhs==0)
	{
		if (getScilabMode() == SCILAB_STD) 
			{
				if (GetConsoleState()) strcpy(Output,"on");
				else strcpy(Output,"off");
					
			}
			else
			{
				sciprint(_("Only on Windows Mode, not in Console Mode.\n"));
				strcpy(Output,"off");
			}
	}
	else
	if (GetType(1) == sci_strings)
		{
			char *param=NULL;

			GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
			param=cstk(l1);

			if ( (strcmp(param,"off")==0) || (strcmp(param,"on")==0) || (strcmp(param,"toggle")==0) )
			{
				if (getScilabMode() == SCILAB_STD) 
				{
					if (strcmp(param,"on")==0)
					{
						SetConsoleState(1);
						ShowScilex();
						strcpy(Output,"on");
					}
					else if (strcmp(param,"off")==0)
					{
						SetConsoleState(0);
						HideScilex();
						strcpy(Output,"off");
					}
					else /* toggle */
					{
						SwitchConsole();
						if (GetConsoleState()) strcpy(Output,"on");
						else strcpy(Output,"off");
					}
				}
				else
				{
						sciprint(_("Only on Windows Mode, not in Console Mode.\n"));
						strcpy(Output,"off");
				}
			}
			else
			{
				Scierror(999,("%s: Wrong input argument: '%s', '%s' or '%s' expected.\n"),fname,"on", "off", "toggle");
				return 0;
			}
		}
		else
		{
			Scierror(999,("%s: Wrong input argument: '%s', '%s' or '%s' expected.\n"),fname,"on", "off", "toggle");
			return 0;
		}

	n1=1;
	CreateVarFromPtr(Rhs+ 1,STRING_DATATYPE,(m1=(int)strlen(Output), &m1),&n1,&Output);
    if (Output) {FREE(Output);Output=NULL;}
	LhsVar(1) = Rhs+1;
	PutLhsVar();	
	return 0;
}
Exemple #28
0
/*--------------------------------------------------------------------------*/
int C2F(getscilabmode)(scilabMode *mode)
{
    *mode = getScilabMode();
    return 0;
}
Exemple #29
0
/*--------------------------------------------------------------------------*/
int C2F(sci_exit)(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    BOOL shouldExit;

    CheckLhs(1, 1);
    CheckRhs(0, 1);

    if (Rhs == 0)
    {
        setExitCodeValue(0);
    }
    else
    {
        int iExit = 0;
        int m1 = 0, n1 = 0;
        int iType1 = 0;
        int *piAddressVarOne = NULL;
        double *pdVarOne = NULL;

        /* get Address of inputs */
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            return 0;
        }

        sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            return 0;
        }

        /* check input type */
        if ( iType1 != sci_matrix )
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 1);
            return 0;
        }

        sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne, &m1, &n1, &pdVarOne);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }

        if ( n1 != 1 || m1 != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 1);
            return 0;
        }

        iExit = (int) * pdVarOne;

        if (*pdVarOne != (double)iExit)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: An integer expected.\n"), fname, 1);
            return 0;
        }

        setExitCodeValue(iExit);
    }

    shouldExit = TRUE;
    if (getScilabMode() != SCILAB_NWNI)
    {
        if (Rhs == 0)
        {
            shouldExit = canCloseMainScilabObject();
        }
        else
        {
            forceCloseMainScilabObject();
        }
    }

    // this value do quit in scirun
    if (shouldExit)
    {
        C2F(com).fun = -999;
    }

    LhsVar(1) = 0;
    PutLhsVar();
    return 0;
}
Exemple #30
0
/*
 * Previously called zzledt... Called by Fortran...
 * Now renamed to EventLoopPrompt
 * @TODO remove unused arg buf_size, menusflag, modex & dummy1
 */
void C2F(eventloopprompt) (char *buffer, int *buf_size, int *len_line, int *eof)
{

    if (getScilabMode() == SCILAB_API)
    {
        return;
    }

    if (!initialJavaHooks && getScilabMode() != SCILAB_NWNI)
    {
        initialJavaHooks = TRUE;
        // Execute the initial hooks registered in Scilab.java
        ExecuteInitialHooks();
    }

    /* if not an interactive terminal */
#ifdef _MSC_VER
    /* if file descriptor returned is -2 stdin is not associated with an input stream */
    /* example : echo plot3d | scilex -nw -e */
    if (!isatty(fileno(stdin)) && (fileno(stdin) != -2) && getScilabMode() != SCILAB_STD)
#else
    if (!isatty(fileno(stdin)) && getScilabMode() != SCILAB_STD)
#endif
    {
        /* remove newline character if there */
        if (__CommandLine != NULL)
        {
            /* read a line into the buffer, but not too
             * big */
            *eof = (fgets(__CommandLine, *buf_size, stdin) == NULL);
            *len_line = (int)strlen(__CommandLine);
            /* remove newline character if there */
            if (__CommandLine[*len_line - 1] == '\n')
            {
                (*len_line)--;
            }
            return;
        }
    }

    if (!initialized)
    {
        initAll();
    }

    __LockSignal(pReadyForLaunch);

    if (__CommandLine)
    {
        FREE(__CommandLine);
        __CommandLine = NULL;
    }
    __CommandLine = strdup("");

    if (ismenu() == 0)
    {
        if (!WatchGetCmdLineThreadAlive)
        {
            if (WatchGetCmdLineThread)
            {
                __WaitThreadDie(WatchGetCmdLineThread);
            }
            if (getScilabMode() != SCILAB_NWNI)
            {

                char *cwd = NULL;

                int err = 0;

                UpdateBrowseVar(TRUE);
                cwd = scigetcwd(&err);
                if (cwd)
                {
                    FileBrowserChDir(cwd);
                    FREE(cwd);
                }
            }
            __CreateThread(&WatchGetCmdLineThread, &watchGetCommandLine);
            WatchGetCmdLineThreadAlive = TRUE;
        }
        if (!WatchStoreCmdThreadAlive)
        {
            if (WatchStoreCmdThread)
            {
                __WaitThreadDie(WatchStoreCmdThread);
            }
            __CreateThread(&WatchStoreCmdThread, &watchStoreCommand);
            WatchStoreCmdThreadAlive = TRUE;
        }

        __Wait(&TimeToWork, pReadyForLaunch);
    }
    __UnLockSignal(pReadyForLaunch);

    /*
    ** WARNING : Old crappy f.... code
    ** do not change reference to buffer
    ** or fortran will be lost !!!!
    */
    if (__CommandLine)
    {
        strcpy(buffer, __CommandLine);
    }
    else
    {
        strcpy(buffer, "");
    }
    *len_line = (int)strlen(buffer);

    *eof = FALSE;
}