author | naoto |
Tue, 31 Aug 2010 11:27:10 -0700 | |
changeset 6489 | 9e7015635425 |
parent 5506 | 202f599c92aa |
child 7017 | f3bfa15db005 |
child 6850 | 56966b0a6a0d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1998, 2006, 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__ |
|
49 |
#define CODESET _NL_CTYPE_CODESET_NAME |
|
50 |
#else |
|
51 |
#ifdef ALT_CODESET_KEY |
|
52 |
#define CODESET ALT_CODESET_KEY |
|
53 |
#endif |
|
54 |
#endif |
|
55 |
||
56 |
/* Take an array of string pairs (map of key->value) and a string (key). |
|
57 |
* Examine each pair in the map to see if the first string (key) matches the |
|
58 |
* string. If so, store the second string of the pair (value) in the value and |
|
59 |
* return 1. Otherwise do nothing and return 0. The end of the map is |
|
60 |
* indicated by an empty string at the start of a pair (key of ""). |
|
61 |
*/ |
|
62 |
static int |
|
63 |
mapLookup(char* map[], const char* key, char** value) { |
|
64 |
int i; |
|
65 |
for (i = 0; strcmp(map[i], ""); i += 2){ |
|
66 |
if (!strcmp(key, map[i])){ |
|
67 |
*value = map[i + 1]; |
|
68 |
return 1; |
|
69 |
} |
|
70 |
} |
|
71 |
return 0; |
|
72 |
} |
|
73 |
||
74 |
/* This function sets an environment variable using envstring. |
|
75 |
* The format of envstring is "name=value". |
|
76 |
* If the name has already existed, it will append value to the name. |
|
77 |
*/ |
|
78 |
static void |
|
79 |
setPathEnvironment(char *envstring) |
|
80 |
{ |
|
81 |
char name[20], *value, *current; |
|
82 |
||
83 |
value = strchr(envstring, '='); /* locate name and value separator */ |
|
84 |
||
85 |
if (! value) |
|
86 |
return; /* not a valid environment setting */ |
|
87 |
||
88 |
/* copy first part as environment name */ |
|
89 |
strncpy(name, envstring, value - envstring); |
|
90 |
name[value-envstring] = '\0'; |
|
91 |
||
92 |
value++; /* set value point to value of the envstring */ |
|
93 |
||
94 |
current = getenv(name); |
|
95 |
if (current) { |
|
96 |
if (! strstr(current, value)) { |
|
97 |
/* value is not found in current environment, append it */ |
|
98 |
char *temp = malloc(strlen(envstring) + strlen(current) + 2); |
|
99 |
strcpy(temp, name); |
|
100 |
strcat(temp, "="); |
|
101 |
strcat(temp, current); |
|
102 |
strcat(temp, ":"); |
|
103 |
strcat(temp, value); |
|
104 |
putenv(temp); |
|
105 |
} |
|
106 |
/* else the value has already been set, do nothing */ |
|
107 |
} |
|
108 |
else { |
|
109 |
/* environment variable is not found */ |
|
110 |
putenv(envstring); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
#ifndef P_tmpdir |
|
115 |
#define P_tmpdir "/var/tmp" |
|
116 |
#endif |
|
117 |
||
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
118 |
static int ParseLocale(int cat, char ** std_language, char ** std_country, char ** std_variant, char ** std_encoding) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
119 |
char temp[64]; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
120 |
char *language = NULL, *country = NULL, *variant = NULL, |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
121 |
*encoding = NULL; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
122 |
char *p, encoding_variant[64]; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
123 |
char *lc; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
124 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
125 |
/* Query the locale set for the category */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
126 |
lc = setlocale(cat, NULL); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
127 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
128 |
#ifndef __linux__ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
129 |
if (lc == NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
130 |
return 0; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
131 |
} |
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 |
if (cat == LC_CTYPE) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
134 |
/* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
135 |
* 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
|
136 |
* 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
|
137 |
* we just remove the qualifier. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
138 |
* 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
|
139 |
* 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
|
140 |
* 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
|
141 |
* Therefore, this code section is Solaris-specific. |
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 |
lc = strdup(lc); /* keep a copy, setlocale trashes original. */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
144 |
strcpy(temp, lc); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
145 |
p = strstr(temp, "@euro"); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
146 |
if (p != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
147 |
*p = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
148 |
setlocale(LC_ALL, temp); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
149 |
} |
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 |
#else |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
152 |
if (lc == NULL || !strcmp(lc, "C") || !strcmp(lc, "POSIX")) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
153 |
lc = "en_US"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
154 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
155 |
#endif |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
156 |
|
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 |
* locale string format in Solaris is |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
159 |
* <language name>_<country name>.<encoding name>@<variant name> |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
160 |
* <country name>, <encoding name>, and <variant name> are optional. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
161 |
*/ |
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 |
strcpy(temp, lc); |
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 |
/* Parse the language, country, encoding, and variant from the |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
166 |
* 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
|
167 |
* 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
|
168 |
* preceded by their delimiter (except for language). |
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 |
* 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
|
171 |
* 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
|
172 |
* 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
|
173 |
* 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
|
174 |
* 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
|
175 |
* 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
|
176 |
* 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
|
177 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
178 |
if ((p = strchr(temp, '.')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
179 |
strcpy(encoding_variant, p); /* Copy the leading '.' */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
180 |
*p = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
181 |
} else if ((p = strchr(temp, '@')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
182 |
strcpy(encoding_variant, p); /* Copy the leading '@' */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
183 |
*p = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
184 |
} else { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
185 |
*encoding_variant = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
186 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
187 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
188 |
if (mapLookup(locale_aliases, temp, &p)) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
189 |
strcpy(temp, p); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
190 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
191 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
192 |
language = temp; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
193 |
if ((country = strchr(temp, '_')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
194 |
*country++ = '\0'; |
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 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
197 |
p = encoding_variant; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
198 |
if ((encoding = strchr(p, '.')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
199 |
p[encoding++ - p] = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
200 |
p = encoding; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
201 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
202 |
if ((variant = strchr(p, '@')) != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
203 |
p[variant++ - p] = '\0'; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
204 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
205 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
206 |
/* Normalize the language name */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
207 |
if (std_language != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
208 |
*std_language = "en"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
209 |
if (language != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
210 |
mapLookup(language_names, language, std_language); |
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 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
214 |
/* Normalize the country name */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
215 |
if (std_country != NULL && country != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
216 |
*std_country = country; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
217 |
mapLookup(country_names, country, std_country); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
218 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
219 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
220 |
/* Normalize the variant name. Note that we only use |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
221 |
* variants listed in the mapping array; others are ignored. */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
222 |
if (std_variant != NULL && variant != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
223 |
mapLookup(variant_names, variant, std_variant); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
224 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
225 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
226 |
/* 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
|
227 |
* '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
|
228 |
* 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
|
229 |
* 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
|
230 |
* (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
|
231 |
* converter for such locales. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
232 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
233 |
if (std_encoding != NULL) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
234 |
/* 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
|
235 |
* Euro locales, in particular. */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
236 |
if (strcmp(p, "ISO8859-15") == 0) |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
237 |
p = "ISO8859-15"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
238 |
else |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
239 |
p = nl_langinfo(CODESET); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
240 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
241 |
/* 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
|
242 |
if (strcmp(p, "646") == 0) |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
243 |
p = "ISO646-US"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
244 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
245 |
/* 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
|
246 |
* in order to use optimizations. */ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
247 |
*std_encoding = (*p != '\0') ? p : "ISO8859-1"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
248 |
|
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
249 |
#ifdef __linux__ |
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 |
* 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
|
252 |
* 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
|
253 |
* 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
|
254 |
* 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
|
255 |
* the variant of "EUC-JP" encoding used on linux |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
256 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
257 |
if (strcmp(p, "EUC-JP") == 0) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
258 |
*std_encoding = "EUC-JP-LINUX"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
259 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
260 |
#else |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
261 |
if (strcmp(p,"eucJP") == 0) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
262 |
/* For Solaris use customized vendor defined character |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
263 |
* customized EUC-JP converter |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
264 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
265 |
*std_encoding = "eucJP-open"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
266 |
} 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
|
267 |
/* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
268 |
* Remap the encoding string to Big5_Solaris which augments |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
269 |
* the default converter for Solaris Big5 locales to include |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
270 |
* seven additional ideographic characters beyond those included |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
271 |
* in the Java "Big5" converter. |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
272 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
273 |
*std_encoding = "Big5_Solaris"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
274 |
} else if (strcmp(p, "Big5-HKSCS") == 0) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
275 |
/* |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
276 |
* Solaris uses HKSCS2001 |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
277 |
*/ |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
278 |
*std_encoding = "Big5-HKSCS-2001"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
279 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
280 |
#endif |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
281 |
} |
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 |
return 1; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
284 |
} |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
285 |
|
2 | 286 |
/* This function gets called very early, before VM_CALLS are setup. |
287 |
* Do not use any of the VM_CALLS entries!!! |
|
288 |
*/ |
|
289 |
java_props_t * |
|
290 |
GetJavaProperties(JNIEnv *env) |
|
291 |
{ |
|
292 |
static java_props_t sprops = {0}; |
|
293 |
char *v; /* tmp var */ |
|
294 |
||
295 |
if (sprops.user_dir) { |
|
296 |
return &sprops; |
|
297 |
} |
|
298 |
||
299 |
/* tmp dir */ |
|
300 |
sprops.tmp_dir = P_tmpdir; |
|
301 |
||
302 |
/* Printing properties */ |
|
303 |
sprops.printerJob = "sun.print.PSPrinterJob"; |
|
304 |
||
305 |
/* patches/service packs installed */ |
|
306 |
sprops.patch_level = "unknown"; |
|
307 |
||
308 |
/* Java 2D properties */ |
|
309 |
sprops.graphics_env = "sun.awt.X11GraphicsEnvironment"; |
|
310 |
sprops.awt_toolkit = NULL; |
|
311 |
||
312 |
/* This is used only for debugging of font problems. */ |
|
313 |
v = getenv("JAVA2D_FONTPATH"); |
|
314 |
sprops.font_dir = v ? v : NULL; |
|
315 |
||
316 |
#ifdef SI_ISALIST |
|
317 |
/* supported instruction sets */ |
|
318 |
{ |
|
319 |
char list[258]; |
|
320 |
sysinfo(SI_ISALIST, list, sizeof(list)); |
|
321 |
sprops.cpu_isalist = strdup(list); |
|
322 |
} |
|
323 |
#else |
|
324 |
sprops.cpu_isalist = NULL; |
|
325 |
#endif |
|
326 |
||
327 |
/* endianness of platform */ |
|
328 |
{ |
|
329 |
unsigned int endianTest = 0xff000000; |
|
330 |
if (((char*)(&endianTest))[0] != 0) |
|
331 |
sprops.cpu_endian = "big"; |
|
332 |
else |
|
333 |
sprops.cpu_endian = "little"; |
|
334 |
} |
|
335 |
||
336 |
/* os properties */ |
|
337 |
{ |
|
338 |
struct utsname name; |
|
339 |
uname(&name); |
|
340 |
sprops.os_name = strdup(name.sysname); |
|
341 |
sprops.os_version = strdup(name.release); |
|
342 |
||
343 |
sprops.os_arch = ARCHPROPNAME; |
|
344 |
||
345 |
if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL) { |
|
346 |
sprops.desktop = "gnome"; |
|
347 |
} |
|
348 |
else { |
|
349 |
sprops.desktop = NULL; |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
/* Determine the language, country, variant, and encoding from the host, |
|
354 |
* and store these in the user.language, user.country, user.variant and |
|
355 |
* file.encoding system properties. */ |
|
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
356 |
setlocale(LC_ALL, ""); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
357 |
if (ParseLocale(LC_CTYPE, |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
358 |
&(sprops.format_language), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
359 |
&(sprops.format_country), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
360 |
&(sprops.format_variant), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
361 |
&(sprops.encoding))) { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
362 |
ParseLocale(LC_MESSAGES, |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
363 |
&(sprops.language), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
364 |
&(sprops.country), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
365 |
&(sprops.variant), |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
366 |
NULL); |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
367 |
} else { |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
368 |
sprops.language = "en"; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
369 |
sprops.encoding = "ISO8859-1"; |
2 | 370 |
} |
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
371 |
sprops.display_language = sprops.language; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
372 |
sprops.display_country = sprops.country; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
373 |
sprops.display_variant = sprops.variant; |
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
374 |
sprops.sun_jnu_encoding = sprops.encoding; |
2 | 375 |
|
376 |
#ifdef __linux__ |
|
377 |
#if __BYTE_ORDER == __LITTLE_ENDIAN |
|
378 |
sprops.unicode_encoding = "UnicodeLittle"; |
|
379 |
#else |
|
380 |
sprops.unicode_encoding = "UnicodeBig"; |
|
381 |
#endif |
|
382 |
#else |
|
383 |
sprops.unicode_encoding = "UnicodeBig"; |
|
384 |
#endif |
|
385 |
||
386 |
/* user properties */ |
|
387 |
{ |
|
388 |
struct passwd *pwent = getpwuid(getuid()); |
|
389 |
sprops.user_name = pwent ? strdup(pwent->pw_name) : "?"; |
|
390 |
sprops.user_home = pwent ? strdup(pwent->pw_dir) : "?"; |
|
391 |
} |
|
392 |
||
393 |
/* User TIMEZONE */ |
|
394 |
{ |
|
395 |
/* |
|
396 |
* We defer setting up timezone until it's actually necessary. |
|
397 |
* Refer to TimeZone.getDefault(). However, the system |
|
398 |
* property is necessary to be able to be set by the command |
|
399 |
* line interface -D. Here temporarily set a null string to |
|
400 |
* timezone. |
|
401 |
*/ |
|
402 |
tzset(); /* for compatibility */ |
|
403 |
sprops.timezone = ""; |
|
404 |
} |
|
405 |
||
406 |
/* Current directory */ |
|
407 |
{ |
|
408 |
char buf[MAXPATHLEN]; |
|
409 |
errno = 0; |
|
410 |
if (getcwd(buf, sizeof(buf)) == NULL) |
|
411 |
JNU_ThrowByName(env, "java/lang/Error", |
|
412 |
"Properties init: Could not determine current working directory."); |
|
413 |
else |
|
414 |
sprops.user_dir = strdup(buf); |
|
415 |
} |
|
416 |
||
417 |
sprops.file_separator = "/"; |
|
418 |
sprops.path_separator = ":"; |
|
419 |
sprops.line_separator = "\n"; |
|
420 |
||
421 |
/* Append CDE message and resource search path to NLSPATH and |
|
422 |
* XFILESEARCHPATH, in order to pick localized message for |
|
423 |
* FileSelectionDialog window (Bug 4173641). |
|
424 |
*/ |
|
425 |
setPathEnvironment("NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat"); |
|
426 |
setPathEnvironment("XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt"); |
|
427 |
||
428 |
return &sprops; |
|
429 |
} |
|
5168
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
430 |
|
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
431 |
jstring |
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
432 |
GetStringPlatform(JNIEnv *env, nchar* cstr) |
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
433 |
{ |
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
434 |
return JNU_NewStringPlatform(env, cstr); |
41e46b5d9b15
4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents:
5167
diff
changeset
|
435 |
} |