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