Exemplo n.º 1
0
void H5SoftLink::getAccessibleAttribute(const std::string & _name, const int pos, void * pvApiCtx) const
{
    SciErr err;
    std::string lower(_name);
    std::transform(_name.begin(), _name.end(), lower.begin(), tolower);

    if (lower == "type")
    {
	const std::string linkType = getLinkType();
        const char * _type = linkType.c_str();
        err = createMatrixOfString(pvApiCtx, pos, 1, 1, &_type);
        if (err.iErr)
        {
            throw H5Exception(__LINE__, __FILE__, _("Cannot create a string on the stack."));
        }

        return;
    }
    else if (lower == "target")
    {
	const std::string linkValue = getLinkValue();
        const char * _target = linkValue.c_str();
        err = createMatrixOfString(pvApiCtx, pos, 1, 1, &_target);
        if (err.iErr)
        {
            throw H5Exception(__LINE__, __FILE__, _("Cannot create a string on the stack."));
        }

        return;
    }

    H5Object::getAccessibleAttribute(_name, pos, pvApiCtx);
}
Exemplo n.º 2
0
/*--------------------------------------------------------------------------*/
int sci_getdebuginfo(char *fname, void* pvApiCtx)
{
    SciErr sciErr;
    char **outputDynamicList = NULL;
    char **outputStaticList = NULL;
    static int n1 = 1, m1 = 0;
    static int n2 = 1, m2 = 0;

    CheckRhs(0, 0);
    CheckLhs(0, 2);

#ifdef _MSC_VER
    outputDynamicList = getDynamicDebugInfo_Windows(&m1);
    outputStaticList = getStaticDebugInfo_Windows(&m2);
#else
    outputDynamicList = getDynamicDebugInfo(&m1, pvApiCtx);
    outputStaticList = getStaticDebugInfo(&m2);
#endif

    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m1, n1, (char const * const*) outputDynamicList);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        freeArrayOfString(outputDynamicList, m1);
        freeArrayOfString(outputStaticList, m2);
        return 0;
    }

    LhsVar(1) = Rhs + 1;

    if (Lhs == 2)
    {
        sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, m2, n2, (char const * const*) outputStaticList);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            freeArrayOfString(outputDynamicList, m1);
            freeArrayOfString(outputStaticList, m2);
            return 0;
        }

        LhsVar(2) = Rhs + 2;
    }
    freeArrayOfString(outputDynamicList, m1);
    freeArrayOfString(outputStaticList, m2);

    PutLhsVar();
    return 0;
}
Exemplo n.º 3
0
    /**
    * The gateway function for soap_servers()
    * @param[in] fname the name of the file for the error messages
    * @return 0 if successful, a negative value otherwise
    */
    int sci_empty_test(char *fname)
    {
        SciErr sciErr;

        // allocate memory for values
        double dOut = 0;
        char *cOut = "zero";

        // this function does not take input arguments
        CheckInputArgument(pvApiCtx, 0, 0);

        // the number of output arguments must be 2
        CheckOutputArgument(pvApiCtx, 2, 2);

        // create results on stack
        sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 0, 0, &dOut);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 0, 0, &cOut);

        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

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

        return 0;
    }
