Example #1
0
/*--------------------------------------------------------------------------*/
int sci_tempname(char *fname, void* pvApiCtx)
{
    SciErr sciErr;
    wchar_t *wcprefix = NULL;
    wchar_t *wcTempFilename = NULL;

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

    if (Rhs == 0)
    {
        wcprefix = (wchar_t *)MALLOC(sizeof(wchar_t) * (wcslen(DEFAULT_PREFIX) + 1));
        wcscpy(wcprefix, DEFAULT_PREFIX);
    }
    else
    {
        int *piAddressVarOne = 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;
        }

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

        if (isStringType(pvApiCtx, piAddressVarOne))
        {
            if (getAllocatedSingleWideString(pvApiCtx, piAddressVarOne, &wcprefix))
            {
                if (wcprefix)
                {
                    freeAllocatedSingleWideString(wcprefix);
                }

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

#if _MSC_VER
            if (wcslen(wcprefix) > 3)
            {
                freeAllocatedSingleWideString(wcprefix);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string (3 characters max.) expected.\n"), fname, 1);
                return 0;
            }
#endif
        }
        else
        {
            freeAllocatedSingleWideString(wcprefix);
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
            return 0;
        }
    }

    wcTempFilename = createtempfilenameW(wcprefix, TRUE);
    freeAllocatedSingleWideString(wcprefix);
    if (wcTempFilename == NULL)
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    if (createSingleWideString(pvApiCtx, Rhs + 1, wcTempFilename))
    {
        FREE(wcTempFilename);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    FREE(wcTempFilename);
    LhsVar(1) = Rhs + 1;
    PutLhsVar();
    return 0;
}
Example #2
0
/*--------------------------------------------------------------------------*/
int sci_movefile(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    wchar_t *pStVarOne = NULL;
    wchar_t *pStVarOneExpanded = NULL;

    int *piAddressVarTwo = NULL;
    wchar_t *pStVarTwo = NULL;
    wchar_t *pStVarTwoExpanded = NULL;

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

    if (!isScalar(pvApiCtx, piAddressVarOne))
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A 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))
    {
        if (pStVarOne)
        {
            FREE(pStVarOne);
            pStVarOne = NULL;
        }
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
        return 0;
    }

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

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

    if (getAllocatedSingleWideString(pvApiCtx, piAddressVarTwo, &pStVarTwo))
    {
        if (pStVarOne)
        {
            freeAllocatedSingleWideString(pStVarOne);
            pStVarOne = NULL;
        }
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    pStVarOneExpanded = expandPathVariableW(pStVarOne);
    pStVarTwoExpanded = expandPathVariableW(pStVarTwo);

    freeAllocatedSingleWideString(pStVarTwo);
    pStVarTwo = NULL;

    freeAllocatedSingleWideString(pStVarOne);
    pStVarOne = NULL;

    if (isdirW(pStVarOneExpanded) || FileExistW(pStVarOneExpanded))
    {
        int ierrMove = 0;

        if (isdirW(pStVarOneExpanded))
        {
            /* move a directory into a directory */
            ierrMove = MoveDirectoryFunction(pStVarTwoExpanded, pStVarOneExpanded);
        }
        else if (FileExistW(pStVarOneExpanded))
        {
            if (isdirW(pStVarTwoExpanded))
            {
                /* move file into a existing directory */
                /* copy file into a existing directory */
                wchar_t *filename = getFilenameWithExtensionForMove(pStVarOneExpanded);

                if (filename)
                {
#define FORMAT_FULLFILENAME "%s/%s"
                    wchar_t *destFullFilename = NULL;

                    /* remove last file separator if it exists */
                    if ((pStVarTwoExpanded[wcslen(pStVarTwoExpanded) - 1] == L'\\') || (pStVarTwoExpanded[wcslen(pStVarTwoExpanded) - 1] == L'/'))
                    {
                        pStVarTwoExpanded[wcslen(pStVarTwoExpanded) - 1] = L'\0';
                    }

                    destFullFilename = (wchar_t *) MALLOC(sizeof(wchar_t) * ((int)wcslen(pStVarTwoExpanded) + (int)wcslen(filename) + (int)wcslen(L"/") + 1));
                    wcscpy(destFullFilename, pStVarTwoExpanded);
                    wcscat(destFullFilename, L"/");
                    wcscat(destFullFilename, filename);

                    ierrMove = MoveFileFunction(destFullFilename, pStVarOneExpanded);

                    FREE(filename);
                    filename = NULL;
                    FREE(destFullFilename);
                    destFullFilename = NULL;
                }
                else
                {
                    if (pStVarOneExpanded)
                    {
                        FREE(pStVarOneExpanded);
                        pStVarOneExpanded = NULL;
                    }
                    if (pStVarTwoExpanded)
                    {
                        FREE(pStVarTwoExpanded);
                        pStVarTwoExpanded = NULL;
                    }

                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 0;
                }
            }
            else
            {
                /* move a file into a file */
                ierrMove = MoveFileFunction(pStVarTwoExpanded, pStVarOneExpanded);
            }
        }
        else
        {
            if (pStVarOneExpanded)
            {
                FREE(pStVarOneExpanded);
                pStVarOneExpanded = NULL;
            }

            if (pStVarTwo)
            {
                FREE(pStVarTwoExpanded);
                pStVarTwoExpanded = NULL;
            }
            Scierror(999, _("%s: Wrong value for input argument #%d: A valid filename or directory expected.\n"), fname, 1);
            return 0;
        }

        returnMoveFileResultOnStack(ierrMove, fname);
    }
    else
    {
        Scierror(999, _("%s: Wrong value for input argument #%d: A valid filename or directory expected.\n"), fname, 1);
    }

    if (pStVarOneExpanded)
    {
        FREE(pStVarOneExpanded);
        pStVarOneExpanded = NULL;
    }
    if (pStVarTwoExpanded)
    {
        FREE(pStVarTwoExpanded);
        pStVarTwoExpanded = NULL;
    }

    return 0;
}
Example #3
0
/*----------------------------------------------------------------------------*/
int sci_isdigit(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;

    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;
    }

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

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

        if (getAllocatedSingleWideString(pvApiCtx, piAddressVarOne, &pStVarOne) != 0)
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }
        else
        {
            int valuesSize = 0;
            BOOL *values = IsDigitW(pStVarOne, &valuesSize);

            freeAllocatedSingleWideString(pStVarOne);
            pStVarOne = NULL;

            if (values)
            {
                int m1 = 1;
                int n1 = valuesSize;
                sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, m1, n1,
                                               (const int *)values);

                FREE(values);
                values = NULL;

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

            LhsVar(1) = Rhs + 1;
            PutLhsVar();
        }
    }
    return 0;
}
Example #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;

    CheckInputArgument(pvApiCtx, 1, 1);
    CheckOutputArgument(pvApiCtx, 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 1;
    }

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

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

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

    //    if ( (m1 != n1) && (n1 != 1) )
    //    {
    //        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
    //        return 1;
    //    }
    //
    //    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 1;
    //    }
    //
    //    pStVarOne = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne + 1));
    //    if (pStVarOne == NULL)
    //    {
    //        Scierror(999, _("%s: Memory allocation error.\n"), fname);
    //        return 1;
    //    }
    //
    //    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 1;
    //    }

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

