2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<setlocale>>, <<localeconv>>---select or query locale
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
setlocale
|
|
|
|
INDEX
|
|
|
|
localeconv
|
|
|
|
INDEX
|
|
|
|
_setlocale_r
|
|
|
|
INDEX
|
|
|
|
_localeconv_r
|
|
|
|
|
|
|
|
ANSI_SYNOPSIS
|
|
|
|
#include <locale.h>
|
|
|
|
char *setlocale(int <[category]>, const char *<[locale]>);
|
|
|
|
lconv *localeconv(void);
|
|
|
|
|
|
|
|
char *_setlocale_r(void *<[reent]>,
|
|
|
|
int <[category]>, const char *<[locale]>);
|
|
|
|
lconv *_localeconv_r(void *<[reent]>);
|
|
|
|
|
|
|
|
TRAD_SYNOPSIS
|
|
|
|
#include <locale.h>
|
|
|
|
char *setlocale(<[category]>, <[locale]>)
|
|
|
|
int <[category]>;
|
|
|
|
char *<[locale]>;
|
|
|
|
|
|
|
|
lconv *localeconv();
|
|
|
|
|
|
|
|
char *_setlocale_r(<[reent]>, <[category]>, <[locale]>)
|
|
|
|
char *<[reent]>;
|
|
|
|
int <[category]>;
|
|
|
|
char *<[locale]>;
|
|
|
|
|
|
|
|
lconv *_localeconv_r(<[reent]>);
|
|
|
|
char *<[reent]>;
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
<<setlocale>> is the facility defined by ANSI C to condition the
|
|
|
|
execution environment for international collating and formatting
|
|
|
|
information; <<localeconv>> reports on the settings of the current
|
|
|
|
locale.
|
|
|
|
|
2003-10-21 02:46:38 +08:00
|
|
|
This is a minimal implementation, supporting only the required <<"C">>
|
2000-02-18 03:39:52 +08:00
|
|
|
value for <[locale]>; strings representing other locales are not
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* configure.in: Define _MB_CAPABLE if mb supported.
* configure: Regenerated.
* configure.host: Remove manual setting of MB_CAPABLE compiler
flag.
* newlib.hin: Add _MB_CAPABLE flag.
* libc/ctype/iswalpha.c, libc/ctype/iswblank.c: Include <newlib.h>
and check for _MB_CAPABLE flag instead of MB_CAPABLE.
* libc/ctype/iswcntrl.c, libc/ctype/iswprint.c: Ditto.
* libc/ctype/iswpunct.c, libc/ctype/iswspace.c: Ditto.
* libc/ctype/jp2uc.c: Ditto.
* libc/ctype/towlower.c, libc/ctype/towupper.c: Ditto.
* libc/locale/locale.c: Ditto
* libc/machine/powerpc/vfscanf.c: Ditto
* libc/stdio/vfprintf.c, libc/stdio/vfscanf.c: Ditto
* libc/stdlib/mblen.c: Ditto
* libc/stdlib/mblen_r.c, libc/stdlib/mbrlen.c: Ditto
* libc/stdlib/mbrtowc.c, libc/stdlib/mbsrtowcs.c: Ditto
* libc/stdlib/mbstowcs.c, libc/stdlib/mbtowc.c: Ditto
* libc/stdlib/mbtowc_r.c, libc/stdlib/wcrtomb.c: Ditto
* libc/stdlib/wcsrtombs.c, libc/stdlib/wcstombs.c: Ditto
* libc/stdlib/wctomb.c, libc/sys/linux/intl/dcigettext.c: Ditto
* libc/sys/linux/intl/explodename.c: Ditto
* libc/sys/linux/intl/finddomain.c: Ditto
* libc/sys/linux/intl/l10nflist.c: Ditto
* libc/sys/linux/intl/loadmsgcat.c: Ditto
* libc/sys/linux/intl/localealias.c: Ditto
2004-04-24 05:44:22 +08:00
|
|
|
honored unless _MB_CAPABLE is defined in which case three new
|
2003-10-21 02:46:38 +08:00
|
|
|
extensions are allowed for LC_CTYPE or LC_MESSAGES only: <<"C-JIS">>,
|
|
|
|
<<"C-EUCJP">>, <<"C-SJIS">>, or <<"C-ISO-8859-1">>. (<<"">> is
|
2002-08-17 13:19:18 +08:00
|
|
|
also accepted; it represents the default locale
|
2003-10-21 02:46:38 +08:00
|
|
|
for an implementation, here equivalent to <<"C">>.)
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
If you use <<NULL>> as the <[locale]> argument, <<setlocale>> returns
|
|
|
|
a pointer to the string representing the current locale (always
|
2003-10-21 02:46:38 +08:00
|
|
|
<<"C">> in this implementation). The acceptable values for
|
2000-02-18 03:39:52 +08:00
|
|
|
<[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.
|
|
|
|
|
|
|
|
<<localeconv>> returns a pointer to a structure (also defined in
|
|
|
|
`<<locale.h>>') describing the locale-specific conventions currently
|
|
|
|
in effect.
|
|
|
|
|
|
|
|
<<_localeconv_r>> and <<_setlocale_r>> are reentrant versions of
|
|
|
|
<<localeconv>> and <<setlocale>> respectively. The extra argument
|
|
|
|
<[reent]> is a pointer to a reentrancy structure.
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
<<setlocale>> returns either a pointer to a string naming the locale
|
2003-10-21 02:46:38 +08:00
|
|
|
currently in effect (always <<"C">> for this implementation, or, if
|
2000-02-18 03:39:52 +08:00
|
|
|
the locale request cannot be honored, <<NULL>>.
|
|
|
|
|
|
|
|
<<localeconv>> returns a pointer to a structure of type <<lconv>>,
|
|
|
|
which describes the formatting and collating conventions in effect (in
|
|
|
|
this implementation, always those of the C locale).
|
|
|
|
|
|
|
|
PORTABILITY
|
|
|
|
ANSI C requires <<setlocale>>, but the only locale required across all
|
|
|
|
implementations is the C locale.
|
|
|
|
|
|
|
|
No supporting OS subroutines are required.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* setlocale, localeconv : internationalize your locale.
|
|
|
|
* (Only "C" or null supported).
|
|
|
|
*/
|
|
|
|
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* configure.in: Define _MB_CAPABLE if mb supported.
* configure: Regenerated.
* configure.host: Remove manual setting of MB_CAPABLE compiler
flag.
* newlib.hin: Add _MB_CAPABLE flag.
* libc/ctype/iswalpha.c, libc/ctype/iswblank.c: Include <newlib.h>
and check for _MB_CAPABLE flag instead of MB_CAPABLE.
* libc/ctype/iswcntrl.c, libc/ctype/iswprint.c: Ditto.
* libc/ctype/iswpunct.c, libc/ctype/iswspace.c: Ditto.
* libc/ctype/jp2uc.c: Ditto.
* libc/ctype/towlower.c, libc/ctype/towupper.c: Ditto.
* libc/locale/locale.c: Ditto
* libc/machine/powerpc/vfscanf.c: Ditto
* libc/stdio/vfprintf.c, libc/stdio/vfscanf.c: Ditto
* libc/stdlib/mblen.c: Ditto
* libc/stdlib/mblen_r.c, libc/stdlib/mbrlen.c: Ditto
* libc/stdlib/mbrtowc.c, libc/stdlib/mbsrtowcs.c: Ditto
* libc/stdlib/mbstowcs.c, libc/stdlib/mbtowc.c: Ditto
* libc/stdlib/mbtowc_r.c, libc/stdlib/wcrtomb.c: Ditto
* libc/stdlib/wcsrtombs.c, libc/stdlib/wcstombs.c: Ditto
* libc/stdlib/wctomb.c, libc/sys/linux/intl/dcigettext.c: Ditto
* libc/sys/linux/intl/explodename.c: Ditto
* libc/sys/linux/intl/finddomain.c: Ditto
* libc/sys/linux/intl/l10nflist.c: Ditto
* libc/sys/linux/intl/loadmsgcat.c: Ditto
* libc/sys/linux/intl/localealias.c: Ditto
2004-04-24 05:44:22 +08:00
|
|
|
#include <newlib.h>
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <locale.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <reent.h>
|
|
|
|
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
int __declspec(dllexport) __mb_cur_max = 1;
|
|
|
|
#else
|
|
|
|
int __mb_cur_max = 1;
|
|
|
|
#endif
|
|
|
|
|
2002-08-17 13:19:18 +08:00
|
|
|
int __nlocale_changed = 0;
|
|
|
|
int __mlocale_changed = 0;
|
|
|
|
char *_PathLocale = NULL;
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
static _CONST struct lconv lconv =
|
|
|
|
{
|
|
|
|
".", "", "", "", "", "", "", "", "", "",
|
|
|
|
CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
|
|
|
|
CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-08-17 13:19:18 +08:00
|
|
|
char * _EXFUN(__locale_charset,(_VOID));
|
|
|
|
|
|
|
|
static char *charset = "ISO-8859-1";
|
2002-09-21 04:13:11 +08:00
|
|
|
char __lc_ctype[12] = "C";
|
2002-08-17 13:19:18 +08:00
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
char *
|
|
|
|
_DEFUN(_setlocale_r, (p, category, locale),
|
|
|
|
struct _reent *p _AND
|
|
|
|
int category _AND
|
|
|
|
_CONST char *locale)
|
|
|
|
{
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* configure.in: Define _MB_CAPABLE if mb supported.
* configure: Regenerated.
* configure.host: Remove manual setting of MB_CAPABLE compiler
flag.
* newlib.hin: Add _MB_CAPABLE flag.
* libc/ctype/iswalpha.c, libc/ctype/iswblank.c: Include <newlib.h>
and check for _MB_CAPABLE flag instead of MB_CAPABLE.
* libc/ctype/iswcntrl.c, libc/ctype/iswprint.c: Ditto.
* libc/ctype/iswpunct.c, libc/ctype/iswspace.c: Ditto.
* libc/ctype/jp2uc.c: Ditto.
* libc/ctype/towlower.c, libc/ctype/towupper.c: Ditto.
* libc/locale/locale.c: Ditto
* libc/machine/powerpc/vfscanf.c: Ditto
* libc/stdio/vfprintf.c, libc/stdio/vfscanf.c: Ditto
* libc/stdlib/mblen.c: Ditto
* libc/stdlib/mblen_r.c, libc/stdlib/mbrlen.c: Ditto
* libc/stdlib/mbrtowc.c, libc/stdlib/mbsrtowcs.c: Ditto
* libc/stdlib/mbstowcs.c, libc/stdlib/mbtowc.c: Ditto
* libc/stdlib/mbtowc_r.c, libc/stdlib/wcrtomb.c: Ditto
* libc/stdlib/wcsrtombs.c, libc/stdlib/wcstombs.c: Ditto
* libc/stdlib/wctomb.c, libc/sys/linux/intl/dcigettext.c: Ditto
* libc/sys/linux/intl/explodename.c: Ditto
* libc/sys/linux/intl/finddomain.c: Ditto
* libc/sys/linux/intl/l10nflist.c: Ditto
* libc/sys/linux/intl/loadmsgcat.c: Ditto
* libc/sys/linux/intl/localealias.c: Ditto
2004-04-24 05:44:22 +08:00
|
|
|
#ifndef _MB_CAPABLE
|
2000-02-18 03:39:52 +08:00
|
|
|
if (locale)
|
|
|
|
{
|
|
|
|
if (strcmp (locale, "C") && strcmp (locale, ""))
|
|
|
|
return 0;
|
|
|
|
p->_current_category = category;
|
|
|
|
p->_current_locale = locale;
|
|
|
|
}
|
|
|
|
return "C";
|
|
|
|
#else
|
2002-08-17 13:19:18 +08:00
|
|
|
static char last_lc_ctype[12] = "C";
|
|
|
|
static char lc_messages[12] = "C";
|
|
|
|
static char last_lc_messages[12] = "C";
|
2000-08-25 00:25:36 +08:00
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
if (locale)
|
|
|
|
{
|
2002-08-29 23:32:08 +08:00
|
|
|
char *locale_name = (char *)locale;
|
2002-08-17 13:19:18 +08:00
|
|
|
if (category != LC_CTYPE && category != LC_MESSAGES)
|
2000-02-18 03:39:52 +08:00
|
|
|
{
|
|
|
|
if (strcmp (locale, "C") && strcmp (locale, ""))
|
|
|
|
return 0;
|
|
|
|
if (category == LC_ALL)
|
|
|
|
{
|
2002-09-21 04:13:11 +08:00
|
|
|
strcpy (last_lc_ctype, __lc_ctype);
|
|
|
|
strcpy (__lc_ctype, "C");
|
2002-08-17 13:19:18 +08:00
|
|
|
strcpy (last_lc_messages, lc_messages);
|
2002-08-29 23:32:08 +08:00
|
|
|
strcpy (lc_messages, "C");
|
2000-02-18 03:39:52 +08:00
|
|
|
__mb_cur_max = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2002-08-17 13:19:18 +08:00
|
|
|
{
|
2002-08-29 23:32:08 +08:00
|
|
|
if (locale[0] == 'C' && locale[1] == '-')
|
2002-08-17 13:19:18 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2002-08-29 23:32:08 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strcmp (locale, "C") && strcmp (locale, ""))
|
|
|
|
return 0;
|
|
|
|
locale_name = "C"; /* C is always the default locale */
|
|
|
|
}
|
2002-08-17 13:19:18 +08:00
|
|
|
|
|
|
|
if (category == LC_CTYPE)
|
|
|
|
{
|
2002-09-21 04:13:11 +08:00
|
|
|
strcpy (last_lc_ctype, __lc_ctype);
|
|
|
|
strcpy (__lc_ctype, locale_name);
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2002-08-17 13:19:18 +08:00
|
|
|
__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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:39:52 +08:00
|
|
|
else
|
2002-08-17 13:19:18 +08:00
|
|
|
{
|
|
|
|
strcpy (last_lc_messages, lc_messages);
|
2002-08-29 23:32:08 +08:00
|
|
|
strcpy (lc_messages, locale_name);
|
2002-08-17 13:19:18 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
|
|
|
p->_current_category = category;
|
|
|
|
p->_current_locale = locale;
|
|
|
|
|
|
|
|
if (category == LC_CTYPE)
|
|
|
|
return last_lc_ctype;
|
2002-08-17 13:19:18 +08:00
|
|
|
else if (category == LC_MESSAGES)
|
|
|
|
return last_lc_messages;
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (category == LC_CTYPE)
|
2002-09-21 04:13:11 +08:00
|
|
|
return __lc_ctype;
|
2002-08-17 13:19:18 +08:00
|
|
|
else if (category == LC_MESSAGES)
|
|
|
|
return lc_messages;
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return "C";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-08-17 13:19:18 +08:00
|
|
|
char *
|
|
|
|
_DEFUN_VOID(__locale_charset)
|
|
|
|
{
|
|
|
|
return charset;
|
|
|
|
}
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
struct lconv *
|
|
|
|
_DEFUN(_localeconv_r, (data),
|
|
|
|
struct _reent *data)
|
|
|
|
{
|
|
|
|
return (struct lconv *) &lconv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
|
|
|
|
char *
|
|
|
|
_DEFUN(setlocale, (category, locale),
|
|
|
|
int category _AND
|
|
|
|
_CONST char *locale)
|
|
|
|
{
|
|
|
|
return _setlocale_r (_REENT, category, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct lconv *
|
|
|
|
_DEFUN_VOID(localeconv)
|
|
|
|
{
|
|
|
|
return _localeconv_r (_REENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|