Exemplo n.º 4
0
/*--------------------------------------------------------------------------*/
SciErr createMatrixOfWideString(void* _pvCtx, int _iVar, int _iRows, int _iCols, const wchar_t* const* _pstwStrings)
{
    char **pStrings = NULL;

    //return empty matrix
    if (_iRows == 0 && _iCols == 0)
    {
        double dblReal = 0;
        SciErr sciErr = createMatrixOfDouble(_pvCtx, _iVar, 0, 0, &dblReal);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createEmptyMatrix");
        }
        return sciErr;
    }

    pStrings = (char**)MALLOC( sizeof(char*) * (_iRows * _iCols) );

    for (int i = 0; i < (_iRows * _iCols) ; i++)
    {
        pStrings[i] = wide_string_to_UTF8(_pstwStrings[i]);
    }

    SciErr sciErr = createMatrixOfString(_pvCtx, _iVar, _iRows, _iCols, pStrings);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_WIDE_STRING, _("%s: Unable to create variable in Scilab memory"), "createMatrixOfWideString");
    }

    freeArrayOfString(pStrings, _iRows * _iCols);

    return sciErr;
}
Exemplo n.º 5
0
/*--------------------------------------------------------------------------*/
int sci_typename_no_rhs(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int numberOfTypes = 0;
    int *TypesNumbers = NULL;

    int m_out1 = 0, n_out1 = 0;

    TypesNumbers = getAllTypesNumber(&numberOfTypes);
    m_out1 = numberOfTypes;
    n_out1 = 1;

    sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + 1, m_out1, n_out1, TypesNumbers);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    if (TypesNumbers)
    {
        FREE(TypesNumbers);
        TypesNumbers = NULL;
    }
    LhsVar(1) = Rhs + 1;

    if (Lhs > 1)
    {
        int m_out2 = 0, n_out2 = 0;
        char **TypesNames = NULL;

        TypesNames = getAllTypesName(&numberOfTypes);
        m_out2 = numberOfTypes;
        n_out2 = 1;

        sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, m_out2, n_out2,
                                      (const char *const *)TypesNames);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }

        if (TypesNames)
        {
            freeArrayOfString(TypesNames, numberOfTypes);
        }
        LhsVar(2) = Rhs + 2;
    }
    PutLhsVar();

    return 0;
}
Exemplo n.º 6
0
/*--------------------------------------------------------------------------*/
int createSingleString(void* _pvCtx, int _iVar, const char* _pstStrings)
{
    SciErr sciErr = createMatrixOfString(_pvCtx, _iVar, 1, 1,	&_pstStrings);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_SINGLE_STRING, _("%s: Unable to get argument data"), "createSingleString");
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    return 0;
}
Exemplo n.º 7
0
int ScilabGateway::getEnvironmentName(char * fname, const int envId, void * pvApiCtx)
{
    SciErr err;
    int * addr = 0;
    int eId = 0;
    std::string envName;
    char * str;

    CheckInputArgument(pvApiCtx, 1, 1);

    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
    if (err.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    if (!ScilabObjects::isExternalObjOrClass(addr, pvApiCtx))
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An External Object expected."), 1);
    }

    eId = ScilabObjects::getEnvironmentId(addr, pvApiCtx);

    ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(eId);
    ScilabGatewayOptions & options = env.getGatewayOptions();
    OptionsHelper::setCopyOccurred(false);
    ScilabObjects::initialization(env, pvApiCtx);
    options.setIsNew(false);

    envName = env.getEnvironmentName();
    str = strdup(envName.c_str());

    err = createMatrixOfString(pvApiCtx, Rhs + 1, 1, 1, (const char * const *)&str);
    free(str);

    LhsVar(1) = Rhs + 1;
    PutLhsVar();

    return 0;
}
Exemplo n.º 8
0
/*--------------------------------------------------------------------------*/
static int xlfont_no_rhs(char * fname)
{
    SciErr sciErr;
    int m1 = 0, n1 = 0;
    int nbElements = 0;
    char **fontsname = getInstalledFontsName(&nbElements);

    m1 = 1;
    n1 = nbElements;

    sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, (const char * const*)fontsname);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    freeArrayOfString(fontsname, nbElements);

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return 0;
}
Exemplo n.º 9
0
/*--------------------------------------------------------------------------*/
int sci_uigetfont(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrfontNameAdr  = NULL;
    int* piAddrfontSizeAdr  = NULL;
    int* piAddrboldAdr      = NULL;
    int* boldAdr            = NULL;
    int* piAddritalicAdr    = NULL;
    int* italicAdr          = NULL;
    double* fontSizeAdr     = NULL;

    int fontChooserID = 0;
    int nbRow = 0;
    int nbCol = 0;

    char **fontNameAdr = NULL;
    int fontNameSize   = 0;

    char *selectedFontName  = NULL;
    int selectedFontSize    = 0;
    BOOL selectedBold       = FALSE;
    BOOL selectedItalic     = FALSE;

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

    /* Default font name */
    if (nbInputArgument(pvApiCtx) >= 1)
    {
        if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfontNameAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

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

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

    /* Default font size */
    if (nbInputArgument(pvApiCtx) >= 2)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrfontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

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

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

    /* Is the default font bold ? */
    if (nbInputArgument(pvApiCtx) >= 3)
    {
        if ((checkInputArgumentType(pvApiCtx, 3, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrboldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 3.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddrboldAdr, &nbRow, &nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 3);
                return 1;
            }

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

        }
        else
        {
            freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
            return FALSE;
        }
    }

    /* Is the default font italic ? */
    if (nbInputArgument(pvApiCtx) >= 4)
    {
        if ((checkInputArgumentType(pvApiCtx, 4, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddritalicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 4.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddritalicAdr, &nbRow, &nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 4);
                return 1;
            }

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

        }
        else
        {
            freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 4);
            return FALSE;
        }
    }

    /* Create the Java Object */
    fontChooserID = createFontChooser();

    /* Default font */
    if (fontNameAdr != NULL)
    {
        setFontChooserFontName(fontChooserID, fontNameAdr[0]);
    }

    /* Default size */
    if (fontSizeAdr != 0)
    {
        setFontChooserFontSize(fontChooserID, (int)fontSizeAdr[0]);
    }

    /* Default bold */
    if (boldAdr != 0)
    {
        setFontChooserBold(fontChooserID, booltoBOOL(boldAdr[0]));
    }

    /* Default italic */
    if (italicAdr != 0)
    {
        setFontChooserItalic(fontChooserID, booltoBOOL(italicAdr[0]));
    }

    /* Display it and wait for a user input */
    fontChooserDisplayAndWait(fontChooserID);

    /* Return the selected font */

    /* Read the user answer */
    selectedFontName = getFontChooserFontName(fontChooserID);


    if (strcmp(selectedFontName, "")) /* The user selected a font */
    {
        selectedFontSize = getFontChooserFontSize(fontChooserID);
        selectedBold = getFontChooserBold(fontChooserID);
        selectedItalic = getFontChooserItalic(fontChooserID);

        nbRow = 1;
        nbCol = 1;
        if (nbOutputArgument(pvApiCtx) >= 1)
        {
            sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, (const char * const*) &selectedFontName);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (selectedFontName)
        {
            freeAllocatedSingleString(selectedFontName);
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &fontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *fontSizeAdr = selectedFontSize;
        }

        if (nbOutputArgument(pvApiCtx) >= 3)
        {
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *boldAdr = selectedBold;
        }

        if (nbOutputArgument(pvApiCtx) >= 4)
        {
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 4, nbRow, nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *italicAdr = selectedItalic;
        }
    }
    else /* The user canceled */
    {
        if (selectedFontName)
        {
            freeAllocatedSingleString(selectedFontName);
        }
        nbRow = 0;
        nbCol = 0;
        if (nbOutputArgument(pvApiCtx) >= 1)
        {
            /* Return "" as font name */
            char* fontNameEmpty = NULL;
            if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow * nbCol, (const char**) &fontNameEmpty))
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            /* Return [] as font size */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &fontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 3)
        {
            /* Return [] as bold value */
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 4)
        {
            /* Return [] as italic value */
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 4, nbRow, nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
    AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
    AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;

    if (fontNameSize)
    {
        freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
    }
    ReturnArguments(pvApiCtx);
    return TRUE;
}
Exemplo n.º 10
0
/*--------------------------------------------------------------------------*/
int sci_mgetl(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    int numberOfLinesToRead = -1;

    Rhs = Max(0, Rhs);

    CheckRhs(1, 2);
    CheckLhs(1, 1);

    if (Rhs == 2)
    {
        int *piAddressVarTwo = NULL;

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

        if ( isDoubleType(pvApiCtx, piAddressVarTwo) )
        {
            double dValue = 0.;
            if (!isScalar(pvApiCtx, piAddressVarTwo))
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: Integer expected.\n"), fname, 2);
                return 0;
            }

            if ( getScalarDouble(pvApiCtx, piAddressVarTwo, &dValue) == 0)
            {
                numberOfLinesToRead = (int)dValue;
            }
            else
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Integer expected.\n"), fname, 2);
            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;
    }

    if ( isStringType(pvApiCtx, piAddressVarOne) || isDoubleType(pvApiCtx, piAddressVarOne) )
    {
        char **wcReadedStrings = NULL;
        int numberOfLinesReaded = 0;
        int fileDescriptor = -1;
        int iErrorMgetl = 0;
        BOOL bCloseFile = FALSE;

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

        if (isStringType(pvApiCtx, piAddressVarOne))
        {
            char *fileName = NULL;
            if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &fileName) == 0)
            {
                char *expandedFileName = expandPathVariable(fileName);
                freeAllocatedSingleString(fileName);
                fileName = NULL;

                if (IsAlreadyOpenedInScilab(expandedFileName))
                {
                    int fd = GetIdFromFilename(expandedFileName);
                    fileDescriptor = fd;
                    if (expandedFileName)
                    {
                        FREE(expandedFileName);
                        expandedFileName = NULL;
                    }
                    bCloseFile = FALSE;
                }
                else
                {
#define READ_ONLY_TEXT_MODE "rt"
                    int fd = 0;
                    int f_swap = 0;
                    double res = 0.0;
                    int ierr = 0;

                    C2F(mopen)(&fd, expandedFileName, READ_ONLY_TEXT_MODE, &f_swap, &res, &ierr);
                    bCloseFile = TRUE;

                    switch (ierr)
                    {
                        case MOPEN_NO_ERROR:
                            fileDescriptor = fd;
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            break;
                        case MOPEN_NO_MORE_LOGICAL_UNIT:
                        {
                            Scierror(66, _("%s: Too many files opened!\n"), fname);
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            return 0;
                        }
                        break;
                        case MOPEN_CAN_NOT_OPEN_FILE:
                        {
                            Scierror(999, _("%s: Cannot open file %s.\n"), fname, expandedFileName);
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            return 0;
                        }
                        break;
                        case MOPEN_NO_MORE_MEMORY:
                        {
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            Scierror(999, _("%s: No more memory.\n"), fname);
                            return 0;
                        }
                        break;
                        case MOPEN_INVALID_FILENAME:
                        {
                            Scierror(999, _("%s: invalid filename %s.\n"), fname, expandedFileName);
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            return 0;
                        }
                        break;
                        case MOPEN_INVALID_STATUS:
                        default:
                        {
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            Scierror(999, _("%s: invalid status.\n"), fname);
                            return 0;
                        }
                        break;
                    }
                }
            }
            else
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }
        }
        else /* double */
        {
            double dValue = 0.;

            if ( !getScalarDouble(pvApiCtx, piAddressVarOne, &dValue) )
            {
                FILE *fd = NULL;
                fileDescriptor = (int)dValue;
                if ((fileDescriptor == STDIN_ID) || (fileDescriptor == STDOUT_ID))
                {
                    SciError(244);
                    return 0;
                }

                fd = GetFileOpenedInScilab(fileDescriptor);
                if (fd == NULL)
                {
                    Scierror(245, _("%s: No input file associated to logical unit %d.\n"), fname, fileDescriptor);
                    return 0;
                }
            }
            else
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }
        }

        wcReadedStrings = mgetl(fileDescriptor, numberOfLinesToRead, &numberOfLinesReaded, &iErrorMgetl);

        if (bCloseFile)
        {
            double dErrClose = 0.;
            C2F(mclose)(&fileDescriptor, &dErrClose);
        }

        switch (iErrorMgetl)
        {
            case MGETL_NO_ERROR:
            {
                if (numberOfLinesReaded == 0)
                {
                    if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0)
                    {
                        Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                }
                else
                {
                    int m = numberOfLinesReaded;
                    int n = 1;

                    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, wcReadedStrings);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(17, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                }

                freeArrayOfString(wcReadedStrings, numberOfLinesReaded);
                wcReadedStrings = NULL;
            }
            break;

            case MGETL_EOF:
            {
                if (numberOfLinesReaded == 0)
                {
                    if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0)
                    {
                        Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                }
                else
                {
                    int m = numberOfLinesReaded;
                    int n = 1;

                    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, wcReadedStrings);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(17, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                    freeArrayOfString(wcReadedStrings, numberOfLinesReaded);
                    wcReadedStrings = NULL;
                }
            }
            break;

            case MGETL_MEMORY_ALLOCATION_ERROR:
            {
                if (wcReadedStrings)
                {
                    freeArrayOfString(wcReadedStrings, numberOfLinesReaded);
                    wcReadedStrings = NULL;
                }
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }
            break;

            case MGETL_ERROR:
            {
                if (wcReadedStrings)
                {
                    freeArrayOfString(wcReadedStrings, numberOfLinesReaded);
                    wcReadedStrings = NULL;
                }
                Scierror(999, _("%s: error.\n"), fname);
                return 0;
            }
            break;
        }

        LhsVar(1) = Rhs + 1;
        PutLhsVar();
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String or logical unit expected.\n"), fname, 1);
    }

    return 0;
}
Exemplo n.º 11
0
/*--------------------------------------------------------------------------*/
int sci_libraryinfo(char *fname,unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;

    CheckRhs(1,1);
    CheckLhs(1,2);

    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 *libraryname = NULL;

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

        if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &libraryname) == 0)
        {
            if (libraryname)
            {
                char *pathlibrary = getlibrarypath(libraryname);
                if (pathlibrary)
                {
                    int sizemacrosarray = 0;
                    char **macros = getlistmacrosfromlibrary(libraryname, &sizemacrosarray);
                    if (macros)
                    {
                        int m = sizemacrosarray;
                        int n = 1;

                        sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, macros);
                        if(sciErr.iErr)
                        {
                            freeArrayOfString(macros, sizemacrosarray);
                            if (pathlibrary) 
                            {
                                FREE(pathlibrary); 
                                pathlibrary = NULL;
                            }

                            if (libraryname) 
                            {
                                freeAllocatedSingleString(libraryname);
                                libraryname = NULL;
                            }
                            printError(&sciErr, 0);
                            Scierror(999,_("%s: Memory allocation error.\n"), fname);
                            return 0;
                        }
                    }
                    else
                    {
                        createEmptyMatrix(pvApiCtx, Rhs + 1);
                    }
                    LhsVar(1) = Rhs+1;

                    freeArrayOfString(macros, sizemacrosarray);

                    if (Lhs == 2)
                    {
                        createSingleString(pvApiCtx, Rhs + 2, pathlibrary);
                        LhsVar(2) = Rhs+2;
                    }

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

                    PutLhsVar();
                }
                else
                {
                    Scierror(999,_("%s: Invalid library %s.\n"),fname, libraryname);
                }

                if (libraryname) 
                {
                    freeAllocatedSingleString(libraryname);
                    libraryname = NULL;
                }
            }
            else
            {
                Scierror(999,_("%s: Memory allocation error.\n"), fname);
            }
        }
        else
        {
            Scierror(999,_("%s: Memory allocation error.\n"), fname);
        }
    }
    else
    {
        Scierror(999,_("%s: Wrong type of input argument #%d: String expected.\n"),fname,1);
    }

    return 0;
}
Exemplo n.º 12
0
/*--------------------------------------------------------------------------*/
int sci_dgettext(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    int *piAddressVarTwo = NULL;

    CheckRhs(2, 2);
    CheckLhs(1, 1);

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

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

    if (isStringType(pvApiCtx, piAddressVarOne) && isStringType(pvApiCtx, piAddressVarTwo))
    {
        char *domain = NULL;

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

        if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &domain) == 0)
        {
            char **stringsToTranslate = NULL;
            char **TranslatedStrings = NULL;
            int m = 0, n = 0;
            int i = 0;

            if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarTwo, &m, &n, &stringsToTranslate) != 0)
            {
                Scierror(999, _("%s: No more memory.\n"), fname);
                return 0;
            }

            TranslatedStrings = (char **)MALLOC(sizeof(char*) * (m * n));
            if (TranslatedStrings == NULL)
            {
                freeAllocatedMatrixOfString(m, n, stringsToTranslate);
                stringsToTranslate = NULL;
                Scierror(999, _("%s: No more memory.\n"), fname);
                return 0;
            }

            for (i = 0; i < m * n; i++)
            {
                if (strcmp(stringsToTranslate[i], "") == 0)
                {
                    TranslatedStrings[i] = strdup("");
                }
                else
                {
                    TranslatedStrings[i] = convertString_dgettext(domain, stringsToTranslate[i]);
                }
            }

            freeAllocatedMatrixOfString(m, n, stringsToTranslate);
            stringsToTranslate = NULL;

            sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n,
                                          (const char *const *)TranslatedStrings);
            freeArrayOfString(TranslatedStrings, m * n);
            TranslatedStrings = NULL;

            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }

            LhsVar(1) = Rhs + 1;
            PutLhsVar();
        }
        else
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
            return 0;
        }
    }
    else
    {
        if (isStringType(pvApiCtx, piAddressVarOne))
        {
            Scierror(999, "%s: Wrong type for input argument #%d: String expected.\n", fname, 2);
        }
        else
        {
            Scierror(999, "%s: Wrong type for input argument #%d: String expected.\n", fname, 1);
        }
    }
    return 0;
}
Exemplo n.º 13
0
int sci_hdf5_listvar_v2(char *fname, int* pvApiCtx)
{
    SciErr sciErr;
    int *piAddr     = NULL;
    char* pstFile   = NULL;
    int iFile       = 0;
    int iNbItem     = 0;
    VarInfo* pInfo  = NULL;
    const int nbIn = nbInputArgument(pvApiCtx);

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

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFile))
    {
        if (pstFile)
        {
            FREE(pstFile);
        }

        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
        return 1;
    }

    char* pstFileName = expandPathVariable(pstFile);
    iFile = openHDF5File(pstFileName, 0);
    if (iFile < 0)
    {
        Scierror(999, _("%s: Unable to open file: %s\n"), fname, pstFile);
        FREE(pstFileName);
        FREE(pstFile);
        return 1;
    }

    FREE(pstFileName);
    FREE(pstFile);

    //manage version information
    int iVersion = getSODFormatAttribute(iFile);
    if (iVersion != SOD_FILE_VERSION)
    {
        if (iVersion > SOD_FILE_VERSION)
        {
            //can't read file with version newer that me !
            closeHDF5File(iFile);
            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname, SOD_FILE_VERSION, iVersion);
            return 1;
        }
        else
        {
            //call older import functions and exit or ... EXIT !
            if (iVersion == 1 || iVersion == -1)
            {
                //sciprint("old sci_listvar_in_hdf5_v1\n");
                return sci_listvar_in_hdf5_v1(fname, pvApiCtx);
            }
        }
    }

    iNbItem = getVariableNames(iFile, NULL);
    if (iNbItem != 0)
    {
        char** pstVarNameList = (char**)MALLOC(sizeof(char*) * iNbItem);
        pInfo = (VarInfo*)MALLOC(iNbItem * sizeof(VarInfo));
        int b;

        if (Lhs == 1)
        {
            sciprint("Name                     Type           Size            Bytes\n");
            sciprint("---------------------------------------------------------------\n");
        }

        iNbItem = getVariableNames(iFile, pstVarNameList);
        for (int i = 0; i < iNbItem; i++)
        {
            int iDataSetId = getDataSetIdFromName(iFile, pstVarNameList[i]);
            if (iDataSetId == 0)
            {
                break;
            }

            strncpy(pInfo[i].varName, pstVarNameList[i], sizeof(pInfo[i].varName) - 1);
            pInfo[i].iSize = 0;
            b = read_data(iDataSetId, 0, NULL, &pInfo[i]) == false;
            if (b)
            {
                break;
            }

            if (Lhs == 1)
            {
                sciprint("%s\n", pInfo[i].pstInfo);
            }
        }

        freeArrayOfString(pstVarNameList, iNbItem);
    }
    else
    {
        //no variable returms [] for each Lhs
        for (int i = 0 ; i < Lhs ; i++)
        {
            createEmptyMatrix(pvApiCtx, nbIn + i + 1);
            AssignOutputVariable(pvApiCtx, i + 1) = nbIn + i + 1;
        }

        ReturnArguments(pvApiCtx);
        return 0;
    }

    closeHDF5File(iFile);

    //1st Lhs
    char** pstVarName = (char**)MALLOC(sizeof(char*) * iNbItem);
    for (int i = 0 ; i < iNbItem ; i++)
    {
        pstVarName[i] = pInfo[i].varName;
    }

    sciErr = createMatrixOfString(pvApiCtx, nbIn + 1, iNbItem, 1, pstVarName);
    FREE(pstVarName);
    if (sciErr.iErr)
    {
        FREE(pInfo);
        printError(&sciErr, 0);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbIn + 1;

    if (Lhs > 1)
    {
        //2nd Lhs
        double* pdblType;
        sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 2, iNbItem, 1, &pdblType);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            FREE(pInfo);
            return 1;
        }

        for (int i = 0 ; i < iNbItem ; i++)
        {
            pdblType[i] = pInfo[i].iType;
        }

        AssignOutputVariable(pvApiCtx, 2) = nbIn + 2;

        if (Lhs > 2)
        {
            //3rd Lhs
            int* pList = NULL;
            sciErr = createList(pvApiCtx, nbIn + 3, iNbItem, &pList);
            for (int i = 0 ; i < iNbItem ; i++)
            {
                double* pdblDims = NULL;
                allocMatrixOfDoubleInList(pvApiCtx, nbIn + 3, pList, i + 1, 1, pInfo[i].iDims, &pdblDims);
                for (int j = 0 ; j < pInfo[i].iDims ; j++)
                {
                    pdblDims[j] = pInfo[i].piDims[j];
                }
            }

            AssignOutputVariable(pvApiCtx, 3) = nbIn + 3;
        }

        if (Lhs > 3)
        {
            //4th Lhs
            double* pdblSize = NULL;
            sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 4, iNbItem, 1, &pdblSize);
            for (int i = 0 ; i < iNbItem ; i++)
            {
                pdblSize[i] = pInfo[i].iSize;
            }

            AssignOutputVariable(pvApiCtx, 4) = nbIn + 4;
        }

    }

    FREE(pInfo);
    ReturnArguments(pvApiCtx);
    return 0;
}
Exemplo n.º 14
0
int read_string(char *fname,unsigned long fname_len)
{
	SciErr sciErr;
	int i,j;
	int iLen		= 0;
	//variable info
	int iRows		= 0;
	int iCols		= 0;
	int* piAddr		= NULL;
	int* piLen		= NULL;
	char** pstData	= NULL;
	//output variable
	int iRowsOut	= 1;
	int iColsOut	= 1;
	char* pstOut	= NULL;
	//check input and output arguments

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

	//get variable address
	sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}

	//fisrt call to retrieve dimensions
	sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}

	piLen = (int*)malloc(sizeof(int) * iRows * iCols);

	//second call to retrieve length of each string
	sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}

	pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
	for(i = 0 ; i < iRows * iCols ; i++)
	{
		pstData[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
	}

	//third call to retrieve data
	sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}

	//computer length of all strings
	for(i = 0 ; i < iRows * iCols ; i++)
	{
		iLen += piLen[i];
	}

	//alloc output variable
	pstOut = (char*)malloc(sizeof(char) * (iLen + iRows * iCols));
	//initialize string to 0x00
	memset(pstOut, 0x00, sizeof(char) * (iLen + iRows * iCols));

	//concat input strings in output string
	for(i = 0 ; i < iRows ; i++)
	{
		for(j = 0 ; j < iCols ; j++)
		{
			int iCurLen = strlen(pstOut);
			if(iCurLen)
			{
				strcat(pstOut, " ");
			}
			strcpy(pstOut + strlen(pstOut), pstData[j * iRows + i]);
		}
	}

	//create new variable
	sciErr = createMatrixOfString(pvApiCtx, InputArgument + 1, iRowsOut, iColsOut, &pstOut);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}

	//free memory
	free(piLen);

	for(i = 0 ; i < iRows * iCols ; i++)
	{
		free(pstData[i]);
	}

	free(pstData);
	free(pstOut);
	AssignOutputVariable(1) = InputArgument + 1;
	return 0;
}
Exemplo n.º 15
0
int ScilabGateway::deff(char * fname, const int envId, void * pvApiCtx)
{
    static int ONE = 1;
    static int TWO = 2;
    static int THREE = 3;

    SciErr err;
    char ** names[] = {0, 0, 0};
    int ret = 0;
    std::ostringstream os;
    char * str;
    int * addr[] = {0, 0, 0};
    int rows[] = {0, 0, 0};
    int cols[] = {0, 0, 0};
    int error = 0;
    char * cwd = 0;

    CheckInputArgument(pvApiCtx, 3, 3);

    ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
    ScilabGatewayOptions & options = env.getGatewayOptions();
    OptionsHelper & helper = env.getOptionsHelper();
    OptionsHelper::setCopyOccurred(false);
    ScilabObjects::initialization(env, pvApiCtx);
    options.setIsNew(false);

    for (int i = 0; i < 3; i++)
    {
        err = getVarAddressFromPosition(pvApiCtx, i + 1, &(addr[i]));
        if (err.iErr)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        if (!isStringType(pvApiCtx, addr[i]))
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A String expected."), 1);
        }

        err = getVarDimension(pvApiCtx, addr[i], &(rows[i]), &(cols[i]));
        if (err.iErr)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }
    }

    if (rows[0] != 1 || cols[0] != 1)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid dimensions for input argument #%d: A single string expected."), 1);
    }

    if (rows[1] != rows[2] || cols[1] != cols[2])
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid dimensions: arguments #2 and #3 must have the same."));
    }

    for (int i = 0; i < 3; i++)
    {
        if (getAllocatedMatrixOfString(pvApiCtx, addr[i], &(rows[i]), &(cols[i]), &(names[i])))
        {
            for (int j = 0; j < i; j++)
            {
                freeAllocatedMatrixOfString(rows[j], cols[j], names[j]);
            }
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }
    }

    cwd = scigetcwd(&error);
    if (error)
    {
        FREE(cwd);
        cwd = 0;
    }

    try
    {
        ret = env.loadclass(names[0][0], cwd, false, helper.getAllowReload());
    }
    catch (std::exception & e)
    {
        FREE(cwd);
        for (int j = 0; j < 3; j++)
        {
            freeAllocatedMatrixOfString(rows[j], cols[j], names[j]);
        }
        throw;
    }
    FREE(cwd);

    for (int i = 0; i < rows[1] * cols[1]; i++)
    {
        err = createMatrixOfString(pvApiCtx, ONE, 1, 1, (const char * const *) & (names[2][i]));
        if (err.iErr)
        {
            for (int j = 0; j < 3; j++)
            {
                freeAllocatedMatrixOfString(rows[j], cols[j], names[j]);
            }
            env.removeobject(ret);
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot create the data"));
        }

        os.str("");
        os << "y=" << names[2][i] << "(varargin)" << std::flush;
        str = strdup(os.str().c_str());

        err = createMatrixOfString(pvApiCtx, TWO, 1, 1, (const char * const *)&str);
        free(str);
        if (err.iErr)
        {
            for (int j = 0; j < 3; j++)
            {
                freeAllocatedMatrixOfString(rows[j], cols[j], names[j]);
            }
            env.removeobject(ret);
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot create the data"));
        }

        os.str("");
        os << "y=invoke_lu(int32(" << ret << "),int32(" << envId << "),\"" << names[1][i] << "\",varargin)" << std::flush;
        str = strdup(os.str().c_str());

        err = createMatrixOfString(pvApiCtx, THREE, 1, 1, (const char * const *)&str);
        free(str);
        if (err.iErr)
        {
            for (int j = 0; j < 3; j++)
            {
                freeAllocatedMatrixOfString(rows[j], cols[j], names[j]);
            }
            env.removeobject(ret);
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot create the data"));
        }

        SciString(&ONE, const_cast<char *>("!_deff_wrapper"), &ONE, &THREE);
    }

    for (int i = 0; i < 3; i++)
    {
        freeAllocatedMatrixOfString(rows[0], cols[0], names[i]);
    }

    LhsVar(1) = 0;
    PutLhsVar();

    return 0;
}
Exemplo n.º 16
0
    /*--------------------------------------------------------------------------*/
    int sci_buildDoc(char *fname, void* pvApiCtx)
    {
        std::string exportFormat;
        std::string SciPath = getSCI(); /* Scilab path */
        std::string masterXML; /* Which file contains all the doc stuff */
        std::string masterXMLTMP;
        std::string outputDirectory;    /* Working directory */
        std::string outputDirectoryTMP;
        std::string language;
        std::string styleSheet; /* the CSS */
        char * fileToExec = NULL;
        SciErr sciErr;
        int *piAddr = NULL;
        int iRet = 0;

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

        styleSheet = SciPath + PATHTOCSS;

        if (Rhs < 1)
        {
            exportFormat = DEFAULTEXPORT;
        }
        else
        {
            char* pstData = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);

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

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

            iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
            if (iRet)
            {
                freeAllocatedSingleString(pstData);
                return iRet;
            }
            exportFormat = std::string(pstData);
            freeAllocatedSingleString(pstData);


        }

        if (Rhs < 3)            /* Language not provided */
        {
            wchar_t* l = getlanguage();
            language = wide_string_to_UTF8(l);
            free(l);
        }
        else
        {
            char* pstData = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);

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

            if (!isStringType(pvApiCtx, piAddr))
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3);
                return 0;
                // Wrong type string
            }

            if (!isScalar(pvApiCtx, piAddr))
            {
                wchar_t* pwstLang = getlanguage();
                language = wide_string_to_UTF8(pwstLang);
                free(pwstLang);
            }
            else
            {
                iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
                if (iRet)
                {
                    freeAllocatedSingleString(pstData);
                    return iRet;
                }
                language = std::string(pstData);
                freeAllocatedSingleString(pstData);

            }

        }

        if (Rhs < 2)
        {
            /* Update the path with the localization */
            masterXMLTMP = std::string("/modules/helptools/master_") + language + std::string("_help.xml");
            masterXML = SciPath + masterXMLTMP;
        }
        else
        {
            char* pstData = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);

            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
                return 0;
            }
            if (!isStringType(pvApiCtx, piAddr))
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
                return 0;
                // Wrong type string
            }


            iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
            if (iRet)
            {
                freeAllocatedSingleString(pstData);
                return iRet;
            }
            masterXML = std::string(pstData);
            freeAllocatedSingleString(pstData);
        }

        if (Rhs == 4)
        {
            char* pstData = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);

            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
                return 0;
            }
            if (!isStringType(pvApiCtx, piAddr))
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 4);
                return 0;
                // Wrong type string
            }

            iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
            if (iRet)
            {
                freeAllocatedSingleString(pstData);
                return iRet;
            }
            outputDirectory = std::string(pstData) + std::string("/scilab_") + language + std::string("_help/");
            freeAllocatedSingleString(pstData);

        }
        else                    /* Scilab help */
        {
            /* Update the path with the localization */
            if (exportFormat != "jar-only")
            {
                outputDirectoryTMP =
                    std::string("/modules/helptools/") + std::string(exportFormat) + std::string("/scilab_") + language + std::string("_help/");
            }
            else
            {
                outputDirectoryTMP =
                    std::string("/modules/helptools/") + std::string("javaHelp") + std::string("/scilab_") + language + std::string("_help/");
            }

            outputDirectory = SciPath + outputDirectoryTMP;
        }

