/*--------------------------------------------------------------------------*/
SciErr createNamedMatrixOfString(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const char* const* _pstStrings)
{
    SciErr sciErr = sciErrInit();

    // check variable name
    if (checkNamedVarFormat(_pvCtx, _pstName) == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Invalid variable name: %s."), "createNamedMatrixOfString", _pstName);
        return sciErr;
    }

    //return empty matrix
    if (_iRows == 0 && _iCols == 0)
    {
        if (createNamedEmptyMatrix(_pvCtx, _pstName))
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createEmptyMatrix");
            return sciErr;
        }

        return sciErr;
    }

    types::String* pS = new types::String(_iRows, _iCols);
    if (pS == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name: %s."), "createNamedMatrixOfString", _pstName);
        return sciErr;
    }

    for (int i = 0 ; i < pS->getSize() ; i++)
    {
        wchar_t* pstTemp = to_wide_string(_pstStrings[i]);
        pS->set(i, pstTemp);
        FREE(pstTemp);
    }

    wchar_t* pwstName = to_wide_string(_pstName);
    symbol::Context* ctx = symbol::Context::getInstance();
    symbol::Symbol sym = symbol::Symbol(pwstName);
    FREE(pwstName);
    if (ctx->isprotected(sym) == false)
    {
        ctx->put(sym, pS);
    }
    else
    {
        delete pS;
        addErrorMessage(&sciErr, API_ERROR_REDEFINE_PERMANENT_VAR, _("Redefining permanent variable.\n"));
    }
    return sciErr;
}
Esempio n. 2
0
/*--------------------------------------------------------------------------*/
wchar_t* computeTMPDIRW(void)
{
    char* pstTemp = computeTMPDIR();
    wchar_t* pstReturn = to_wide_string(pstTemp);
    FREE(pstTemp);
    return pstReturn;
}
Esempio n. 3
0
/*--------------------------------------------------------------------------*/
wchar_t* getenvTMPDIRW()
{
    char *SciTemp = getenvTMPDIR();
    wchar_t* pstTemp = to_wide_string(SciTemp);
    delete[] SciTemp;
    return pstTemp;
}
Esempio n. 4
0
const mxArray *mexGetVariablePtr(const char *workspace, const char *name)
{
    symbol::Context *context = symbol::Context::getInstance();
    wchar_t *key = to_wide_string(name);
    types::InternalType *value = NULL;
    symbol::Symbol sym = symbol::Symbol(key);
    if (strcmp(workspace, "base") == 0)
    {
        value = context->get(sym);
    }
    else if (strcmp(workspace, "caller") == 0)
    {
        if (context->isGlobalVisible(sym) == false)
        {
            value = context->get(sym);
        }
    }
    else if (strcmp(workspace, "global") == 0)
    {
        if (context->isGlobalVisible(sym))
        {
            value = context->getGlobalValue(sym);
        }
    }
    FREE(key);
    return (mxArray *)value;
}
Esempio n. 5
0
String* String::set(int _iPos, const char* _pcData)
{
    wchar_t* w = to_wide_string(_pcData);
    String* ret = set(_iPos, w);
    FREE(w);
    return ret;
}
Esempio n. 6
0
int mexPutVariable(const char *workspace, const char *varname, const mxArray *pm)
{
    symbol::Context *context = symbol::Context::getInstance();
    wchar_t *dest = to_wide_string(varname);
    if (strcmp(workspace, "base") == 0)
    {
        context->putInPreviousScope(context->getOrCreate(symbol::Symbol(dest)), (types::InternalType *)pm);
    }
    else if (strcmp(workspace, "caller") == 0)
    {
        context->put(symbol::Symbol(dest), (types::InternalType *)pm);
    }
    else if (strcmp(workspace, "global") == 0)
    {
        context->setGlobalVisible(symbol::Symbol(dest), true);
        context->put(symbol::Symbol(dest), (types::InternalType *)pm);
    }
    else
    {
        FREE(dest);
        return 1;
    }
    FREE(dest);
    return 0;
}
Esempio n. 7
0
static bool import_variable(int file, std::string& name)
{
    int dataset = getDataSetIdFromName(file, name.data());
    if (dataset <= 0)
    {
        return false;
    }

    types::InternalType* data = import_data(dataset);
    if (data != nullptr)
    {
        wchar_t* var = to_wide_string(name.data());
        //update macro name
        if (data->isMacro())
        {
            types::Macro* macro = data->getAs<types::Macro>();
            macro->setName(var);
            symbol::Context::getInstance()->addMacro(macro);
        }
        else
        {
            //add to context
            symbol::Context::getInstance()->put(symbol::Symbol(var), data);
        }
        FREE(var);
        return true;
    }

    return false;
}
Esempio n. 8
0
/*--------------------------------------------------------------------------*/
char *getlongpathname(char *shortpathname,BOOL *convertok)
{
	char *LongName = NULL;
	wchar_t *wcshortpathname = to_wide_string(shortpathname);
	if (wcshortpathname)
	{
		wchar_t *wcLongName = getlongpathnameW(wcshortpathname, convertok);
		if (wcLongName)
		{
			LongName = wide_string_to_UTF8(wcLongName);
			FREE(wcLongName); wcLongName = NULL;
		}
		else
		{
			LongName = strdup(shortpathname);
			*convertok = FALSE;
		}
	}
	else
	{
		LongName = strdup(shortpathname);
		*convertok = FALSE;
	}
	return LongName;
}
Esempio n. 9
0
static int CopyLineAtPrompt(char **wk_buf, char *line, unsigned int *cursor, unsigned int *cursor_max)
{
    FREE(*wk_buf);
    if (line)
    {
        wchar_t *wtmp = NULL;
        //** Copy line to current command buffer, usefull in completion case.
        *wk_buf = MALLOC(sizeof(char) * strlen(line) + 1);
        strcpy(*wk_buf, line);
        backspace(*cursor);     /* backspace to beginning of line */
        printf("%s", *wk_buf);   /* copy to screen */

        wtmp = to_wide_string(*wk_buf);
        *cursor = wcslen(wtmp); /* cursor set at end of line */
        FREE(wtmp);

        /* erase extra characters left over if any */
        erase_nchar(GET_MAX(0, (*cursor_max - *cursor)));
        *cursor_max = *cursor;
        return 1;
    }
    else
    {
        *wk_buf = (char*) MALLOC(sizeof(char));
        (*wk_buf)[0] = '\0';
    }
    return 0;
}
Esempio n. 10
0
/*--------------------------------------------------------------------------*/ 
BOOL FileExist(char *filename)
{
#ifdef _MSC_VER
	wchar_t *wcFilename = to_wide_string(filename);
	if (wcFilename)
	{
		BOOL bOK = FileExistW(wcFilename);
		FREE(wcFilename);
		return bOK;
	}
	return FALSE;
#else
	FILE* tmpFile=fopen(filename,"r");
	if(tmpFile) 
		{ 
			fclose(tmpFile); 
			return TRUE;
		} 
	else 
		{ 
			return FALSE;
		} 
#endif

}
/*--------------------------------------------------------------------------*/
BOOL Set_HOME_PATH(char *DefaultPath)
{
    wchar_t *wHOME = _wgetenv(L"HOME");
    if (wHOME == NULL)
    {
        wchar_t *wUserProfile = _wgetenv(L"USERPROFILE");
        if (wUserProfile)
        {
            return SetEnvironmentVariableW(L"HOME", wUserProfile);
        }
        else
        {
            /* if USERPROFILE is not defined , we use default profile */
            wchar_t *wAllUsersProfile = _wgetenv(L"ALLUSERSPROFILE");
            if (wAllUsersProfile)
            {
                return SetEnvironmentVariableW(L"HOME", wUserProfile);
            }
            else
            {
                BOOL bRes = FALSE;
                wchar_t *wDefault = to_wide_string(DefaultPath);
                if (wDefault)
                {
                    bRes = SetEnvironmentVariableW(L"HOME", wDefault);
                    FREE(wDefault);
                    wDefault = NULL;
                }
                return bRes;
            }
        }
    }
    return TRUE;
}
Esempio n. 12
0
static int mexCallSCILAB(int nlhs, mxArray **plhs, int nrhs, mxArray **prhs, const char *name)
{
    wchar_t* pwst = to_wide_string(name);
    symbol::Context *context = symbol::Context::getInstance();
    symbol::Symbol *symbol = new symbol::Symbol(pwst);
    FREE(pwst);

    types::InternalType *value = context->get(*symbol);
    types::Function *func = value->getAs<types::Function>();
    if (func == NULL)
    {
        return 1;
    }

    types::typed_list in;
    types::typed_list out;
    types::optional_list opt;
    for (int i = 0; i < nrhs; i++)
    {
        in.push_back((types::InternalType*)prhs[i]);
    }

    func->call(in, opt, nlhs, out);

    for (int i = 0; i < nlhs; i++)
    {
        plhs[i] = (mxArray *) (out[i]);
    }

    return 0;
}
Esempio n. 13
0
/*--------------------------------------------------------------------------*/ 
static void printf_scilab(char *buffer)
{
	if (buffer)
	{
		wchar_t *wcBuffer = NULL;
		if (getScilabMode() == SCILAB_STD)
		{
			ConsolePrintf(buffer);
		}
		else
		{
			#ifdef _MSC_VER
			TermPrintf_Windows(buffer);
			#else
			printf("%s",buffer);
			#endif
		}

		wcBuffer = to_wide_string(buffer);
		if (wcBuffer)
		{
			diaryWrite(wcBuffer, FALSE);
			FREE(wcBuffer);
			wcBuffer = NULL;
		}
	}
}
Esempio n. 14
0
/*--------------------------------------------------------------------------*/
int  Scierror(int iv, const char *fmt, ...)
{
    int retval = 0;
    wchar_t* pwstError = NULL;
    char s_buf[bsiz];
    va_list ap;

    va_start(ap, fmt);

#if defined (vsnprintf) || defined (linux)
    retval = vsnprintf(s_buf, bsiz - 1, fmt, ap );
#else
    retval = vsnprintf(s_buf, bsiz - 1, fmt, ap);
#endif
    if (retval < 0)
    {
        s_buf[bsiz - 1] = '\0';
    }

    va_end(ap);

    pwstError = to_wide_string(s_buf);
    setLastError(iv, pwstError, 0, NULL);

    FREE(pwstError);
    return retval;
}
Esempio n. 15
0
/*--------------------------------------------------------------------------*/
char *get_full_path(char *_FullPath, const char *_Path, size_t _SizeInBytes)
{
#if defined(_MSC_VER)
    char *returnedFullPath = NULL;

    wchar_t *wPath = to_wide_string((char *)_Path);
    wchar_t *wFullPath = (wchar_t *) MALLOC(sizeof(wchar_t) * _SizeInBytes);

    _wfullpath(wFullPath, wPath, _SizeInBytes);
    returnedFullPath = wide_string_to_UTF8(wFullPath);
    if (returnedFullPath)
    {
        strcpy(_FullPath, returnedFullPath);
        FREE(returnedFullPath);
        returnedFullPath = NULL;
    }

    if (wPath)
    {
        FREE(wPath);
        wPath = NULL;
    }
    if (wFullPath)
    {
        FREE(wFullPath);
        wFullPath = NULL;
    }

    return _FullPath;
#else
    char *rp = NULL;
    int lenPath = (int)strlen(_Path);

    rp = realpath(_Path, _FullPath);
    int lenFullPath = 0;
    int haveFileSep = ((lenPath > 1) && isDirSeparator(_Path[lenPath - 1]));
    int addFileSep = 0;

    if (!rp)
    {
        strcpy(_FullPath, _Path);
        normalizePath(_FullPath);
    }
    lenFullPath = (int)strlen(_FullPath);
    addFileSep = ((lenFullPath > 1) && (!isDirSeparator(_FullPath[lenFullPath - 1])) && haveFileSep);
    if (addFileSep)
    {
        char *bufTmp = (char *)MALLOC(sizeof(char) * (lenFullPath + strlen(DIR_SEPARATOR) + 1));

        if (bufTmp)
        {
            sprintf(bufTmp, "%s%s", _FullPath, DIR_SEPARATOR);
            strcpy(_FullPath, bufTmp);
            FREE(bufTmp);
            bufTmp = NULL;
        }
    }
    return _FullPath;
#endif
}
Esempio n. 16
0
/*--------------------------------------------------------------------------*/ 
char *FindFileExtension(char *filename)
{
	char *extension = NULL;
	if (filename)
	{
		#ifndef _MSC_VER
		int lengthfilename = (int) strlen(filename);
		int  i = lengthfilename;

		while(filename[i] != '.' && i > 0) i--;

		if(i > 0)
		{
			int lengthextension = lengthfilename - i;
			extension = (char*)MALLOC(sizeof(char)*(lengthextension+1));
			if (extension) sprintf(extension,"%s",&filename[i]);
		}
		#else
		{
			wchar_t *wcFilename = to_wide_string(filename);
			if (wcFilename)
			{
				extension = wide_string_to_UTF8(PathFindExtensionW(wcFilename));
				FREE(wcFilename);
				wcFilename = NULL;
			}
		}
		#endif
	}
	return extension;
}
Esempio n. 17
0
/*--------------------------------------------------------------------------*/
char *createtempfilename(const char *prefix, BOOL bShortFormat)
{
    char *tempfilename = NULL;
#ifdef _MSC_VER
    wchar_t *wcprefix = to_wide_string(prefix);
    wchar_t *wcresult = createtempfilenameW(wcprefix, bShortFormat);

    tempfilename = wide_string_to_UTF8(wcresult);

    if (wcresult)
    {
        FREE(wcresult);
        wcresult = NULL;
    }
    if (wcresult)
    {
        FREE(wcresult);
        wcresult = NULL;
    }
#else
    char *TmpDir = getTMPDIR();
    if (TmpDir)
    {
        char TempFileName[PATH_MAX];
        sprintf(TempFileName, "%s/%sXXXXXX", TmpDir, prefix);
        int fd = mkstemp(TempFileName);
        if (fd != -1)
        {
            close(fd);
        }
        tempfilename = strdup(TempFileName);
    }
#endif
    return tempfilename;
}
Esempio n. 18
0
SciErr createComplexHypermatOfPoly(void *_pvCtx, int _iVar, char* _pstVarName, int * _dims, int _ndims, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg)
{
    SciErr sciErr = sciErrInit();
    types::GatewayStruct* pStr = (types::GatewayStruct*)_pvCtx;
    types::typed_list in = *pStr->m_pIn;
    types::InternalType** out = pStr->m_pOut;
    int rhs = _iVar - *getNbInputArgument(_pvCtx);

    wchar_t* w = to_wide_string(_pstVarName);
    types::Polynom* p = new types::Polynom(w, _ndims, _dims, _piNbCoef);
    p->setComplex(true);

    int size = p->getSize();
    if (size == 0)
    {
        delete p;
        out[rhs - 1] = types::Double::Empty();
        FREE(w);
        return sciErr;
    }

    types::SinglePoly** s = p->get();

    for (int i = 0; i < size; ++i)
    {
        s[i]->setCoef(_pdblReal[i], _pdblImg[i]);
    }

    out[rhs - 1] = p;
    FREE(w);
    return sciErr;
}
Esempio n. 19
0
SciErr createHypermatOfString(void *_pvCtx, int _iVar, int * _dims, int _ndims, const char* const* _pstStrings)
{
    SciErr sciErr = sciErrInit();
    types::GatewayStruct* pStr = (types::GatewayStruct*)_pvCtx;
    types::typed_list in = *pStr->m_pIn;
    types::InternalType** out = pStr->m_pOut;
    int rhs = _iVar - *getNbInputArgument(_pvCtx);

    types::String* p = new types::String(_ndims, _dims);
    int size = p->getSize();

    if (size == 0)
    {
        delete p;
        out[rhs - 1] = types::Double::Empty();
        return sciErr;
    }

    for (int i = 0; i < size; ++i)
    {
        wchar_t* w = to_wide_string(_pstStrings[i]);
        p->set(i, w);
        FREE(w);
    }

    out[rhs - 1] = p;
    return sciErr;
}
Esempio n. 20
0
/*--------------------------------------------------------------------------*/
int wcstat(char* filename, struct _stat *st)
{
    int stat_result = 0;
    wchar_t *wfilename = to_wide_string(filename);
    stat_result = _wstat(wfilename, st);
    FREE(wfilename);
    return stat_result;
}
SciErr createCommonMatrixOfPoly(void* _pvCtx, int _iVar, int _iComplex, char* _pstVarName, int _iRows, int _iCols, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg)
{
    SciErr sciErr = sciErrInit();
    if (_pvCtx == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), _iComplex ? "createComplexMatrixOfPoly" : "createMatrixOfPoly");
        return sciErr;
    }

    types::GatewayStruct* pStr = (types::GatewayStruct*)_pvCtx;
    types::InternalType** out = pStr->m_pOut;
    int rhs = _iVar - *getNbInputArgument(_pvCtx);

    //return empty matrix
    if (_iRows == 0 && _iCols == 0)
    {
        types::Double *pDbl = new types::Double(_iRows, _iCols);
        if (pDbl == NULL)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createEmptyMatrix");
            return sciErr;
        }

        out[rhs - 1] = pDbl;
        return sciErr;
    }

    wchar_t* pstTemp = to_wide_string(_pstVarName);
    std::wstring wstTemp(pstTemp);
    types::Polynom* pP = new types::Polynom(wstTemp, _iRows, _iCols, _piNbCoef);
    FREE(pstTemp);
    if (pP == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocated variable"), _iComplex ? "createComplexMatrixOfPoly" : "createMatrixOfPoly");
        return sciErr;
    }

    if (_iComplex)
    {
        pP->setComplex(true);
    }

    out[rhs - 1] = pP;

    for (int i = 0 ; i < pP->getSize() ; i++)
    {
        types::Double* pD = new types::Double(_piNbCoef[i], 1, _iComplex == 1);
        pD->set(_pdblReal[i]);
        if (_iComplex)
        {
            pD->setImg(_pdblImg[i]);
        }
        pP->setCoef(i, pD);
        delete pD;
    }

    return sciErr;
}
wchar_t *getLocaleUserInfo(void)
{
    char *cUserLanguage = NULL;
    CFLocaleRef userLocaleRef = CFLocaleCopyCurrent();
    CFStringRef userLanguage = CFLocaleGetIdentifier(userLocaleRef);

    if (getenv( "LANG" ))
    {
        /* Mac OS X does not respect the LANG variable. We do it ourself. */
        return to_wide_string(getenv("LANG"));
    }
    else
    {
        cUserLanguage = (char *) malloc(((int) CFStringGetLength(userLanguage) + 1) * sizeof(char));
        CFStringGetCString(userLanguage, cUserLanguage, ((int) CFStringGetLength(userLanguage)) + 1, kCFStringEncodingUTF8);
    }
    return to_wide_string(cUserLanguage);
}
Esempio n. 23
0
/*--------------------------------------------------------------------------*/
static int GetIndexLastModifiedFileInList(char **ListFilename, int numberelemnts)
{
#ifdef _MSC_VER
    struct _stat buf;
#else
    struct stat buf;
#endif

    int i = 0;
    int RetVal = 0;

    int RetIndex = 1;
    long int MaxTime = 0;

    for (i = 0; i < numberelemnts ; i++)
    {

        int resultstat = 0;
        char *FileName = NULL;

        FileName = expandPathVariable(ListFilename[i]);

#ifdef _MSC_VER
        if (FileName)
        {
            if ( (FileName[strlen(FileName) - 1] == '/') || (FileName[strlen(FileName) - 1] == '\\') )
            {
                FileName[strlen(FileName) - 1] = '\0';
            }

        }

        {
            wchar_t *pszFileName = to_wide_string(FileName);
            resultstat = _wstat(pszFileName, &buf );
            FREE(pszFileName);
        }
#else
        resultstat = stat(FileName, &buf );
#endif
        if (resultstat == 0)
        {
            if ((long int)buf.st_mtime > MaxTime)
            {
                MaxTime = (long int)buf.st_mtime;
                RetIndex = i + 1;
            }
        }

        FREE(FileName);
        FileName = NULL;
    }

    RetVal = RetIndex;
    return RetVal;
}
Esempio n. 24
0
void ConfigVariable::setCommandLineArgs(int _iArgs, char** _pstArgs)
{
    m_Args.clear();
    for (int i = 0 ; i < _iArgs ; i++)
    {
        wchar_t * ws = to_wide_string(_pstArgs[i]);
        m_Args.push_back(ws);
        FREE(ws);
    }
}
Esempio n. 25
0
/*--------------------------------------------------------------------------*/
BOOL setenvc(const char *stringIn, const char *valueIn)
{
#ifdef _MSC_VER
    wchar_t* wstringIn = to_wide_string(stringIn);
    wchar_t* wvalueIn = to_wide_string(valueIn);

    if (setenvcW(wstringIn, wvalueIn) == 0)
    {
        FREE(wstringIn);
        FREE(wvalueIn);
        return FALSE;
    }

    FREE(wstringIn);
    FREE(wvalueIn);
#else
    /* linux and Mac OS X */
    /* setenv() function is strongly preferred to putenv() */
    /* http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/setenv.3.html */

#ifndef _MAX_ENV
#define _MAX_ENV 32767
#endif

    int len_env = (int)(strlen(stringIn) + strlen(valueIn) + 1);
    if (len_env < _MAX_ENV)
    {
        if ( setenv(stringIn, valueIn, 1) )
        {
            return FALSE;
        }
    }
    else
    {
        return FALSE;
    }

    setenvtcl(stringIn, valueIn);
#endif

    return TRUE;
}
Esempio n. 26
0
int mxAddField(mxArray *ptr, const char *fieldname)
{
    if (!mxIsStruct(ptr))
    {
        return -1;
    }
    Struct *pa = (Struct *)ptr;
    wchar_t *wfieldname = to_wide_string(fieldname);
    pa->addField(wfieldname);
    return mxGetFieldNumber(ptr, fieldname);
}
Esempio n. 27
0
static char *getLineBeforeCaret(char *wk_buf, unsigned int *cursor)
{
    char *line = NULL;
    wchar_t * wtmp = to_wide_string(wk_buf);

    wtmp[*cursor] = 0;
    line = wide_string_to_UTF8(wtmp);
    FREE(wtmp);

    return line;
}
Esempio n. 28
0
mxArray *mxCreateStructArray(int ndim, const int *dims, int nfields, const char **field_names)
{
    types::Struct *ptr = new types::Struct(ndim, (int *)dims);
    for (int i = 0; i < nfields; i++)
    {
        wchar_t *name = to_wide_string(field_names[i]);
        ptr->addField(name);
        FREE(name);
    }
    return (mxArray *)ptr;
}
FILE *fdopen(int handle, const char *mode)
{
	WCHAR *wmode = to_wide_string(mode);
	FILE *result;

	if(wmode != NULL)
		result = _wfdopen((void *)handle, wmode);
	else
		result = NULL;
	free(wmode);
	return result;
}
Esempio n. 30
0
String::String(const char *_pstData)
{
    wchar_t** pwsData = NULL;
    int piDims[] = {1, 1};
    create(piDims, 2, &pwsData, NULL);
    wchar_t* data = to_wide_string(const_cast<char*>(_pstData));
    set(0, 0, data);
    FREE(data);
#ifndef NDEBUG
    Inspector::addItem(this);
#endif
}