コード例 #1
0
/*--------------------------------------------------------------------------*/
int createSingleWideString(void* _pvCtx, int _iVar, const wchar_t* _pwstStrings)
{
    SciErr sciErr = createMatrixOfWideString(_pvCtx, _iVar, 1, 1,	&_pwstStrings);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_SINGLE_WIDE_STRING, _("%s: Unable to get argument data"), "createSingleWideString");
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    return 0;
}
コード例 #2
0
ファイル: sci_strchr.c プロジェクト: ASP1234/Scilabv5.5.2
/*----------------------------------------------------------------------------*/
int sci_strchr(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int iErr = 0;

    wchar_t **pStrVarOne = NULL;
    int m1 = 0;
    int n1 = 0;

    wchar_t **pStrVarTwo = NULL;
    int m2 = 0;
    int n2 = 0;

    int i = 0;
    BOOL do_strchr = (strcmp(fname, "strchr") == 0);

    wchar_t **wcOutput_Strings = NULL;

    pStrVarOne = getInputArgumentAsMatrixOfWideString(pvApiCtx, 1, fname, &m1, &n1, &iErr);
    if (iErr)
    {
        if (pStrVarOne)
        {
            freeAllocatedMatrixOfWideString(m1, n1, pStrVarOne);
        }
        return 0;
    }

    pStrVarTwo = getInputArgumentAsMatrixOfWideString(pvApiCtx, 2, fname, &m2, &n2, &iErr);
    if (iErr)
    {
        if (pStrVarOne)
        {
            freeAllocatedMatrixOfWideString(m1, n1, pStrVarOne);
        }

        if (pStrVarTwo)
        {
            freeAllocatedMatrixOfWideString(m2, n2, pStrVarTwo);
        }
        return 0;
    }

    for (i = 0; i < m2 * n2; i++)
    {
        if (wcslen(pStrVarTwo[i]) != 1)
        {
            freeAllocatedMatrixOfWideString(m1, n1, pStrVarOne);
            freeAllocatedMatrixOfWideString(m2, n2, pStrVarTwo);
            Scierror(999, _("%s: Wrong size for input argument #%d: A character expected.\n"), fname, 2);
            return 0;
        }
    }

    wcOutput_Strings = strings_wcsrchr((const wchar_t**)pStrVarOne, m1 * n1, (const wchar_t**)pStrVarTwo, m2 * n2, do_strchr);
    freeAllocatedMatrixOfWideString(m1, n1, pStrVarOne);
    freeAllocatedMatrixOfWideString(m2, n2, pStrVarTwo);

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

    sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 1 , m1, n1, wcOutput_Strings);
    freeAllocatedMatrixOfWideString(m1, n1, wcOutput_Strings);

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

    LhsVar(1) = Rhs + 1 ;
    PutLhsVar();
    return 0;
}
コード例 #3
0
ファイル: sci_movefile.c プロジェクト: ZhanlinWang/scilab
/*--------------------------------------------------------------------------*/
static int returnMoveFileResultOnStack(int ierr, char *fname)
{
    double dError = 0.;
    wchar_t **sciError = NULL;
    int m_out = 1, n_out = 1;

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

#ifdef _MSC_VER
    if (ierr)
    {
#define BUFFER_SIZE 1024
        DWORD dw = GetLastError();
        wchar_t buffer[BUFFER_SIZE];

        if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
                           dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, BUFFER_SIZE, NULL) == 0)
        {
            wcscpy(buffer, L"Unknown Error");
        }

        // for compatibilty with copyfile, we return 0 (error)
        //dError = (double) dw;
        dError = (double)0;

        sciError[0] = (wchar_t *) MALLOC(sizeof(wchar_t) * ((int)wcslen(buffer) + 1));
        if (sciError[0] == NULL)
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }

        wcscpy(sciError[0], buffer);
    }
    else
    {
        dError = 1.;
        sciError[0] = (wchar_t *) MALLOC(sizeof(wchar_t) * 1);
        if (sciError[0] == NULL)
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }
        wcscpy(sciError[0], L"");
    }
#else
    if (ierr)
    {
        // for compatibilty with copyfile, we return 0 (error)
        //dError = (double) ierr;
        dError = (double)0.;

        sciError[0] = to_wide_string(strerror(errno));
        if (sciError[0] == NULL)
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }
    }
    else
    {
        dError = 1.;
        sciError[0] = (wchar_t *) MALLOC(sizeof(wchar_t) * 1);
        if (sciError[0] == NULL)
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            freeArrayOfWideString(sciError, 1);
            return 0;
        }
        wcscpy(sciError[0], L"");
    }