#ifdef _MSC_VER
        __slashToAntislash(&outputDirectory);
        __slashToAntislash(&styleSheet);
        __slashToAntislash(&masterXML);
#endif

        try
        {
            org_scilab_modules_helptools::SciDocMain * doc = new org_scilab_modules_helptools::SciDocMain(getScilabJavaVM());

            if (doc->setOutputDirectory((char *)outputDirectory.c_str()))
            {
                doc->setWorkingLanguage((char *)language.c_str());
                doc->setExportFormat((char *)exportFormat.c_str());
                doc->setIsToolbox(Rhs == 4);
                fileToExec = doc->process((char *)masterXML.c_str(), (char *)styleSheet.c_str());
            }
            else
            {
                Scierror(999, _("%s: Could find or create the working directory %s.\n"), fname, outputDirectory.c_str());
                return FALSE;
            }
            if (doc != NULL)
            {
                delete doc;
            }
        }
        catch (GiwsException::JniException ex)
        {
            Scierror(999, _("%s: Error while building documentation: %s.\n"), fname, ex.getJavaDescription().c_str());
            Scierror(999, _("%s: Execution Java stack: %s.\n"), fname, ex.getJavaStackTrace().c_str());
            Scierror(999,
                     _
                     ("If Scilab is started in a chroot, you might want to try to set the two environment variables: SCI_DISABLE_TK=1 SCI_JAVA_ENABLE_HEADLESS=1\n"));
            return FALSE;
        }

        if (fileToExec)
        {
            createMatrixOfString(pvApiCtx, Rhs + 1, 1, 1, &fileToExec);
            delete [] fileToExec;
        }
        else
        {
            createEmptyMatrix(pvApiCtx, Rhs + 1);
        }

        LhsVar(1) = Rhs + 1;
        PutLhsVar();

        return 0;
    }
