Пример #1
0
/*--------------------------------------------------------------------------*/
int getAllocatedSingleWideString(void* _pvCtx, int* _piAddress, wchar_t** _pwstData)
{
    SciErr sciErr = sciErrInit();
    int iRows = 0;
    int iCols = 0;
    int iLen = 0;

    if (isScalar(_pvCtx, _piAddress) == 0 || isStringType(_pvCtx, _piAddress) == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_WIDE_STRING, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "getAllocatedSingleWideString", getRhsFromAddress(_pvCtx, _piAddress));
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    sciErr = getMatrixOfWideString(_pvCtx, _piAddress, &iRows, &iCols, &iLen, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_WIDE_STRING, _("%s: Unable to get argument data"), "getAllocatedSingleWideString");
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    *_pwstData = (wchar_t*)MALLOC(sizeof(wchar_t) * (iLen + 1)); //+1 for null termination

    sciErr = getMatrixOfWideString(_pvCtx, _piAddress, &iRows, &iCols, &iLen, _pwstData);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_WIDE_STRING, _("%s: Unable to get argument data"), "getAllocatedSingleWideString");
        printError(&sciErr, 0);
        FREE(*_pwstData);
        return sciErr.iErr;
    }

    return 0;
}
Пример #2
0
/*--------------------------------------------------------------------------*/
int getAllocatedMatrixOfWideString(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, wchar_t*** _pwstData)
{
    SciErr sciErr = getMatrixOfWideString(_pvCtx, _piAddress, _piRows, _piCols, NULL, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_WIDE_STRING_MATRIX, _("%s: Unable to get argument data"), "getAllocatedMatrixOfWideString");
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    int* piLen = (int*)MALLOC(sizeof(int) **_piRows **_piCols);

    sciErr = getMatrixOfWideString(_pvCtx, _piAddress, _piRows, _piCols, piLen, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_WIDE_STRING_MATRIX, _("%s: Unable to get argument data"), "getAllocatedMatrixOfWideString");
        if (piLen)
        {
            FREE(piLen);
            piLen = NULL;
        }
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    *_pwstData = (wchar_t**)MALLOC(sizeof(wchar_t*) **_piRows **_piCols);
    for (int i = 0 ; i < *_piRows **_piCols ; i++)
    {
        (*_pwstData)[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (piLen[i] + 1));//+1 for null termination
    }

    sciErr = getMatrixOfWideString(_pvCtx, _piAddress, _piRows, _piCols, piLen, *_pwstData);

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

    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_WIDE_STRING_MATRIX, _("%s: Unable to get argument data"), "getAllocatedMatrixOfWideString");
        printError(&sciErr, 0);
        for (int i = 0 ; i < *_piRows **_piCols ; i++)
        {
            FREE((*_pwstData)[i]);
        }
        FREE(*_pwstData);
        return sciErr.iErr;
    }
    return 0;
}
Пример #3
0
/*--------------------------------------------------------------------------*/
SciErr readNamedMatrixOfWideString(void* _pvCtx, const char* _pstName, int* _piRows, int* _piCols, int* _piwLength, wchar_t** _pwstStrings)
{
    int* piAddr = NULL;

    SciErr sciErr = getVarAddressFromName(_pvCtx, _pstName, &piAddr);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_READ_NAMED_WIDE_STRING, _("%s: Unable to get variable \"%s\""), "readNamedMatrixOfWideString", _pstName);
        return sciErr;
    }

    sciErr = getMatrixOfWideString(_pvCtx, piAddr, _piRows, _piCols, _piwLength, _pwstStrings);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_READ_NAMED_WIDE_STRING, _("%s: Unable to get variable \"%s\""), "readNamedMatrixOfWideString", _pstName);
        return sciErr;
    }

    return sciErr;
}
Пример #4
0
/*--------------------------------------------------------------------------*/
int sci_Playsound (char *fname,unsigned long fname_len)
{
	SciErr sciErr;
	int *piAddressVarOne = NULL;
	wchar_t *pStVarOne = NULL;
	int iType1 = 0;
	int lenStVarOne = 0;
	int m1 = 0, n1 = 0;
	wchar_t *expandedPath = NULL;

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

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

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

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

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

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

	pStVarOne = (wchar_t*)MALLOC(sizeof(wchar_t)*(lenStVarOne + 1));
	if (pStVarOne == NULL)
	{
		Scierror(999,_("%s: Memory allocation error.\n"),fname);
		return 0;
	}

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

	expandedPath = expandPathVariableW(pStVarOne);
	if (pStVarOne) {FREE(pStVarOne); pStVarOne = NULL;}

#ifdef _MSC_VER
	{
		if (expandedPath)
		{
			playsound(expandedPath);
			FREE(expandedPath);
			expandedPath = NULL;
		}
		
		LhsVar(1) = 0;
		PutLhsVar();
	}
#else
	{
		if (expandedPath) {FREE(expandedPath); expandedPath = NULL;}
		Scierror(999,_("%s: An error occurred: %s\n"),fname,_("Cannot play file.") );
	}
#endif
	return 0;
}
Пример #5
0
/*--------------------------------------------------------------------------*/
int sci_basename(char *fname,unsigned long fname_len)
{
	SciErr sciErr;
	BOOL flagexpand = TRUE; /* default */

	int *piAddressVarOne = NULL;
	wchar_t **pStVarOne = NULL;
	int *lenStVarOne = NULL;
	int iType1					= 0;
	int m1 = 0, n1 = 0;

	wchar_t **pStResult = NULL;

	/* Check Input & Output parameters */
	CheckRhs(1,3);
	CheckLhs(1,1);

	if (Rhs > 2)
	{
		int *piAddressVarThree = NULL;
		int *piData = NULL;
		int iType3	= 0;
		int m3 = 0, n3 = 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;
		}

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

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

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

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

		if ( (m3 != n3) && (n3 != 1) ) 
		{
			Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
			return 0;
		}

		flagexpand = piData[0];
	}

	if (Rhs > 1)
	{
		int *piAddressVarTwo = NULL;
		int *piData = NULL;
		int iType2	= 0;
		int m2 = 0, n2 = 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;
		}

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

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

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

		if ( (m2 != n2) && (n2 != 1) ) 
		{
			Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2);
			return 0;
		}

		sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarTwo, &m2, &n2,  &piData);
		if(sciErr.iErr)
		{
			printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\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;
	}

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

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

		if ( (m1 == n1) && (m1 == 0) )
		{
			sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, 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: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
		}
	}
	else if (iType1 == sci_strings)
	{
		int i = 0;

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

		lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));
		if (lenStVarOne == NULL)
		{
			Scierror(999,_("%s: Memory allocation error.\n"),fname);
			return 0;
		}

		// get lenStVarOne value
		sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, NULL);
		if(sciErr.iErr)
		{
			freeArrayOfWideString(pStVarOne, m1 * n1);
			if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
			printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
			return 0;
		}

		pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
		if (pStVarOne == NULL)
		{
			if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
			Scierror(999,_("%s: Memory allocation error.\n"),fname);
			return 0;
		}

		for (i = 0; i < (m1 * n1); i++)
		{
			pStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));
			if (pStVarOne[i] == NULL)
			{
				freeArrayOfWideString(pStVarOne, m1 * n1);
				if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
				Scierror(999,_("%s: Memory allocation error.\n"),fname);
				return 0;
			}
		}

		// get pStVarOne
		sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
		if(sciErr.iErr)
		{
			freeArrayOfWideString(pStVarOne, m1 * n1);
			if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
			printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
			return 0;
		}

		pStResult = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));

		if (pStResult == NULL)
		{
			if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
			Scierror(999,_("%s: Memory allocation error.\n"),fname);
			return 0;
		}

		for (i=0;i< m1 * n1; i++)
		{
			pStResult[i] = basenameW(pStVarOne[i], flagexpand);
		}

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

		LhsVar(1) = Rhs + 1;

		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
		freeArrayOfWideString(pStResult, m1 * n1);
		freeArrayOfWideString(pStVarOne, m1 * n1);

        PutLhsVar();

	}
	else
	{
		Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
	}
	return 0;
}
Пример #6
0
/*--------------------------------------------------------------------------*/
int sci_isdir(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    wchar_t **pStVarOne = NULL;
    int iType = 0;
    int *lenStVarOne = NULL;
    int m1 = 0, n1 = 0;

    BOOL *results = NULL;
    int i = 0;

    /* Check Input & Output parameters */
    CheckRhs(1, 1);
    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);
        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 (iType != sci_strings)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
        return 0;
    }

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

    lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));
    if (lenStVarOne == NULL)
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    results = (BOOL*)MALLOC(sizeof(BOOL) * (m1 * n1));
    if (results == NULL)
    {
        if (lenStVarOne)
        {
            FREE(lenStVarOne);
            lenStVarOne = NULL;
        }
        freeArrayOfWideString(pStVarOne, m1 * n1);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, NULL);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        FREE(results);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 0;
    }

    pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
    if (pStVarOne == NULL)
    {
        FREE(lenStVarOne);
        lenStVarOne = NULL;
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    for (i = 0; i < m1 * n1; i++)
    {
        pStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));
        if (pStVarOne[i] == NULL)
        {
            freeArrayOfWideString(pStVarOne, m1 * n1);
            if (lenStVarOne)
            {
                FREE(lenStVarOne);
                lenStVarOne = NULL;
            }
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }
    }

    sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
    if (sciErr.iErr)
    {
        freeArrayOfWideString(pStVarOne, m1 * n1);
        if (lenStVarOne)
        {
            FREE(lenStVarOne);
            lenStVarOne = NULL;
        }
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 0;
    }

    for (i = 0; i < m1 * n1; i++)
    {
        wchar_t *expandedPath = expandPathVariableW(pStVarOne[i]);
        if (expandedPath)
        {
            results[i] = isdirW(expandedPath);
            FREE(expandedPath);
            expandedPath = NULL;
        }
        else
        {
            results[i] = FALSE;
        }
    }

    if (lenStVarOne)
    {
        FREE(lenStVarOne);
        lenStVarOne = NULL;
    }
    freeArrayOfWideString(pStVarOne, m1 * n1);

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

    LhsVar(1) = Rhs + 1;

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

    PutLhsVar();
    return 0;
}
Пример #7
0
/*--------------------------------------------------------------------------*/
static int isasciiStrings(char *fname, int *piAddressVarOne)
{
    SciErr sciErr;
    int m1 = 0, n1 = 0;
    wchar_t **pwcStVarOne = NULL;
    int *lenStVarOne = NULL;

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

    lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));

    if (lenStVarOne)
    {
        BOOL *bOutputMatrix = NULL;
        int i = 0;
        int lengthAllStrings = 0;

        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, NULL);
        if (sciErr.iErr)
        {
            if (lenStVarOne)
            {
                FREE(lenStVarOne);
                lenStVarOne = NULL;
            }

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

        pwcStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
        for (i = 0; i < (m1 * n1); i++)
        {
            lengthAllStrings = lengthAllStrings + lenStVarOne[i];

            pwcStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));

            if (pwcStVarOne[i] == NULL)
            {
                if (lenStVarOne)
                {
                    FREE(lenStVarOne);
                    lenStVarOne = NULL;
                }

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

        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pwcStVarOne);
        if (sciErr.iErr)
        {
            if (lenStVarOne)
            {
                FREE(lenStVarOne);
                lenStVarOne = NULL;
            }

            freeArrayOfWideString(pwcStVarOne, m1 * n1);
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            return 0;
        }

        bOutputMatrix = (BOOL*)MALLOC(sizeof(BOOL) * lengthAllStrings);
        if (bOutputMatrix)
        {
            int mOut = 0;
            int nOut = 0;
            int x = 0;

            for (i = 0; i < (m1 * n1); i++)
            {
                int j = 0;
                wchar_t* wcInput = pwcStVarOne[i];
                int len = (int)wcslen(wcInput);

                for (j = 0; j < len; j++)
                {
                    if (iswascii(wcInput[j]))
                    {
                        bOutputMatrix[x] = (int)TRUE;
                    }
                    else
                    {
                        bOutputMatrix[x] = (int)FALSE;
                    }
                    x++;
                }
            }

            mOut = 1;
            nOut = lengthAllStrings;

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

            if (lenStVarOne)
            {
                FREE(lenStVarOne);
                lenStVarOne = NULL;
            }
            freeArrayOfWideString(pwcStVarOne, m1 * n1);
            if (bOutputMatrix)
            {
                FREE(bOutputMatrix);
                bOutputMatrix = NULL;
            }

            LhsVar(1) = Rhs + 1;
            PutLhsVar();
        }
        else
        {
            if (lenStVarOne)
            {
                FREE(lenStVarOne);
                lenStVarOne = NULL;
            }
            freeArrayOfWideString(pwcStVarOne, m1 * n1);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
        }
    }
    else
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
    }
    return 0;
}
Пример #8
0
/*--------------------------------------------------------------------------*/
int sci_scinotes(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

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

    if (Rhs == 0)
    {
        try
        {
            callSciNotesW(NULL, 0);
        }
        catch (GiwsException::JniCallMethodException exception)
        {
            Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
        }
        catch (GiwsException::JniException exception)
        {
            Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
        }
    }
    else
    {
        int m1 = 0, n1 = 0;
        int *piAddressVarOne = NULL;
        wchar_t **pStVarOne = NULL;
        int *lenStVarOne = NULL;
        int i = 0;
        int iType1 = 0;
        char *functionName = NULL;

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

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

        if (iType1 != sci_strings)
        {
            Scierror(999, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1);
            return 0;
        }

        /* get dimensions */
        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            return 0;
        }

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

        /* get lengths */
        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            FREE(lenStVarOne);
            return 0;
        }

        pStVarOne = (wchar_t **) MALLOC(sizeof(wchar_t *) * (m1 * n1));
        if (pStVarOne == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
            FREE(lenStVarOne);
            return 0;
        }

        for (i = 0; i < m1 * n1; i++)
        {
            pStVarOne[i] = (wchar_t *) MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));
            if (pStVarOne[i] == NULL)
            {
                Scierror(999, _("%s: No more memory.\n"), fname);
                for (; i >= 0; i--)
                {
                    FREE(pStVarOne[i]);
                }
                FREE(pStVarOne);
                FREE(lenStVarOne);
                return 0;
            }
        }

        /* get strings */
        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            freeArrayOfWideString(pStVarOne, m1 * n1);
            FREE(lenStVarOne);
            return 0;
        }

        if (Rhs >= 2)           //get line numbers
        {
            int *piAddressVarTwo = NULL;
            int m2 = 0, n2 = 0;
            double *pdblVarTwo = NULL;
            int iType2 = 0;

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

            sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
                freeArrayOfWideString(pStVarOne, m1 * n1);
                FREE(lenStVarOne);
                return 0;
            }

            if (iType2 != sci_matrix && iType2 != sci_strings)
            {
                Scierror(999, _("%s: Wrong type for argument #%d: Real matrix or \'readonly\' expected.\n"), fname, 2);
                freeArrayOfWideString(pStVarOne, m1 * n1);
                FREE(lenStVarOne);
                return 0;
            }

            if (iType2 == sci_strings)
            {
                /* get dimensions */
                wchar_t **pStVarTwo = NULL;
                int *lenStVarTwo = NULL;

                sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, NULL);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                if (m2 != 1 || n2 != 1)
                {
                    Scierror(999, _("%s: Wrong type for argument #%d: Real matrix or \'readonly\' expected.\n"), fname, 2);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                lenStVarTwo = (int *)MALLOC(sizeof(int));
                if (lenStVarTwo == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), fname);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                /* get lengths */
                sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, pStVarTwo);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
                    FREE(lenStVarTwo);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                pStVarTwo = (wchar_t **) MALLOC(sizeof(wchar_t *));
                if (pStVarTwo == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), fname);
                    FREE(lenStVarTwo);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                pStVarTwo[0] = (wchar_t *) MALLOC(sizeof(wchar_t) * (lenStVarTwo[0] + 1));
                if (pStVarTwo[0] == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), fname);
                    FREE(pStVarTwo);
                    FREE(lenStVarTwo);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                /* get strings */
                sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo, &m2, &n2, lenStVarTwo, pStVarTwo);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
                    FREE(pStVarTwo);
                    FREE(lenStVarTwo);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                try
                {
                    callSciNotesWWithOption(pStVarOne, pStVarTwo, m1 * n1);
                }
                catch (GiwsException::JniCallMethodException exception)
                {
                    Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
                    FREE(pStVarTwo);
                    FREE(lenStVarTwo);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }
                catch (GiwsException::JniException exception)
                {
                    Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
                    FREE(pStVarTwo);
                    FREE(lenStVarTwo);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }
                freeArrayOfWideString(pStVarTwo, 1);
                FREE(lenStVarTwo);
            }
            else
            {
                if (isVarComplex(pvApiCtx, piAddressVarTwo) == 1)
                {
                    Scierror(999, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), fname, 2);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarTwo, &m2, &n2, &pdblVarTwo);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                if (m2 * n2 != m1 * n1)
                {
                    Scierror(999, _("%s: Wrong size for input arguments #%d and #%d: Same dimensions expected.\n"), fname, 1, 2);
                    freeArrayOfWideString(pStVarOne, m1 * n1);
                    FREE(lenStVarOne);
                    return 0;
                }

                if (Rhs == 3)
                {
                    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 (!isStringType(pvApiCtx, piAddressVarThree))
                    {
                        Scierror(999, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 3);
                        freeArrayOfWideString(pStVarOne, m1 * n1);
                        FREE(lenStVarOne);
                        return 0;
                    }

                    int ret = getAllocatedSingleString(pvApiCtx, piAddressVarThree, &functionName);

                    if (ret)
                    {
                        Scierror(999, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 3);
                        freeArrayOfWideString(pStVarOne, m1 * n1);
                        FREE(lenStVarOne);
                        return 0;
                    }
                }

                try
                {
                    callSciNotesWWithLineNumberAndFunction(pStVarOne, pdblVarTwo, functionName, m1 * n1);
                }
                catch (GiwsException::JniCallMethodException exception)
                {
                    Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
                }
                catch (GiwsException::JniException exception)
                {
                    Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
                }
            }
        }
        else
        {
            try
            {
                callSciNotesW(pStVarOne, m1 * n1);
            }
            catch (GiwsException::JniCallMethodException exception)
            {
                Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
            }
            catch (GiwsException::JniException exception)
            {
                Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
            }
        }

        freeArrayOfWideString(pStVarOne, m1 * n1);
        FREE(lenStVarOne);
        if (functionName)
        {
            freeAllocatedSingleString(functionName);
        }
    }

    LhsVar(1) = 0;
    PutLhsVar();
    return 0;
}
Пример #9
0
/*--------------------------------------------------------------------------*/
int sci_chdir(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    wchar_t *pStVarOne = NULL;
    int iType1	= 0;
    int lenStVarOne = 0;
    int m1 = 0, n1 = 0;

    wchar_t *expandedPath = NULL;

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

    if (Rhs == 0)
    {
        pStVarOne = (wchar_t*)MALLOC(sizeof(wchar_t) * ((int)wcslen(L"home") + 1));
        if (pStVarOne)
        {
            wcscpy(pStVarOne, L"home");
        }
    }
    else
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            return 0;
        }

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

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

        // get value of lenStVarOne
        sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, &lenStVarOne, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            return 0;
        }

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

        pStVarOne = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne + 1));
        if (pStVarOne == NULL)
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }

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

    expandedPath = expandPathVariableW(pStVarOne);
    if (pStVarOne)
    {
        FREE(pStVarOne);
        pStVarOne = NULL;
    }

    if (expandedPath)
    {
        /* get value of PWD scilab variable (compatiblity scilab 4.x) */
        if (wcscmp(expandedPath, L"PWD") == 0)
        {
            sciErr = getNamedVarType(pvApiCtx, "PWD", &iType1);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Can not read named argument %s.\n"), fname, "PWD");
                return 0;
            }

            if (iType1 == sci_strings)
            {
                wchar_t *VARVALUE = NULL;
                int VARVALUElen = 0;
                int m = 0, n = 0;
                sciErr = readNamedMatrixOfWideString(pvApiCtx, "PWD", &m, &n, &VARVALUElen, &VARVALUE);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Can not read named argument %s.\n"), fname, "PWD");
                    return 0;
                }

                if ( (m == 1) && (n == 1) )
                {
                    VARVALUE = (wchar_t*)MALLOC(sizeof(wchar_t) * (VARVALUElen + 1));
                    if (VARVALUE)
                    {
                        readNamedMatrixOfWideString(pvApiCtx, "PWD", &m, &n, &VARVALUElen, &VARVALUE);
                        FREE(expandedPath);
                        expandedPath = VARVALUE;
                    }
                }
            }
        }

        if (strcmp(fname, "chdir") == 0) /* chdir output boolean */
        {
            BOOL *bOutput = (BOOL*)MALLOC(sizeof(BOOL));

            int ierr = scichdirW(expandedPath);

            if (ierr)
            {
                bOutput[0] = FALSE;
            }
            else
            {
                bOutput[0] = TRUE;
            }

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

            LhsVar(1) = Rhs + 1;

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

            PutLhsVar();
        }
        else /* cd output string current path */
        {
            if ( isdirW(expandedPath) || (wcscmp(expandedPath, L"/") == 0) ||
                    (wcscmp(expandedPath, L"\\") == 0) )
            {
                int ierr = scichdirW(expandedPath);
                wchar_t *currentDir = scigetcwdW(&ierr);
                if ( (ierr == 0) && currentDir)
                {
                    sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 1, 1, 1, &currentDir);
                }
                else
                {
                    sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 0, 0, NULL);
                }

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

                LhsVar(1) = Rhs + 1;
                if (currentDir)
                {
                    FREE(currentDir);
                    currentDir = NULL;
                }
                PutLhsVar();
            }
            else
            {
                char *path = wide_string_to_UTF8(expandedPath);
                if (path)
                {
                    Scierror(998, _("%s: Cannot go to directory %s\n"), fname, path);
                    FREE(path);
                    path = NULL;
                }
                else
                {
                    Scierror(998, _("%s: Cannot go to directory.\n"), fname);
                }
            }
        }

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

    return 0;
}