| ︙ | | |
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
361
362
363
364
365
366
|
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
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
long tclMacOSXDarwinRelease = 0;
#endif
/*
*---------------------------------------------------------------------------
*
* GetLocEncFromEnv --
*
* Read initial locale-dependend encoding (or language), corresponding
* environment specified parameters.
*
* Typically called once by process initialization (before "setlocale").
*
* Results:
* String contains encoding/language or NULL.
*
*---------------------------------------------------------------------------
*/
static const char *
GetLocEncFromEnv()
{
const char *encoding;
encoding = getenv("LC_ALL");
if (encoding == NULL || encoding[0] == '\0') {
encoding = getenv("LC_CTYPE");
}
if (encoding == NULL || encoding[0] == '\0') {
encoding = getenv("LANG");
}
if (encoding == NULL || encoding[0] == '\0') {
encoding = NULL;
}
return encoding;
}
/*
*---------------------------------------------------------------------------
*
* TclpInitPlatform --
*
* Initialize all the platform-dependant things like signals and
* floating-point error handling.
*
* Called at process initialization time.
*
* Results:
* None.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static const char *init_EnvEnc = NULL;
static const char *init_LocCType = NULL;
void
TclpInitPlatform(void)
{
/*
* Save current env/locale encoding before set locale (because it could change
* later env-var "LANG" to "C" (if selected local unsupported).
*/
init_EnvEnc = GetLocEncFromEnv();
#ifdef DJGPP
tclPlatform = TCL_PLATFORM_WINDOWS;
#else
tclPlatform = TCL_PLATFORM_UNIX;
#endif
/*
|
| ︙ | | |
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
|
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
-
+
|
* methods to work properly on X11. We only do this for 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, "");
init_LocCType = setlocale(LC_CTYPE, "");
/*
* 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.
*/
|
| ︙ | | |
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
|
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
|
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
|
return NULL;
}
const char *
Tcl_GetEncodingNameFromEnvironment(
Tcl_DString *bufPtr)
{
const char *encoding;
const char *knownEncoding;
const char *encoding, *initEncoding, *knownEncoding;
const char *initLocCType;
Tcl_DStringInit(bufPtr);
/*
* First time called during initialization process (once).
*/
initEncoding = init_EnvEnc;
init_EnvEnc = NULL;
initLocCType = init_LocCType;
init_LocCType = NULL;
/*
* 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
if (
#ifdef WEAK_IMPORT_NL_LANGINFO
nl_langinfo != NULL &&
#endif
(initLocCType != NULL ||
setlocale(LC_CTYPE, "") != NULL) {
(initLocCType = setlocale(LC_CTYPE, "")) != NULL) &&
/* avoid implicit fallback to C */
(strcmp(initLocCType, "C") != 0 ||
!initEncoding || strcmp(initEncoding, "C") == 0)
) {
Tcl_DString ds;
/*
* Use a DString so we can modify case.
*/
Tcl_DStringInit(&ds);
|
| ︙ | | |
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
|
-
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
|
#endif /* HAVE_LANGINFO */
/*
* Classic fallback check. This tries a homebrew algorithm to determine
* what encoding should be used based on env vars.
*/
encoding = getenv("LC_ALL");
if (encoding == NULL || encoding[0] == '\0') {
encoding = getenv("LC_CTYPE");
/* Try to determine proper encoding after locale was changed (setlocale). */
encoding = GetLocEncFromEnv();
if (initEncoding && strcmp(initEncoding, "C") != 0 &&
}
if (encoding == NULL || encoding[0] == '\0') {
encoding = getenv("LANG");
(!initLocCType || strcmp(initLocCType, "C") == 0)
) {
/* use initial encoding, setlocale has not found better suitable one. */
}
if (encoding == NULL || encoding[0] == '\0') {
encoding = NULL;
encoding = initEncoding;
}
if (encoding != NULL) {
const char *p;
Tcl_DString ds;
Tcl_DStringInit(&ds);
|
| ︙ | | |