]> git.pld-linux.org Git - packages/tcl.git/blob - tcl-system_encoding.patch
- updated to 8.4.3
[packages/tcl.git] / tcl-system_encoding.patch
1 diff -durN tcl8.3.4.orig/unix/tclUnixInit.c tcl8.3.4/unix/tclUnixInit.c
2 --- tcl8.3.4.orig/unix/tclUnixInit.c    Fri Aug 24 19:13:22 2001
3 +++ tcl8.3.4/unix/tclUnixInit.c Sat Jan 11 12:39:18 2003
4 @@ -13,6 +13,7 @@
5  #include "tclInt.h"
6  #include "tclPort.h"
7  #include <locale.h>
8 +#include <langinfo.h>
9  #if defined(__FreeBSD__)
10  #   include <floatingpoint.h>
11  #endif
12 @@ -385,72 +386,37 @@
13  TclpSetInitialEncodings()
14  {
15      CONST char *encoding;
16 -    int i;
17 +    char buf[129];
18 +    int i,j,r;
19      Tcl_Obj *pathPtr;
20 -    char *langEnv;
21 -
22 -    /*
23 -     * Determine the current encoding from the LC_* or LANG environment
24 -     * variables.  We previously used setlocale() to determine the locale,
25 -     * but this does not work on some systems (e.g. Linux/i386 RH 5.0).
26 -     */
27 -
28 -    langEnv = getenv("LC_ALL");
29 -
30 -    if (langEnv == NULL || langEnv[0] == '\0') {
31 -       langEnv = getenv("LC_CTYPE");
32 -    }
33 -    if (langEnv == NULL || langEnv[0] == '\0') {
34 -       langEnv = getenv("LANG");
35 -    }
36 -    if (langEnv == NULL || langEnv[0] == '\0') {
37 -       langEnv = NULL;
38 -    }
39 -
40 -    encoding = NULL;
41 -    if (langEnv != NULL) {
42 -       for (i = 0; localeTable[i].lang != NULL; i++) {
43 -           if (strcmp(localeTable[i].lang, langEnv) == 0) {
44 -               encoding = localeTable[i].encoding;
45 -               break;
46 -           }
47 -       }
48 -       /*
49 -        * There was no mapping in the locale table.  If there is an
50 -        * encoding subfield, we can try to guess from that.
51 -        */
52 -
53 -       if (encoding == NULL) {
54 -           char *p;
55 -           for (p = langEnv; *p != '\0'; p++) {
56 -               if (*p == '.') {
57 -                   p++;
58 -                   break;
59 -               }
60 -           }
61 -           if (*p != '\0') {
62 -               Tcl_DString ds;
63 -               Tcl_DStringInit(&ds);
64 -               Tcl_DStringAppend(&ds, p, -1);
65  
66 -               encoding = Tcl_DStringValue(&ds);
67 -               Tcl_UtfToLower(Tcl_DStringValue(&ds));
68 -               if (Tcl_SetSystemEncoding(NULL, encoding) == TCL_OK) {
69 -                   Tcl_DStringFree(&ds);
70 -                   goto resetPath;
71 -               }
72 -               Tcl_DStringFree(&ds);
73 -               encoding = NULL;
74
75 +    /* read the encoding from locale settings */
76 +    setlocale(LC_CTYPE, "");
77 +    encoding=nl_langinfo(CODESET);
78 +    
79 +    /* reset the LC_CTYPE locale to "C", so ctype works for ASCII as it should */
80 +    setlocale(LC_CTYPE, "C");
81 +    if (encoding){
82 +           j=0;
83 +           for(i=0;i<128 && encoding[i];i++){
84 +                   if (i==3 && buf[0]=='i' && buf[1]=='s' && buf[2]=='o' 
85 +                       && encoding[i]=='-') continue;
86 +                   buf[j++]=tolower(encoding[i]);
87             }
88 -       }
89 +           buf[j]=0;
90 +           encoding=buf;
91      }
92 +    
93      if (encoding == NULL) {
94         encoding = "iso8859-1";
95      }
96 +    r=Tcl_SetSystemEncoding(NULL, encoding);
97  
98 -    Tcl_SetSystemEncoding(NULL, encoding);
99 +    if (r != TCL_OK){
100 +        Tcl_SetSystemEncoding(NULL, "iso8859-1");
101 +    }
102  
103 -    resetPath:
104      /*
105       * Initialize the C library's locale subsystem.  This is required
106       * for input methods to work properly on X11.  We only do this for
107 @@ -461,7 +427,7 @@
108       */
109  
110      setlocale(LC_CTYPE, "");
111 -
112
113      /*
114       * In case the initial locale is not "C", ensure that the numeric
115       * processing is done in "C" locale regardless.  This is needed because
This page took 0.042036 seconds and 3 git commands to generate.