Exemplo n.º 1
0
types::Function::ReturnValue sci_hdf5_listvar(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    int rhs = static_cast<int>(in.size());
    if (rhs < 1)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    if (in[0]->getId() != types::InternalType::IdScalarString)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
    char* cfilename = wide_string_to_UTF8(wfilename);
    std::string filename = cfilename;
    FREE(wfilename);
    FREE(cfilename);

    int iFile = openHDF5File(filename.data(), 0);
    if (iFile < 0)
    {
        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
        return types::Function::Error;
    }

    std::wstring wstFuncName;
    //manage version information
    int version = getSODFormatAttribute(iFile);
    closeHDF5File(iFile);
    switch (version)
    {
        case -1:
        case 1:
        case 2:
        {
            wstFuncName = L"hdf5_listvar_v2";
            break;
        }
        case 3:
        {
            wstFuncName = L"hdf5_listvar_v3";
            break;
        }
        default:
        {
            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, version);
            return types::Function::Error;
        }
    }


    ast::ExecVisitor exec;
    return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
}
/*--------------------------------------------------------------------------*/
char *expandPathVariable(char* str)
{
    char *expanded = NULL;
    wchar_t *wstr = to_wide_string(str);

    if (wstr)
    {
        wchar_t *wcexpanded = expandPathVariableW(wstr);
        if (wcexpanded)
        {
            expanded = wide_string_to_UTF8(wcexpanded);
            FREE(wcexpanded);
            wcexpanded = NULL;
        }
        FREE(wstr);
        wstr = NULL;
    }
    return expanded;
}
types::Function::ReturnValue sci_hdf5_file_version(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    int rhs = static_cast<int>(in.size());
    if (rhs < 1)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    if (in[0]->getId() != types::InternalType::IdScalarString)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
    char* cfilename = wide_string_to_UTF8(wfilename);
    std::string filename = cfilename;
    FREE(wfilename);
    FREE(cfilename);

    int iFile = openHDF5File(filename.data(), 0);
    if (iFile < 0)
    {
        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
        return types::Function::Error;
    }

    std::wstring wstFuncName;
    //manage version information
    int version = getSODFormatAttribute(iFile);
    closeHDF5File(iFile);

    if (version == -1)
    {
        version = 1;
    }

    out.push_back(new types::Double(static_cast<double>(version)));
    return types::Function::OK;
}
Exemplo n.º 4
0
/*--------------------------------------------------------------------------*/
BOOL winopen(wchar_t *scilabfilename)
{
    BOOL bOK = FALSE;
    wchar_t *wcfilename = NULL;
    HINSTANCE error = NULL;

    wcfilename = expandPathVariableW(scilabfilename);
    if (wcfilename)
    {
        error = ShellExecuteW(NULL, L"open", wcfilename, NULL, NULL, SW_SHOWNORMAL);
        if ( error <= (HINSTANCE)32)
        {
            bOK = FALSE;
        }
        else
        {
            bOK = TRUE;
        }

        FREE(wcfilename);
    }
    return bOK;
}
Exemplo n.º 5
0
types::Function::ReturnValue sci_mopen(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    int iErr                = 0;
    int iID                 = 0;
    wchar_t* pstFilename    = NULL;
    const wchar_t* pstMode  = L"rb";
    int iSwap               = 0;

    //check output parameters
    if (_iRetCount != 1 && _iRetCount != 2)
    {
        Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), "mopen", 1, 2);
        return types::Function::Error;
    }

    //check input parameters
    if (in.size() >= 1)
    {
        //filename
        if (in[0]->isString() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), "mopen", 1);
            return types::Function::Error;
        }

        types::String* pS1 = in[0]->getAs<types::String>();
        if (pS1->getSize() != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "mopen" , 1);
            return types::Function::Error;
        }

        pstFilename = expandPathVariableW(pS1->get(0));

        if (in.size() >= 2)
        {
            //mode
            if (in[1]->isString() == false)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), "mopen", 2);
                return types::Function::Error;
            }

            types::String* pS2 = in[1]->getAs<types::String>();
            if (pS2->getSize() != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), "mopen" , 2);
                return types::Function::Error;
            }

            pstMode = pS2->get(0);

            if (in.size() >= 3)
            {
                //swap
                if (in[2]->isDouble() == false)
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: An integer expected.\n"), "mopen" , 3);
                    return types::Function::Error;
                }

                types::Double* pD3 = in[2]->getAs<types::Double>();
                if (pD3->getSize() != 1 || pD3->isComplex())
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: An integer expected.\n"), "mopen", 3);
                    return types::Function::Error;
                }

                //if value == 0 set swap to 0 otherwise let to 1
                if (pD3->getReal(0, 0) == 0)
                {
                    iSwap = 0;
                }

                if (in.size() >= 4)
                {
                    Scierror(999, _("%s: Wrong number of input arguments: %d to %d expected.\n"), "mopen" , 1, 3);
                    return types::Function::Error;
                }

            }
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d to %d expected.\n"), "mopen" , 1, 3);
        return types::Function::Error;
    }

    wchar_t* pwstTemp = (wchar_t*)MALLOC(sizeof(wchar_t) * (PATH_MAX * 2));
    get_full_pathW(pwstTemp, (const wchar_t*)pstFilename, PATH_MAX * 2);
    iErr = mopen(pwstTemp, pstMode, iSwap, &iID);
    if (iErr != MOPEN_NO_ERROR)
    {
        //mange file open errors
        if (_iRetCount == 1)
        {
            switch (iErr)
            {
                case MOPEN_CAN_NOT_OPEN_FILE:
                {
                    char* pst = wide_string_to_UTF8(pstFilename);
                    Scierror(999, _("%s: Cannot open file %s.\n"), "mopen", pst);
                    FREE(pst);
                    FREE(pstFilename);
                    FREE(pwstTemp);
                    pstFilename = NULL;
                    return types::Function::Error;
                }
                case MOPEN_INVALID_FILENAME:
                {
                    Scierror(999, _("%s: invalid filename.\n"), "mopen");
                    FREE(pstFilename);
                    FREE(pwstTemp);
                    pstFilename = NULL;
                    return types::Function::Error;
                }
                case MOPEN_INVALID_STATUS:
                {
                    Scierror(999, _("%s: invalid status.\n"), "mopen");
                    FREE(pstFilename);
                    FREE(pwstTemp);
                    pstFilename = NULL;
                    return types::Function::Error;
                }
            }
        }
    }

    FREE(pwstTemp);
    FREE(pstFilename);

    types::Double* pD = new types::Double(static_cast<double>(iID));
    out.push_back(pD);

    if (_iRetCount == 2)
    {
        types::Double* pD2 = new types::Double(iErr);
        out.push_back(pD2);
    }
    return types::Function::OK;
}
Exemplo n.º 6
0
// =============================================================================
csvResult* csvRead(const char *filename, const char *separator, const char *decimal, const char **toreplace, int sizetoreplace, const char *regexpcomments, int header)
{
    wchar_t *expandedFilename = NULL;
    wchar_t *wideFilename = NULL;
    csvResult *result = NULL;
    int fd = 0;
    int f_swap = 0;
    double res = 0.0;
    int errMOPEN = MOPEN_INVALID_STATUS;
    int errMGETL = MGETL_ERROR;
    wchar_t **pwstLines = NULL;
    char **pstLines = NULL;
    int nblines = 0;
    char **replacedInLines = NULL;
    char **pComments = NULL;
    int nbComments = 0;

    if ((filename == NULL) || (separator == NULL) || (decimal == NULL))
    {
        return NULL;
    }

    wideFilename = to_wide_string((char*)filename);
    expandedFilename = expandPathVariableW(wideFilename);
    FREE(wideFilename);

    if (!FileExistW(expandedFilename))
    {
        result = (csvResult*)(MALLOC(sizeof(csvResult)));
        if (result)
        {
            result->err = CSV_READ_FILE_NOT_EXIST;
            result->m = 0;
            result->n = 0;
            result->pstrValues = NULL;
            result->pstrComments = NULL;
            result->nbComments = 0;
        }

        FREE(expandedFilename);
        return result;
    }

    errMOPEN = mopen(expandedFilename, L"rt", f_swap, &fd); // rt = read only
    if (expandedFilename)
    {
        FREE(expandedFilename);
        expandedFilename = NULL;
    }

    if (errMOPEN != MOPEN_NO_ERROR)
    {
        result = (csvResult*)(MALLOC(sizeof(csvResult)));
        if (result)
        {
            result->err = CSV_READ_MOPEN_ERROR;
            result->m = 0;
            result->n = 0;
            result->pstrValues = NULL;
            result->pstrComments = NULL;
            result->nbComments = 0;

        }
        return result;
    }

    if (header != 0)
    {
        mgetl(fd, header, &nblines, &errMGETL);
    }

    pwstLines = mgetl(fd, -1, &nblines, &errMGETL);
    pstLines = (char**)MALLOC(sizeof(char*) * nblines);

    {
        int i = 0;
        for (i = 0 ; i < nblines ; i++)
        {
            pstLines[i] = wide_string_to_UTF8(pwstLines[i]);
        }

    }

    mclose(fd);

    if (errMGETL != MGETL_NO_ERROR)
    {
        if (pwstLines)
        {
            freeArrayOfWideString(pwstLines, nblines);
            pwstLines = NULL;
        }

        result = (csvResult*)(MALLOC(sizeof(csvResult)));
        if (result)
        {
            result->err = CSV_READ_READLINES_ERROR;
            result->m = 0;
            result->n = 0;
            result->pstrValues = NULL;
            result->pstrComments = NULL;
            result->nbComments = 0;
        }
        return result;
    }

    if (regexpcomments)
    {
        int iErr = 0;

        pComments = extractComments((const char**)pstLines, nblines, regexpcomments, &nbComments, &iErr);

        if ((iErr == CAN_NOT_COMPILE_PATTERN) || (iErr == DELIMITER_NOT_ALPHANUMERIC))
        {
            result = (csvResult*)(MALLOC(sizeof(csvResult)));
            if (result)
            {
                if ((iErr == CAN_NOT_COMPILE_PATTERN) || (iErr == DELIMITER_NOT_ALPHANUMERIC))
                {
                    iErr = CSV_READ_REGEXP_ERROR;
                }
                result->err = (csvReadError)iErr;
                result->m = 0;
                result->n = 0;
                result->pstrValues = NULL;
                result->pstrComments = NULL;
                result->nbComments = 0;
            }
            return result;
        }

        if (pComments)
        {
            char **pCleanedLines = NULL;
            int nbCleanedLines = 0;
            int i = 0;

            pCleanedLines = removeComments((const char**)pstLines, nblines, (const char*)regexpcomments, &nbCleanedLines, &iErr);
            if (pCleanedLines)
            {
                if (pwstLines)
                {
                    freeArrayOfWideString(pwstLines, nblines);
                    pwstLines = NULL;
                }
                FREE(pstLines);
                pstLines = pCleanedLines;
                nblines = nbCleanedLines;
            }

        }
    }

    if (toreplace && (sizetoreplace > 0))
    {
        replacedInLines = replaceStrings((const char**)pstLines, nblines, toreplace, sizetoreplace);
        if (replacedInLines)
        {
            freeArrayOfString(pstLines, nblines);
            pstLines = replacedInLines;
        }
    }

    result = csvTextScan((const char**)pstLines, nblines, (const char*)separator, (const char*)decimal);
    freeArrayOfString(pstLines, nblines);
    freeArrayOfWideString(pwstLines, nblines);

    if (result)
    {
        result->pstrComments = pComments;
        result->nbComments = nbComments;
    }
    else
    {
        freeArrayOfString(pComments, nbComments);
    }


    return result;
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
types::Function::ReturnValue sci_hdf5_listvar_v3(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    int rhs = static_cast<int>(in.size());
    if (rhs != 1)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    if (_iRetCount < 1 && _iRetCount > 4)
    {
        Scierror(999, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), fname.data(), 1, 4);
        return types::Function::Error;
    }

    //get filename
    if (in[0]->getId() != types::InternalType::IdScalarString)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    //open hdf5 file
    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
    char* cfilename = wide_string_to_UTF8(wfilename);
    std::string filename = cfilename;
    FREE(wfilename);
    FREE(cfilename);

    int iFile = openHDF5File(filename.data(), 0);
    if (iFile < 0)
    {
        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
        return types::Function::Error;
    }

    //manage version information
    int iVersion = getSODFormatAttribute(iFile);
    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.data(), SOD_FILE_VERSION, iVersion);
        return types::Function::Error;
    }

    int items = getVariableNames6(iFile, nullptr);
    std::vector<VarInfo6> info(items);
    if (items != 0)
    {
        std::vector<char*> vars(items);
        items = getVariableNames6(iFile, vars.data());

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

        for (int i = 0; i < items; i++)
        {
            info[i].name = vars[i];
            FREE(vars[i]);
            info[i].size = 0;

            int dset = getDataSetIdFromName(iFile, info[i].name.data());
            if (dset == 0)
            {
                break;
            }


            if (_iRetCount != 2)
            {
                if (read_data(dset, info[i]) == false)
                {
                    break;
                }

                if (_iRetCount == 1)
                {
                    sciprint("%s\n", info[i].info);
                }
            }
            else // == 2
            {
                if (read_short_data(dset, info[i]) == false)
                {
                    break;
                }
            }
        }
    }
    else
    {
        //no variable returms [] for each Lhs
        for (int i = 0; i < _iRetCount; i++)
        {
            out.push_back(types::Double::Empty());
        }

        return types::Function::OK;
    }

    closeHDF5File(iFile);

    //1st Lhs
    types::String* out1 = new types::String(items, 1);
    for (int i = 0; i < items; i++)
    {
        out1->set(i, info[i].name.data());
    }

    out.push_back(out1);

    //2nd
    if (_iRetCount > 1)
    {
        types::Double* out2 = new types::Double(items, 1);
        double* pout2 = out2->get();
        for (int i = 0; i < items; i++)
        {
            pout2[i] = info[i].type;
        }

        out.push_back(out2);
    }

    if (_iRetCount > 2)
    {
        //3rd Lhs
        types::List* out3 = new types::List();
        for (int i = 0; i < items; i++)
        {
            int dims = info[i].dims;
            types::Double* item = new types::Double(1, dims);
            double* pitem = item->get();
            for (int j = 0; j < dims; j++)
            {
                pitem[j] = static_cast<double>(info[i].pdims[j]);
            }

            out3->append(item);
        }

        out.push_back(out3);
    }

    if (_iRetCount > 3)
    {
        //4th Lhs
        types::Double* out4 = new types::Double(items, 1);
        double* pout4 = out4->get();
        for (int i = 0; i < items; i++)
        {
            pout4[i] = info[i].size;
        }

        out.push_back(out4);
    }

    return types::Function::OK;
}
Exemplo n.º 9
0
    void CoverResult::toJSON(const std::wstring & outputDir)
    {
        std::wostringstream out;
        const std::wstring tab1(L"    ");
        const std::wstring tab2(L"        ");
        const std::wstring tab3(L"            ");
        out << L"{" << std::endl

            << tab1 << L"\"name\": \"" << name << L"\"," << std::endl
            << tab1 << L"\"file\": \"" << info.macroFilePath << L"\"," << std::endl
            << tab1 << L"\"module\": \"" << info.macroModule << L"\"," << std::endl
            << tab1 << L"\"instrs_count\": \"" << info.instrsCount << L"\"," << std::endl
            << tab1 << L"\"branches_count\": \"" << info.branchesCount << L"\"," << std::endl
            << tab1 << L"\"paths_count\": \"" << info.pathsCount << L"\"," << std::endl

            << tab1 << L"\"result\": {" << std::endl
            << tab2 << L"\"instrs_count\": \"" << (info.instrsCount - uncoveredInstrs) << L"\"," << std::endl
            << tab2 << L"\"branches_count\": \"" << (info.branchesCount - uncoveredBranches) << L"\"," << std::endl
            << tab2 << L"\"paths_count\": \"" << 0 << L"\"," << std::endl
            << tab1 << L"}," << std::endl;

        if (branches.empty())
        {
            out << tab1 << L"\"branches\": []," << std::endl;
        }
        else
        {
            out << tab1 << L"\"branches\": [" << std::endl;
            const auto last = std::prev(branches.end());
            for (auto i = branches.begin(), end = branches.end(); i != end; ++i)
            {
                const std::vector<uint64_t> & counters = i->second;
                const std::size_t size = counters.size();
                const Location & loc = i->first;
                out << tab2 << L"{" << std::endl
                    << tab3 << L"\"location\": { \"first_line\": \"" << loc.first_line << L"\""
                    << L", \"first_column\": \"" << loc.first_column << L"\""
                    << L", \"last_line\": \"" << loc.last_line << L"\""
                    << L", \"last_column\": \"" << loc.last_column << L"\""
                    << L"}," << std::endl
                    << tab3 << L"\"counters\": [";

                for (std::size_t j = 0; j < size - 1; ++j)
                {
                    out << L"\"" << counters[j] << L"\", ";
                }
                out << L"\"" << counters[size - 1] << L"\"]" << std::endl;

                if (i != last)
                {
                    out << tab2 << L"}, " << std::endl;
                }
                else
                {
                    out << tab2 << L"}" << std::endl;
                }
            }
            out << tab1 << L"]," << std::endl;
        }

        if (unused.empty())
        {
            out << tab1 << L"\"uncovered\": []" << std::endl;
        }
        else
        {
            out << tab1 << L"\"uncovered\": [" << std::endl;
            const auto last = std::prev(unused.end());
            for (auto i = unused.begin(), end = unused.end(); i != end; ++i)
            {
                const Location & loc = *i;
                out << tab2 << L"{ \"first_line\": \"" << loc.first_line << L"\""
                    << L", \"first_column\": \"" << loc.first_column << L"\""
                    << L", \"last_line\": \"" << loc.last_line << L"\""
                    << L", \"last_column\": \"" << loc.last_column << L"\"";
                if (i != last)
                {
                    out << L"}," << std::endl;
                }
                else
                {
                    out << L"}" << std::endl;
                }
            }
            out << tab1 << L"]" << std::endl;
        }

        out << L"}";

        char * code = wide_string_to_UTF8(out.str().c_str());
        wchar_t * _output = expandPathVariableW((wchar_t *)outputDir.c_str());
        const std::wstring filename = std::wstring(_output) + DIR_SEPARATORW + name + L".json";
        char * _filename = wide_string_to_UTF8(filename.c_str());
        std::fstream file(_filename, std::ios::out | std::ios::trunc);
        file.write(code, std::strlen(code));
        file.close();
        FREE(code);
        FREE(_filename);
        FREE(_output);
    }