Exemplo n.º 17
0
/*--------------------------------------------------------------------------*/
int sci_fftw_flags(char *fname, unsigned long fname_len)
{
    /* declaration of variables to store scilab parameters address */
    static int m1 = 0, n1 = 0;

    char **Str1 = NULL;
    char **Str3 = NULL;

    unsigned int uiVar1 = 0;
    int* piDataOut = NULL;
    int* piAddr1 = NULL;
    int* piLen = NULL;
    int iType = 0;

    /* please update me ! */
    static int nb_flag = 22;
    static char *Str[] =
    {
        /* documented flags */
        "FFTW_MEASURE",
        "FFTW_DESTROY_INPUT",
        "FFTW_UNALIGNED",
        "FFTW_CONSERVE_MEMORY",
        "FFTW_EXHAUSTIVE",
        "FFTW_PRESERVE_INPUT",
        "FFTW_PATIENT",
        "FFTW_ESTIMATE",

        /* undocumented beyond-guru flags */
        "FFTW_ESTIMATE_PATIENT",
        "FFTW_BELIEVE_PCOST",
        "FFTW_NO_DFT_R2HC",
        "FFTW_NO_NONTHREADED",
        "FFTW_NO_BUFFERING",
        "FFTW_NO_INDIRECT_OP",
        "FFTW_ALLOW_LARGE_GENERIC",
        "FFTW_NO_RANK_SPLITS",
        "FFTW_NO_VRANK_SPLITS",
        "FFTW_NO_VRECURSE",
        "FFTW_NO_SIMD",
        "FFTW_NO_SLOW",
        "FFTW_NO_FIXED_RADIX_LARGE_N",
        "FFTW_ALLOW_PRUNING"
    };

    static unsigned flagt[] =
    {
        /* documented flags */
        FFTW_MEASURE,
        FFTW_DESTROY_INPUT,
        FFTW_UNALIGNED,
        FFTW_CONSERVE_MEMORY,
        FFTW_EXHAUSTIVE,
        FFTW_PRESERVE_INPUT,
        FFTW_PATIENT,
        FFTW_ESTIMATE,

        /* undocumented beyond-guru flags */
        FFTW_ESTIMATE_PATIENT,
        FFTW_BELIEVE_PCOST,
        FFTW_NO_DFT_R2HC,
        FFTW_NO_NONTHREADED,
        FFTW_NO_BUFFERING,
        FFTW_NO_INDIRECT_OP,
        FFTW_ALLOW_LARGE_GENERIC,
        FFTW_NO_RANK_SPLITS,
        FFTW_NO_VRANK_SPLITS,
        FFTW_NO_VRECURSE,
        FFTW_NO_SIMD,
        FFTW_NO_SLOW,
        FFTW_NO_FIXED_RADIX_LARGE_N,
        FFTW_ALLOW_PRUNING
    };

    unsigned flagv = 0;

    int i = 0, j = 0;

    SciErr sciErr;
    CheckInputArgument(pvApiCtx, 0, 1);

    if (nbInputArgument(pvApiCtx) == 0)
    {
        // nothing
    }
    else
    {
        //get variable address of the input argument
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        getVarType(pvApiCtx, piAddr1, &iType);
        switch (iType)
        {
            case sci_ints:
            {
                /* int */
                int iPrecision = 0;
                int* pi32Data = NULL;
                unsigned int* pui32Data = NULL;

                getMatrixOfIntegerPrecision(pvApiCtx, piAddr1, &iPrecision);
                if (iPrecision != SCI_INT32 && iPrecision != SCI_UINT32)
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A int32 expected.\n"), fname, 1);
                    return 1;
                }

                if (iPrecision == SCI_INT32)
                {
                    sciErr = getMatrixOfInteger32(pvApiCtx, piAddr1, &m1, &n1, pi32Data);
                    uiVar1 = (unsigned int)pi32Data[0];
                }
                else
                {
                    sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, piAddr1, &m1, &n1, pui32Data);
                    uiVar1 = pui32Data[0];
                }

                if (sciErr.iErr)
                {
                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
                    printError(&sciErr, 0);
                    return 1;
                }
                break;
            }
            case sci_matrix:
            {
                /* double */
                double* pdblData = NULL;
                sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &m1, &n1, &pdblData);
                if (sciErr.iErr)
                {
                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
                    printError(&sciErr, 0);
                    return 1;
                }

                uiVar1 = (unsigned int)pdblData[0];
                break;
            }
            case sci_strings:
            {
                /* string */
                //fisrt call to retrieve dimensions
                sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, NULL, NULL);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                piLen = (int*)malloc(sizeof(int) * m1 * n1);

                //second call to retrieve length of each string
                sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, piLen, NULL);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                Str1 = (char**)malloc(sizeof(char*) * m1 * n1);
                for (i = 0 ; i < m1 * n1 ; i++)
                {
                    Str1[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
                }

                //third call to retrieve data
                sciErr = getMatrixOfString(pvApiCtx, piAddr1, &m1, &n1, piLen, Str1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                for (j = 0; j < m1 * n1; j++)
                {
                    for (i = 0; i < nb_flag; i++)
                    {
                        if (strcmp(Str1[j], Str[i]) == 0)
                        {
                            break;
                        }
                    }

                    if (i == nb_flag)
                    {
                        freeArrayOfString(Str1, m1 * n1);
                        Scierror(999, _("%s: Wrong values for input argument #%d: FFTW flag expected.\n"), fname, 1);
                        return 0;
                    }
                    else
                    {
                        if (i > 0)
                        {
                            flagv = ( flagv | (1U << (i - 1)) );
                        }
                    }
                }

                uiVar1 = (unsigned int)flagv;
                freeArrayOfString(Str1, m1 * n1);
                m1 = 1;
                n1 = 1;
                break;
            }
            default:
                Scierror(53, _("%s: Wrong type for input argument #%d.\n"), fname, 1);
                return 1;
        }

        CheckDims(1, m1, n1, 1, 1);
        setCurrentFftwFlags(uiVar1);
    }

    /* return value of Sci_Plan.flags in position 2 */
    sciErr = allocMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, 1, &piDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: No more memory.\n"), fname);
        return 1;
    }

    piDataOut[0] = (int) getCurrentFftwFlags();

    /*Test for only FFTW_MEASURE*/
    if (getCurrentFftwFlags() == 0)
    {
        j = 1;
        if ((Str3 = (char **)MALLOC(sizeof(char *))) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
            return 1;
        }

        Str3[0] = strdup(Str[0]);
        if (Str3[0] == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
            return 1;
        }
    }
    else
    {
        j = 0;
        for (i = 1; i < nb_flag; i++)
        {
            if ((getCurrentFftwFlags() & flagt[i]) == flagt[i])
            {
                j++;
                if (Str3)
                {
                    Str3 = (char **)REALLOC(Str3, sizeof(char *) * j);
                }
                else
                {
                    Str3 = (char **)MALLOC(sizeof(char *) * j);
                }

                if ( Str3 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), fname);
                    return 1;
                }

                Str3[j - 1] = strdup(Str[i]);
                if (Str3[j - 1] == NULL)
                {
                    freeArrayOfString(Str3, j);
                    Scierror(999, _("%s: No more memory.\n"), fname);
                    return 1;
                }
            }
        }
    }

    /* Create the string matrix as return of the function */
    sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 3, j, 1, Str3);
    freeArrayOfString(Str3, j); // Data have been copied into Scilab memory
    if (sciErr.iErr)
    {
        freeArrayOfString(Str3, j); // Make sure everything is cleanup in case of error
        printError(&sciErr, 0);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 2;
    AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 3;
    ReturnArguments(pvApiCtx);
    return 0;
}
Exemplo n.º 18
0
/*--------------------------------------------------------------------------*/
static int xlfont_one_rhs(char * fname)
{
    SciErr sciErr;
    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        int* piAddrl1 = NULL;
        int* l1 = NULL;
        char* strl1 = NULL;
        int m1 = 0, n1 = 0;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &strl1))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

        if (strcmp(strl1, "AVAILABLE_FONTS") == 0)
        {
            int nbElements = 0;
            char **fontsname = getAvailableFontsName(&nbElements);

            m1 = nbElements;
            n1 = 1;

            sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, (const char * const*)fontsname);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            freeArrayOfString(fontsname, nbElements);
            freeAllocatedSingleString(strl1);
            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            ReturnArguments(pvApiCtx);
            return 0;
        }
        else if (strcmp(strl1, "reset") == 0)
        {
            resetFontManager();
            freeAllocatedSingleString(strl1);
            AssignOutputVariable(pvApiCtx, 1) = 0;
            ReturnArguments(pvApiCtx);
            return 0;
        }
        else
        {
            if (isAvailableFontsName(strl1))
            {
                int fontID = addFont(strl1);

                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = fontID;

                freeAllocatedSingleString(strl1);
                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
                return 0;
            }
            else if (FileExist(strl1))
            {
                int fontID = addFontFromFilename(strl1);

                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = fontID;

                freeAllocatedSingleString(strl1);
                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
                return 0;
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: A valid fontname expected.\n"), fname, 1);
            }
        }

        freeAllocatedSingleString(strl1);
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
        return 0;
    }

    return 0;
}
Exemplo n.º 19
0
/*--------------------------------------------------------------------------*/
int sci_dec2base(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    int *piAddressVarTwo = NULL;
    int m = 0, n = 0;

    double *dValues = NULL;
    char **convertedValues = NULL;
    unsigned int iBaseUsed = 0;
    double dBaseUsed = 0.;
    unsigned int nbDigits = 0;
    error_convertbase err = ERROR_CONVERTBASE_NOK;

    CheckRhs(2, 3);
    CheckLhs(1, 1);

    if (Rhs == 3)
    {
        double dParamThree = 0.;
        unsigned int iParamThree = 0;
        int *piAddressVarThree = NULL;
        sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
            return 0;
        }

        if (!isDoubleType(pvApiCtx, piAddressVarThree))
        {
            Scierror(999,_("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 3);
            return 0;
        }

        if (!isScalar(pvApiCtx, piAddressVarThree))
        {
            Scierror(999,_("%s: Wrong size for input argument #%d: A scalar integer value expected.\n"), fname, 3);
            return 0;
        }

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

        iParamThree = (unsigned int)dParamThree;

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

        nbDigits = iParamThree;
    }

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

    if (!isDoubleType(pvApiCtx, piAddressVarTwo))
    {
        Scierror(999,_("%s: Wrong type for input argument #%d: A integer value expected.\n"), fname, 2);
        return 0;
    }

    if (!isScalar(pvApiCtx, piAddressVarTwo))
    {
        Scierror(999,_("%s: Wrong size for input argument #%d.\n"), fname, 2);
        return 0;
    }

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

    iBaseUsed = (unsigned int)dBaseUsed;
    if (dBaseUsed != (double)iBaseUsed)
    {
        Scierror(999, _("%s: Wrong value for input argument #%d: A integer value expected.\n"), fname, 2);
        return 0;
    }

    if ((iBaseUsed < 2) && (iBaseUsed > 36))
    {
        Scierror(999, _("%s: Wrong value for input argument #%d: Must be between %d and %d."), fname, 2, 2, 36);
        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;
    }

    if (isEmptyMatrix(pvApiCtx, piAddressVarOne))
    {
        if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0)
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
            return 0;
        }
        else
        {
            LhsVar(1) = Rhs + 1;
            PutLhsVar();
            return 0;
        }
    }

    if (!isDoubleType(pvApiCtx, piAddressVarOne))
    {
        Scierror(999,_("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), fname, 1);
        return 0;
    }

    if (isVarComplex(pvApiCtx, piAddressVarOne))
    {
        Scierror(999,_("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), fname, 1);
        return 0;
    }

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

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

    convertedValues = convertMatrixOfDec2Base(dValues, m * n, iBaseUsed, nbDigits, &err);
    if ((err != ERROR_CONVERTBASE_OK) || (convertedValues == NULL))
    {
        freeArrayOfString(convertedValues, m * n);
        convertedValues = NULL;

        switch (err)
        {
        case ERROR_CONVERTBASE_NOT_INTEGER_VALUE:
            Scierror(999, _("%s: Wrong value for input argument #%d: Must be between 0 and 2^52.\n"), fname, 1);
            return 0;

        case ERROR_CONVERTBASE_NOT_IN_INTERVAL:
            Scierror(999,_("%s: Wrong value(s) for input argument #%d: A matrix of positive integer values expected.\n"), fname, 1);
            return 0;

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

        case ERROR_CONVERTBASE_NOK: default:
            Scierror(999, _("%s: Wrong value for input argument #%d: cannot convert value(s).\n"), fname, 1);
            return 0;
        }
    }

    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, convertedValues);
    freeArrayOfString(convertedValues, m * n);
    convertedValues = NULL;

    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999,_("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    LhsVar(1) = Rhs + 1;
    PutLhsVar();

    return 0;
}
Exemplo n.º 20
0
/*--------------------------------------------------------------------------*/
int sci_fscanfMat(char *fname, void* pvApiCtx)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    int m1 = 0, n1 = 0;
    int iType1 = 0;

    char *filename = NULL;
    char *expandedFilename = NULL;
    char *Format = NULL;
    char *separator = NULL;
    BOOL bIsDefaultSeparator = TRUE;

    fscanfMatResult *results = NULL;

    CheckRhs(1, 3);
    CheckLhs(1, 2);

    if (Rhs == 3)
    {
        int *piAddressVarThree = NULL;
        int m3 = 0, n3 = 0;
        int iType3 = 0;

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

        if (isStringType(pvApiCtx, piAddressVarThree) == 0 || isScalar(pvApiCtx, piAddressVarThree) == 0)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3);
            return 0;
        }

        if (getAllocatedSingleString(pvApiCtx, piAddressVarThree, &separator))
        {
            freeVar(&filename, &expandedFilename, &Format, &separator);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }

        bIsDefaultSeparator = FALSE;
    }

    if (Rhs >= 2)
    {
        int *piAddressVarTwo = NULL;
        int m2 = 0, n2 = 0;
        int iType2 = 0;

        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
        if (sciErr.iErr)
        {
            freeVar(&filename, &expandedFilename, &Format, &separator);
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
            return 0;
        }

        sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2);
        if (sciErr.iErr)
        {
            freeVar(&filename, &expandedFilename, &Format, &separator);
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
            return 0;
        }

        if (isStringType(pvApiCtx, piAddressVarTwo) == 0 || isScalar(pvApiCtx, piAddressVarTwo) == 0)
        {
            freeVar(&filename, &expandedFilename, &Format, &separator);
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
            return 0;
        }

        if (getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &Format))
        {
            freeVar(&filename, &expandedFilename, &Format, &separator);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }
    }
    else
    {
        Format = os_strdup(DEFAULT_FSCANFMAT_FORMAT);
    }

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

    if (isStringType(pvApiCtx, piAddressVarOne) == 0 || isScalar(pvApiCtx, piAddressVarOne) == 0)
    {
        freeVar(&filename, &expandedFilename, &Format, &separator);
        Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
        return 0;
    }

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

    expandedFilename = expandPathVariable(filename);
    if (bIsDefaultSeparator)
    {
#define NB_DEFAULT_SUPPORTED_SEPARATORS 2

        /* bug 8148 */
        /* default separator can be a space or a tabulation */
        char *supportedSeparators[NB_DEFAULT_SUPPORTED_SEPARATORS] = {DEFAULT_FSCANFMAT_SEPARATOR, "\t"};
        int i = 0;

        for (i = 0; i < NB_DEFAULT_SUPPORTED_SEPARATORS; i++)
        {
            results = fscanfMat(expandedFilename, Format, supportedSeparators[i]);
            if (results && results->err == FSCANFMAT_NO_ERROR)
            {
                break;
            }

            freeFscanfMatResult(results);
        }
    }
    else
    {
        results = fscanfMat(expandedFilename, Format, separator);
    }

    if (results == NULL)
    {
        freeVar(&filename, &expandedFilename, &Format, &separator);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    freeVar(NULL, &expandedFilename, &Format, &separator);
    switch (results->err)
    {
        case FSCANFMAT_NO_ERROR:
        {
            if ( (results->values) && (results->m > 0) && (results->n > 0))
            {
                sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, results->m, results->n, results->values);
                if (sciErr.iErr)
                {
                    FREE(filename);
                    freeFscanfMatResult(results);
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 0;
                }
            }
            else
            {
                if (createEmptyMatrix(pvApiCtx, Rhs + 1))
                {
                    FREE(filename);
                    freeFscanfMatResult(results);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 0;
                }
            }

            LhsVar(1) = Rhs + 1;

            if (Lhs == 2)
            {
                if (results->text)
                {
                    sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, results->sizeText, 1, (char const * const*) results->text);
                    if (sciErr.iErr)
                    {
                        FREE(filename);
                        freeFscanfMatResult(results);
                        printError(&sciErr, 0);
                        Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                }
                else
                {
                    if (createSingleString(pvApiCtx, Rhs + 2, ""))
                    {
                        FREE(filename);
                        freeFscanfMatResult(results);
                        Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                }

                LhsVar(2) = Rhs + 2;
            }

            freeFscanfMatResult(results);
            FREE(filename);
            PutLhsVar();
            return 0;
        }
        case FSCANFMAT_MOPEN_ERROR:
        {
            Scierror(999, _("%s: can not open file %s.\n"), fname, filename);
            FREE(filename);
            return 0;
        }
        case FSCANFMAT_READLINES_ERROR:
        {
            Scierror(999, _("%s: can not read file %s.\n"), fname, filename);
            FREE(filename);
            return 0;
        }
        case FSCANFMAT_FORMAT_ERROR:
        {
            Scierror(999, _("%s: Invalid format.\n"), fname);
            FREE(filename);
            return 0;
        }
        case FSCANFMAT_MEMORY_ALLOCATION:
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            FREE(filename);
            return 0;
        }
        default:
        case FSCANFMAT_ERROR:
        {
            Scierror(999, _("%s: error.\n"), fname);
            FREE(filename);
            return 0;
        }
    }

    FREE(filename);
    freeFscanfMatResult(results);
    return 0;
}
Exemplo n.º 21
0
// =============================================================================
static int sci_csvDefault_no_rhs(char *fname, void* pvApiCtx)
{
    int sizeArray = NUMBER_FIELD * 2;
    char **arrayOut = (char**)MALLOC(sizeof(char*) * sizeArray);

    if (arrayOut)
    {
        SciErr sciErr;

        int nbRows = NUMBER_FIELD;
        int nbCols = 2;
        const char *currentEol = getCsvDefaultEOL();

        arrayOut[0] = os_strdup(SEPARATOR_FIELDNAME);
        arrayOut[1] = os_strdup(DECIMAL_FIELDNAME);
        arrayOut[2] = os_strdup(CONVERSION_FIELDNAME);
        arrayOut[3] = os_strdup(PRECISION_FIELDNAME);
        arrayOut[4] = os_strdup(COMMENTSREGEXP_FIELDNAME);
        arrayOut[5] = os_strdup(EOL_FIELDNAME);
        arrayOut[6] = os_strdup(ENCODING_FIELDNAME);
        arrayOut[7] = os_strdup(BLANK_FIELDNAME);

        arrayOut[8] = os_strdup(getCsvDefaultSeparator());
        arrayOut[9] = os_strdup(getCsvDefaultDecimal());
        arrayOut[10] = os_strdup(getCsvDefaultConversion());
        arrayOut[11] = os_strdup(getCsvDefaultPrecision());
        arrayOut[12] = os_strdup(getCsvDefaultCommentsRegExp());

        if (currentEol)
        {
            if (strcmp(currentEol, MACOS9_EOL) == 0)
            {
                arrayOut[13] = os_strdup(MACOS9_EOL_STRING);
            }
            else if (strcmp(currentEol, WINDOWS_EOL) == 0)
            {
                arrayOut[13] = os_strdup(WINDOWS_EOL_STRING);
            }
            else if (strcmp(currentEol, LINUX_EOL) == 0)
            {
                arrayOut[13] = os_strdup(LINUX_EOL_STRING);
            }
            else
            {
                arrayOut[13] = os_strdup("ERROR");
            }
        }
        else
        {
            arrayOut[13] = os_strdup("ERROR");
        }

        arrayOut[14] = os_strdup(getCsvDefaultEncoding());
        arrayOut[15] = os_strdup(getCsvDefaultCsvIgnoreBlankLine());

        sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, nbRows, nbCols, arrayOut);
        freeArrayOfString(arrayOut, sizeArray);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        LhsVar(1) = Rhs + 1;
        PutLhsVar();
    }
    else
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
    }

    return 0;
}
Exemplo n.º 22
0
int sci_listvar_in_hdf5_v1(char *fname, int* pvCtx)
{
    SciErr sciErr;
    int *piAddr     = NULL;
    char* pstFile   = NULL;
    int iFile       = 0;
    int iNbItem     = 0;
    VarInfo_v1* pInfo  = NULL;

    CheckInputArgument(pvCtx, 1, 1);
    CheckOutputArgument(pvCtx, 1, 4);

    sciErr = getVarAddressFromPosition(pvCtx, 1, &piAddr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    if (getAllocatedSingleString(pvCtx, piAddr, &pstFile))
    {
        if (pstFile)
        {
            FREE(pstFile);
        }

        Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1);
        return 1;
    }

    char* pstFileName = expandPathVariable(pstFile);
    iFile = openHDF5File(pstFileName, 0);
    if (iFile < 0)
    {
        FREE(pstFileName);
        Scierror(999, _("%s: Unable to open file: %s\n"), fname, pstFile);
        FREE(pstFile);
        return 1;
    }
    FREE(pstFileName);
    FREE(pstFile);

    iNbItem = getVariableNames_v1(iFile, NULL);
    if (iNbItem != 0)
    {
        char** pstVarNameList = (char**)MALLOC(sizeof(char*) * iNbItem);
        bool b;
        pInfo = (VarInfo_v1*)MALLOC(iNbItem * sizeof(VarInfo_v1));

        if (nbOutputArgument(pvCtx) == 1)
        {
            sciprint("Name                     Type           Size            Bytes\n");
            sciprint("---------------------------------------------------------------\n");
        }

        iNbItem = getVariableNames_v1(iFile, pstVarNameList);
        for (int i = 0; i < iNbItem; i++)
        {
            int iDataSetId = getDataSetIdFromName_v1(iFile, pstVarNameList[i]);
            if (iDataSetId == 0)
            {
                break;
            }

            strncpy(pInfo[i].varName, pstVarNameList[i], sizeof(pInfo[i].varName));
            b = read_data_v1(pvCtx, iDataSetId, 0, NULL, &pInfo[i]) == false;
            closeDataSet_v1(iDataSetId);

            if (b)
            {
                break;
            }

            if (nbOutputArgument(pvCtx) == 1)
            {
                sciprint("%s\n", pInfo[i].pstInfo);
            }
        }

        freeArrayOfString(pstVarNameList, iNbItem);
    }
    else
    {
        //no variable returms [] for each Lhs
        for (int i = 0 ; i < nbOutputArgument(pvCtx) ; i++)
        {
            createEmptyMatrix(pvCtx, nbInputArgument(pvCtx) + i + 1);
            AssignOutputVariable(pvCtx, i + 1) = nbInputArgument(pvCtx) + i + 1;
        }

        ReturnArguments(pvCtx);
        return 0;
    }

    closeHDF5File(iFile);

    //1st Lhs
    char** pstVarName = (char**)MALLOC(sizeof(char*) * iNbItem);
    for (int i = 0 ; i < iNbItem ; i++)
    {
        pstVarName[i] = pInfo[i].varName;
    }

    sciErr = createMatrixOfString(pvCtx, nbInputArgument(pvCtx) + 1, iNbItem, 1, pstVarName);
    FREE(pstVarName);
    if (sciErr.iErr)
    {
        FREE(pInfo);
        printError(&sciErr, 0);
        return 1;
    }

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

    if (nbOutputArgument(pvCtx) > 1)
    {
        //2nd Lhs
        double* pdblType;
        sciErr = allocMatrixOfDouble(pvCtx, nbInputArgument(pvCtx) + 2, iNbItem, 1, &pdblType);
        if (sciErr.iErr)
        {
            FREE(pInfo);
            printError(&sciErr, 0);
            return 1;
        }

        for (int i = 0 ; i < iNbItem ; i++)
        {
            pdblType[i] = pInfo[i].iType;
        }

        AssignOutputVariable(pvCtx, 2) = nbInputArgument(pvCtx) + 2;

        if (nbOutputArgument(pvCtx) > 2)
        {
            //3rd Lhs
            int* pList = NULL;
            sciErr = createList(pvCtx, nbInputArgument(pvCtx) + 3, iNbItem, &pList);
            for (int i = 0 ; i < iNbItem ; i++)
            {
                double* pdblDims = NULL;
                allocMatrixOfDoubleInList(pvCtx, nbInputArgument(pvCtx) + 3, pList, i + 1, 1, pInfo[i].iDims, &pdblDims);
                for (int j = 0 ; j < pInfo[i].iDims ; j++)
                {
                    pdblDims[j] = pInfo[i].piDims[j];
                }
            }

            AssignOutputVariable(pvCtx, 3) = nbInputArgument(pvCtx) + 3;
        }

        if (nbOutputArgument(pvCtx) > 3)
        {
            //4th Lhs
            double* pdblSize;
            sciErr = allocMatrixOfDouble(pvCtx, nbInputArgument(pvCtx) + 4, iNbItem, 1, &pdblSize);
            for (int i = 0 ; i < iNbItem ; i++)
            {
                pdblSize[i] = pInfo[i].iSize;
            }

            AssignOutputVariable(pvCtx, 4) = nbInputArgument(pvCtx) + 4;
        }

    }

    FREE(pInfo);
    ReturnArguments(pvCtx);
    return 0;
}
Exemplo n.º 23
0
/*--------------------------------------------------------------------------*/
int sci_winqueryreg(char *fname, unsigned long l)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    int *piAddressVarTwo = NULL;
    int *piAddressVarThree = NULL;

    char *pStrParamOne = NULL;
    char *pStrParamTwo = NULL;
    char *pStrParamThree = NULL;

    char *pStrOutput = NULL;
    int iOutput = 0;

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

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

        if (!isStringType(pvApiCtx, piAddressVarThree))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 3);
            return 0;
        }

        if (!isScalar(pvApiCtx, piAddressVarThree))
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname, 3);
            return 0;
        }

        if (getAllocatedSingleString(pvApiCtx, piAddressVarThree, &pStrParamThree) != 0)
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            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;
    }

    if (!isStringType(pvApiCtx, piAddressVarOne))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
        return 0;
    }

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

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

    if (!isStringType(pvApiCtx, piAddressVarTwo))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 2);
        return 0;
    }

    if (!isScalar(pvApiCtx, piAddressVarTwo))
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname, 2);
        return 0;
    }

    if (getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &pStrParamTwo) != 0)
    {
        if (pStrParamThree)
        {
            freeAllocatedSingleString(pStrParamThree);
            pStrParamThree = NULL;
        }
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &pStrParamOne) != 0)
    {
        if (pStrParamThree)
        {
            freeAllocatedSingleString(pStrParamThree);
            pStrParamThree = NULL;
        }

        if (pStrParamTwo)
        {
            freeAllocatedSingleString(pStrParamTwo);
            pStrParamTwo = NULL;
        }

        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    if (Rhs == 3)
    {
        BOOL bKey = strcmp(pStrParamOne, "key") == 0;
        BOOL bValue = strcmp(pStrParamOne, "name") == 0;

        if (bValue || bKey)
        {
            int NumbersElm = 0;
            if (bValue)
            {
                WindowsQueryRegistryNumberOfValuesInList(pStrParamTwo, pStrParamThree, &NumbersElm);
            }
            else
            {
                WindowsQueryRegistryNumberOfKeysInList(pStrParamTwo, pStrParamThree, &NumbersElm);
            }

            if (NumbersElm)
            {
                BOOL bResult = FALSE;
#define MAX_ELMT_REGLIST 255
                char **ListKeysName = NULL;
                int i = 0;

                if (NumbersElm > MAX_ELMT_REGLIST)
                {
                    NumbersElm = MAX_ELMT_REGLIST;
                }
                ListKeysName = (char **)MALLOC(sizeof(char*) * NumbersElm);
                for (i = 0; i < NumbersElm; i++)
                {
                    ListKeysName[i] = NULL;
                }

                if (bValue)
                {
                    bResult = WindowsQueryRegistryValuesList(pStrParamTwo, pStrParamThree, NumbersElm, ListKeysName);
                }
                else
                {
                    bResult = WindowsQueryRegistryKeysList(pStrParamTwo, pStrParamThree, NumbersElm, ListKeysName);
                }

                if (bResult)
                {
                    int nOne = 1;
                    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, NumbersElm, nOne, ListKeysName);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    }
                    else
                    {
                        LhsVar(1) = Rhs + 1;
                        PutLhsVar();
                    }
                }
                else
                {
                    Scierror(999, _("%s: Cannot open Windows registry.\n"), fname);
                }
                freeArrayOfString(ListKeysName, NumbersElm);
            }
            else
            {
                createEmptyMatrix(pvApiCtx, Rhs + 1);
                LhsVar(1) = Rhs + 1;
                PutLhsVar();
            }

            if (pStrParamThree)
            {
                freeAllocatedSingleString(pStrParamThree);
                pStrParamThree = NULL;
            }

            if (pStrParamTwo)
            {
                freeAllocatedSingleString(pStrParamTwo);
                pStrParamTwo = NULL;
            }

            if (pStrParamOne)
            {
                freeAllocatedSingleString(pStrParamOne);
                pStrParamOne = NULL;
            }
            return 0;
        }
    }

    pStrOutput = (char*)MALLOC(PATH_MAX * sizeof(char));
    if (pStrOutput)
    {
        BOOL OuputIsREG_SZ = FALSE;
        BOOL TestWinQuery = WindowsQueryRegistry(pStrParamOne, pStrParamTwo, pStrParamThree, pStrOutput, &iOutput, &OuputIsREG_SZ);
        if ( TestWinQuery )
        {
            if (OuputIsREG_SZ)
            {
                createSingleString(pvApiCtx, Rhs + 1, pStrOutput);
            }
            else
            {
                createScalarDouble(pvApiCtx, Rhs + 1, (double)iOutput);
            }

            LhsVar(1) = Rhs + 1;
            PutLhsVar();
        }
        else
        {
            Scierror(999, _("%s: Cannot query value of this type.\n"), fname);
        }

        FREE( pStrOutput);
        pStrOutput = NULL;
    }
    else
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
    }

    if (pStrParamThree)
    {
        freeAllocatedSingleString(pStrParamThree);
        pStrParamThree = NULL;
    }

    if (pStrParamTwo)
    {
        freeAllocatedSingleString(pStrParamTwo);
        pStrParamTwo = NULL;
    }

    if (pStrParamOne)
    {
        freeAllocatedSingleString(pStrParamOne);
        pStrParamOne = NULL;
    }

    return 0;

}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
/* Return text of fftw wisdom
*
* Scilab Calling sequence :
*   -->tt=get_fftw_wisdom();
*
* Input : Nothing
*
* Output : a scilab string matrix
*
*/
int sci_get_fftw_wisdom(char *fname, void* pvApiCtx)
{
    int n1 = 0, i = 0, j = 0;
    char *Str = NULL;
    char **Str1 = NULL;

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

    if ((Str = call_fftw_export_wisdom_to_string()) == NULL)
    {
        Scierror(999, _("%s: MKL fftw library does not implement wisdom functions yet.\n"), fname);
        return 1;
    }

    n1 = 0;
    j = 0;
    if (Str)
    {
        int lenStr = (int)strlen(Str);
        for (i = 0; i < lenStr; i++)
        {
            if (Str[i] == '\n')
            {
                int len = 0;
                int k = 0;

                n1++;

                if (Str1)
                {
                    Str1 = (char **)REALLOC(Str1, sizeof(char *) * n1);
                }
                else
                {
                    Str1 = (char **)MALLOC(sizeof(char *) * n1);
                }

                if (Str1 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), fname);
                    if (Str)
                    {
                        // According to the FFTW documentation we should free Str
                        // string but doing makes Scilab crash!?
                        //free(Str);
                    }
                    return 1;
                }

                len = i - j;

                if ((Str1[n1 - 1] = (char *)MALLOC(sizeof(char) * (len + 1))) == NULL)
                {
                    freeArrayOfString(Str1, n1 - 1);
                    if (Str)
                    {
                        // According to the FFTW documentation we should free Str
                        // string but doing makes Scilab crash!?
                        //free(Str);
                    }
                    Scierror(999, _("%s: No more memory.\n"), fname);
                    return 1;
                }

                for (k = 0; k < len; k++)
                {
                    Str1[n1 - 1][k] = Str[k + j];
                }
                Str1[n1 - 1][len] = '\0';
                j = i + 1;
            }
        }
    }

    n1++;

    if (Str1)
    {
        Str1 = (char **)REALLOC(Str1, sizeof(char *) * n1);
    }
    else
    {
        Str1 = (char **)MALLOC(sizeof(char *) * n1);
    }

    if (Str1 == NULL)
    {
        Scierror(999, _("%s: No more memory.\n"), fname);
        if (Str)
        {
            // According to the FFTW documentation we should free Str
            // string but doing makes Scilab crash!?
            //free(Str);
        }
        return 1;
    }

    if ((Str1[n1 - 1] = (char *)MALLOC(sizeof(char))) == NULL)
    {
        freeArrayOfString(Str1, n1 - 1);
        if (Str)
        {
            // According to the FFTW documentation we should free Str
            // string but doing makes Scilab crash!?
            //free(Str);
        }
        Scierror(999, _("%s: No more memory.\n"), fname);
        return 1;
    }
    Str1[n1 - 1][0] = '\0';

    createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, n1, 1, Str1);

    freeArrayOfString(Str1, n1);
    if (Str)
    {
        // According to the FFTW documentation we should free Str
        // string but doing makes Scilab crash!?
        //free(Str);
    }

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

    return 0;
}
Exemplo n.º 26
0
void H5Group::getAccessibleAttribute(const std::string & _name, const int pos, void * pvApiCtx) const
{
    SciErr err;
    std::string lower(_name);

    std::transform(_name.begin(), _name.end(), lower.begin(), tolower);

    if (lower == "attributes")
    {
        std::vector<std::string> names;
        getNames(*this, names, ATTRIBUTE);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "groups")
    {
        std::vector<std::string> names;
        getNames(*this, names, GROUP);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "datasets")
    {
        std::vector<std::string> names;
        getNames(*this, names, DATASET);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "types")
    {
        std::vector<std::string> names;
        getNames(*this, names, TYPE);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "externals")
    {
        std::vector<std::string> names;
        getNames(*this, names, EXTERNAL);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "softs")
    {
        std::vector<std::string> names;
        getNames(*this, names, SOFT);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "danglings")
    {
        std::vector<std::string> names;
        getNames(*this, names, DANGLING);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "hards")
    {
        std::vector<std::string> names;
        getNames(*this, names, HARD);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "links")
    {
        std::vector<std::string> names;
        std::vector<std::string> types;
        std::vector<std::string> linkstype;
        std::vector<const char *> _str;
        H5Object::getLinksInfo(*this, names, types, linkstype);
        _str.reserve(names.size() * 3);

        for (unsigned int i = 0; i < names.size(); i++)
        {
            _str.push_back(names[i].c_str());
        }
        for (unsigned int i = 0; i < names.size(); i++)
        {
            _str.push_back(linkstype[i].c_str());
        }
        for (unsigned int i = 0; i < names.size(); i++)
        {
            _str.push_back(types[i].c_str());
        }

        err = createMatrixOfString(pvApiCtx, pos, (int)names.size(), 3, &(_str[0]));
        if (err.iErr)
        {
            throw H5Exception(__LINE__, __FILE__, _("Cannot create a column of strings on the stack."));
        }

        return;
    }
    else
    {
        try
        {
            H5Object & obj = H5Object::getObject(*const_cast<H5Group *>(this), _name);
            obj.createOnScilabStack(pos, pvApiCtx);
            return;
        }
        catch (const H5Exception & /*e*/) { }
    }

    H5Object::getAccessibleAttribute(_name, pos, pvApiCtx);
}
Exemplo n.º 27
0
/*--------------------------------------------------------------------------*/
int C2F(sci_predef)(char *fname,unsigned long fname_len)
{
    int previous_n_var_protected = 0;

    Rhs = Max(0, Rhs);

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

    previous_n_var_protected = getNumberPredefVariablesProtected();

    if (Rhs == 0)
    {
        int one = 1 ,l = 0;

        CreateVar(Rhs+1, MATRIX_OF_INTEGER_DATATYPE, &one, &one,&l);
        *istk(l) = (int) previous_n_var_protected;

        LhsVar(1) = Rhs + 1;
        PutLhsVar();
    }
    else /* Rhs == 1 */
    {
        int *out_values = NULL;
        int nout = 0 , mout = 0;
        int new_n_var_protected = 0;

        if ( VarType(1) == sci_matrix )
        {
            int m1 = 0, n1 = 0, l1 = 0;
            GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1);
            if ( (m1 == n1) && (n1 == 1) )
            {
                double dn_var = *stk(l1);
                int n_var = (int) dn_var;

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

                setNumberPredefVariablesProtected(n_var);
            }
            else
            {
                Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"),fname,1);
                return 0;
            }
        }
        else if ( VarType(1) == sci_strings )
        {	
            int m1 = 0, n1 = 0, l1 = 0;
            char *protectMode = NULL;

            GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
            protectMode = cstk(l1);
            if (protectMode)
            {
                if ( ((strlen(protectMode) == 1 ) && (protectMode[0] == 'c')) ||
                    (strcmp(protectMode,"clear") == 0) )
                {
                    clearPredef();
                }
                else if ( ((strlen(protectMode) == 1 ) && (protectMode[0] == 'a')) ||
                    (strcmp(protectMode,"all") == 0) )
                {
                    predefAll();
                }
                else if (strcmp(protectMode,"names") == 0)
                {
                    int nbElements = 0;
                    char **variablesPredef = getPredefinedVariablesName(&nbElements);
                    if (variablesPredef && (nbElements > 0))
                    {
                        SciErr sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, nbElements, 1, variablesPredef);
                        freeArrayOfString(variablesPredef, nbElements);
                        variablesPredef = NULL;
                        if(sciErr.iErr)
                        {
                            printError(&sciErr, 0);
                            Scierror(999,_("%s: Memory allocation error.\n"), fname);
                        }
                        else
                        {
                            LhsVar(1) = Rhs + 1;
                            PutLhsVar();
                        }
                        return 0;
                    }
                    else
                    {
                        createEmptyMatrix(pvApiCtx, Rhs + 1);
                        LhsVar(1) = Rhs + 1;
                        PutLhsVar();
                        return 0;
                    }
                }
                else
                {
                    Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),fname,1,"clear","all");
                    return 0;
                }
            }
        }
        else
        {
            Scierror(999,_("%s: Wrong type for input argument #%d: A scalar or a string expected.\n"),fname,1);
            return 0;
        }

        new_n_var_protected = getNumberPredefVariablesProtected();

        out_values = (int*)MALLOC(sizeof(int)*2);
        out_values[0] = previous_n_var_protected;
        out_values[1] = new_n_var_protected;

        nout = 1 ; mout = 2;
        CreateVarFromPtr(Rhs+1,MATRIX_OF_INTEGER_DATATYPE, &nout, &mout, &out_values);
        if (out_values) {FREE(out_values); out_values = NULL;}

        LhsVar(1) = Rhs + 1;
        PutLhsVar();
    }
    return 0;
}
Exemplo n.º 28
0
/*--------------------------------------------------------------------------*/
int sci_gettext(char *fname, void* pvApiCtx)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    char* pstDomain = NULL;
    char **TranslatedStrings = NULL;
    int m = 0;
    int n = 0;
    char **StringsToTranslate = NULL;
    int i = 0;

    int iCurrentRhs = 1;

    int iRhs = nbInputArgument(pvApiCtx);
    int iLhs = nbOutputArgument(pvApiCtx);

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

    if (iRhs == 2)
    {
        //get domain name
        sciErr = getVarAddressFromPosition(pvApiCtx, iCurrentRhs, &piAddressVarOne);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, iCurrentRhs);
        }

        if (isStringType(pvApiCtx, piAddressVarOne) == 0 || isScalar(pvApiCtx, piAddressVarOne) == 0)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname, iCurrentRhs);
            return 0;
        }

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

        iCurrentRhs++;
    }

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

    if (isStringType(pvApiCtx, piAddressVarOne) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
        freeAllocatedSingleString(pstDomain);
        return 0;
    }

    if (getAllocatedMatrixOfString(pvApiCtx, piAddressVarOne, &m, &n, &StringsToTranslate) != 0)
    {
        Scierror(999, _("%s: No more memory.\n"), fname);
        freeAllocatedSingleString(pstDomain);
        return 0;
    }

    TranslatedStrings = (char **)MALLOC(sizeof(char*) * (m * n));
    if (TranslatedStrings == NULL)
    {
        Scierror(999, _("%s: No more memory.\n"), fname);
        freeAllocatedSingleString(pstDomain);
        freeAllocatedMatrixOfString(m, n, StringsToTranslate);
        StringsToTranslate = NULL;
        return 0;
    }

    for (i = 0; i < m * n; i++)
    {
        if (strcmp(StringsToTranslate[i], "") == 0)
        {
            TranslatedStrings[i] = strdup("");
        }
        else
        {
            //if pstDomain is NULL, default domain will be use
            TranslatedStrings[i] = convertString_dgettext(pstDomain, StringsToTranslate[i]);
        }
    }

    freeAllocatedSingleString(pstDomain);
    freeAllocatedMatrixOfString(m, n, StringsToTranslate);
    StringsToTranslate = NULL;

    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, TranslatedStrings);
    freeArrayOfString(TranslatedStrings, m * n);
    TranslatedStrings = NULL;

    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    LhsVar(1) = Rhs + 1;
    PutLhsVar();
    return 0;
}
    /*--------------------------------------------------------------------------*/
    int sci_getinstalledlookandfeels(char *fname, unsigned long fname_len)
    {
        SciErr sciErr;
        CheckInputArgument(pvApiCtx, 0, 0);
        CheckOutputArgument(pvApiCtx, 1, 1);

        org_scilab_modules_gui_utils::LookAndFeelManager * lnf = 0;
        try
        {
            lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM());
        }
        catch (const GiwsException::JniException & e)
        {
            Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str());
            return 1;
        }

        if (lnf)
        {
            char **lookandfeels = NULL;
            int nbElems = 0;
            int nbCol = 0;

            lookandfeels = lnf->getInstalledLookAndFeels();
            nbElems = lnf->numbersOfInstalledLookAndFeels();

            nbCol = 1;

            sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbElems, nbCol, lookandfeels);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            if (lookandfeels)
            {
                int i = 0;

                for (i = 0; i < nbElems; i++)
                {
                    if (lookandfeels[i])
                    {
                        delete[]lookandfeels[i];
                    }
                }
                delete[]lookandfeels;
                lookandfeels = NULL;
            }
            delete lnf;

            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            returnArguments(pvApiCtx);
        }
        else
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
        }
        return 0;
    }
