Exemplo n.º 1
0
/*--------------------------------------------------------------------------*/
BOOL setenvcW(const wchar_t *wstringIn, const wchar_t *wvalueIn)
{
    BOOL ret = TRUE;
    int len_env = 0;
#ifdef _MSC_VER
    if (SetEnvironmentVariableW(wstringIn, wvalueIn) == 0)
    {
        return FALSE;
    }

    char * stringIn = wide_string_to_UTF8(wstringIn);
    char * valueIn = wide_string_to_UTF8(wvalueIn);
    setenvtcl(stringIn, valueIn);
    FREE(stringIn);
    FREE(valueIn);
#else
    char * stringIn = wide_string_to_UTF8(wstringIn);
    char * valueIn = wide_string_to_UTF8(wvalueIn);
    ret = setenvc(stringIn, valueIn);
    FREE(stringIn);
    FREE(valueIn);
#endif

    return ret;
}
Exemplo n.º 2
0
/**
 * Export the variable LC_XXXX to the system
 *
 * @param locale the locale (ex : fr_FR or en_US)
 */
BOOL exportLocaleToSystem(char *locale)
{

    if (locale == NULL)
    {
#ifdef _MSC_VER
        fprintf(stderr, "Localization: Have not been able to find a suitable locale. Remains to default %s.\n", "LC_CTYPE");
#else
        fprintf(stderr, "Localization: Have not been able to find a suitable locale. Remains to default %s.\n", EXPORTENVLOCALESTR);
#endif
        return FALSE;
    }

    /* It will put in the env something like LC_MESSAGES=fr_FR */
    if (!setenvc(EXPORTENVLOCALESTR, locale))
    {
#ifdef _MSC_VER
        fprintf(stderr, "Localization: Failed to declare the system variable %s.\n", "LC_CTYPE");
#else
        fprintf(stderr, "Localization: Failed to declare the system variable %d.\n", EXPORTENVLOCALE);
#endif
        return FALSE;
    }

#ifdef _MSC_VER
#ifdef USE_SAFE_GETTEXT_DLL
    {
        /* gettext is buggy on Windows */
        /* We need to set a external environment variable to scilab env. */

        char env[MAX_PATH];

        sprintf(env, "%s=%s", EXPORTENVLOCALESTR, locale);
        gettext_putenv(env);
    }
#endif
#else
    /* Export LC_NUMERIC to the system to make sure that the rest of system
     * is using the english notation (Java, Tcl ...) */
    setenvc("LC_NUMERIC", LCNUMERICVALUE);
#endif

    return TRUE;
}
Exemplo n.º 3
0
/*--------------------------------------------------------------------------*/
void putenvTMPDIR(const char *_sci_tmpdir)
{
    char *ShortPath = NULL;
    char *CopyOfDefaultPath = NULL;

    /* to be sure that it's unix 8.3 format */
    /* c:/progra~1/scilab-5.0 */
    BOOL bConvertOK = FALSE;
    ShortPath = getshortpathname(_sci_tmpdir, &bConvertOK);
    //GetShortPathName(_sci_path,ShortPath,PATH_MAX);

    CopyOfDefaultPath = new char[strlen(_sci_tmpdir) + 1];
    AntislashToSlash(ShortPath, CopyOfDefaultPath);

    setenvc("TMPDIR", ShortPath);

    delete[] CopyOfDefaultPath;
    FREE(ShortPath);
}
Exemplo n.º 4
0
/*--------------------------------------------------------------------------*/
int sci_setenv(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int m1 = 0, n1 = 0;
    int *piAddressVarOne = NULL;
    int iType1 = 0;
    char *pStVarOne = NULL;
    int lenStVarOne = 0;

    int m2 = 0, n2 = 0;
    int *piAddressVarTwo = NULL;
    int iType2 = 0;
    char *pStVarTwo = NULL;
    int lenStVarTwo = 0;

    int m_out1 = 0, n_out1 = 0;

    int result = 0;

    Rhs = Max(0, Rhs);
    CheckRhs(2, 2);
    CheckLhs(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 0;
    }

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

    sciErr = getVarType(pvApiCtx, 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;
    }

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

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

    sciErr = getMatrixOfString(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;
    }

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

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

    pStVarOne = (char*)MALLOC(sizeof(char) * (lenStVarOne + 1));
    if (pStVarOne)
    {
        sciErr = getMatrixOfString(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;
        }

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

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

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

    result = setenvc(pStVarOne, pStVarTwo);

    FREE(pStVarOne);
    pStVarOne = NULL;
    FREE(pStVarTwo);
    pStVarTwo = NULL;

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

    LhsVar(1) = Rhs + 1;

    PutLhsVar();
    return 0;
}
Exemplo n.º 5
0
/*--------------------------------------------------------------------------*/
BOOL setlanguage(char *lang)
{
    if (lang)
    {
        if (LanguageIsOK(lang))
        {
#ifndef _MSC_VER
            if (needtochangelanguage(lang))
            {
#endif
                /* Load the locale from the system */
#if !defined(_MSC_VER) && !defined(__APPLE__)
                //for mbstowcs
                char *newlang = NULL;
                char *ret = setlocale(LC_CTYPE, lang);
                if (ret == NULL)
                {
                    if (lang == NULL || *lang == 0)
                    {
                        lang = getenv("LANG");
                    }

                    ret = setlocale(LC_CTYPE, lang);
                    if (ret == NULL)
                    {
                        // On some OSes we need to precise the charset (e.g. on Debian, fr_FR is not accepted but fr_FR.UTF-8 is)
                        int i = 0;
                        for (; i < NumberOfCharsets; i++)
                        {
                            newlang = (char*)MALLOC(strlen(lang) + strlen(CHARSETS[i]) + 1 + 1);
                            sprintf(newlang, "%s.%s", lang, CHARSETS[i]);
                            ret = setlocale(LC_CTYPE, newlang);
                            if (ret == NULL)
                            {
                                FREE(newlang);
                                newlang = NULL;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                if (ret == NULL)
                {
                    fprintf(stderr,
                            "Warning: Localization issue. Failed to change the LC_CTYPE locale category. Does not support the locale '%s' %s %s.\nDid you install the system locales?\n",
                            lang, ret, setlocale(LC_CTYPE, NULL));
                }

                //for gettext
                if (newlang)
                {
                    ret = setlocale(LC_MESSAGES, newlang);
                }
                else
                {
                    ret = setlocale(LC_MESSAGES, lang);
                }
#else
                /* Load the user locale from the system */
                char *ret = getLocaleUserInfo();
#endif

                //                This stuff causes pb when locales have been compiled
                if (ret == NULL)
                {
#ifndef _MSC_VER
                    fprintf(stderr, "Warning: Localization issue. Does not support the locale '%s'\nReturned: %s\nCurrent system locale: %s\nDid you install the system locales?\n", lang,
                            ret, setlocale(LC_MESSAGES, NULL));
#else
                    fprintf(stderr, "Warning: Localization issue. Cannot detect user locale.\n");
#endif
                }

                /* change language */
                if (strcmp(lang, "C") == 0 || ret == NULL || strcmp(ret, "C") == 0)
                {
                    /* The lang is the default one... ie en_US */
                    strcpy(CURRENTLANGUAGESTRING, SCILABDEFAULTLANGUAGE);
                    exportLocaleToSystem(CURRENTLANGUAGESTRING);
                }
                else
                {
                    if (strcmp(lang, "") == 0)
                    {
                        /* The requested language is the one of the system ...
                         * which we don't really know which one is it
                         * but if setlocale worked, we get it from the return
                         */
                        strncpy(CURRENTLANGUAGESTRING, ret, 5); /* 5 is the number of char in fr_FR for example */
                        exportLocaleToSystem(ret);
                    }
                    else
                    {
#if !defined(_MSC_VER) && !defined(__APPLE__)
                        if (newlang)
                        {
                            setenvc("LANG", newlang);
                            strncpy(CURRENTLANGUAGESTRING, newlang, 5);
                            exportLocaleToSystem(newlang);
                        }
                        else
#endif
                        {

                            strcpy(CURRENTLANGUAGESTRING, lang);
                            exportLocaleToSystem(lang);
                        }
                    }
                }
#ifndef _MSC_VER
                setlanguagecode(CURRENTLANGUAGESTRING);
#ifndef __APPLE__
                if (newlang)
                {
                    FREE(newlang);
                }
#endif
#endif

                return TRUE;
            }
#ifndef _MSC_VER
        }
#endif
    }
    return FALSE;
}
Exemplo n.º 6
0
//windows : find main DLL and extract path
//linux and macos : scilab script fill SCI env variable
char* computeTMPDIR()
{
#ifdef _MSC_VER
    wchar_t wcTmpDirDefault[PATH_MAX];

    if (!GetTempPathW(PATH_MAX, wcTmpDirDefault))
    {
        MessageBoxA(NULL, _("Cannot find Windows temporary directory (1)."), _("Error"), MB_ICONERROR);
        exit(1);
    }
    else
    {
        wchar_t wctmp_dir[PATH_MAX + FILENAME_MAX + 1];
        static wchar_t bufenv[PATH_MAX + 16];
        char *TmpDir = NULL;
        os_swprintf(wctmp_dir, PATH_MAX + FILENAME_MAX + 1, L"%lsSCI_TMP_%d_", wcTmpDirDefault, _getpid());
        if (CreateDirectoryW(wctmp_dir, NULL) == FALSE)
        {
            DWORD attribs = GetFileAttributesW(wctmp_dir);
            if (attribs & FILE_ATTRIBUTE_DIRECTORY)
            {
                /* Repertoire existant */
            }
            else
            {
#ifdef _DEBUG
                {
                    char MsgErr[1024];
                    wsprintfA(MsgErr, _("Impossible to create : %s"), wctmp_dir);
                    MessageBoxA(NULL, MsgErr, _("Error"), MB_ICONERROR);
                    exit(1);
                }
#else
                {
                    GetTempPathW(PATH_MAX, wcTmpDirDefault);
                    wcscpy(wctmp_dir, wcTmpDirDefault);
                    wctmp_dir[wcslen(wctmp_dir) - 1] = '\0'; /* Remove last \ */
                }
#endif
            }
        }

        os_swprintf(bufenv, PATH_MAX + 16, L"TMPDIR=%ls", wctmp_dir);
        _wputenv(bufenv);

        TmpDir = wide_string_to_UTF8(wctmp_dir);
        if (TmpDir)
        {
            return TmpDir;
        }
        else
        {
            return NULL;
        }
    }
    return NULL;
#else
    char *tmpdir;

    char* env_dir = (char*)MALLOC(sizeof(char) * (PATH_MAX + 16));
    /* If the env variable TMPDIR is set, honor this preference */
    tmpdir = getenv("TMPDIR");
    if (tmpdir != NULL && strlen(tmpdir) < (PATH_MAX) && strstr(tmpdir, "SCI_TMP_") == NULL)
    {
        strcpy(env_dir, tmpdir);
    }
    else
    {
        strcpy(env_dir, "/tmp");
    }

    /* XXXXXX will be randomized by mkdtemp */
    char *env_dir_strdup = os_strdup(env_dir); /* Copy to avoid to have the same buffer as input and output for sprintf */
    sprintf(env_dir, "%s/SCI_TMP_%d_XXXXXX", env_dir_strdup, (int)getpid());
    free(env_dir_strdup);

    if (mkdtemp(env_dir) == NULL)
    {
        fprintf(stderr, _("Error: Could not create %s: %s\n"), env_dir, strerror(errno));
    }

    setenvc("TMPDIR", env_dir);
    return env_dir;
#endif
}