]> git.pld-linux.org Git - packages/X11.git/blob - X11-glibc-charset.patch
- changing just comment makes no sense
[packages/X11.git] / X11-glibc-charset.patch
1 --- X11-6.8.1/xc/lib/X11/lcFile.c.orig  2004-09-26 00:27:04.984369960 +0200
2 +++ X11-6.8.1/xc/lib/X11/lcFile.c       2004-09-26 00:29:50.926142976 +0200
3 @@ -80,6 +80,8 @@
4  #endif
5  #endif
6  #endif
7 +#include <locale.h>
8 +#include <langinfo.h>
9  
10  #define NUM_LOCALEDIR  64
11  
12 @@ -389,6 +391,48 @@
13  #define LOCALE_ALIAS    "locale.alias"
14  #endif
15  
16 +/* To be translated: ISO-8859-.* => ISO8859-.* */
17 +static char *
18 +canonCharmap(char *alias)
19 +{
20 +       static char canonIso[] = "ISO8859-xx";
21 +       
22 +       if (strncmp(alias, "ISO-8859-", 9) != 0) return alias;
23 +       if (strlen(alias) > 9 + 2) return alias;
24 +       strcpy(&canonIso[8], &alias[9]);
25 +       return canonIso;
26 +}
27 +
28 +/* Substitute aa_BB[.CC][@dd] with aa_BB.`locale charmap`[@dd] */
29 +static char *
30 +appendCharset(const char *locale)
31 +{
32 +       char *oldLocale;
33 +       char *charmap;
34 +       char *dot, *at;
35 +       char *fullName;
36 +       
37 +       if (strcmp(locale, "C") == 0 || strcmp(locale, "POSIX") == 0) {
38 +               fullName = Xmalloc(strlen(locale) + 1);
39 +               strcpy(fullName, locale);
40 +               return fullName;
41 +       }
42 +       oldLocale = setlocale(LC_CTYPE, locale);
43 +       charmap = canonCharmap(nl_langinfo(CODESET));
44 +       setlocale(LC_CTYPE, oldLocale);
45 +       dot = strchr(locale, '.');
46 +       if (dot == NULL) dot = strchr(locale, '\0');
47 +       at = strchr(dot, '@');
48 +       if (at == NULL) at = strchr(dot, '\0');
49 +       fullName = Xmalloc(strlen(locale) - (at-dot) + strlen(charmap) + 2);
50 +       memset(fullName, 0, strlen(locale) - (at-dot) + strlen(charmap) + 2);
51 +       strncpy(fullName, locale, dot-locale);
52 +       strcat(fullName, ".");
53 +       strcat(fullName, charmap);
54 +       strcat(fullName, at);
55 +       return fullName;
56 +}
57 +
58  int
59  _XlcResolveLocaleName(
60      const char* lc_name,
61 @@ -416,11 +460,14 @@
62  
63      if (name == NULL) {
64         /* vendor locale name == Xlocale name, no expansion of alias */
65 -       pub->siname = Xmalloc (strlen (lc_name) + 1);
66 -       strcpy (pub->siname, lc_name);
67 +       tmp_siname = Xmalloc (strlen (lc_name) + 1);
68 +       strcpy (tmp_siname, lc_name);
69      } else {
70 -       pub->siname = name;
71 +       tmp_siname = name;
72      }
73 +    
74 +    pub->siname = appendCharset(tmp_siname);
75 +    Xfree(tmp_siname);
76  
77      sinamelen = strlen (pub->siname);
78      if (sinamelen == 1 && pub->siname[0] == 'C') {
79 @@ -499,16 +546,20 @@
80         }
81    
82         /* If name is not an alias, use lc_name for locale.dir search */
83 -       if (name == NULL)
84 -           name = lc_name;
85 +       if (name == NULL) {
86 +           name = appendCharset(lc_name);
87 +       } else {
88 +           char *tmp_name = name;
89 +           name = appendCharset(tmp_name);
90 +           Xfree(tmp_name);
91 +       }
92   
93         /* look at locale.dir */
94   
95         target_dir = args[i];
96         if (!target_dir) {
97             /* something wrong */
98 -           if (name != lc_name)
99 -               Xfree(name);
100 +           Xfree(name);
101             continue;
102         }
103         if ((1 + (target_dir ? strlen (target_dir) : 0) +
104 @@ -516,8 +567,7 @@
105             sprintf(buf, "%s/locale.dir", target_dir);
106             target_name = resolve_name(name, buf, RtoL);
107         }
108 -       if (name != lc_name)
109 -           Xfree(name);
110 +       Xfree(name);
111         if (target_name != NULL) {
112             char *p = 0;
113             if ((p = strstr(target_name, "/XLC_LOCALE"))) {
114 --- X11-6.8.1/xc/lib/X11/lcWrap.c.orig  2004-09-26 00:27:36.684550800 +0200
115 +++ X11-6.8.1/xc/lib/X11/lcWrap.c       2004-09-26 00:27:31.716306088 +0200
116 @@ -255,7 +255,18 @@
117  #endif
118  
119      if (name == NULL) {
120 +       /* Set locale from env before querying it */
121 +       char *oldLocale = NULL;
122 +       name = setlocale(LC_CTYPE, "");
123 +       if (name != NULL) { /* if NULL, locale is unsupported by glibc */
124 +               oldLocale = Xmalloc(strlen(name) + 1);
125 +               strcpy(oldLocale, name);
126 +       }
127         name = setlocale (LC_CTYPE, (char *)NULL);
128 +       if (oldLocale != NULL) {
129 +               setlocale(LC_CTYPE, oldLocale);
130 +               Xfree(oldLocale);
131 +       }
132  #if !defined(X_LOCALE)
133          /* 
134           * _XlMapOSLocaleName will return the same string or a substring 
This page took 0.038336 seconds and 3 git commands to generate.