Exemplo n.º 30
0
// =============================================================================
int sci_csvTextScan(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int iErr = 0;
    int i = 0;

    int *piAddressVarOne = NULL;
    int m1 = 0, n1 = 0;
    int iType1 = 0;

    char **text = NULL;
    int *lengthText = NULL;
    int nbLines = 0;

    char *separator = NULL;
    char *decimal = NULL;
    char *conversion = NULL;

    double * dRealValues = NULL;

    int *iRange = NULL;
    int haveRange = 0;

    csvResult *result = NULL;

    CheckRhs(1, 5);
    CheckLhs(1, 1);

    if (Rhs == 5)
    {
        int m5 = 0, n5 = 0;

        iRange = csv_getArgumentAsMatrixofIntFromDouble(pvApiCtx, 5, fname, &m5, &n5, &iErr);
        if (iErr)
        {
            return 0;
        }

        if ((m5 * n5 != SIZE_RANGE_SUPPORTED) )
        {
            if (iRange)
            {
                FREE(iRange);
                iRange = NULL;
            }
            Scierror(999, _("%s: Wrong size for input argument #%d: Four entries expected.\n"), fname, 5);
            return 0;
        }

        if ((m5 != 1) && (n5 != 1))
        {
            if (iRange)
            {
                FREE(iRange);
                iRange = NULL;
            }
            Scierror(999, _("%s: Wrong size for input argument #%d: A column or row vector expected.\n"), fname, 5);
            return 0;
        }

        if (isValidRange(iRange, m5 * n5))
        {
            haveRange = 1;
        }
        else
        {
            if (iRange)
            {
                FREE(iRange);
                iRange = NULL;
            }
            Scierror(999, _("%s: Wrong value for input argument #%d: Inconsistent range.\n"), fname, 5);
            return 0;
        }
    }

    if (Rhs >= 4)
    {
        conversion = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 4, fname, getCsvDefaultConversion(), &iErr);
        if (iErr)
        {
            if (iRange)
            {
                FREE(iRange);
                iRange = NULL;
            }
            return 0;
        }

        if (!((strcmp(conversion, CONVTOSTR) == 0) || (strcmp(conversion, CONVTODOUBLE) == 0)))
        {
            if (iRange)
            {
                FREE(iRange);
                iRange = NULL;
            }
            if (conversion)
            {
                FREE(conversion);
                conversion = NULL;
            }

            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' string expected.\n"), fname, 4, "double", "string");
            return 0;
        }
    }
    else
    {
        conversion = strdup(getCsvDefaultConversion());
    }

    if (Rhs >= 3)
    {
        decimal = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 3, fname, getCsvDefaultDecimal(), &iErr);
        if (iErr)
        {
            if (iRange)
            {
                FREE(iRange);
                iRange = NULL;
            }
            if (conversion)
            {
                FREE(conversion);
                conversion = NULL;
            }
            return 0;
        }

        if (decimal[0] != '.' && decimal[0] != ',')
        {
            if (iRange)
            {
                FREE(iRange);
                iRange = NULL;
            }
            if (conversion)
            {
                FREE(conversion);
                conversion = NULL;
            }

            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' string expected.\n"), fname, 3, ",", ".");
            return 0;
        }
    }
    else
    {
        decimal = strdup(getCsvDefaultDecimal());
    }

    if (Rhs >= 2)
    {
        separator = csv_getArgumentAsStringWithEmptyManagement(pvApiCtx, 2, fname, getCsvDefaultSeparator(), &iErr);
        if (iErr)
        {
            if (iRange)
            {
                FREE(iRange);
                iRange = NULL;
            }
            if (decimal)
            {
                FREE(decimal);
                decimal = NULL;
            }
            if (conversion)
            {
                FREE(conversion);
                conversion = NULL;
            }
            return 0;
        }
    }
    else
    {
        separator = strdup(getCsvDefaultSeparator());
    }

    if (!csv_isRowVector(pvApiCtx, 1) &&
            !csv_isColumnVector(pvApiCtx, 1) &&
            !csv_isScalar(pvApiCtx, 1))
    {
        if (iRange)
        {
            FREE(iRange);
            iRange = NULL;
        }
        if (separator)
        {
            FREE(separator);
            separator = NULL;
        }
        if (decimal)
        {
            FREE(decimal);
            decimal = NULL;
        }
        if (conversion)
        {
            FREE(conversion);
            conversion = NULL;
        }
        Scierror(999, _("%s: Wrong size for input argument #%d: Vector string expected.\n"), fname, 1);
        return 0;
    }

    text = csv_getArgumentAsMatrixOfString(pvApiCtx, 1, fname, &m1, &n1, &iErr);
    if (iErr)
    {
        if (iRange)
        {
            FREE(iRange);
            iRange = NULL;
        }
        if (separator)
        {
            FREE(separator);
            separator = NULL;
        }
        if (decimal)
        {
            FREE(decimal);
            decimal = NULL;
        }
        if (conversion)
        {
            FREE(conversion);
            conversion = NULL;
        }
        return 0;
    }

    nbLines = m1 * n1;
    result = csvTextScan((const char**)text, nbLines, separator, decimal);

    if (text)
    {
        if (separator)
        {
            FREE(separator);
            separator = NULL;
        }
        freeArrayOfString(text, nbLines);
        text = NULL;
    }

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

    if (result)
    {
        switch (result->err)
        {
            case CSV_READ_SEPARATOR_DECIMAL_EQUAL:
            {
                Scierror(999, _("%s: separator and decimal must have different values.\n"), fname);
            }
            break;

            case CSV_READ_NO_ERROR:
            {
                if (strcmp(conversion, CONVTOSTR) == 0)
                {
                    if (haveRange)
                    {
                        int newM = 0;
                        int newN = 0;

                        char **pStrRange = getRangeAsString((const char**)result->pstrValues, result->m, result->n, iRange, &newM, &newN);
                        if (pStrRange)
                        {
                            sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, newM, newN, pStrRange);
                            freeArrayOfString(pStrRange, newM * newN);
                        }
                        else
                        {
                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        }

                    }
                    else
                    {
                        sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, result->m, result->n, result->pstrValues);
                    }
                }
                else /* to double */
                {
                    stringToComplexError ierr = STRINGTOCOMPLEX_ERROR;
                    csv_complexArray *ptrCsvComplexArray = stringsToCsvComplexArray((const char**)result->pstrValues, result->m * result->n, decimal, TRUE, &ierr);
                    if (ptrCsvComplexArray == NULL)
                    {
                        freeCsvResult(result);
                        if (decimal)
                        {
                            FREE(decimal);
                            decimal = NULL;
                        }
                        if (conversion)
                        {
                            FREE(conversion);
                            conversion = NULL;
                        }
                        if (iRange)
                        {
                            FREE(iRange);
                            iRange = NULL;
                        }
                        if (ierr == STRINGTOCOMPLEX_ERROR)
                        {
                            Scierror(999, _("%s: can not convert data.\n"), fname);
                        }
                        else
                        {
                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        }
                        return 0;
                    }

                    switch (ierr)
                    {
                        case STRINGTOCOMPLEX_NOT_A_NUMBER:
                        case STRINGTOCOMPLEX_NO_ERROR:
                        {
                            if (haveRange)
                            {
                                int newM = 0;
                                int newN = 0;
                                csv_complexArray *csvComplexRange = getRangeAsCsvComplexArray(ptrCsvComplexArray, result->m, result->n, iRange, &newM, &newN);
                                if (csvComplexRange)
                                {
                                    if (csvComplexRange->isComplex)
                                    {
                                        sciErr = createComplexMatrixOfDouble(pvApiCtx, Rhs + 1, newM, newN, ptrCsvComplexArray->realPart, ptrCsvComplexArray->imagPart);
                                    }
                                    else
                                    {
                                        sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, newM, newN, csvComplexRange->realPart);
                                    }
                                    freeCsvComplexArray(csvComplexRange);
                                    csvComplexRange = NULL;
                                }
                                else
                                {
                                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                                }
                            }
                            else
                            {
                                if (ptrCsvComplexArray->isComplex)
                                {
                                    sciErr = createComplexMatrixOfDouble(pvApiCtx, Rhs + 1, result->m, result->n, ptrCsvComplexArray->realPart, ptrCsvComplexArray->imagPart);
                                }
                                else
                                {
                                    sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, result->m, result->n, ptrCsvComplexArray->realPart);
                                }
                            }
                            freeCsvComplexArray(ptrCsvComplexArray);
                            ptrCsvComplexArray = NULL;
                        }
                        break;

                        case STRINGTOCOMPLEX_MEMORY_ALLOCATION:
                        {
                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        }
                        default:
                        case STRINGTOCOMPLEX_ERROR:
                        {
                            Scierror(999, _("%s: can not convert data.\n"), fname);
                        }
                    }
                }

                if (sciErr.iErr)
                {
                    freeCsvResult(result);
                    if (decimal)
                    {
                        FREE(decimal);
                        decimal = NULL;
                    }
                    if (conversion)
                    {
                        FREE(conversion);
                        conversion = NULL;
                    }
                    if (iRange)
                    {
                        FREE(iRange);
                        iRange = NULL;
                    }
                    printError(&sciErr, 0);
                    Scierror(17, _("%s: Memory allocation error.\n"), fname);
                    return 0;
                }
                else
                {
                    LhsVar(1) = Rhs + 1;
                    PutLhsVar();
                }
            }
            break;

            case CSV_READ_MEMORY_ALLOCATION:
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
            }
            break;

            case CSV_READ_COLUMNS_ERROR:
            {
                Scierror(999, _("%s: can not read text: Error in the column structure\n"), fname);
            }
            break;

            case CSV_READ_READLINES_ERROR:
            case CSV_READ_ERROR:
            {
                Scierror(999, _("%s: can not read text.\n"), fname);
            }
            break;
        }
    }
    else
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
    }
    freeCsvResult(result);
    if (decimal)
    {
        FREE(decimal);
        decimal = NULL;
    }
    if (conversion)
    {
        FREE(conversion);
        conversion = NULL;
    }
    if (iRange)
    {
        FREE(iRange);
        iRange = NULL;
    }

    return 0;
}