Пример #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;
}
Пример #2
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;
}
Пример #3
0
/*--------------------------------------------------------------------------*/
BOOL SetTclTkEnvironment(char *DefaultPath)
{
#define TCL_LIBRARY "TCL_LIBRARY"
#define TCL_LIBRARY_FORMAT "%s/modules/tclsci/tcl/tcl%d.%d"

#define TK_LIBRARY "TK_LIBRARY"
#define TK_LIBRARY_FORMAT "%s/modules/tclsci/tcl/tk%d.%d"

#define TCL_DEFAULT_ENCODING_DIR_FORMAT "%s/modules/tclsci/tcl/tcl%d.%d/encoding"

    int tcl_major = 8;
    int tcl_minor = 4; /* default */
    int tcl_patchLevel = 0;
    int tcl_type = 0;

    BOOL bOK = TRUE;

    char TCL_LIBRARY_PATH[PATH_MAX];
    char TK_LIBRARY_PATH[PATH_MAX];
    char TCL_DEFAULT_ENCODING_DIR[PATH_MAX];

    Tcl_DString encodingName;

    char ShortPath[PATH_MAX];
    char *CopyOfDefaultPath = NULL;

    Tcl_Obj *pathPtr = NULL;
    Tcl_Obj *objPtr = NULL;

    CopyOfDefaultPath = MALLOC(((int)strlen(DefaultPath) + 1) * sizeof(char));
    if (CopyOfDefaultPath == NULL)
    {
        return FALSE;
    }

    if (getScilabMode() == SCILAB_STD)
    {
        /* redirect stdout, stderr in console */
        freopen("CONOUT$", "wb", stdout); /* redirect stdout --> CONOUT$*/
        freopen("CONOUT$", "wb", stderr); /* redirect stderr --> CONOUT$*/
    }

    Tcl_GetVersion(&tcl_major, &tcl_minor, &tcl_patchLevel, &tcl_type);

    GetShortPathName(DefaultPath, ShortPath, PATH_MAX);
    AntislashToSlash(ShortPath, CopyOfDefaultPath);
    sprintf (TCL_LIBRARY_PATH, TCL_LIBRARY_FORMAT, CopyOfDefaultPath, tcl_major, tcl_minor);
    sprintf (TK_LIBRARY_PATH, TK_LIBRARY_FORMAT, CopyOfDefaultPath, tcl_major, tcl_minor);
    sprintf (TCL_DEFAULT_ENCODING_DIR,
             TCL_DEFAULT_ENCODING_DIR_FORMAT,
             CopyOfDefaultPath,
             tcl_major,
             tcl_minor);

    if (CopyOfDefaultPath)
    {
        FREE(CopyOfDefaultPath);
        CopyOfDefaultPath = NULL;
    }

    /* TCL_LIBRARY initialization */
    SetEnvironmentVariable(TCL_LIBRARY, TCL_LIBRARY_PATH);
    setenvtcl(TCL_LIBRARY, TCL_LIBRARY_PATH);
    if (Tcl_SetVar(getTclInterp(), "tcl_library", TCL_LIBRARY_PATH, TCL_GLOBAL_ONLY) == NULL)
    {
        releaseTclInterp();
        fprintf(stderr, _("%s: An error occurred: %s\n"), "tcl_library",
                _("Impossible to set environment variable."));
        bOK = FALSE;
    }
    releaseTclInterp();

    if (Tcl_SetVar(getTclInterp(), "tclDefaultLibrary", TCL_LIBRARY_PATH, TCL_GLOBAL_ONLY) == NULL)
    {
        releaseTclInterp();
        fprintf(stderr, _("%s: An error occurred: %s\n"), "tclDefaultLibrary",
                _("Impossible to set environment variable."));
        bOK = FALSE;
    }
    releaseTclInterp();

    if (Tcl_SetVar(getTclInterp(), "tcl_pkgPath", TCL_LIBRARY_PATH, TCL_GLOBAL_ONLY) == NULL)
    {
        releaseTclInterp();
        fprintf(stderr, _("%s: An error occurred: %s\n"), "tcl_pkgPath",
                _("Impossible to set environment variable."));
        bOK = FALSE;
    }
    releaseTclInterp();

    pathPtr = Tcl_NewStringObj(TCL_LIBRARY_PATH, -1);

    /* TK_LIBRARY initialization */
    SetEnvironmentVariable(TK_LIBRARY, TK_LIBRARY_PATH);
    setenvtcl(TK_LIBRARY, TK_LIBRARY_PATH);
    if (Tcl_SetVar(getTclInterp(), "tk_library", TK_LIBRARY_PATH, TCL_GLOBAL_ONLY) == NULL)
    {
        releaseTclInterp();
        fprintf(stderr, _("%s: An error occurred: %s\n"), "tk_library",
                _("Impossible to set environment variable."));
        bOK = FALSE;
    }
    releaseTclInterp();

    objPtr = Tcl_NewStringObj(TK_LIBRARY_PATH, -1);
    Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
    TclSetLibraryPath(pathPtr);

    /* encoding initialization */
    Tcl_SetDefaultEncodingDir(TCL_DEFAULT_ENCODING_DIR);
    if ( Tcl_SetSystemEncoding(NULL, Tcl_GetEncodingNameFromEnvironment(&encodingName)) == TCL_ERROR )
    {
        fprintf(stderr, _("%s: An error occurred: %s\n"), "Tcl_SetSystemEncoding",
                _("Impossible to set system encoding."));
        bOK = FALSE;
    }
    Tcl_DStringFree(&encodingName);

    return bOK ;
}