#ifdef _MSC_VER
    {
        if (expandedPath)
        {
            playsound(expandedPath);
            FREE(expandedPath);
            expandedPath = NULL;
        }

        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
    }
#else
    {
        if (expandedPath)
        {
            FREE(expandedPath);
            expandedPath = NULL;
        }
        Scierror(999, _("%s: An error occurred: %s\n"), fname, _("Cannot play file.") );
    }
#endif
    return 0;
}
Example #5
0
/*--------------------------------------------------------------------------*/
int sci_dos(char *fname, void* pvApiCtx)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    int iType1	= 0;
    wchar_t *pStVarOne = NULL;

    char **Output = NULL;
    int numberoflines = 0;
    BOOL ECHOMODE = FALSE;

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

    if (Rhs == 2)
    {
        int *piAddressVarTwo = NULL;
        int m2 = 0, n2 = 0;
        int iType2 = 0;
        char *pStVarTwo = NULL;
        int lenStVarTwo = 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_strings )
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
            return 0;
        }

        sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, &lenStVarTwo, NULL);
        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: string expected.\n"), fname, 2);
            return 0;
        }

        pStVarTwo = (char*)MALLOC(sizeof(char) * (lenStVarTwo + 1));
        if (pStVarTwo)
        {
            sciErr = getMatrixOfString(pvApiCtx, piAddressVarTwo, &m2, &n2, &lenStVarTwo, &pStVarTwo);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
                return 0;
            }

            if ( strcmp(pStVarTwo, "-echo") )
            {
                FREE(pStVarTwo);
                pStVarTwo = NULL;
                Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 2, "-echo");
                return 0;
            }
            else
            {
                ECHOMODE = TRUE;
            }
        }
        else
        {
            Scierror(999, _("%s: No more memory.\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;
    }

    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: string expected.\n"), fname, 1);
        return 0;
    }

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

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

    double exitCode = 0.;
    BOOL DetachProcessOption = FALSE;
    BOOL *StatusExit = NULL;

    DetachProcessOption = DetectDetachProcessInCommandLine(pStVarOne);
    exitCode = (double)spawncommand(pStVarOne, DetachProcessOption);
    freeAllocatedSingleWideString(pStVarOne);

    StatusExit = (BOOL*)MALLOC(sizeof(BOOL));

    if (DetachProcessOption)
    {
        if (strlen((const char *)(pipeSpawnErr.OutputBuffer)))
        {
            /* StdErr will be "Output" */
            *StatusExit = FALSE;
            Output = CreateOuput(&pipeSpawnErr, DetachProcessOption);
            numberoflines = pipeSpawnErr.NumberOfLines;
        }
        else
        {
            /* StdOut will be "Output" */
            *StatusExit = TRUE;
            Output = CreateOuput(&pipeSpawnOut, DetachProcessOption);
            numberoflines = pipeSpawnOut.NumberOfLines;
        }
    }
    else
    {
        char FileTMPDir[PATH_MAX + 16];
        BOOL bConvert = FALSE;

        char *TMPDirLong = getTMPDIR();
        char *TMPDirShort = getshortpathname(TMPDirLong, &bConvert);

        sprintf(FileTMPDir, "%s\\DOS.OK", TMPDirLong);
        FREE(TMPDirLong);
        TMPDirLong = NULL;
        FREE(TMPDirShort);
        TMPDirShort = NULL;

        if (FileExist(FileTMPDir))
        {
            DeleteFile(FileTMPDir);
            /* StdOut will be "Output" */
            *StatusExit = TRUE;
            Output = CreateOuput(&pipeSpawnOut, DetachProcessOption);
            numberoflines = pipeSpawnOut.NumberOfLines;
        }
        else
        {
            /* StdErr will be "Output" */
            *StatusExit = FALSE;
            Output = CreateOuput(&pipeSpawnErr, DetachProcessOption);
            numberoflines = pipeSpawnErr.NumberOfLines;
        }
    }

    if (ECHOMODE)
    {
        PrintOuput(Output, numberoflines);
    }

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

        LhsVar(1) = Rhs + 1;
    }
    else
    {
        int m_out2 = 1;
        int n_out2 = 1;

        if (Output && Output[0])
        {
            int m_out1 = numberoflines;
            int n_out1 = 1;
            sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m_out1, n_out1, Output);
        }
        else
        {
            /* returns [] */
            int m_out1 = 0;
            int n_out1 = 0;
            sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m_out1, n_out1, NULL);
        }

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

        LhsVar(1) = Rhs + 1;

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

        LhsVar(2) = Rhs + 2;
    }

    if (Lhs > 2)
    {
        int m_out3 = 1, n_out3 = 1;
        sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 3, m_out3, n_out3, &exitCode);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }

        LhsVar(3) = Rhs + 3;
    }
    if (StatusExit)
    {
        FREE(StatusExit);
        StatusExit = NULL;
    }

    freeArrayOfString(Output, numberoflines);

    ClosePipeInfo(pipeSpawnOut);
    ClosePipeInfo(pipeSpawnErr);

    PutLhsVar();

    return 0;
}