예제 #1
0
/*--------------------------------------------------------------------------*/
int isEmptyMatrix(void *_pvCtx, int *_piAddress)
{
    if (checkVarType(_pvCtx, _piAddress, sci_matrix))
    {
        return checkVarDimension(_pvCtx, _piAddress, 0, 0);
    }
    return 0;
}
예제 #2
0
char *csv_getArgumentAsString(void* _pvCtx, int _iVar,
                              const char *fname, int *iErr)
{
    SciErr sciErr;

    int *piAddressVar = NULL;
    int m = 0, n = 0;
    int iType = 0;

    char *returnedValue = NULL;

    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
    if (sciErr.iErr)
    {
        *iErr = sciErr.iErr;
        printError(&sciErr, 0);
        return NULL;
    }

    sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
    if (sciErr.iErr)
    {
        *iErr = sciErr.iErr;
        printError(&sciErr, 0);
        return NULL;
    }

    if (iType != sci_strings)
    {
        *iErr = API_ERROR_INVALID_TYPE;
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
        return NULL;
    }

    *iErr = checkVarDimension(pvApiCtx, piAddressVar, 1, 1);

    if (*iErr == 0 )
    {
        *iErr = API_ERROR_CHECK_VAR_DIMENSION;
        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, _iVar);
        return NULL;
    }

    *iErr = getAllocatedSingleString(pvApiCtx, piAddressVar, &returnedValue);
    if (*iErr)
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return NULL;
    }
    return returnedValue;
}
예제 #3
0
/*--------------------------------------------------------------------------*/
int sci_xinit(char * fname, void *pvApiCtx)
{
    SciErr err;
    int * addr = 0;
    char * path = 0;
    char * realPath = 0;

    CheckInputArgument(pvApiCtx, 1, 1);

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

    if (!isStringType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1))
    {
        Scierror(999, gettext("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
        return 0;
    }

    if (getAllocatedSingleString(pvApiCtx, addr, &path) != 0)
    {
        Scierror(999, _("%s: No more memory.\n"), fname);
        return 0;
    }

    realPath = expandPathVariable(path);

    if (realPath)
    {
        org_scilab_modules_graphic_export::Driver::setPath(getScilabJavaVM(), realPath);
        FREE(realPath);
    }
    else
    {
        Scierror(999, _("%s: Invalid path: %s.\n"), fname, path);
        return 0;
    }

    freeAllocatedSingleString(path);

    LhsVar(1) = 0;
    PutLhsVar();

    return 0;
}
예제 #4
0
// =============================================================================
int csv_getArgumentAsScalarBoolean(void* _pvCtx, int _iVar,
                                   const char *fname, int *iErr)
{
    SciErr sciErr;
    int bValue = 0;
    int *piAddressVar = NULL;
    int m = 0, n = 0;
    int iType = 0;

    sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddressVar);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        *iErr = sciErr.iErr;
        return 0;
    }

    sciErr = getVarType(pvApiCtx, piAddressVar, &iType);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        *iErr = sciErr.iErr;
        return 0;
    }

    if (iType != sci_boolean)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, _iVar);
        *iErr =  API_ERROR_INVALID_TYPE;
        return 0;
    }

    *iErr = checkVarDimension(pvApiCtx, piAddressVar, 1, 1);

    if (*iErr == 0 )
    {
        *iErr = API_ERROR_CHECK_VAR_DIMENSION;
        Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, _iVar);
        return 0;
    }

    *iErr = getScalarBoolean(pvApiCtx, piAddressVar, &bValue);
    return bValue;
}
예제 #5
0
/*--------------------------------------------------------------------------*/
int sci_msprintf(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int iType = 0;
    int *piAddressVarOne = NULL;
    char *ptrFormat = NULL;
    int K = 0;
    int i = 0;
    int lenghtFormat = 0;
    int NumberPercent = 0;
    int NumberCols = 0;
    int nmax = 0;
    int cat_to_last = 0;
    int ll = 0;
    char **pStrs = NULL;
    char **pOutputStrings = NULL;
    char *pStrTmp = NULL;
    char *pStrTmp1 = NULL;
    int lcount = 0;
    int rval = 0;
    int blk = 200;

    int k = 0;
    int mOut = 0;
    int nOut = 0;
    int lenghtSplitChar = (int)strlen(SPLIT_ON_CR_IN_FORMAT);

    Nbvars = 0;
    CheckRhs(1, 1000);
    CheckLhs(0, 1);

    for (K = 2; K <= Rhs; K++)
    {
        int iTypeK = 0;
        int *piAddressVarK = NULL;

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

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

        if ( (iTypeK != sci_matrix) && (iTypeK != sci_strings) )
        {
            OverLoad(K);
            return 0;
        }
    }

    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, &iType);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 0;
    }

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

    if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &ptrFormat))
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    if (ptrFormat == NULL)
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }
    else
    {
        char *ptrFormatTmp = strsub(ptrFormat, CR_IN_FORMAT, SPLIT_ON_CR_IN_FORMAT);
        if (ptrFormatTmp)
        {
            freeAllocatedSingleString(ptrFormat);
            ptrFormat = ptrFormatTmp;
        }
        else
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }
    }

    lenghtFormat = (int)strlen(ptrFormat);
    for (i = 0; i < lenghtFormat; i++)
    {
        if (ptrFormat[i] == PERCENT_CHAR)
        {
            NumberPercent++;
            if ( (i + 1 < lenghtFormat) && (ptrFormat[i + 1] == PERCENT_CHAR))
            {
                NumberPercent--;
                i++;
            }
        }
    }

    if ( (Rhs - 1) > NumberPercent )
    {
        if (ptrFormat)
        {
            FREE(ptrFormat);
            ptrFormat = NULL;
        }

        Scierror(999, _("%s: Wrong number of input arguments: at most %d expected.\n"), fname, NumberPercent);
        return 0;
    }

    if ( Rhs > 1 )
    {
        for ( i = 2 ; i <= Rhs ; i++ )
        {
            int iRows = 0;
            int iCols = 0;
            int *piAddressVarI = NULL;

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

            sciErr = getVarDimension(pvApiCtx, piAddressVarI, &iRows, &iCols);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i);
                return 0;
            }
            NumberCols += iCols;
        }
    }

    if ( NumberCols != NumberPercent )
    {
        if (ptrFormat)
        {
            FREE(ptrFormat);
            ptrFormat = NULL;
        }
        Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), fname);
        return 0;
    }

    mOut = 0; /* output line counter */
    nmax = 0;
    pOutputStrings = NULL;
    lcount = 1;
    cat_to_last = 0;

    while (1)
    {
        if ((rval = do_xxprintf("msprintf", (FILE *) 0, ptrFormat, Rhs, 1, lcount, (char **) &pStrs)) < 0)
        {
            break;
        }

        lcount++;
        pStrTmp = (char *)pStrs;
        if (pStrTmp == NULL)
        {
            if (ptrFormat)
            {
                FREE(ptrFormat);
                ptrFormat = NULL;
            }

            Scierror(999, _("%s: Wrong value of input argument #%d: data doesn't fit with format.\n"), fname, 1);
            return 0;
        }

        pStrTmp1 = pStrTmp;
        while (*pStrTmp != '\0')
        {
            if (strncmp(pStrTmp, SPLIT_ON_CR_IN_FORMAT, lenghtSplitChar) == 0)
            {
                k = (int)(pStrTmp - pStrTmp1);
                if (!cat_to_last)
                {
                    /*add a new line */
                    if (mOut == nmax)
                    {
                        nmax += blk;
                        if (pOutputStrings)
                        {
                            pOutputStrings = (char **) REALLOC(pOutputStrings, nmax * sizeof(char **));
                        }
                        else
                        {
                            pOutputStrings = (char **) MALLOC(nmax * sizeof(char **));
                        }

                        if (pOutputStrings == NULL)
                        {
                            if (ptrFormat)
                            {
                                FREE(ptrFormat);
                                ptrFormat = NULL;
                            }

                            Scierror(999, _("%s: No more memory.\n"), fname);
                            return 0;
                        }
                    }

                    pOutputStrings[mOut] = (char*)MALLOC((k + 1) * sizeof(char));
                    if (pOutputStrings[mOut] == NULL)
                    {
                        if (ptrFormat)
                        {
                            FREE(ptrFormat);
                            ptrFormat = NULL;
                        }

                        Scierror(999, _("%s: No more memory.\n"), fname);
                        return 0;
                    }
                    strncpy(pOutputStrings[mOut], pStrTmp1, k);
                    pOutputStrings[mOut][k] = EMPTY_CHAR;
                    mOut++;
                }
                else
                {
                    /* cat to previous line */
                    ll = (int)strlen(pOutputStrings[mOut - 1]);
                    pOutputStrings[mOut - 1] = (char*)REALLOC(pOutputStrings[mOut - 1], (k + 1 + ll) * sizeof(char));
                    if (pOutputStrings[mOut - 1] == NULL)
                    {
                        if (ptrFormat)
                        {
                            FREE(ptrFormat);
                            ptrFormat = NULL;
                        }

                        Scierror(999, _("%s: No more memory.\n"), fname);
                        return 0;
                    }
                    strncpy(&(pOutputStrings[mOut - 1][ll]), pStrTmp1, k);
                    pOutputStrings[mOut - 1][k + ll] = EMPTY_CHAR;
                }
                k = 0;
                pStrTmp += lenghtSplitChar;
                pStrTmp1 = pStrTmp;
                cat_to_last = 0;
            }
            else
            {
                pStrTmp++;
            }
        }
        k = (int)(pStrTmp - pStrTmp1);
        if (k > 0)
        {
            if ((!cat_to_last) || (mOut == 0))
            {
                /*add a new line */
                if (mOut == nmax)
                {
                    nmax += blk;
                    if (pOutputStrings)
                    {
                        pOutputStrings = (char **) REALLOC(pOutputStrings, nmax * sizeof(char **));
                        if (pOutputStrings == NULL)
                        {
                            if (ptrFormat)
                            {
                                FREE(ptrFormat);
                                ptrFormat = NULL;
                            }

                            Scierror(999, _("%s: No more memory.\n"), fname);
                            return 0;
                        }
                    }
                    else
                    {
                        pOutputStrings = (char **) MALLOC(nmax * sizeof(char **));
                        if (pOutputStrings == NULL)
                        {
                            if (ptrFormat)
                            {
                                FREE(ptrFormat);
                                ptrFormat = NULL;
                            }

                            Scierror(999, _("%s: No more memory.\n"), fname);
                            return 0;
                        }
                    }
                }

                pOutputStrings[mOut] = (char*) MALLOC((k + 1) * sizeof(char));
                if (pOutputStrings[mOut] == NULL)
                {
                    if (ptrFormat)
                    {
                        FREE(ptrFormat);
                        ptrFormat = NULL;
                    }

                    Scierror(999, _("%s: No more memory.\n"), fname);
                    return 0;
                }
                strncpy(pOutputStrings[mOut], pStrTmp1, k);
                pOutputStrings[mOut][k] = EMPTY_CHAR;
                mOut++;
            }
            else
            {
                /* cat to previous line */
                ll = (int)strlen(pOutputStrings[mOut - 1]);
                pOutputStrings[mOut - 1] = (char*)REALLOC(pOutputStrings[mOut - 1], (k + 1 + ll) * sizeof(char));
                if (pOutputStrings[mOut - 1] == NULL)
                {
                    if (ptrFormat)
                    {
                        FREE(ptrFormat);
                        ptrFormat = NULL;
                    }

                    Scierror(999, _("%s: No more memory.\n"), fname);
                    return 0;
                }
                strncpy(&(pOutputStrings[mOut - 1][ll]), pStrTmp1, k);
                pOutputStrings[mOut - 1][k + ll] = EMPTY_CHAR;
            }
        }

        if (strncmp(pStrTmp - lenghtSplitChar, SPLIT_ON_CR_IN_FORMAT, lenghtSplitChar) != 0)
        {
            cat_to_last = 1;
        }
        if (Rhs == 1) break;

    }

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

    if (rval == RET_BUG) return 0;

    /* Create a Scilab String */
    nOut = 1;
    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1 , mOut, nOut, pOutputStrings);

    /* lstr must not be freed */
    freeArrayOfString(pOutputStrings, mOut * nOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
    }
    else
    {
        LhsVar(1) = Rhs + 1;
        PutLhsVar();
    }
    return 0;
}
예제 #6
0
/*--------------------------------------------------------------------------*/
static int sci_format_onerhs(char *fname)
{
    int *piAddressVarOne = NULL;
    SciErr 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;
    }

    if (isStringType(pvApiCtx, piAddressVarOne))
    {
        char *param = NULL;

        if (!isScalar(pvApiCtx, piAddressVarOne))
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, e_type_format, v_type_format);
            return 0;
        }

        if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &param) == 0)
        {
            if ((strcmp(e_type_format, param) == 0) || (strcmp(v_type_format, param) == 0))
            {
                double previous_mode = 0;
                double previous_numberDigits = 0;

                getFormat(&previous_mode, &previous_numberDigits);
                if (strcmp(e_type_format, param) == 0)
                {
                    set_e_Format((int)previous_numberDigits);
                }
                else            /* v_type_format */
                {
                    setVariableFormat((int)previous_numberDigits);
                }

                freeAllocatedSingleString(param);
                param = NULL;

                LhsVar(1) = 0;
                PutLhsVar();
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, e_type_format, v_type_format);
                return 0;
            }
        }
        else
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
            return 0;
        }
    }
    else if (isDoubleType(pvApiCtx, piAddressVarOne))
    {
        if (isScalar(pvApiCtx, piAddressVarOne))
        {
            double dValue = 0.;

            if (getScalarDouble(pvApiCtx, piAddressVarOne, &dValue) == 0)
            {
                double mode = 0.;
                double previous_numberDigits = 0.;

                unsigned int value = (int)dValue;

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

                getFormat(&mode, &previous_numberDigits);

                if (mode == mode_e)
                {
                    if ((value < format_e_MIN) || (value > format_MAX))
                    {
                        Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the interval [%d, %d].\n"), fname, 1, format_e_MIN,
                                 format_MAX);
                        return 0;
                    }

                    set_e_Format(value);
                }
                else            /* mode_variable */
                {
                    if ((value < format_MIN) || (value > format_MAX))
                    {
                        Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the interval [%d, %d].\n"), fname, 1, format_MIN,
                                 format_MAX);
                        return 0;
                    }

                    setVariableFormat(value);
                }
            }
            LhsVar(1) = 0;
            PutLhsVar();
        }
        else
        {
            if (checkVarDimension(pvApiCtx, piAddressVarOne, 1, 2) || checkVarDimension(pvApiCtx, piAddressVarOne, 2, 1))
            {
                int nbRowsOne = 0;
                int nbColsOne = 0;
                double *pDouble = NULL;

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

                if ((pDouble[1] != mode_e) && (pDouble[1] != mode_variable))
                {
                    Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 1);
                    return 0;
                }
                else
                {
                    if (pDouble[1] == mode_e)
                    {
                        if ((pDouble[0] < format_e_MIN) || (pDouble[0] > format_MAX))
                        {
                            Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 1);
                            return 0;
                        }
                        set_e_Format((int)pDouble[0]);

                    }
                    else        /* mode_variable */
                    {
                        if ((pDouble[0] < format_MIN) || (pDouble[0] > format_MAX))
                        {
                            Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 1);
                            return 0;
                        }
                        setVariableFormat((int)pDouble[0]);
                    }

                    LhsVar(1) = 0;
                    PutLhsVar();
                }
            }
            else
            {
                Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 1);
                return 0;
            }
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string or a scalar integer value expected.\n"), fname, 1);
    }
    return 0;
}