コード例 #1
0
ファイル: api_struct.hpp プロジェクト: opencollab/scilab
int API_PROTO(getFields)(scilabEnv env, scilabVar var, wchar_t***  fields)
{
    types::Struct* s = (types::Struct*)var;
#ifdef __API_SCILAB_SAFE__
    if (s->isStruct() == false)
    {
        scilab_setInternalError(env, L"getFields", _W("var must be a struct variable"));
        return STATUS_ERROR;
    }
#endif

    if (s->getSize() == 0)
    {
        return 0;
    }

    std::unordered_map<std::wstring, int> fieldsMap = s->get(0)->getFields();
    *fields = new wchar_t*[fieldsMap.size()];
    for (const auto & field : fieldsMap)
    {
        (*fields)[field.second] = os_wcsdup(field.first.data());
    }

    return (int)fieldsMap.size();
}
コード例 #2
0
wchar_t* String::copyValue(const wchar_t* _pwstData)
{
    if (_pwstData == nullValue())
    {
        return nullValue();
    }

    return os_wcsdup(_pwstData);
}
コード例 #3
0
ファイル: strsubst.c プロジェクト: leowzukw/scilab-mirror
/*-------------------------------------------------------------------------------------*/
wchar_t *wcssub_reg(const wchar_t* _pwstInput, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace, int* _piErr)
{
    pcre_error_code iPcreStatus = PCRE_FINISHED_OK;
    int iStart = 0;
    int iEnd = 0;
    int iLen = 0;

    wchar_t* pwstOutput = NULL;

    if (_pwstInput == NULL)
    {
        return NULL;
    }

    if (_pwstSearch == NULL || _pwstReplace == NULL)
    {
        return os_wcsdup(_pwstInput);
    }

    iPcreStatus = wide_pcre_private((wchar_t*)_pwstInput, (wchar_t*)_pwstSearch, &iStart, &iEnd, NULL, NULL);
    if (iPcreStatus != PCRE_FINISHED_OK)
    {
        *_piErr = iPcreStatus;
        return os_wcsdup(_pwstInput);
    }

    //compute new size of output string
    iLen += (int)wcslen(_pwstReplace) - (iEnd - iStart);

    pwstOutput = (wchar_t*)MALLOC(sizeof(wchar_t) * (wcslen(_pwstInput) + iLen + 1));
    memset(pwstOutput, 0x00, sizeof(wchar_t) * (wcslen(_pwstInput) + iLen + 1));

    //copy start of original string
    wcsncpy(pwstOutput, _pwstInput, iStart);
    //copy replace string
    wcscpy(pwstOutput + wcslen(pwstOutput), _pwstReplace);
    //copy end of original string
    wcscpy(pwstOutput + wcslen(pwstOutput), _pwstInput + iEnd);

    *_piErr = iPcreStatus;
    return pwstOutput;
}
コード例 #4
0
ファイル: configvariable.cpp プロジェクト: scitao/scilab
void ConfigVariable::setEntryPointName(ConfigVariable::EntryPointStr* _pEntryPoint, wchar_t* _pwstEntryPointName)
{
    if (_pEntryPoint)
    {
        if (_pEntryPoint->pwstEntryPointName)
        {
            FREE(_pEntryPoint->pwstEntryPointName);
        }
        _pEntryPoint->pwstEntryPointName = os_wcsdup(_pwstEntryPointName);;
    }
}
コード例 #5
0
ファイル: configvariable.cpp プロジェクト: scitao/scilab
void ConfigVariable::setLibraryName(ConfigVariable::DynamicLibraryStr* _pDynamicLibrary, wchar_t* _pwstLibraryName)
{
    if (_pDynamicLibrary)
    {
        if (_pDynamicLibrary->pwstLibraryName)
        {
            FREE(_pDynamicLibrary->pwstLibraryName);
        }
        _pDynamicLibrary->pwstLibraryName = os_wcsdup(_pwstLibraryName);
    }
}
コード例 #6
0
static wchar_t *getLanguageFromAlias(wchar_t *alias)
{
    if (alias)
    {
        if ( wcscmp(alias, L"en") == 0 )
        {
            return os_wcsdup(L"en_US");
        }

        if ( wcscmp(alias, L"fr") == 0 )
        {
            return os_wcsdup(L"fr_FR");
        }

        return os_wcsdup(alias);
    }

    /* "" value fixed by system */
    return os_wcsdup(L"");
}
コード例 #7
0
ファイル: createGUID.c プロジェクト: leowzukw/scilab-mirror
/*--------------------------------------------------------------------------*/
wchar_t *createGUID(void)
{
    GUID guid;
    wchar_t* pwstrGUID = NULL;
    wchar_t* ret = NULL;

    CoCreateGuid (&guid);
    StringFromCLSID(&guid, &pwstrGUID);

    //remove first '{' and last '}'
    pwstrGUID[wcslen(pwstrGUID) - 1] = L'\0';
    ret = os_wcsdup(pwstrGUID + 1);
    CoTaskMemFree(pwstrGUID);
    return ret;
}
コード例 #8
0
ファイル: string.cpp プロジェクト: leowzukw/scilab-mirror
wchar_t* String::copyValue(wchar_t* _pwstData)
{
    try
    {
        return os_wcsdup(_pwstData);
    }
    catch (std::bad_alloc & /*e*/)
    {
        char message[bsiz];
        os_sprintf(message, _("Can not allocate data.\n"));
        throw ast::InternalError(message);
    }

    return NULL;
}
コード例 #9
0
/*--------------------------------------------------------------------------*/
wchar_t *getVariableValueDefinedInScilab(VARIABLEALIAS* _var)
{
    if (_var)
    {
        if (_var->var == NULL)
        {
            _var->var = symbol::Context::getInstance()->getOrCreate(symbol::Symbol(_var->VariableName));
        }

        types::InternalType *pIT = _var->var->get();
        if (pIT == NULL || pIT->isString() == false)
        {
            return NULL;
        }

        types::String* pS = pIT->getAs<types::String>();
        return os_wcsdup(pS->get(0));
    }
    return NULL;
}
コード例 #10
0
ファイル: isdir.c プロジェクト: leowzukw/scilab-mirror
/*--------------------------------------------------------------------------*/
BOOL isdirW(const wchar_t * wcpath)
{
    BOOL bOK = FALSE;
#ifndef _MSC_VER
    struct stat buf;
    char *path = wide_string_to_UTF8(wcpath);
    if (path == NULL)
    {
        return FALSE;
    }
    bOK = isdir(path);
    FREE(path);
#else
    if (isDriveW(wcpath))
    {
        return TRUE;
    }
    else
    {
        DWORD attr = 0;
        wchar_t *tmpPath = os_wcsdup(wcpath);

        if ( (tmpPath[wcslen(tmpPath) - 1] == L'\\') || (tmpPath[wcslen(tmpPath) - 1] == L'/') )
        {
            tmpPath[wcslen(tmpPath) - 1] = L'\0';
        }
        attr = GetFileAttributesW(tmpPath);
        FREE(tmpPath);
        if (attr == INVALID_FILE_ATTRIBUTES)
        {
            return FALSE;
        }
        return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) ? TRUE : FALSE;
    }
