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.14 1999/04/21 22:00:29 stanton Exp $
*/
#include "tclInt.h"
#include "tclPort.h"
#include <locale.h>
#if defined(__FreeBSD__)
# include <floatingpoint.h>
|
|
|
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.14.4.1 1999/05/14 18:26:13 stanton Exp $
*/
#include "tclInt.h"
#include "tclPort.h"
#include <locale.h>
#if defined(__FreeBSD__)
# include <floatingpoint.h>
|
| ︙ | | | ︙ | |
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
* 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;
typedef struct LocaleTable {
CONST char *lang;
CONST char *encoding;
} LocaleTable;
static CONST LocaleTable localeTable[] = {
{"ja_JP.SJIS", "shiftjis"},
|
>
>
>
>
>
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
* 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;
/*
* The following table is used to map from Unix locale strings to
* encoding files.
*/
typedef struct LocaleTable {
CONST char *lang;
CONST char *encoding;
} LocaleTable;
static CONST LocaleTable localeTable[] = {
{"ja_JP.SJIS", "shiftjis"},
|
| ︙ | | | ︙ | |
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
{"ko", "euc-kr"},
{"ko_KR", "euc-kr"},
{"ko_KR.EUC", "euc-kr"},
{"ko_KR.euc", "euc-kr"},
{"ko_KR.eucKR", "euc-kr"},
{"korean", "euc-kr"},
{"zh", "cp936"},
{NULL, NULL}
};
/*
*---------------------------------------------------------------------------
|
>
>
>
>
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
{"ko", "euc-kr"},
{"ko_KR", "euc-kr"},
{"ko_KR.EUC", "euc-kr"},
{"ko_KR.euc", "euc-kr"},
{"ko_KR.eucKR", "euc-kr"},
{"korean", "euc-kr"},
{"ru", "iso8859-5"},
{"ru_RU", "iso8859-5"},
{"ru_SU", "iso8859-5"},
{"zh", "cp936"},
{NULL, NULL}
};
/*
*---------------------------------------------------------------------------
|
| ︙ | | | ︙ | |
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
void
TclpSetInitialEncodings()
{
CONST char *encoding;
int i;
Tcl_Obj *pathPtr;
char *langEnv;
/*
* 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).
*/
langEnv = getenv("LC_CTYPE");
if (langEnv == NULL || langEnv[0] == '\0') {
langEnv = getenv("LANG");
}
if (langEnv == NULL || langEnv[0] == '\0') {
langEnv = NULL;
}
encoding = "iso8859-1";
if (langEnv != NULL) {
for (i = 0; localeTable[i].lang != NULL; i++) {
if (strcmp(localeTable[i].lang, langEnv) == 0) {
encoding = localeTable[i].encoding;
}
}
}
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:
*
* 1. It was safe to allow the Tcl_SetSystemEncoding() call to
|
>
|
>
>
>
|
|
|
>
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
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
460
461
462
463
464
465
|
void
TclpSetInitialEncodings()
{
CONST char *encoding;
int i;
Tcl_Obj *pathPtr;
char *langEnv;
Tcl_DString ds;
/*
* 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).
*/
langEnv = getenv("LC_ALL");
if (langEnv == NULL || langEnv[0] == '\0') {
langEnv = getenv("LC_CTYPE");
}
if (langEnv == NULL || langEnv[0] == '\0') {
langEnv = getenv("LANG");
}
if (langEnv == NULL || langEnv[0] == '\0') {
langEnv = NULL;
}
encoding = NULL;
if (langEnv != NULL) {
for (i = 0; localeTable[i].lang != NULL; i++) {
if (strcmp(localeTable[i].lang, langEnv) == 0) {
encoding = localeTable[i].encoding;
break;
}
}
/*
* There was no mapping in the locale table. If there is an
* encoding subfield, we can try to guess from that.
*/
if (encoding == NULL) {
char *p;
for (p = langEnv; *p != '\0'; p++) {
if (*p == '.') {
p++;
break;
}
}
if (*p != '\0') {
Tcl_DString ds;
Tcl_DStringInit(&ds);
Tcl_DStringAppend(&ds, p, -1);
encoding = Tcl_DStringValue(&ds);
Tcl_UtfToLower(Tcl_DStringValue(&ds));
if (Tcl_SetSystemEncoding(NULL, encoding) == TCL_OK) {
Tcl_DStringFree(&ds);
goto resetPath;
}
Tcl_DStringFree(&ds);
encoding = NULL;
}
}
}
if (encoding == NULL) {
encoding = "iso8859-1";
}
Tcl_SetSystemEncoding(NULL, encoding);
/*
* Initialize the C library's locale subsystem. This is required
* for input methods to work properly on X11. Note that we need to
* retore the initial "C" locale so that Tcl can parse numbers
* properly. The side effect of setting the default locale should be to
* load any locale specific modules that are needed by X.
*/
Tcl_DStringInit(&ds);
Tcl_DStringAppend(&ds, setlocale(LC_ALL, NULL), -1);
setlocale(LC_ALL, "");
setlocale(LC_ALL, Tcl_DStringValue(&ds));
Tcl_DStringFree(&ds);
/*
* 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.
*/
setlocale(LC_NUMERIC, "C");
/*
* 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:
*
* 1. It was safe to allow the Tcl_SetSystemEncoding() call to
|
| ︙ | | | ︙ | |
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
* Now that the system encoding was actually successfully set,
* translate all the names in the library path to UTF-8. That way,
* next time we search the library path, we'll translate the names
* from UTF-8 to the system encoding which will be the native
* encoding.
*/
pathPtr = TclGetLibraryPath();
if (pathPtr != NULL) {
int objc;
Tcl_Obj **objv;
objc = 0;
Tcl_ListObjGetElements(NULL, pathPtr, &objc, &objv);
|
>
|
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
* Now that the system encoding was actually successfully set,
* translate all the names in the library path to UTF-8. That way,
* next time we search the library path, we'll translate the names
* from UTF-8 to the system encoding which will be the native
* encoding.
*/
resetPath:
pathPtr = TclGetLibraryPath();
if (pathPtr != NULL) {
int objc;
Tcl_Obj **objv;
objc = 0;
Tcl_ListObjGetElements(NULL, pathPtr, &objc, &objv);
|
| ︙ | | | ︙ | |