diff options
Diffstat (limited to 'newlib/libc/locale/locale.c')
-rw-r--r-- | newlib/libc/locale/locale.c | 155 |
1 files changed, 26 insertions, 129 deletions
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c index d48a53a87..e1f45335a 100644 --- a/newlib/libc/locale/locale.c +++ b/newlib/libc/locale/locale.c @@ -42,17 +42,16 @@ execution environment for international collating and formatting information; <<localeconv>> reports on the settings of the current locale. -This is a minimal implementation, supporting only the required <<"C">> +This is a minimal implementation, supporting only the required <<``C''>> value for <[locale]>; strings representing other locales are not -honored unless _MB_CAPABLE is defined in which case three new -extensions are allowed for LC_CTYPE or LC_MESSAGES only: <<"C-JIS">>, -<<"C-EUCJP">>, <<"C-SJIS">>, or <<"C-ISO-8859-1">>. (<<"">> is -also accepted; it represents the default locale -for an implementation, here equivalent to <<"C">>.) +honored unless MB_CAPABLE is defined in which case three new +extensions are allowed for LC_CTYPE only: <<''C-JIS''>>, <<''C-EUCJP''>>, +and <<''C-SJIS''>>. (<<``''>> is also accepted; it represents the default locale +for an implementation, here equivalent to <<``C''>>.) If you use <<NULL>> as the <[locale]> argument, <<setlocale>> returns a pointer to the string representing the current locale (always -<<"C">> in this implementation). The acceptable values for +<<``C''>> in this implementation). The acceptable values for <[category]> are defined in `<<locale.h>>' as macros beginning with <<"LC_">>, but this implementation does not check the values you pass in the <[category]> argument. @@ -67,7 +66,7 @@ in effect. RETURNS <<setlocale>> returns either a pointer to a string naming the locale -currently in effect (always <<"C">> for this implementation, or, if +currently in effect (always <<``C''>> for this implementation, or, if the locale request cannot be honored, <<NULL>>. <<localeconv>> returns a pointer to a structure of type <<lconv>>, @@ -86,7 +85,6 @@ No supporting OS subroutines are required. * (Only "C" or null supported). */ -#include <newlib.h> #include <locale.h> #include <string.h> #include <limits.h> @@ -98,10 +96,6 @@ int __declspec(dllexport) __mb_cur_max = 1; int __mb_cur_max = 1; #endif -int __nlocale_changed = 0; -int __mlocale_changed = 0; -char *_PathLocale = NULL; - static _CONST struct lconv lconv = { ".", "", "", "", "", "", "", "", "", "", @@ -110,18 +104,13 @@ static _CONST struct lconv lconv = }; -char * _EXFUN(__locale_charset,(_VOID)); - -static char *charset = "ISO-8859-1"; -char __lc_ctype[12] = "C"; - char * _DEFUN(_setlocale_r, (p, category, locale), struct _reent *p _AND int category _AND _CONST char *locale) { -#ifndef _MB_CAPABLE +#ifndef MB_CAPABLE if (locale) { if (strcmp (locale, "C") && strcmp (locale, "")) @@ -131,136 +120,49 @@ _DEFUN(_setlocale_r, (p, category, locale), } return "C"; #else - static char last_lc_ctype[12] = "C"; - static char lc_messages[12] = "C"; - static char last_lc_messages[12] = "C"; + static char lc_ctype[8] = "C"; + static char last_lc_ctype[8] = "C"; if (locale) { - char *locale_name = (char *)locale; - if (category != LC_CTYPE && category != LC_MESSAGES) + if (category != LC_CTYPE) { if (strcmp (locale, "C") && strcmp (locale, "")) return 0; if (category == LC_ALL) { - strcpy (last_lc_ctype, __lc_ctype); - strcpy (__lc_ctype, "C"); - strcpy (last_lc_messages, lc_messages); - strcpy (lc_messages, "C"); + strcpy (last_lc_ctype, lc_ctype); + strcpy (lc_ctype, locale); __mb_cur_max = 1; } } else - { - if (locale[0] == 'C' && locale[1] == '-') - { - switch (locale[2]) - { - case 'U': - if (strcmp (locale, "C-UTF-8")) - return 0; - break; - case 'J': - if (strcmp (locale, "C-JIS")) - return 0; - break; - case 'E': - if (strcmp (locale, "C-EUCJP")) - return 0; - break; - case 'S': - if (strcmp (locale, "C-SJIS")) - return 0; - break; - case 'I': - if (strcmp (locale, "C-ISO-8859-1")) - return 0; - break; - default: - return 0; - } - } - else - { - if (strcmp (locale, "C") && strcmp (locale, "")) - return 0; - locale_name = "C"; /* C is always the default locale */ - } + { + if (strcmp (locale, "C") && strcmp (locale, "") && + strcmp (locale, "C") && strcmp (locale, "C-JIS") && + strcmp (locale, "C-EUCJP") && strcmp (locale, "C-SJIS")) + return 0; - if (category == LC_CTYPE) - { - strcpy (last_lc_ctype, __lc_ctype); - strcpy (__lc_ctype, locale_name); + strcpy (last_lc_ctype, lc_ctype); + strcpy (lc_ctype, locale); - __mb_cur_max = 1; - if (locale[1] == '-') - { - switch (locale[2]) - { - case 'U': - __mb_cur_max = 6; - break; - case 'J': - __mb_cur_max = 8; - break; - case 'E': - __mb_cur_max = 2; - break; - case 'S': - __mb_cur_max = 2; - break; - case 'I': - default: - __mb_cur_max = 1; - } - } - } + if (!strcmp (locale, "C-JIS")) + __mb_cur_max = 8; + else if (strlen (locale) > 1) + __mb_cur_max = 2; else - { - strcpy (last_lc_messages, lc_messages); - strcpy (lc_messages, locale_name); - - charset = "ISO-8859-1"; - if (locale[1] == '-') - { - switch (locale[2]) - { - case 'U': - charset = "UTF-8"; - break; - case 'J': - charset = "JIS"; - break; - case 'E': - charset = "EUCJP"; - break; - case 'S': - charset = "SJIS"; - break; - case 'I': - charset = "ISO-8859-1"; - break; - default: - return 0; - } - } - } + __mb_cur_max = 1; } p->_current_category = category; p->_current_locale = locale; if (category == LC_CTYPE) return last_lc_ctype; - else if (category == LC_MESSAGES) - return last_lc_messages; } else { if (category == LC_CTYPE) - return __lc_ctype; - else if (category == LC_MESSAGES) - return lc_messages; + return lc_ctype; } return "C"; @@ -268,11 +170,6 @@ _DEFUN(_setlocale_r, (p, category, locale), } -char * -_DEFUN_VOID(__locale_charset) -{ - return charset; -} struct lconv * _DEFUN(_localeconv_r, (data), |