1 --- utf2.c.orig Fri Feb 18 15:49:55 2005
2 +++ utf2.c Fri Feb 18 15:52:07 2005
7 +/* dumb down UTF-8 to do UTF2 */
8 __FBSDID("$FreeBSD: src/lib/libc/locale/utf8.c,v 1.11 2004/07/27 06:29:48 tjr Exp $");
10 +#include "xlocale_private.h"
19 -size_t _UTF8_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
20 - mbstate_t * __restrict);
21 -int _UTF8_mbsinit(const mbstate_t *);
22 -size_t _UTF8_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
23 - size_t, size_t, mbstate_t * __restrict);
24 -size_t _UTF8_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
25 -size_t _UTF8_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
26 - size_t, size_t, mbstate_t * __restrict);
27 +#define UTF2_MB_CUR_MAX 3
29 +static size_t _UTF2_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
30 + mbstate_t * __restrict, locale_t);
31 +static int _UTF2_mbsinit(const mbstate_t *, locale_t);
32 +static size_t _UTF2_mbsnrtowcs(wchar_t * __restrict, const char ** __restrict,
33 + size_t, size_t, mbstate_t * __restrict, locale_t);
34 +static size_t _UTF2_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict, locale_t);
35 +static size_t _UTF2_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
36 + size_t, size_t, mbstate_t * __restrict, locale_t);
46 -_UTF8_init(_RuneLocale *rl)
47 +__private_extern__ int
48 +_UTF2_init(struct __xlocale_st_runelocale *xrl)
51 - __mbrtowc = _UTF8_mbrtowc;
52 - __wcrtomb = _UTF8_wcrtomb;
53 - __mbsinit = _UTF8_mbsinit;
54 - __mbsnrtowcs = _UTF8_mbsnrtowcs;
55 - __wcsnrtombs = _UTF8_wcsnrtombs;
56 - _CurrentRuneLocale = rl;
58 + xrl->__mbrtowc = _UTF2_mbrtowc;
59 + xrl->__wcrtomb = _UTF2_wcrtomb;
60 + xrl->__mbsinit = _UTF2_mbsinit;
61 + xrl->__mbsnrtowcs = _UTF2_mbsnrtowcs;
62 + xrl->__wcsnrtombs = _UTF2_wcsnrtombs;
63 + xrl->__mb_cur_max = UTF2_MB_CUR_MAX;
69 -_UTF8_mbsinit(const mbstate_t *ps)
71 +_UTF2_mbsinit(const mbstate_t *ps, locale_t loc)
74 - return (ps == NULL || ((const _UTF8State *)ps)->want == 0);
75 + return (ps == NULL || ((const _UTF2State *)ps)->want == 0);
79 -_UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
80 - mbstate_t * __restrict ps)
82 +_UTF2_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
83 + mbstate_t * __restrict ps, locale_t loc)
87 int ch, i, mask, want;
90 - us = (_UTF8State *)ps;
91 + us = (_UTF2State *)ps;
93 - if (us->want < 0 || us->want > 6) {
94 + if (us->want < 0 || us->want > 3) {
102 - } else if ((ch & 0xf8) == 0xf0) {
106 - } else if ((ch & 0xfc) == 0xf8) {
110 - } else if ((ch & 0xfc) == 0xfc) {
113 - lbound = 0x4000000;
116 - * Malformed input; input is not UTF-8.
117 + * Malformed input; input is not UTF2.
121 @@ -194,17 +186,17 @@
122 return (wch == L'\0' ? 0 : want);
126 -_UTF8_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
127 - size_t nms, size_t len, mbstate_t * __restrict ps)
129 +_UTF2_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
130 + size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
139 - us = (_UTF8State *)ps;
140 + us = (_UTF2State *)ps;
148 - else if ((nb = _UTF8_mbrtowc(&wc, s, nms, ps)) ==
149 + else if ((nb = _UTF2_mbrtowc(&wc, s, nms, ps, loc)) ==
151 /* Invalid sequence - mbrtowc() sets errno. */
157 - } else if ((nb = _UTF8_mbrtowc(dst, s, nms, ps)) ==
158 + } else if ((nb = _UTF2_mbrtowc(dst, s, nms, ps, loc)) ==
162 @@ -276,14 +268,14 @@
167 -_UTF8_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
169 +_UTF2_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps, locale_t loc)
176 - us = (_UTF8State *)ps;
177 + us = (_UTF2State *)ps;
182 } else if ((wc & ~0xffff) == 0) {
185 - } else if ((wc & ~0x1fffff) == 0) {
188 - } else if ((wc & ~0x3ffffff) == 0) {
191 - } else if ((wc & ~0x7fffffff) == 0) {
197 @@ -344,17 +327,17 @@
202 -_UTF8_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
203 - size_t nwc, size_t len, mbstate_t * __restrict ps)
205 +_UTF2_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
206 + size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc)
210 char buf[MB_LEN_MAX];
215 - us = (_UTF8State *)ps;
216 + us = (_UTF2State *)ps;
221 if (0 <= *s && *s < 0x80)
222 /* Fast path for plain ASCII characters. */
224 - else if ((nb = _UTF8_wcrtomb(buf, *s, ps)) ==
225 + else if ((nb = _UTF2_wcrtomb(buf, *s, ps, loc)) ==
227 /* Invalid character - wcrtomb() sets errno. */
230 /* Fast path for plain ASCII characters. */
233 - } else if (len > (size_t)MB_CUR_MAX) {
234 + } else if (len > (size_t)UTF2_MB_CUR_MAX) {
235 /* Enough space to translate in-place. */
236 - if ((nb = (int)_UTF8_wcrtomb(dst, *s, ps)) < 0) {
237 + if ((nb = (int)_UTF2_wcrtomb(dst, *s, ps, loc)) < 0) {
243 * May not be enough space; use temp. buffer.
245 - if ((nb = (int)_UTF8_wcrtomb(buf, *s, ps)) < 0) {
246 + if ((nb = (int)_UTF2_wcrtomb(buf, *s, ps, loc)) < 0) {