author | dholmes |
Fri, 25 Mar 2011 07:09:38 -0400 | |
changeset 9002 | 6ee0abf0167f |
parent 7668 | d4a77089c587 |
child 11665 | 98dad53a8ba1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9002 | 2 |
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#ifdef __linux__ |
|
27 |
#include <stdio.h> |
|
28 |
#include <ctype.h> |
|
29 |
#endif |
|
30 |
#include <pwd.h> |
|
31 |
#include <locale.h> |
|
32 |
#ifndef ARCHPROPNAME |
|
33 |
#error "The macro ARCHPROPNAME has not been defined" |
|
34 |
#endif |
|
35 |
#include <sys/utsname.h> /* For os_name and os_version */ |
|
36 |
#include <langinfo.h> /* For nl_langinfo */ |
|
37 |
#include <stdlib.h> |
|
38 |
#include <string.h> |
|
39 |
#include <sys/types.h> |
|
40 |
#include <unistd.h> |
|
41 |
#include <sys/param.h> |
|
42 |
#include <time.h> |
|
43 |
#include <errno.h> |
|
44 |
||
45 |
#include "locale_str.h" |
|
46 |
#include "java_props.h" |
|
47 |
||
48 |
#ifdef __linux__ |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6489
diff
changeset
|
49 |
#ifndef CODESET |
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6489
diff
changeset
|
50 |
#define CODESET _NL_CTYPE_CODESET_NAME |
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6489
diff
changeset
|
51 |
#endif |
2 | 52 |
#else |
53 |
#ifdef ALT_CODESET_KEY |
|
54 |
#define CODESET ALT_CODESET_KEY |
|
55 |
#endif |
|
56 |
#endif |
|
57 |
||
9002 | 58 |
#ifdef JAVASE_EMBEDDED |
59 |
#include <dlfcn.h> |
|
60 |
#include <sys/stat.h> |
|
61 |
#endif |
|
62 |
||
2 | 63 |
/* Take an array of string pairs (map of key->value) and a string (key). |
64 |
* Examine each pair in the map to see if the first string (key) matches the |
|
65 |
* string. If so, store the second string of the pair (value) in the value and |
|
66 |
* return 1. Otherwise do nothing and return 0. The end of the map is |
|
67 |
* indicated by an empty string at the start of a pair (key of ""). |
|
68 |
*/ |
|
69 |
static int |
|
70 |
mapLookup(char* map[], const char* key, char** value) { |
|
71 |
int i; |
|
72 |
for (i = 0; strcmp(map[i], ""); i += 2){ |
|
73 |
if (!strcmp(key, map[i])){ |
|
74 |
*value = map[i + 1]; |
|
75 |
return 1; |
|
76 |
} |
|
77 |
} |
|
78 |
return 0; |
|
79 |
} |
|
80 |
||
81 |
/* This function sets an environment variable using envstring. |
|
82 |
* The format of envstring is "name=value". |
|
83 |
* If the name has already existed, it will append value to the name. |
|
84 |
*/ |
|
85 |
static void |
|
86 |
setPathEnvironment(char *envstring) |
|
87 |
{ |
|
88 |
char name[20], *value, *current; |
|
89 |
||
90 |
value = strchr(envstring, '='); /* locate name and value separator */ |
|
91 |
||
92 |
if (! value) |
|
93 |
return; /* not a valid environment setting */ |
|
94 |
||
95 |
/* copy first part as environment name */ |
|
96 |
strncpy(name, envstring, value - envstring); |
|
97 |
name[value-envstring] = '\0'; |
|
98 |
||
99 |
value++; /* set value point to value of the envstring */ |
|
100 |
||
101 |
current = getenv(name); |
|
102 |
if (current) { |
|
103 |
if (! strstr(current, value)) { |
|
104 |
/* value is not found in current environment, append it */ |
|
105 |
char *temp = malloc(strlen(envstring) + strlen(current) + 2); |
|
106 |
strcpy(temp, name); |
|
107 |
strcat(temp, "="); |
|
108 |
strcat(temp, current); |
|
109 |
strcat(temp, ":"); |
|
110 |
strcat(temp, value); |
|
111 |
putenv(temp); |
|
112 |
} |
|
113 |
/* else the value has already been set, do nothing */ |
|
114 |
} |
|
115 |
else { |
|
116 |
/* environment variable is not found */ |
|
117 |
putenv(envstring); |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
#ifndef P_tmpdir |
|
122 |
#define P_tmpdir "/var/tmp" |
|
123 |
#endif |
|
124 |
||
7017 | 125 |
static int ParseLocale(int cat, char ** std_language, char ** std_script, |
126 |
char ** std_country, char ** std_variant, char ** std_encoding) { |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
127 |
char temp[64]; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
128 |
char *language = NULL, *country = NULL, *variant = NULL, |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
129 |
*encoding = NULL; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
130 |
char *p, encoding_variant[64]; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
131 |
char *lc; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
132 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
133 |
/* Query the locale set for the category */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
134 |
lc = setlocale(cat, NULL); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
135 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
136 |
#ifndef __linux__ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
137 |
if (lc == NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
138 |
return 0; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
139 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
140 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
141 |
if (cat == LC_CTYPE) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
142 |
/* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
143 |
* Workaround for Solaris bug 4201684: Xlib doesn't like @euro |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
144 |
* locales. Since we don't depend on the libc @euro behavior, |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
145 |
* we just remove the qualifier. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
146 |
* On Linux, the bug doesn't occur; on the other hand, @euro |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
147 |
* is needed there because it's a shortcut that also determines |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
148 |
* the encoding - without it, we wouldn't get ISO-8859-15. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
149 |
* Therefore, this code section is Solaris-specific. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
150 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
151 |
lc = strdup(lc); /* keep a copy, setlocale trashes original. */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
152 |
strcpy(temp, lc); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
153 |
p = strstr(temp, "@euro"); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
154 |
if (p != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
155 |
*p = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
156 |
setlocale(LC_ALL, temp); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
157 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
158 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
159 |
#else |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
160 |
if (lc == NULL || !strcmp(lc, "C") || !strcmp(lc, "POSIX")) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
161 |
lc = "en_US"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
162 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
163 |
#endif |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
164 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
165 |
/* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
166 |
* locale string format in Solaris is |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
167 |
* <language name>_<country name>.<encoding name>@<variant name> |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
168 |
* <country name>, <encoding name>, and <variant name> are optional. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
169 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
170 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
171 |
strcpy(temp, lc); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
172 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
173 |
/* Parse the language, country, encoding, and variant from the |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
174 |
* locale. Any of the elements may be missing, but they must occur |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
175 |
* in the order language_country.encoding@variant, and must be |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
176 |
* preceded by their delimiter (except for language). |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
177 |
* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
178 |
* If the locale name (without .encoding@variant, if any) matches |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
179 |
* any of the names in the locale_aliases list, map it to the |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
180 |
* corresponding full locale name. Most of the entries in the |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
181 |
* locale_aliases list are locales that include a language name but |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
182 |
* no country name, and this facility is used to map each language |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
183 |
* to a default country if that's possible. It's also used to map |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
184 |
* the Solaris locale aliases to their proper Java locale IDs. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
185 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
186 |
if ((p = strchr(temp, '.')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
187 |
strcpy(encoding_variant, p); /* Copy the leading '.' */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
188 |
*p = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
189 |
} else if ((p = strchr(temp, '@')) != NULL) { |
7017 | 190 |
strcpy(encoding_variant, p); /* Copy the leading '@' */ |
191 |
*p = '\0'; |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
192 |
} else { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
193 |
*encoding_variant = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
194 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
195 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
196 |
if (mapLookup(locale_aliases, temp, &p)) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
197 |
strcpy(temp, p); |
7017 | 198 |
// check the "encoding_variant" again, if any. |
199 |
if ((p = strchr(temp, '.')) != NULL) { |
|
200 |
strcpy(encoding_variant, p); /* Copy the leading '.' */ |
|
201 |
*p = '\0'; |
|
202 |
} else if ((p = strchr(temp, '@')) != NULL) { |
|
203 |
strcpy(encoding_variant, p); /* Copy the leading '@' */ |
|
204 |
*p = '\0'; |
|
205 |
} |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
206 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
207 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
208 |
language = temp; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
209 |
if ((country = strchr(temp, '_')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
210 |
*country++ = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
211 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
212 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
213 |
p = encoding_variant; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
214 |
if ((encoding = strchr(p, '.')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
215 |
p[encoding++ - p] = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
216 |
p = encoding; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
217 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
218 |
if ((variant = strchr(p, '@')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
219 |
p[variant++ - p] = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
220 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
221 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
222 |
/* Normalize the language name */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
223 |
if (std_language != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
224 |
*std_language = "en"; |
7248
6a95f692e203
6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents:
7018
diff
changeset
|
225 |
if (language != NULL && mapLookup(language_names, language, std_language) == 0) { |
6a95f692e203
6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents:
7018
diff
changeset
|
226 |
*std_language = malloc(strlen(language)+1); |
6a95f692e203
6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents:
7018
diff
changeset
|
227 |
strcpy(*std_language, language); |
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
228 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
229 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
230 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
231 |
/* Normalize the country name */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
232 |
if (std_country != NULL && country != NULL) { |
7248
6a95f692e203
6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents:
7018
diff
changeset
|
233 |
if (mapLookup(country_names, country, std_country) == 0) { |
6a95f692e203
6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents:
7018
diff
changeset
|
234 |
*std_country = malloc(strlen(country)+1); |
6a95f692e203
6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents:
7018
diff
changeset
|
235 |
strcpy(*std_country, country); |
6a95f692e203
6997999: Remove duplicated entries from ISO language/country code tables
naoto
parents:
7018
diff
changeset
|
236 |
} |
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
237 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
238 |
|
7017 | 239 |
/* Normalize the script and variant name. Note that we only use |
240 |
* variants listed in the mapping array; others are ignored. |
|
241 |
*/ |
|
242 |
if (variant != NULL) { |
|
243 |
if (std_script != NULL) { |
|
244 |
mapLookup(script_names, variant, std_script); |
|
245 |
} |
|
246 |
||
247 |
if (std_variant != NULL) { |
|
248 |
mapLookup(variant_names, variant, std_variant); |
|
249 |
} |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
250 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
251 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
252 |
/* Normalize the encoding name. Note that we IGNORE the string |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
253 |
* 'encoding' extracted from the locale name above. Instead, we use the |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
254 |
* more reliable method of calling nl_langinfo(CODESET). This function |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
255 |
* returns an empty string if no encoding is set for the given locale |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
256 |
* (e.g., the C or POSIX locales); we use the default ISO 8859-1 |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
257 |
* converter for such locales. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
258 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
259 |
if (std_encoding != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
260 |
/* OK, not so reliable - nl_langinfo() gives wrong answers on |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
261 |
* Euro locales, in particular. */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
262 |
if (strcmp(p, "ISO8859-15") == 0) |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
263 |
p = "ISO8859-15"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
264 |
else |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
265 |
p = nl_langinfo(CODESET); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
266 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
267 |
/* Convert the bare "646" used on Solaris to a proper IANA name */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
268 |
if (strcmp(p, "646") == 0) |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
269 |
p = "ISO646-US"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
270 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
271 |
/* return same result nl_langinfo would return for en_UK, |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
272 |
* in order to use optimizations. */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
273 |
*std_encoding = (*p != '\0') ? p : "ISO8859-1"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
274 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
275 |
#ifdef __linux__ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
276 |
/* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
277 |
* Remap the encoding string to a different value for japanese |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
278 |
* locales on linux so that customized converters are used instead |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
279 |
* of the default converter for "EUC-JP". The customized converters |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
280 |
* omit support for the JIS0212 encoding which is not supported by |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
281 |
* the variant of "EUC-JP" encoding used on linux |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
282 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
283 |
if (strcmp(p, "EUC-JP") == 0) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
284 |
*std_encoding = "EUC-JP-LINUX"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
285 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
286 |
#else |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
287 |
if (strcmp(p,"eucJP") == 0) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
288 |
/* For Solaris use customized vendor defined character |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
289 |
* customized EUC-JP converter |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
290 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
291 |
*std_encoding = "eucJP-open"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
292 |
} else if (strcmp(p, "Big5") == 0 || strcmp(p, "BIG5") == 0) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
293 |
/* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
294 |
* Remap the encoding string to Big5_Solaris which augments |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
295 |
* the default converter for Solaris Big5 locales to include |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
296 |
* seven additional ideographic characters beyond those included |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
297 |
* in the Java "Big5" converter. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
298 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
299 |
*std_encoding = "Big5_Solaris"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
300 |
} else if (strcmp(p, "Big5-HKSCS") == 0) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
301 |
/* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
302 |
* Solaris uses HKSCS2001 |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
303 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
304 |
*std_encoding = "Big5-HKSCS-2001"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
305 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
306 |
#endif |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
307 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
308 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
309 |
return 1; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
310 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
311 |
|
9002 | 312 |
#ifdef JAVASE_EMBEDDED |
313 |
/* Determine the default embedded toolkit based on whether lib/xawt/ |
|
314 |
* exists in the JRE. This can still be overridden by -Dawt.toolkit=XXX |
|
315 |
*/ |
|
316 |
static char* getEmbeddedToolkit() { |
|
317 |
Dl_info dlinfo; |
|
318 |
char buf[MAXPATHLEN]; |
|
319 |
int32_t len; |
|
320 |
char *p; |
|
321 |
struct stat statbuf; |
|
322 |
||
323 |
/* Get address of this library and the directory containing it. */ |
|
324 |
dladdr((void *)getEmbeddedToolkit, &dlinfo); |
|
325 |
realpath((char *)dlinfo.dli_fname, buf); |
|
326 |
len = strlen(buf); |
|
327 |
p = strrchr(buf, '/'); |
|
328 |
/* Default AWT Toolkit on Linux and Solaris is XAWT. */ |
|
329 |
strncpy(p, "/xawt/", MAXPATHLEN-len-1); |
|
330 |
/* Check if it exists */ |
|
331 |
if (stat(buf, &statbuf) == -1 && errno == ENOENT) { |
|
332 |
/* No - this is a reduced-headless-jre so use special HToolkit */ |
|
333 |
return "sun.awt.HToolkit"; |
|
334 |
} |
|
335 |
else { |
|
336 |
/* Yes - this is a headful JRE so fallback to SE defaults */ |
|
337 |
return NULL; |
|
338 |
} |
|
339 |
} |
|
340 |
#endif |
|
341 |
||
2 | 342 |
/* This function gets called very early, before VM_CALLS are setup. |
343 |
* Do not use any of the VM_CALLS entries!!! |
|
344 |
*/ |
|
345 |
java_props_t * |
|
346 |
GetJavaProperties(JNIEnv *env) |
|
347 |
{ |
|
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6489
diff
changeset
|
348 |
static java_props_t sprops; |
2 | 349 |
char *v; /* tmp var */ |
350 |
||
351 |
if (sprops.user_dir) { |
|
352 |
return &sprops; |
|
353 |
} |
|
354 |
||
355 |
/* tmp dir */ |
|
356 |
sprops.tmp_dir = P_tmpdir; |
|
357 |
||
358 |
/* Printing properties */ |
|
359 |
sprops.printerJob = "sun.print.PSPrinterJob"; |
|
360 |
||
361 |
/* patches/service packs installed */ |
|
362 |
sprops.patch_level = "unknown"; |
|
363 |
||
364 |
/* Java 2D properties */ |
|
365 |
sprops.graphics_env = "sun.awt.X11GraphicsEnvironment"; |
|
9002 | 366 |
|
367 |
#ifdef JAVASE_EMBEDDED |
|
368 |
sprops.awt_toolkit = getEmbeddedToolkit(); |
|
369 |
if (sprops.awt_toolkit == NULL) // default as below |
|
370 |
#endif |
|
371 |
sprops.awt_toolkit = "sun.awt.X11.XToolkit"; |
|
2 | 372 |
|
373 |
/* This is used only for debugging of font problems. */ |
|
374 |
v = getenv("JAVA2D_FONTPATH"); |
|
375 |
sprops.font_dir = v ? v : NULL; |
|
376 |
||
377 |
#ifdef SI_ISALIST |
|
378 |
/* supported instruction sets */ |
|
379 |
{ |
|
380 |
char list[258]; |
|
381 |
sysinfo(SI_ISALIST, list, sizeof(list)); |
|
382 |
sprops.cpu_isalist = strdup(list); |
|
383 |
} |
|
384 |
#else |
|
385 |
sprops.cpu_isalist = NULL; |
|
386 |
#endif |
|
387 |
||
388 |
/* endianness of platform */ |
|
389 |
{ |
|
390 |
unsigned int endianTest = 0xff000000; |
|
391 |
if (((char*)(&endianTest))[0] != 0) |
|
392 |
sprops.cpu_endian = "big"; |
|
393 |
else |
|
394 |
sprops.cpu_endian = "little"; |
|
395 |
} |
|
396 |
||
397 |
/* os properties */ |
|
398 |
{ |
|
399 |
struct utsname name; |
|
400 |
uname(&name); |
|
401 |
sprops.os_name = strdup(name.sysname); |
|
402 |
sprops.os_version = strdup(name.release); |
|
403 |
||
404 |
sprops.os_arch = ARCHPROPNAME; |
|
405 |
||
406 |
if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL) { |
|
407 |
sprops.desktop = "gnome"; |
|
408 |
} |
|
409 |
else { |
|
410 |
sprops.desktop = NULL; |
|
411 |
} |
|
412 |
} |
|
413 |
||
414 |
/* Determine the language, country, variant, and encoding from the host, |
|
415 |
* and store these in the user.language, user.country, user.variant and |
|
416 |
* file.encoding system properties. */ |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
417 |
setlocale(LC_ALL, ""); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
418 |
if (ParseLocale(LC_CTYPE, |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
419 |
&(sprops.format_language), |
7017 | 420 |
&(sprops.format_script), |
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
421 |
&(sprops.format_country), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
422 |
&(sprops.format_variant), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
423 |
&(sprops.encoding))) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
424 |
ParseLocale(LC_MESSAGES, |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
425 |
&(sprops.language), |
7017 | 426 |
&(sprops.script), |
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
427 |
&(sprops.country), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
428 |
&(sprops.variant), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
429 |
NULL); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
430 |
} else { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
431 |
sprops.language = "en"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
432 |
sprops.encoding = "ISO8859-1"; |
2 | 433 |
} |
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
434 |
sprops.display_language = sprops.language; |
7017 | 435 |
sprops.display_script = sprops.script; |
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
436 |
sprops.display_country = sprops.country; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
437 |
sprops.display_variant = sprops.variant; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
438 |
sprops.sun_jnu_encoding = sprops.encoding; |
2 | 439 |
|
440 |
#ifdef __linux__ |
|
441 |
#if __BYTE_ORDER == __LITTLE_ENDIAN |
|
442 |
sprops.unicode_encoding = "UnicodeLittle"; |
|
443 |
#else |
|
444 |
sprops.unicode_encoding = "UnicodeBig"; |
|
445 |
#endif |
|
446 |
#else |
|
447 |
sprops.unicode_encoding = "UnicodeBig"; |
|
448 |
#endif |
|
449 |
||
450 |
/* user properties */ |
|
451 |
{ |
|
452 |
struct passwd *pwent = getpwuid(getuid()); |
|
453 |
sprops.user_name = pwent ? strdup(pwent->pw_name) : "?"; |
|
454 |
sprops.user_home = pwent ? strdup(pwent->pw_dir) : "?"; |
|
455 |
} |
|
456 |
||
457 |
/* User TIMEZONE */ |
|
458 |
{ |
|
459 |
/* |
|
460 |
* We defer setting up timezone until it's actually necessary. |
|
461 |
* Refer to TimeZone.getDefault(). However, the system |
|
462 |
* property is necessary to be able to be set by the command |
|
463 |
* line interface -D. Here temporarily set a null string to |
|
464 |
* timezone. |
|
465 |
*/ |
|
466 |
tzset(); /* for compatibility */ |
|
467 |
sprops.timezone = ""; |
|
468 |
} |
|
469 |
||
470 |
/* Current directory */ |
|
471 |
{ |
|
472 |
char buf[MAXPATHLEN]; |
|
473 |
errno = 0; |
|
474 |
if (getcwd(buf, sizeof(buf)) == NULL) |
|
475 |
JNU_ThrowByName(env, "java/lang/Error", |
|
476 |
"Properties init: Could not determine current working directory."); |
|
477 |
else |
|
478 |
sprops.user_dir = strdup(buf); |
|
479 |
} |
|
480 |
||
481 |
sprops.file_separator = "/"; |
|
482 |
sprops.path_separator = ":"; |
|
483 |
sprops.line_separator = "\n"; |
|
484 |
||
485 |
/* Append CDE message and resource search path to NLSPATH and |
|
486 |
* XFILESEARCHPATH, in order to pick localized message for |
|
487 |
* FileSelectionDialog window (Bug 4173641). |
|
488 |
*/ |
|
489 |
setPathEnvironment("NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat"); |
|
490 |
setPathEnvironment("XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt"); |
|
491 |
||
492 |
return &sprops; |
|
493 |
} |
|
5168
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
494 |
|
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
495 |
jstring |
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
496 |
GetStringPlatform(JNIEnv *env, nchar* cstr) |
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
497 |
{ |
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
498 |
return JNU_NewStringPlatform(env, cstr); |
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
499 |
} |