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

Subversion Repositories or1k

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

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 56 joel
#ifdef __CYGWIN__
94
int __declspec(dllexport) __mb_cur_max = 1;
95
#else
96 39 lampret
int __mb_cur_max = 1;
97 56 joel
#endif
98 39 lampret
 
99
static _CONST struct lconv lconv =
100
{
101
  ".", "", "", "", "", "", "", "", "", "",
102
  CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
103
  CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
104
};
105
 
106
 
107
char *
108
_DEFUN(_setlocale_r, (p, category, locale),
109
       struct _reent *p _AND
110
       int category _AND
111
       _CONST char *locale)
112
{
113
  static char lc_ctype[8] = "C";
114
  static char last_lc_ctype[8] = "C";
115
 
116
#ifndef MB_CAPABLE
117
  if (locale)
118
    {
119
      if (strcmp (locale, "C") && strcmp (locale, ""))
120
        return 0;
121
      p->_current_category = category;
122
      p->_current_locale = locale;
123
    }
124
  return "C";
125
#else
126
  if (locale)
127
    {
128
      if (category != LC_CTYPE)
129
        {
130
          if (strcmp (locale, "C") && strcmp (locale, ""))
131
            return 0;
132
          if (category == LC_ALL)
133
            {
134
              strcpy (last_lc_ctype, lc_ctype);
135
              strcpy (lc_ctype, locale);
136
              __mb_cur_max = 1;
137
            }
138
        }
139
      else
140
        {
141
          if (strcmp (locale, "C") && strcmp (locale, "") &&
142
              strcmp (locale, "C") && strcmp (locale, "C-JIS") &&
143
              strcmp (locale, "C-EUCJP") && strcmp (locale, "C-SJIS"))
144
            return 0;
145
 
146
          strcpy (last_lc_ctype, lc_ctype);
147
          strcpy (lc_ctype, locale);
148
 
149
          if (!strcmp (locale, "C-JIS"))
150
            __mb_cur_max = 8;
151
          else if (strlen (locale) > 1)
152
            __mb_cur_max = 2;
153
          else
154
            __mb_cur_max = 1;
155
        }
156
      p->_current_category = category;
157
      p->_current_locale = locale;
158
 
159
      if (category == LC_CTYPE)
160
        return last_lc_ctype;
161
    }
162
  else
163
    {
164
      if (category == LC_CTYPE)
165
        return lc_ctype;
166
    }
167
 
168
  return "C";
169
#endif
170
 
171
}
172
 
173
 
174
struct lconv *
175
_DEFUN(_localeconv_r, (data),
176
      struct _reent *data)
177
{
178
  return (struct lconv *) &lconv;
179
}
180
 
181
#ifndef _REENT_ONLY
182
 
183
char *
184
_DEFUN(setlocale, (category, locale),
185
       int category _AND
186
       _CONST char *locale)
187
{
188
  return _setlocale_r (_REENT, category, locale);
189
}
190
 
191
 
192
struct lconv *
193
_DEFUN_VOID(localeconv)
194
{
195
  return _localeconv_r (_REENT);
196
}
197
 
198
#endif

powered by: WebSVN 2.1.0

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