OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [locale/] [locale.c] - Blame information for rev 39

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/*
2
FUNCTION
3
<<setlocale>>, <<localeconv>>---select or query locale
4
 
5
INDEX
6
        setlocale
7
INDEX
8
        localeconv
9
INDEX
10
        _setlocale_r
11
INDEX
12
        _localeconv_r
13
 
14
ANSI_SYNOPSIS
15
        #include <locale.h>
16
        char *setlocale(int <[category]>, const char *<[locale]>);
17
        lconv *localeconv(void);
18
 
19
        char *_setlocale_r(void *<[reent]>,
20
                        int <[category]>, const char *<[locale]>);
21
        lconv *_localeconv_r(void *<[reent]>);
22
 
23
TRAD_SYNOPSIS
24
        #include <locale.h>
25
        char *setlocale(<[category]>, <[locale]>)
26
        int <[category]>;
27
        char *<[locale]>;
28
 
29
        lconv *localeconv();
30
 
31
        char *_setlocale_r(<[reent]>, <[category]>, <[locale]>)
32
        char *<[reent]>;
33
        int <[category]>;
34
        char *<[locale]>;
35
 
36
        lconv *_localeconv_r(<[reent]>);
37
        char *<[reent]>;
38
 
39
DESCRIPTION
40
<<setlocale>> is the facility defined by ANSI C to condition the
41
execution environment for international collating and formatting
42
information; <<localeconv>> reports on the settings of the current
43
locale.
44
 
45
This is a minimal implementation, supporting only the required <<``C''>>
46
value for <[locale]>; strings representing other locales are not
47
honored unless MB_CAPABLE is defined in which case three new
48
extensions are allowed for LC_CTYPE only: <<''C-JIS''>>, <<''C-EUCJP''>>,
49
and <<''C-SJIS''>>.  (<<``''>> is also accepted; it represents the default locale
50
for an implementation, here equivalent to <<``C''>>.)
51
 
52
If you use <<NULL>> as the <[locale]> argument, <<setlocale>> returns
53
a pointer to the string representing the current locale (always
54
<<``C''>> in this implementation).  The acceptable values for
55
<[category]> are defined in `<<locale.h>>' as macros beginning with
56
<<"LC_">>, but this implementation does not check the values you pass
57
in the <[category]> argument.
58
 
59
<<localeconv>> returns a pointer to a structure (also defined in
60
`<<locale.h>>') describing the locale-specific conventions currently
61
in effect.
62
 
63
<<_localeconv_r>> and <<_setlocale_r>> are reentrant versions of
64
<<localeconv>> and <<setlocale>> respectively.  The extra argument
65
<[reent]> is a pointer to a reentrancy structure.
66
 
67
RETURNS
68
<<setlocale>> returns either a pointer to a string naming the locale
69
currently in effect (always <<``C''>> for this implementation, or, if
70
the locale request cannot be honored, <<NULL>>.
71
 
72
<<localeconv>> returns a pointer to a structure of type <<lconv>>,
73
which describes the formatting and collating conventions in effect (in
74
this implementation, always those of the C locale).
75
 
76
PORTABILITY
77
ANSI C requires <<setlocale>>, but the only locale required across all
78
implementations is the C locale.
79
 
80
No supporting OS subroutines are required.
81
*/
82
 
83
/*
84
 * setlocale, localeconv : internationalize your locale.
85
 *                         (Only "C" or null supported).
86
 */
87
 
88
#include <locale.h>
89
#include <string.h>
90
#include <limits.h>
91
#include <reent.h>
92
 
93
int __mb_cur_max = 1;
94
 
95
static _CONST struct lconv lconv =
96
{
97
  ".", "", "", "", "", "", "", "", "", "",
98
  CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
99
  CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
100
};
101
 
102
 
103
char *
104
_DEFUN(_setlocale_r, (p, category, locale),
105
       struct _reent *p _AND
106
       int category _AND
107
       _CONST char *locale)
108
{
109
  static char lc_ctype[8] = "C";
110
  static char last_lc_ctype[8] = "C";
111
 
112
#ifndef MB_CAPABLE
113
  if (locale)
114
    {
115
      if (strcmp (locale, "C") && strcmp (locale, ""))
116
        return 0;
117
      p->_current_category = category;
118
      p->_current_locale = locale;
119
    }
120
  return "C";
121
#else
122
  if (locale)
123
    {
124
      if (category != LC_CTYPE)
125
        {
126
          if (strcmp (locale, "C") && strcmp (locale, ""))
127
            return 0;
128
          if (category == LC_ALL)
129
            {
130
              strcpy (last_lc_ctype, lc_ctype);
131
              strcpy (lc_ctype, locale);
132
              __mb_cur_max = 1;
133
            }
134
        }
135
      else
136
        {
137
          if (strcmp (locale, "C") && strcmp (locale, "") &&
138
              strcmp (locale, "C") && strcmp (locale, "C-JIS") &&
139
              strcmp (locale, "C-EUCJP") && strcmp (locale, "C-SJIS"))
140
            return 0;
141
 
142
          strcpy (last_lc_ctype, lc_ctype);
143
          strcpy (lc_ctype, locale);
144
 
145
          if (!strcmp (locale, "C-JIS"))
146
            __mb_cur_max = 8;
147
          else if (strlen (locale) > 1)
148
            __mb_cur_max = 2;
149
          else
150
            __mb_cur_max = 1;
151
        }
152
      p->_current_category = category;
153
      p->_current_locale = locale;
154
 
155
      if (category == LC_CTYPE)
156
        return last_lc_ctype;
157
    }
158
  else
159
    {
160
      if (category == LC_CTYPE)
161
        return lc_ctype;
162
    }
163
 
164
  return "C";
165
#endif
166
 
167
}
168
 
169
 
170
struct lconv *
171
_DEFUN(_localeconv_r, (data),
172
      struct _reent *data)
173
{
174
  return (struct lconv *) &lconv;
175
}
176
 
177
#ifndef _REENT_ONLY
178
 
179
char *
180
_DEFUN(setlocale, (category, locale),
181
       int category _AND
182
       _CONST char *locale)
183
{
184
  return _setlocale_r (_REENT, category, locale);
185
}
186
 
187
 
188
struct lconv *
189
_DEFUN_VOID(localeconv)
190
{
191
  return _localeconv_r (_REENT);
192
}
193
 
194
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.