Diff
Not logged in

Differences From Artifact [f9d36f036e]:

To Artifact [a157d2646c]:


1
2
3
4
5
6
7
8
9
10

11
12
13
14
15



16
17
18
19
20
21
22
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25









-
+





+
+
+







/* 
 * tclUnixInit.c --
 *
 *	Contains the Unix-specific interpreter initialization functions.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1999 by Scriptics Corporation.
 * All rights reserved.
 *
 * RCS: @(#) $Id: tclUnixInit.c,v 1.24 2001/08/27 02:14:08 dgp Exp $
 * RCS: @(#) $Id: tclUnixInit.c,v 1.25 2001/11/16 20:55:40 hobbs Exp $
 */

#include "tclInt.h"
#include "tclPort.h"
#include <locale.h>
#ifdef HAVE_LANGINFO
#include <langinfo.h>
#endif
#if defined(__FreeBSD__)
#   include <floatingpoint.h>
#endif
#if defined(__bsdi__)
#   include <sys/param.h>
#   if _BSDI_VERSION > 199501
#	include <dlfcn.h>
45
46
47
48
49
50
51

52
53
54
55
56
57
58
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62







+







 * Directory in which to look for packages (each package is typically
 * installed as a subdirectory of this directory).  The symbol is
 * defined by Makefile.
 */

static char pkgPath[sizeof(TCL_PACKAGE_PATH)+200] = TCL_PACKAGE_PATH;

#ifndef HAVE_LANGINFO
/*
 * The following table is used to map from Unix locale strings to
 * encoding files.
 */

typedef struct LocaleTable {
    CONST char *lang;
93
94
95
96
97
98
99

100
101
102
103
104
105
106
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111







+







    {"ru_RU",		"iso8859-5"},		
    {"ru_SU",		"iso8859-5"},		

    {"zh",		"cp936"},

    {NULL, NULL}
};
#endif /* !HAVE_LANGINFO */

/*
 *---------------------------------------------------------------------------
 *
 * TclpInitPlatform --
 *
 *	Initialize all the platform-dependant things like signals and
392
393
394
395
396
397
398
399
400
401
402
403
404
405


406








































407
408
409
410
411
412
413
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459







-






+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







void
TclpSetInitialEncodings()
{
    if (libraryPathEncodingFixed == 0) {
	CONST char *encoding;
	int i;
	Tcl_Obj *pathPtr;
	char *langEnv;

	/*
	 * Determine the current encoding from the LC_* 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).
	 */
#ifdef HAVE_LANGINFO
	Tcl_DString ds;

	setlocale(LC_CTYPE,"");
	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, nl_langinfo(CODESET), -1);
	encoding = Tcl_DStringValue(&ds);

	Tcl_UtfToLower(Tcl_DStringValue(&ds));
	if (encoding[0] == 'i' && encoding[1] == 's' && encoding[2] == 'o'
		&& encoding[3] == '-') {
	    char *p, *q;
	    /* need to strip extra - from ISO-* encoding */
	    for(p = Tcl_DStringValue(&ds)+3, q = Tcl_DStringValue(&ds)+4; *p;
		*p++ = *q++);
	} else if (encoding[0] == 'i' && encoding[1] == 'b'
		&& encoding[2] == 'm' && encoding[3] >= '0'
		&& encoding[3] <= '9') {
	    char *p, *q;
	    /* if langinfo reports IBMxxx we should use cpXXX*/
	    p = Tcl_DStringValue(&ds);
	    *p++='c'; *p++='p';
	    for(q=p+1;*p;*p++= *q++);
	} else if (!strcmp(encoding, "ansi_x3.4-1968") || *encoding == '\0') {
	    /*
	     * Use iso8859-1 for empty or 'ansi_x3.4-1968' encoding.
	     */
	    Tcl_DStringSetLength(&ds, 0);
	    Tcl_DStringAppend(&ds, "iso8859-1", -1);
	}
	if (Tcl_SetSystemEncoding(NULL, encoding) != TCL_OK) {
	    Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);
	    if (errChannel) {
		char msg[100];
		sprintf(msg, "Couldn't set encoding to '%.50s'\n", encoding);
		Tcl_Write(errChannel, msg, -1);
	    }
	    encoding = "iso8859-1";
	    Tcl_SetSystemEncoding(NULL, encoding);
	}
	Tcl_DStringFree(&ds);
#else
	char *langEnv;
	langEnv = getenv("LC_ALL");

	if (langEnv == NULL || langEnv[0] == '\0') {
	    langEnv = getenv("LC_CTYPE");
	}
	if (langEnv == NULL || langEnv[0] == '\0') {
	    langEnv = getenv("LANG");
466
467
468
469
470
471
472

473
474
475
476
477
478
479
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526







+







	 * LC_CTYPE because that's the necessary one, and we don't want to
	 * affect LC_TIME here.  The side effect of setting the default locale
	 * should be to load any locale specific modules that are needed by X.
	 * [BUG: 5422 3345 4236 2522 2521].
	 */

	setlocale(LC_CTYPE, "");
#endif /* HAVE_LANGINFO */

	/*
	 * In case the initial locale is not "C", ensure that the numeric
	 * processing is done in "C" locale regardless.  This is needed because
	 * Tcl relies on routines like strtod, but should not have locale
	 * dependent behavior.
	 */