#endif

    createMatrixOfDouble(pvApiCtx, Rhs + 1, m_out, n_out, &dError);
    LhsVar(1) = Rhs + 1;

    if (Lhs == 2)
    {
        createMatrixOfWideString(pvApiCtx, Rhs + 2, m_out, n_out, sciError);
        LhsVar(2) = Rhs + 2;
    }

    freeArrayOfWideString(sciError, 1);

    PutLhsVar();
    return 0;
}
コード例 #4
0
ファイル: sci_basename.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/
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;
}
コード例 #5
0
int sci_hdf5_load_v2(char *fn, int* pvApiCtx)
{
    SciErr sciErr;

    int* piAddr = NULL;
    char* pstFilename = NULL;
    char* pstExpandedFilename = NULL;
    bool bImport = true;
    const int nbIn = nbInputArgument(pvApiCtx);
    int iSelectedVar = nbIn - 1;

    CheckInputArgumentAtLeast(pvApiCtx , 1);
    CheckOutputArgument(pvApiCtx, 1, 1);

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

    if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFilename))
    {
        if (pstFilename)
        {
            freeAllocatedSingleString(pstFilename);
        }

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

    //open hdf5 file
    pstExpandedFilename = expandPathVariable(pstFilename);
    int iFile = openHDF5File(pstExpandedFilename, 0);
    if (iFile < 0)
    {
        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), pstFilename);
        FREE(pstExpandedFilename);
        FREE(pstFilename);
        return 1;
    }

    FREE(pstExpandedFilename);
    FREE(pstFilename);

    //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 !
            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion);
            return 1;
        }
        else
        {
            //call older import functions and exit or ... EXIT !
            if (iVersion == 1 || iVersion == -1)
            {
                return sci_hdf5_load_v1(fn, pvApiCtx);
            }
        }
    }

    std::vector<wchar_t*> varList;
    if (iSelectedVar)
    {
        //selected variable
        char* pstVarName = NULL;
        for (int i = 0 ; i < iSelectedVar ; i++)
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, i + 2, &piAddr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            if (getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName))
            {
                if (pstVarName)
                {
                    freeAllocatedSingleString(pstVarName);
                }

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

            if (import_variable(pvApiCtx, iFile, pstVarName) == false)
            {
                FREE(pstVarName);
                bImport = false;
                break;
            }

            varList.push_back(to_wide_string(pstVarName));
            FREE(pstVarName);
            pstVarName = NULL;
        }
    }
    else
    {
        //all variables
        int iNbItem = 0;
        iNbItem = getVariableNames(iFile, NULL);
        if (iNbItem != 0)
        {
            char **pstVarNameList = (char **)MALLOC(sizeof(char *) * iNbItem);

            iNbItem = getVariableNames(iFile, pstVarNameList);

            //import all data
            for (int i = 0; i < iNbItem; i++)
            {
                if (import_variable(pvApiCtx, iFile, pstVarNameList[i]) == false)
                {
                    bImport = false;
                    break;
                }

                varList.push_back(to_wide_string(pstVarNameList[i]));
            }

            freeArrayOfString(pstVarNameList, iNbItem);
        }
    }
    //close the file
    closeHDF5File(iFile);

    if (bImport == true && varList.size() != 0)
    {
        createMatrixOfWideString(pvApiCtx, nbIn + 1, 1, static_cast<int>(varList.size()), varList.data());
    }
    else
    {
        createEmptyMatrix(pvApiCtx, nbIn + 1);
    }

    for (auto & i : varList)
    {
        FREE(i);
    }

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

    //  printf("End gateway !!!\n");
    return 0;
}
コード例 #6
0
int sci_hdf5_load_v1(char *fn, int* pvApiCtx)
{
    SciErr sciErr;

    int* piAddr = NULL;
    char* pstFilename = NULL;
    char* pstExpandedFilename = NULL;
    bool bImport = true;

    const int nbIn = Rhs;
    int iSelectedVar = Rhs - 1;

    CheckInputArgumentAtLeast(pvApiCtx, 1);
    CheckOutputArgument(pvApiCtx, 1, 1);

    iCloseList = 0;

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

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

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

    //open hdf5 file
    pstExpandedFilename = expandPathVariable(pstFilename);
    int iFile = openHDF5File(pstExpandedFilename, 0);
    if (iFile < 0)
    {
        FREE(pstExpandedFilename);
        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), pstFilename);
        FREE(pstFilename);
        return 1;
    }

    FREE(pstExpandedFilename);
    FREE(pstFilename);

    std::vector<wchar_t*> varList;
    if (iSelectedVar)
    {
        //selected variable
        char* pstVarName = NULL;
        for (int i = 0 ; i < iSelectedVar ; i++)
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, i + 2, &piAddr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

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

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

            if (import_variable_v1(pvApiCtx, iFile, pstVarName) == false)
            {
                FREE(pstVarName);
                bImport = false;
                break;
            }

            varList.push_back(to_wide_string(pstVarName));
            FREE(pstVarName);
            pstVarName = NULL;
        }
    }
    else
    {
        //all variables
        int iNbItem = 0;
        iNbItem = getVariableNames_v1(iFile, NULL);
        if (iNbItem != 0)
        {
            char **pstVarNameList = (char **)MALLOC(sizeof(char *) * iNbItem);

            iNbItem = getVariableNames_v1(iFile, pstVarNameList);

            //import all data
            for (int i = 0; i < iNbItem; i++)
            {
                if (import_variable_v1(pvApiCtx, iFile, pstVarNameList[i]) == false)
                {
                    bImport = false;
                    break;
                }

                varList.push_back(to_wide_string(pstVarNameList[i]));
            }

            freeArrayOfString(pstVarNameList, iNbItem);
        }
    }
    //close the file
    closeHDF5File(iFile);

    if (bImport == true && varList.size() != 0)
    {
        createMatrixOfWideString(pvApiCtx, nbIn + 1, 1, static_cast<int>(varList.size()), varList.data());
    }
    else
    {
        createEmptyMatrix(pvApiCtx, nbIn + 1);
    }

    for (auto & i : varList)
    {
        FREE(i);
    }

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

    //  printf("End gateway !!!\n");
    return 0;
}
コード例 #7
0
ファイル: sci_chdir.c プロジェクト: quanpan302/scilab
/*--------------------------------------------------------------------------*/
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;
}