summaryrefslogtreecommitdiffstats
path: root/lib/libc/locale/big5.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2003-11-02 10:09:33 +0000
committertjr <tjr@FreeBSD.org>2003-11-02 10:09:33 +0000
commit1c3a3f7e2621ff295c7e7b931e81655cef49d115 (patch)
tree824f8d75e428ea4465ffd6a2314d3084178e9224 /lib/libc/locale/big5.c
parent69c81d4892abdd3dea4d40d0a43d101eeb956109 (diff)
downloadFreeBSD-src-1c3a3f7e2621ff295c7e7b931e81655cef49d115.zip
FreeBSD-src-1c3a3f7e2621ff295c7e7b931e81655cef49d115.tar.gz
Convert the Big5, EUC, MSKanji and UTF-8 encoding methods to implement
mbrtowc() and wcrtomb() directly. GB18030, GBK and UTF2 are left unconverted; GB18030 will be done eventually, but GBK and UTF2 may just be removed, as they are subsets of GB18030 and UTF-8 respectively.
Diffstat (limited to 'lib/libc/locale/big5.c')
-rw-r--r--lib/libc/locale/big5.c103
1 files changed, 50 insertions, 53 deletions
diff --git a/lib/libc/locale/big5.c b/lib/libc/locale/big5.c
index 12cc312..7c0c981 100644
--- a/lib/libc/locale/big5.c
+++ b/lib/libc/locale/big5.c
@@ -1,4 +1,5 @@
/*-
+ * Copyright (c) 2002, 2003 Tim J. Robbins. All rights reserved.
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
@@ -40,80 +41,76 @@ static char sccsid[] = "@(#)big5.c 8.1 (Berkeley) 6/4/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <rune.h>
+#include <sys/types.h>
+#include <runetype.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/types.h>
+#include <wchar.h>
+
+extern size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
+ size_t, mbstate_t * __restrict);
+extern size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict);
-rune_t _BIG5_sgetrune(const char *, size_t, char const **);
-int _BIG5_sputrune(rune_t, char *, size_t, char **);
+int _BIG5_init(_RuneLocale *);
+size_t _BIG5_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+size_t _BIG5_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
int
-_BIG5_init(rl)
- _RuneLocale *rl;
+_BIG5_init(_RuneLocale *rl)
{
- rl->sgetrune = _BIG5_sgetrune;
- rl->sputrune = _BIG5_sputrune;
+
+ __mbrtowc = _BIG5_mbrtowc;
+ __wcrtomb = _BIG5_wcrtomb;
_CurrentRuneLocale = rl;
__mb_cur_max = 2;
return (0);
}
-static inline int
-_big5_check(c)
- u_int c;
+static __inline int
+_big5_check(u_int c)
{
+
c &= 0xff;
return ((c >= 0xa1 && c <= 0xfe) ? 2 : 1);
}
-rune_t
-_BIG5_sgetrune(string, n, result)
- const char *string;
- size_t n;
- char const **result;
+size_t
+_BIG5_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+ mbstate_t * __restrict ps __unused)
{
- rune_t rune = 0;
- int len;
+ wchar_t wc;
+ int i, len;
- if (n < 1 || (len = _big5_check(*string)) > n) {
- if (result)
- *result = string;
- return (_INVALID_RUNE);
- }
- while (--len >= 0)
- rune = (rune << 8) | ((u_int)(*string++) & 0xff);
- if (result)
- *result = string;
- return rune;
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (0);
+ if (n == 0 || (size_t)(len = _big5_check(*s)) > n)
+ /* Incomplete multibyte sequence */
+ return ((size_t)-2);
+ wc = 0;
+ i = len;
+ while (i-- > 0)
+ wc = (wc << 8) | (unsigned char)*s++;
+ if (pwc != NULL)
+ *pwc = wc;
+ return (wc == L'\0' ? 0 : len);
}
-int
-_BIG5_sputrune(c, string, n, result)
- rune_t c;
- char *string, **result;
- size_t n;
+size_t
+_BIG5_wcrtomb(char * __restrict s, wchar_t wc,
+ mbstate_t * __restrict ps __unused)
{
- if (c & 0x8000) {
- if (n >= 2) {
- string[0] = (c >> 8) & 0xff;
- string[1] = c & 0xff;
- if (result)
- *result = string + 2;
- return (2);
- }
- }
- else {
- if (n >= 1) {
- *string = c & 0xff;
- if (result)
- *result = string + 1;
- return (1);
- }
+
+ if (s == NULL)
+ /* Reset to initial shift state (no-op) */
+ return (1);
+ if (wc & 0x8000) {
+ *s++ = (wc >> 8) & 0xff;
+ *s = wc & 0xff;
+ return (2);
}
- if (result)
- *result = string;
- return (0);
-
+ *s = wc & 0xff;
+ return (1);
}
OpenPOWER on IntegriCloud