Diff
Not logged in

Differences From Artifact [e63616c280]:

To Artifact [4ec534dc53]:


1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18










-
+







/* 
 * tclUnixInit.c --
 *
 *	Contains the Unix-specific interpreter initialization functions.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclUnixInit.c,v 1.1.2.11 1999/03/14 21:41:57 surles Exp $
 * RCS: @(#) $Id: tclUnixInit.c,v 1.1.2.12 1999/03/30 23:56:19 stanton Exp $
 */

#include "tclInt.h"
#include "tclPort.h"
#include <locale.h>
#if defined(__FreeBSD__)
#   include <floatingpoint.h>
311
312
313
314
315
316
317
318

319
320
321

322
323
324



325
326
327
328

329
330
331
332
333


334


335

336
337
338
339
340
341
342
343
344
345
346
347









348
349
350
351
352
353
354
355
356
357
358
359
360
311
312
313
314
315
316
317

318
319
320

321
322
323

324
325
326
327
328


329
330




331
332
333
334
335

336












337
338
339
340
341
342
343
344
345






346
347
348
349
350
351
352







-
+


-
+


-
+
+
+


-
-
+

-
-
-
-
+
+

+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-







 *
 *---------------------------------------------------------------------------
 */

void
TclpSetInitialEncodings()
{
    CONST char *locale, *encoding;
    CONST char *encoding;
    int i;
    Tcl_Obj *pathPtr;
    Tcl_DString ds;
    char *langEnv;

    /*
     * Retrieve the old locale setting so we can restore it when we are done.
     * Determine the current encoding from the LC_TYPE or LANG environment
     * variables.  We previously used setlocale() to determine the locale,
     * but this does not work on some systems (e.g. Linux/i386 RH 5.0).
     */

    Tcl_DStringInit(&ds);
    Tcl_DStringAppend(&ds, setlocale(LC_ALL, NULL), -1);
    langEnv = getenv("LC_CTYPE");

    setlocale(LC_ALL, "");
    locale = setlocale(LC_CTYPE, NULL);
    if (locale == NULL) {
	locale = "C";
    if (langEnv == NULL || langEnv[0] == '\0') {
	langEnv = getenv("LANG");
    }
    if (langEnv == NULL || langEnv[0] == '\0') {
	langEnv = NULL;

    }
    /*
     * Default encoding if locale cannot be identified.
     */
     
    encoding = "iso8859-1";

    for (i = 0; localeTable[i].lang != NULL; i++) {
	if (strcmp(localeTable[i].lang, locale) == 0) {
	    encoding = localeTable[i].encoding;
	}
    }


    encoding = "iso-8859-1";
    if (langEnv != NULL) {
	for (i = 0; localeTable[i].lang != NULL; i++) {
	    if (strcmp(localeTable[i].lang, langEnv) == 0) {
		encoding = localeTable[i].encoding;
	    }
	}
    }
    /*
     * Restore the locale settings.
     */

    setlocale(LC_ALL, Tcl_DStringValue(&ds));
    Tcl_DStringFree(&ds);

    Tcl_SetSystemEncoding(NULL, encoding);

    /*
     * Until the system encoding was actually set, the library path was
     * actually in the native multi-byte encoding, and not really UTF-8
     * as advertised.  We cheated as follows: