Diff
Not logged in

Differences From Artifact [a157d2646c]:

To Artifact [5c04e387d8]:


1
2
3
4
5
6
7
8
9
10

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

10
11
12
13
14
15
16
17









-
+







/* 
 * 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.25 2001/11/16 20:55:40 hobbs Exp $
 * RCS: @(#) $Id: tclUnixInit.c,v 1.26 2001/11/16 23:40:41 hobbs Exp $
 */

#include "tclInt.h"
#include "tclPort.h"
#include <locale.h>
#ifdef HAVE_LANGINFO
#include <langinfo.h>
48
49
50
51
52
53
54
55
56
57



58

59
60
61
62
63
64
65
66



67
68
69
70
71
72
73
48
49
50
51
52
53
54

55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78







-


+
+
+
-
+








+
+
+







 * 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.  If HAVE_LANGINFO is defined, then this is a fallback
 * table when the result from nl_langinfo isn't a recognized encoding.
 * Otherwise this is the first list checked for a mapping from env
 * encoding files.
 * encoding to Tcl encoding name.
 */

typedef struct LocaleTable {
    CONST char *lang;
    CONST char *encoding;
} LocaleTable;

static CONST LocaleTable localeTable[] = {
#ifdef HAVE_LANGINFO
    {"gb2312-1980",	"gb2312"},
#else
    {"ja_JP.SJIS",	"shiftjis"},
    {"ja_JP.EUC",	"euc-jp"},
    {"ja_JP.eucJP",     "euc-jp"},
    {"ja_JP.JIS",	"iso2022-jp"},
    {"ja_JP.mscode",	"shiftjis"},
    {"ja_JP.ujis",	"euc-jp"},
    {"ja_JP",		"euc-jp"},
94
95
96
97
98
99
100
101

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

106
107
108

109
110
111
112
113
114
115







-
+


-







    {"korean",          "euc-kr"},

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

    {"zh",		"cp936"},

#endif /* !HAVE_LANGINFO */
    {NULL, NULL}
};
#endif /* !HAVE_LANGINFO */

/*
 *---------------------------------------------------------------------------
 *
 * TclpInitPlatform --
 *
 *	Initialize all the platform-dependant things like signals and
405
406
407
408
409
410
411

412
413
414
415
416
417
418
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423







+







	/*
	 * 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;
	int code;

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

	Tcl_UtfToLower(Tcl_DStringValue(&ds));
433
434
435
436
437
438
439
440











441
442
443
444
445
446
447
438
439
440
441
442
443
444

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462







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







	} 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) {
	code = Tcl_SetSystemEncoding(NULL, encoding);
	if (code != TCL_OK) {
	    for (i = 0; localeTable[i].lang != NULL; i++) {
		if (strcmp(localeTable[i].lang, encoding) == 0) {
		    encoding = localeTable[i].encoding;
		    code = Tcl_SetSystemEncoding(NULL, encoding);
		    break;
		}
	    }
	}
	if (code != 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";