427519a21ff46598a85330facb5569726826f69b
[musl] / src / multibyte / internal.h
1 /* 
2  * This code was written by Rich Felker in 2010; no copyright is claimed.
3  * This code is in the public domain. Attribution is appreciated but
4  * unnecessary.
5  */
6
7 #define LIBC
8 #ifndef LIBC
9 /* rename functions not to conflict with libc */
10 #ifndef myprefix
11 #define myprefix fsmu8_
12 #endif
13 #define concat2(a,b) a ## b
14 #define concat(a,b) concat2(a,b)
15 #define prefix(b) concat(myprefix,b)
16
17 #undef mblen
18 #undef mbrlen
19 #undef mbrtowc
20 #undef mbsinit
21 #undef mbsnrtowcs
22 #undef mbsrtowcs
23 #undef wcrtomb
24 #undef wcsrtombs
25 #undef wcstombs
26 #undef wctomb
27 #define mblen prefix(mblen)
28 #define mbrlen prefix(mbrlen)
29 #define mbrtowc prefix(mbrtowc)
30 #define mbsinit prefix(mbsinit)
31 #define mbsnrtowcs prefix(mbsnrtowcs)
32 #define mbsrtowcs prefix(mbsrtowcs)
33 #define mbstowcs prefix(mbstowcs)
34 #define wcrtomb prefix(wcrtomb)
35 #define wcsnrtombs prefix(wcsnrtombs)
36 #define wcsrtombs prefix(wcsrtombs)
37 #define wcstombs prefix(wcstombs)
38 #define wctomb prefix(wctomb)
39
40 #define bittab prefix(bittab)
41 #else
42 #define bittab __fsmu8
43 #endif
44
45 extern const uint32_t bittab[];
46
47 /* Upper 6 state bits are a negative integer offset to bound-check next byte */
48 /*    equivalent to: ( (b-0x80) | (b+offset) ) & ~0x3f      */
49 #define OOB(c,b) (((((b)>>3)-0x10)|(((b)>>3)+((int32_t)(c)>>26))) & ~7)
50
51 /* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */
52 #define R(a,b) ((uint32_t)((a==0x80 ? 0x40-b : -a) << 23))
53 #define FAILSTATE R(0x80,0x80)
54
55 #ifdef I_FAILED_TO_RTFM_RFC3629
56 #define SA 0xc2
57 #define SB 0xfe
58 #else
59 #define SA 0xc2
60 #define SB 0xf5
61 #endif