Home | History | Annotate | Line # | Download | only in libhack
multibyte.c revision 1.3
      1  1.3       dsl /*      $NetBSD: multibyte.c,v 1.3 2008/07/12 19:20:03 dsl Exp $      */
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Ignore all multibyte sequences, removes all the citrus code.
      5  1.1  christos  * Probably only used by vfprintf() when parsing the format string.
      6  1.3       dsl  * And possibly from libcurses if compiled with HAVE_WCHAR.
      7  1.1  christos  */
      8  1.1  christos 
      9  1.1  christos #include <wchar.h>
     10  1.1  christos 
     11  1.1  christos size_t
     12  1.1  christos mbrtowc(wchar_t *wc, const char *str, size_t max_sz, mbstate_t *ps)
     13  1.1  christos {
     14  1.3       dsl 	return str == NULL || (*wc = *str) == 0 ? 0 : 1;
     15  1.1  christos }
     16  1.1  christos 
     17  1.1  christos size_t
     18  1.1  christos wcrtomb(char *str, wchar_t wc, mbstate_t *ps)
     19  1.1  christos {
     20  1.1  christos     *str = wc;
     21  1.1  christos     return 1;
     22  1.1  christos }
     23  1.1  christos 
     24  1.1  christos int
     25  1.1  christos wctob(wint_t x)
     26  1.1  christos {
     27  1.1  christos 	return x;
     28  1.1  christos }
     29  1.1  christos 
     30  1.1  christos wint_t
     31  1.1  christos btowc(int x) {
     32  1.1  christos 	return x;
     33  1.1  christos }
     34  1.1  christos 
     35  1.1  christos size_t
     36  1.1  christos mbrlen(const char * __restrict p, size_t l, mbstate_t * __restrict v)
     37  1.1  christos {
     38  1.1  christos 	size_t i;
     39  1.1  christos 	for (i = 0; i < l; i++)
     40  1.1  christos 		if (p[i] == '\0')
     41  1.1  christos 			return i;
     42  1.1  christos 	return l;
     43  1.1  christos }
     44  1.1  christos 
     45  1.1  christos int
     46  1.1  christos mbsinit(const mbstate_t *s)
     47  1.1  christos {
     48  1.1  christos 	return 0;
     49  1.1  christos }
     50  1.1  christos 
     51  1.1  christos size_t
     52  1.1  christos mbsrtowcs(wchar_t * __restrict pwcs, const char ** __restrict s, size_t n,
     53  1.1  christos     mbstate_t * __restrict ps)
     54  1.1  christos {
     55  1.2        he 	const char *p;
     56  1.2        he 	wchar_t *d;
     57  1.2        he 	size_t count;
     58  1.2        he 
     59  1.2        he 	for (p = *s, d = pwcs, count = 0;
     60  1.2        he 		count <= n;
     61  1.2        he 		count++, d++, p++)
     62  1.2        he 	{
     63  1.2        he 		if (mbrtowc(d, p, 1, ps) == 0)
     64  1.2        he 			break;
     65  1.2        he 	}
     66  1.2        he 	return count;
     67  1.1  christos }
     68  1.1  christos 
     69  1.1  christos size_t
     70  1.1  christos wcsrtombs(char * __restrict s, const wchar_t ** __restrict pwcs, size_t n,
     71  1.1  christos     mbstate_t * __restrict ps)
     72  1.1  christos {
     73  1.2        he 	char *d;
     74  1.2        he 	const wchar_t *p;
     75  1.2        he 	size_t count;
     76  1.2        he 
     77  1.2        he 	for (p = *pwcs, d = s, count = 0;
     78  1.2        he 		count <= n && *p != 0;
     79  1.2        he 		count++, d++, p++)
     80  1.2        he 	{
     81  1.2        he 		wcrtomb(d, *p, ps);
     82  1.2        he 	}
     83  1.2        he 	*d = 0;
     84  1.2        he 	return count;
     85  1.1  christos }
     86