113 |
113 |
114 #ifndef P_tmpdir |
114 #ifndef P_tmpdir |
115 #define P_tmpdir "/var/tmp" |
115 #define P_tmpdir "/var/tmp" |
116 #endif |
116 #endif |
117 |
117 |
118 static int ParseLocale(int cat, char ** std_language, char ** std_country, char ** std_variant, char ** std_encoding) { |
118 static int ParseLocale(int cat, char ** std_language, char ** std_script, |
|
119 char ** std_country, char ** std_variant, char ** std_encoding) { |
119 char temp[64]; |
120 char temp[64]; |
120 char *language = NULL, *country = NULL, *variant = NULL, |
121 char *language = NULL, *country = NULL, *variant = NULL, |
121 *encoding = NULL; |
122 *encoding = NULL; |
122 char *p, encoding_variant[64]; |
123 char *p, encoding_variant[64]; |
123 char *lc; |
124 char *lc; |
177 */ |
178 */ |
178 if ((p = strchr(temp, '.')) != NULL) { |
179 if ((p = strchr(temp, '.')) != NULL) { |
179 strcpy(encoding_variant, p); /* Copy the leading '.' */ |
180 strcpy(encoding_variant, p); /* Copy the leading '.' */ |
180 *p = '\0'; |
181 *p = '\0'; |
181 } else if ((p = strchr(temp, '@')) != NULL) { |
182 } else if ((p = strchr(temp, '@')) != NULL) { |
182 strcpy(encoding_variant, p); /* Copy the leading '@' */ |
183 strcpy(encoding_variant, p); /* Copy the leading '@' */ |
183 *p = '\0'; |
184 *p = '\0'; |
184 } else { |
185 } else { |
185 *encoding_variant = '\0'; |
186 *encoding_variant = '\0'; |
186 } |
187 } |
187 |
188 |
188 if (mapLookup(locale_aliases, temp, &p)) { |
189 if (mapLookup(locale_aliases, temp, &p)) { |
189 strcpy(temp, p); |
190 strcpy(temp, p); |
|
191 // check the "encoding_variant" again, if any. |
|
192 if ((p = strchr(temp, '.')) != NULL) { |
|
193 strcpy(encoding_variant, p); /* Copy the leading '.' */ |
|
194 *p = '\0'; |
|
195 } else if ((p = strchr(temp, '@')) != NULL) { |
|
196 strcpy(encoding_variant, p); /* Copy the leading '@' */ |
|
197 *p = '\0'; |
|
198 } |
190 } |
199 } |
191 |
200 |
192 language = temp; |
201 language = temp; |
193 if ((country = strchr(temp, '_')) != NULL) { |
202 if ((country = strchr(temp, '_')) != NULL) { |
194 *country++ = '\0'; |
203 *country++ = '\0'; |
215 if (std_country != NULL && country != NULL) { |
224 if (std_country != NULL && country != NULL) { |
216 *std_country = country; |
225 *std_country = country; |
217 mapLookup(country_names, country, std_country); |
226 mapLookup(country_names, country, std_country); |
218 } |
227 } |
219 |
228 |
220 /* Normalize the variant name. Note that we only use |
229 /* Normalize the script and variant name. Note that we only use |
221 * variants listed in the mapping array; others are ignored. */ |
230 * variants listed in the mapping array; others are ignored. |
222 if (std_variant != NULL && variant != NULL) { |
231 */ |
223 mapLookup(variant_names, variant, std_variant); |
232 if (variant != NULL) { |
|
233 if (std_script != NULL) { |
|
234 mapLookup(script_names, variant, std_script); |
|
235 } |
|
236 |
|
237 if (std_variant != NULL) { |
|
238 mapLookup(variant_names, variant, std_variant); |
|
239 } |
224 } |
240 } |
225 |
241 |
226 /* Normalize the encoding name. Note that we IGNORE the string |
242 /* Normalize the encoding name. Note that we IGNORE the string |
227 * 'encoding' extracted from the locale name above. Instead, we use the |
243 * 'encoding' extracted from the locale name above. Instead, we use the |
228 * more reliable method of calling nl_langinfo(CODESET). This function |
244 * more reliable method of calling nl_langinfo(CODESET). This function |
354 * and store these in the user.language, user.country, user.variant and |
370 * and store these in the user.language, user.country, user.variant and |
355 * file.encoding system properties. */ |
371 * file.encoding system properties. */ |
356 setlocale(LC_ALL, ""); |
372 setlocale(LC_ALL, ""); |
357 if (ParseLocale(LC_CTYPE, |
373 if (ParseLocale(LC_CTYPE, |
358 &(sprops.format_language), |
374 &(sprops.format_language), |
|
375 &(sprops.format_script), |
359 &(sprops.format_country), |
376 &(sprops.format_country), |
360 &(sprops.format_variant), |
377 &(sprops.format_variant), |
361 &(sprops.encoding))) { |
378 &(sprops.encoding))) { |
362 ParseLocale(LC_MESSAGES, |
379 ParseLocale(LC_MESSAGES, |
363 &(sprops.language), |
380 &(sprops.language), |
|
381 &(sprops.script), |
364 &(sprops.country), |
382 &(sprops.country), |
365 &(sprops.variant), |
383 &(sprops.variant), |
366 NULL); |
384 NULL); |
367 } else { |
385 } else { |
368 sprops.language = "en"; |
386 sprops.language = "en"; |
369 sprops.encoding = "ISO8859-1"; |
387 sprops.encoding = "ISO8859-1"; |
370 } |
388 } |
371 sprops.display_language = sprops.language; |
389 sprops.display_language = sprops.language; |
|
390 sprops.display_script = sprops.script; |
372 sprops.display_country = sprops.country; |
391 sprops.display_country = sprops.country; |
373 sprops.display_variant = sprops.variant; |
392 sprops.display_variant = sprops.variant; |
374 sprops.sun_jnu_encoding = sprops.encoding; |
393 sprops.sun_jnu_encoding = sprops.encoding; |
375 |
394 |
376 #ifdef __linux__ |
395 #ifdef __linux__ |