#endif
    return bOK;
}
コード例 #11
0
/*--------------------------------------------------------------------------*/
wchar_t *getlanguage(void)
{
    return os_wcsdup(CURRENTLANGUAGESTRING);
}
コード例 #12
0
ファイル: sci_file.cpp プロジェクト: FOSSEE-Internship/scilab
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_file_one_rhs(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    if (in[0]->isDouble() == false || in[0]->getAs<types::Double>()->getSize() != 1)
    {
        Scierror(201, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "file", 1);
        return types::Function::Error;
    }

    types::Double* pD = in[0]->getAs<types::Double>();
    int iID = static_cast<int>(pD->getReal()[0]);

    //check if double value is an integer to exclude decimal values
    if (static_cast<double>(iID) != pD->getReal()[0])
    {
        Scierror(201, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "file", 1);
        return types::Function::Error;
    }

    types::File *pF = FileManager::getFile(iID);
    if (pF == NULL)
    {
        for (int i = 0 ; i < _iRetCount ; i++)
        {
            out.push_back(types::Double::Empty());
        }
        return types::Function::OK;
    }

    out.push_back(new types::Double(iID));
    if (_iRetCount > 1) /*type*/
    {
        wchar_t* pstType = os_wcsdup(pF->getFileTypeAsString().c_str());
        if (pstType != NULL)
        {
            types::String* pS = new types::String(pstType);
            out.push_back(pS);
            FREE(pstType);
        }
    }

    if (_iRetCount > 2) /*name*/
    {
        wchar_t* pstName =  os_wcsdup(pF->getFilename().c_str());
        if (pstName != NULL)
        {
            types::String* pS = new types::String(pstName);
            out.push_back(pS);
            FREE(pstName);
        }
    }

    if (_iRetCount > 3) /* mod */
    {
        if (pF->getFileType() == 1)
        {
            out.push_back(new types::Double((double)pF->getFileFortranMode()));
        }
        else // if(pF->getFileType() == 2)
        {
            out.push_back(new types::Double((double)pF->getFileModeAsInt()));
        }
    }

    if (_iRetCount > 4) /* swap */
    {
        out.push_back(new types::Double(pF->getFileSwap()));
    }
    return types::Function::OK;
}
コード例 #13
0
ファイル: string.cpp プロジェクト: leowzukw/scilab-mirror
wchar_t* String::copyValue(const wchar_t* _pwstData)
{
    return os_wcsdup(_pwstData);
}
コード例 #14
0
ファイル: string.cpp プロジェクト: leowzukw/scilab-mirror
wchar_t* String::getNullValue()
{
    return os_wcsdup(L"");
}
コード例 #15
0
ファイル: strsubst.c プロジェクト: leowzukw/scilab-mirror
/*-------------------------------------------------------------------------------------*/
wchar_t *wcssub(const wchar_t* _pwstInput, const wchar_t* _pwstSearch, const wchar_t* _pwstReplace)
{
    int i               = 0;
    int iOccurs         = 0;
    size_t iReplace     = 0;
    size_t iSearch      = 0;
    size_t iOffset      = 0;

    size_t* piStart     = NULL;

    const wchar_t* pwstPos  = NULL;
    wchar_t* pwstOutput     = NULL;

    if (_pwstInput == NULL)
    {
        return NULL;
    }

    if (_pwstInput[0] == L'\0')
    {
        return os_wcsdup(L"");
    }

    if (_pwstSearch == NULL || _pwstReplace == NULL)
    {
        return os_wcsdup(_pwstInput);
    }

    iSearch     = wcslen(_pwstSearch);
    iReplace    = wcslen(_pwstReplace);
    piStart     = (size_t*)MALLOC(sizeof(size_t) * wcslen(_pwstInput));
    pwstPos     = _pwstInput;

    while (pwstPos)
    {
        pwstPos = wcsstr(pwstPos, _pwstSearch);
        if (pwstPos)
        {
            piStart[iOccurs++]  = pwstPos - _pwstInput;
            iOffset             += iReplace - iSearch;
            pwstPos++;
        }
    }

    pwstOutput = (wchar_t*)MALLOC(sizeof(wchar_t) * (wcslen(_pwstInput) + iOffset + 1));
    memset(pwstOutput, 0x00, sizeof(wchar_t) * (wcslen(_pwstInput) + iOffset + 1));

    if (iOccurs == 0)
    {
        wcscpy(pwstOutput, _pwstInput);
    }
    else
    {
        for (i = 0 ; i < iOccurs ; i++)
        {
            if (i == 0)
            {
                //copy start of original string
                wcsncpy(pwstOutput, _pwstInput, piStart[i]);
            }
            else
            {
                //copy start of original string
                wcsncpy(pwstOutput + wcslen(pwstOutput), _pwstInput + piStart[i - 1] + iSearch, piStart[i] - (iSearch + piStart[i - 1]));
            }
            //copy replace string
            wcscpy(pwstOutput + wcslen(pwstOutput), _pwstReplace);
        }
        //copy end of original string
        wcscpy(pwstOutput + wcslen(pwstOutput), _pwstInput + piStart[iOccurs - 1] + iSearch);
    }

    FREE(piStart);
    return pwstOutput;
}
コード例 #16
0
ファイル: sci_tmpdir.cpp プロジェクト: Macisia/scilab
/*--------------------------------------------------------------------------*/
wchar_t* getTMPDIRW(void)
{
    return os_wcsdup(ConfigVariable::getTMPDIR().c_str());
}
コード例 #17
0
int sci_string_test(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt opt, int nout, scilabVar* out)
{
    int i = 0;
    int inr1 = 0;
    int inc1 = 0;
    int size1 = 0;
    wchar_t** in1 = NULL;

    wchar_t* in2 = 0;

    int dim1 = 3;
    int dims1[] = {0, 0, 2};
    wchar_t** out1 = NULL;

    wchar_t* out2;
    int len2 = 0;

    if (nin != 2)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2);
        return STATUS_ERROR;
    }

    if (nout != 2)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname, 3);
        return STATUS_ERROR;
    }

    //in[0] : matrix 2d of string
    if (scilab_isString(env, in[0]) == 0 || scilab_isMatrix2d(env, in[0]) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string matrix expected.\n"), fname, 1);
        return STATUS_ERROR;
    }

    size1 = scilab_getDim2d(env, in[0], &inr1, &inc1);
    scilab_getStringArray(env, in[0], &in1);

    //in[1] : string
    if (scilab_isString(env, in[1]) == 0 || scilab_isScalar(env, in[1]) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A double expected.\n"), fname, 2);
        return STATUS_ERROR;
    }

    scilab_getString(env, in[1], &in2);

    //out1 : matrix 2d of string with same size of in[0]
    dims1[0] = inr1;
    dims1[1] = inc1;
    out[0] = scilab_createStringMatrix(env, dim1, dims1);
    scilab_getStringArray(env, out[0], &out1);

    for (i = 0; i < size1; ++i)
    {
        wchar_t temp[128];
        wcscpy(temp, in1[i]);
        wcscat(temp, L".one");
        out1[i] = os_wcsdup(temp);

        wcscpy(temp, in1[i]);
        wcscat(temp, L".two");
        out1[i + size1] = os_wcsdup(temp);
    }

    //out2 : string
    out2 = os_wcsdup(in2);
    len2 = wcslen(out2);
    for (i = 0; i < len2; ++i)
    {
        if (out2[i] >= L'a' && out2[i] <= L'z')
        {
            out2[i] = ((out2[i] - 'a' + 26 - 1) % 26) + 'a';
        }
        else if (out2[i] >= L'A' && out2[i] <= L'Z')
        {
            out2[i] = ((out2[i] - 'A' + 26 - 1) % 26) + 'A';
        }
        else
        {
            //no change
        }
    }

    out[1] = scilab_createString(env, out2);
    FREE(out2);
    return STATUS_OK;
}