Exemplo n.º 10
0
/*--------------------------------------------------------------------------*/
wchar_t *pathconvertW(wchar_t* wcpath, BOOL flagtrail, BOOL flagexpand, PathConvertType PType)
{
    wchar_t *convertedPath = NULL;
    if (wcpath)
    {
        BOOL bConvCyg = FALSE;
        wchar_t *expandedPath = NULL;
        PathConvertType PTypelocal = PType;
        int i = 0;

        if (PType == AUTO_STYLE)
        {
#ifdef _MSC_VER
            PTypelocal = WINDOWS_STYLE;
#else
            PTypelocal = UNIX_STYLE;
#endif
        }

        if (flagexpand)
        {
            expandedPath = expandPathVariableW(wcpath);
        }
        else
        {
            expandedPath = (wchar_t*)MALLOC(sizeof(wchar_t) * ((int)wcslen(wcpath) + 1));
            wcscpy(expandedPath, wcpath);
        }

        if (PTypelocal == WINDOWS_STYLE)
        {
            convertedPath = cygwintowindowspath(expandedPath, &bConvCyg);
        }
        else
        {
            convertedPath = windowstocygwinpath(expandedPath, &bConvCyg);
        }

        if (convertedPath)
        {
            if (expandedPath)
            {
                FREE(expandedPath);
                expandedPath = NULL;
            }

            if (flagtrail)
            {
                int currentLen = (int) wcslen(convertedPath);
                if ( (convertedPath[currentLen - 1] != L'/') && (convertedPath[currentLen - 1] != L'\\') )
                {
                    convertedPath = (wchar_t*)REALLOC(convertedPath, (currentLen + 2) * sizeof(wchar_t));
                    if (PTypelocal == WINDOWS_STYLE)
                    {
                        wcscat(convertedPath, L"\\");
                    }
                    else
                    {
                        wcscat(convertedPath, L"/");
                    }
                }
            }
            else
            {
                int currentLen = (int) wcslen(convertedPath);
                if ( (convertedPath[currentLen - 1] == L'/') || (convertedPath[currentLen - 1] == L'\\') )
                {
                    convertedPath[currentLen - 1] = L'\0';
                }
            }

            for (i = 0; i < (int)wcslen(convertedPath); i++)
            {
                if (PTypelocal == WINDOWS_STYLE)
                {
                    if (convertedPath[i] == L'/')
                    {
                        convertedPath[i] = L'\\';
                    }
                }
                else
                {
                    if (convertedPath[i] == L'\\')
                    {
                        convertedPath[i] = L'/';
                    }
                }
            }
        }
    }
    return convertedPath;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
types::Function::ReturnValue sci_hdf5_load(types::typed_list &in, int _iRetCount, types::typed_list& out)
{
    int rhs = static_cast<int>(in.size());
    if (rhs < 1)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    if (in[0]->getId() != types::InternalType::IdScalarString)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    wchar_t* wcfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
    char* cfilename = wide_string_to_UTF8(wcfilename);
    std::string filename(cfilename);
    std::wstring wfilename(wcfilename);
    FREE(cfilename);
    FREE(wcfilename);

    if (FileExistW(wfilename.data()) == FALSE)
    {
        Scierror(999, _("%s: Unable to open file: '%s'.\n"), fname.data(), filename.data());
        return types::Function::Error;
    }

    //library ?
    if (isHDF5File(filename.data()) == false)
    {
        //lib file
        int err = 0;
        types::Library* lib = loadlib(in[0]->getAs<types::String>()->get()[0], &err);

        switch (err)
        {
            case 0:
                break;
            case 2:
                Scierror(999, "%s: %s", fname.data(), _("Redefining permanent variable.\n"));
                return types::Function::Error;
            default:
                Scierror(999, _("%s: %s is not a valid lib file.\n"), fname.data(), filename.data());
                return types::Function::Error;
        }

        lib->killMe();
        return types::Function::OK;
    }

    int iFile = openHDF5File(filename.data(), 0);
    if (iFile < 0)
    {
        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
        return types::Function::Error;
    }

    std::wstring wstFuncName;
    //manage version information
    int version = getSODFormatAttribute(iFile);
    closeHDF5File(iFile);

    bool needReprocess = false;
    switch (version)
    {
        case -1:
        case 1:
        {
            wstFuncName = L"hdf5_load_v1";
            needReprocess = true;
            break;
        }
        case 2:
        {
            wstFuncName = L"hdf5_load_v2";
            needReprocess = true;
            break;
        }
        case 3:
        {
            wstFuncName = L"hdf5_load_v3";
            break;
        }
        default :
        {
            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, version);
            return types::Function::Error;
        }
    }

    types::typed_list out1;
    types::Function::ReturnValue ret = Overload::call(wstFuncName, in, _iRetCount, out1);

    if (ret != types::Function::OK)
    {
        Scierror(999, _("%s: Unable to load '%s'\n"), fname.data(), filename.data());
        return types::Function::Error;
    }

    if (needReprocess)
    {
        //call %sodload
        types::String* vars = out1[0]->getAs<types::String>();
        vars->IncreaseRef();
        int size = vars->getSize();
        types::typed_list in2(1, vars);
        types::typed_list out2;
        std::wstring wstFuncName = L"%_sodload";
        ret = Overload::call(wstFuncName, in2, size, out2);
        vars->DecreaseRef();

        symbol::Context* ctx = symbol::Context::getInstance();
        wchar_t** names = vars->get();

        //update context with values return by %_sodload
        for (int i = 0; i < size; ++i)
        {
            ctx->put(symbol::Symbol(names[i]), out2[i]);
        }

        vars->killMe();
    }
    else
    {
        out.push_back(out1.front());
    }

    return ret;
}
Exemplo n.º 13
0
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_mgetl(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    int iFileID                 = 0;
    int iErr                    = 0;
    bool bCloseFile             = false;
    int iLinesExcepted          = -1;
    int iLinesRead              = -1;
    wchar_t** wcReadedStrings   = NULL;

    if (in.size() < 1 || in.size() > 2)
    {
        Scierror(77, _("%s: Wrong number of input arguments: %d to %d expected.\n"), "mgetl" , 1, 2);
        return types::Function::OK;
    }

    if (in.size() == 2)
    {
        //number of lines
        if (in[1]->isDouble() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: An integer value expected.\n"), "mgetl", 2);
            return types::Function::Error;
        }

        if (in[1]->getAs<types::Double>()->isScalar() == false)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: An integer value expected.\n"), "mgetl", 2);
            return types::Function::Error;
        }

        if (in[1]->getAs<types::Double>()->get(0) != (int)in[1]->getAs<types::Double>()->get(0))
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: An integer value expected.\n"), "mgetl", 2);
            return types::Function::Error;
        }

        iLinesExcepted = static_cast<int>(in[1]->getAs<types::Double>()->get(0));
    }

    if (in[0]->isDouble() && in[0]->getAs<types::Double>()->getSize() == 1)
    {
        iFileID = static_cast<int>(in[0]->getAs<types::Double>()->get(0));
    }
    else if (in[0]->isString() && in[0]->getAs<types::String>()->getSize() == 1)
    {
        wchar_t *expandedFileName = expandPathVariableW(in[0]->getAs<types::String>()->get(0));

        iErr = mopen(expandedFileName, L"rt", 0, &iFileID);

        if (iErr)
        {
            char* pst = wide_string_to_UTF8(expandedFileName);
            switch (iErr)
            {
                case MOPEN_NO_MORE_LOGICAL_UNIT:
                    Scierror(66, _("%s: Too many files opened!\n"), "mgetl");
                    break;
                case MOPEN_CAN_NOT_OPEN_FILE:
                    Scierror(999, _("%s: Cannot open file %s.\n"), "mgetl", pst);
                    break;
                case MOPEN_NO_MORE_MEMORY:
                    Scierror(999, _("%s: No more memory.\n"), "mgetl");
                    break;
                case MOPEN_INVALID_FILENAME:
                    Scierror(999, _("%s: invalid filename %s.\n"), "mgetl", pst);
                    break;
                default: //MOPEN_INVALID_STATUS
                    Scierror(999, _("%s: invalid status.\n"), "mgetl");
                    break;
            }

            FREE(pst);
            FREE(expandedFileName);
            return types::Function::Error;
        }
        FREE(expandedFileName);
        bCloseFile = true;
    }
    else
    {
        //Error
        Scierror(999, _("%s: Wrong type for input argument #%d: a String or Integer expected.\n"), "mgetl", 1);
        return types::Function::Error;
    }

    switch (iFileID)
    {
        case 0: // stderr
        case 6: // stdout
            Scierror(999, _("%s: Wrong file descriptor: %d.\n"), "mgetl", iFileID);
            return types::Function::Error;
        default :
        {
            types::File* pFile = FileManager::getFile(iFileID);
            // file opened with fortran open function
            if (pFile == NULL || pFile->getFileType() == 1)
            {
                Scierror(999, _("%s: Wrong file descriptor: %d.\n"), "mgetl", iFileID);
                return types::Function::Error;
            }

            wcReadedStrings = mgetl(iFileID, iLinesExcepted, &iLinesRead, &iErr);

            switch (iErr)
            {
                case MGETL_MEMORY_ALLOCATION_ERROR :
                    break;

            }
        }
    }

    if (wcReadedStrings && iLinesRead > 0)
    {
        types::String *pS = new types::String(iLinesRead, 1);
        pS->set(wcReadedStrings);
        out.push_back(pS);
        freeArrayOfWideString(wcReadedStrings, iLinesRead);
    }
    else
    {
        out.push_back(types::Double::Empty());
        if (wcReadedStrings)
        {
            FREE(wcReadedStrings);
        }
    }

    if (bCloseFile)
    {
        mclose(iFileID);
    }

    return types::Function::OK;
}
Exemplo n.º 14
0
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_hdf5_load_v3(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    std::string filename;
    int rhs = static_cast<int>(in.size());

    if (rhs < 1)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    if (in[0]->getId() != types::InternalType::IdScalarString)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
    char* cfilename = wide_string_to_UTF8(wfilename);
    filename = cfilename;
    FREE(wfilename);
    FREE(cfilename);

    int iFile = openHDF5File(filename.data(), 0);
    if (iFile < 0)
    {
        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
        return types::Function::Error;
    }

    //manage version information
    int iVersion = getSODFormatAttribute(iFile);
    if (iVersion != SOD_FILE_VERSION)
    {
        //can't read file with version newer that me !
        Scierror(999, _("%s: Wrong SOD file format version. Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion);
        return types::Function::Error;
    }

    if (rhs > 1)
    {
        for (int i = 1; i < rhs; ++i)
        {
            std::string var;
            char* cvar = wide_string_to_UTF8(in[i]->getAs<types::String>()->get()[0]);
            var = cvar;
            FREE(cvar);

            if (import_variable(iFile, var) == false)
            {
                Scierror(999, _("%s: Unable to load \'%s\'.\n"), fname.data(), var.data());
                return types::Function::Error;
            }
        }
    }
    else
    {
        //restore all variables
        int iNbItem = 0;
        iNbItem = getVariableNames6(iFile, NULL);
        if (iNbItem != 0)
        {
            std::vector<char*> vars(iNbItem);
            iNbItem = getVariableNames6(iFile, vars.data());
            for (auto & var : vars)
            {
                std::string s(var);
                FREE(var);
                if (import_variable(iFile, s) == false)
                {
                    Scierror(999, _("%s: Unable to load \'%s\'.\n"), fname.data(), s.data());
                    return types::Function::Error;
                }
            }
        }
    }

    //close the file
    closeHDF5File(iFile);

    out.push_back(new types::Bool(1));
    return types::Function::OK;
}
Exemplo n.º 15
0
types::Library* loadlib(const std::wstring& _wstXML, int* err, bool _isFile, bool _bAddInContext)
{
    types::Library* lib = NULL;

    wchar_t* pwstPathLib = expandPathVariableW((wchar_t*)_wstXML.c_str());

    wchar_t* pwstTemp = (wchar_t*)MALLOC(sizeof(wchar_t) * (PATH_MAX * 2));
    get_full_pathW(pwstTemp, pwstPathLib, PATH_MAX * 2);
    FREE(pwstPathLib);

    std::wstring wstOriginalPath(_wstXML);
    std::wstring wstFile(pwstTemp);
    std::wstring wstPath(pwstTemp);
    FREE(pwstTemp);

    if (_isFile)
    {
        //remove / or \ at the end
        size_t pos = wstPath.find_last_of(L"/\\");
        wstPath = wstPath.substr(0, pos);
        pos = wstOriginalPath.find_last_of(L"/\\");
        wstOriginalPath = wstOriginalPath.substr(0, pos + 1); //with ending /
    }
    else
    {
        if (wstFile.empty() == false && *wstFile.rbegin() != DIR_SEPARATORW[0])
        {
            wstFile += DIR_SEPARATORW;
        }

        wstFile += L"lib";
    }

    std::wstring libname;
    MacroInfoList lst;
    *err = parseLibFile(wstFile, lst, libname);
    if (*err)
    {
        return lib;
    }

    lib = new types::Library(wstOriginalPath);

    std::wstring stFilename(wstPath);
    if (stFilename.empty() == false && *stFilename.rbegin() != DIR_SEPARATORW[0])
    {
        stFilename += DIR_SEPARATORW;
    }


    for (const auto & macro : lst)
    {
        lib->add(macro.second.name, new types::MacroFile(macro.second.name, stFilename + macro.second.file, libname));
    }


    if (_bAddInContext)
    {
        symbol::Context* ctx = symbol::Context::getInstance();
        symbol::Symbol sym = symbol::Symbol(libname);
        if (ctx->isprotected(sym) == false)
        {
            ctx->put(sym, lib);
        }
        else
        {
            *err = 2;
            delete lib;
            lib = NULL;
        }
    }

    return lib;
}
Exemplo n.º 16
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;
}
Exemplo n.º 17
0
    void CoverResult::toXML(const std::wstring & outputDir)
    {
        std::wostringstream out;
        const std::wstring tab1(L"  ");
        const std::wstring tab2(L"    ");
        const std::wstring tab3(L"      ");
        out << L"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << std::endl

            << L"<cover name=\"" << name << L"\""
            << L" file=\"" << info.macroFilePath << L"\""
            << L" module=\"" << info.macroModule << L"\""
            << L" instrs_count=\"" << info.instrsCount << L"\""
            << L" branches_count=\"" << info.branchesCount << L"\""
            << L" paths_count=\"" << info.pathsCount << L"\""
            << L">" << std::endl

            << tab1 << L"<result instrs_count=\"" << (info.instrsCount - uncoveredInstrs) << L"\""
            << L" branches_count=\"" << (info.branchesCount - uncoveredBranches) << L"\""
            << L" paths_count=\"" << 0 << L"\""
            << L"/>" << std::endl;

        if (branches.empty())
        {
            out << tab1 << L"<branches/>" << std::endl;
        }
        else
        {
            out << tab1 << L"<branches>" << std::endl;
            for (const auto & p : branches)
            {
                const std::vector<uint64_t> & counters = p.second;
                const std::size_t size = counters.size();
                const Location & loc = p.first;
                out << tab2 << L"<exp branches_number=\"" << size << L"\">" << std::endl

                    << tab3 << L"<location first_line=\"" << loc.first_line << L"\""
                    << L" first_column=\"" << loc.first_column << L"\""
                    << L" last_line=\"" << loc.last_line << L"\""
                    << L" last_column=\"" << loc.last_column << L"\""
                    << L"/>" << std::endl;

                for (std::size_t i = 0; i < size; ++i)
                {
                    out << tab3 << L"<branche index=\"" << (i + 1) << L"\""
                        << L" counter=\"" << counters[i] << L"\""
                        << L"/>" << std::endl;
                }

                out << tab2 << L"</exp>" << std::endl;
            }
            out << tab1 << L"</branches>" << std::endl;
        }

        if (unused.empty())
        {
            out << tab1 << L"<uncovered/>" << std::endl;
        }
        else
        {
            out << tab1 << L"<uncovered>" << std::endl;
            for (const auto & loc : unused)
            {
                out << tab2 << L"<location first_line=\"" << loc.first_line << L"\""
                    << L" first_column=\"" << loc.first_column << L"\""
                    << L" last_line=\"" << loc.last_line << L"\""
                    << L" last_column=\"" << loc.last_column << L"\""
                    << L"/>" << std::endl;
            }
            out << tab1 << L"</uncovered>" << std::endl;
        }

        out << L"</cover>";

        char * code = wide_string_to_UTF8(out.str().c_str());
        wchar_t * _output = expandPathVariableW((wchar_t *)outputDir.c_str());
        const std::wstring filename = std::wstring(_output) + DIR_SEPARATORW + name + L".xml";
        char * _filename = wide_string_to_UTF8(filename.c_str());
        std::fstream file(_filename, std::ios::out | std::ios::trunc);
        file.write(code, std::strlen(code));
        file.close();
        FREE(code);
        FREE(_filename);
        FREE(_output);
    }
Exemplo n.º 18
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;
}