unxz: new applet, complete with xzcat and xz -d aliases
[oweals/busybox.git] / include / unicode.h
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Licensed under the GPL version 2, see the file LICENSE in this tarball.
4  */
5 #ifndef UNICODE_H
6 #define UNICODE_H 1
7
8 #if ENABLE_UNICODE_USING_LOCALE
9 # include <wchar.h>
10 # include <wctype.h>
11 #endif
12
13 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
14
15 enum {
16         UNICODE_UNKNOWN = 0,
17         UNICODE_OFF = 1,
18         UNICODE_ON = 2,
19 };
20
21 #define unicode_bidi_isrtl(wc) 0
22 #define unicode_bidi_is_neutral_wchar(wc) (wc <= 126 && !isalpha(wc))
23
24 #if !ENABLE_UNICODE_SUPPORT
25
26 # define unicode_strlen(string) strlen(string)
27 # define unicode_status UNICODE_OFF
28 # define init_unicode() ((void)0)
29
30 #else
31
32 # if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
33 #  undef CONFIG_LAST_SUPPORTED_WCHAR
34 #  define CONFIG_LAST_SUPPORTED_WCHAR 0x2ffff
35 # endif
36
37 # if CONFIG_LAST_SUPPORTED_WCHAR < 0x300
38 #  undef ENABLE_UNICODE_COMBINING_WCHARS
39 #  define ENABLE_UNICODE_COMBINING_WCHARS 0
40 # endif
41
42 # if CONFIG_LAST_SUPPORTED_WCHAR < 0x1100
43 #  undef ENABLE_UNICODE_WIDE_WCHARS
44 #  define ENABLE_UNICODE_WIDE_WCHARS 0
45 # endif
46
47 # if CONFIG_LAST_SUPPORTED_WCHAR < 0x590
48 #  undef  ENABLE_UNICODE_BIDI_SUPPORT
49 #  define ENABLE_UNICODE_BIDI_SUPPORT 0
50 # endif
51
52 size_t FAST_FUNC unicode_strlen(const char *string);
53 enum {
54         UNI_FLAG_PAD = (1 << 0),
55 };
56 //UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
57 //UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
58 char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
59 char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
60 char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
61
62 # if ENABLE_UNICODE_USING_LOCALE
63
64 extern uint8_t unicode_status;
65 void init_unicode(void) FAST_FUNC;
66
67 # else
68
69 /* Homegrown Unicode support. It knows only C and Unicode locales. */
70
71 #  if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
72 #   define unicode_status UNICODE_ON
73 #   define init_unicode() ((void)0)
74 #  else
75 extern uint8_t unicode_status;
76 void init_unicode(void) FAST_FUNC;
77 #  endif
78
79 #  undef MB_CUR_MAX
80 #  define MB_CUR_MAX 6
81
82 /* Prevent name collisions */
83 #  define wint_t    bb_wint_t
84 #  define mbstate_t bb_mbstate_t
85 #  define mbstowcs  bb_mbstowcs
86 #  define wcstombs  bb_wcstombs
87 #  define wcrtomb   bb_wcrtomb
88 #  define iswspace  bb_iswspace
89 #  define iswalnum  bb_iswalnum
90 #  define iswpunct  bb_iswpunct
91 #  define wcwidth   bb_wcwidth
92
93 typedef int32_t wint_t;
94 typedef struct {
95         char bogus;
96 } mbstate_t;
97
98 size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
99 size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
100 size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
101 int iswspace(wint_t wc) FAST_FUNC;
102 int iswalnum(wint_t wc) FAST_FUNC;
103 int iswpunct(wint_t wc) FAST_FUNC;
104 int wcwidth(unsigned ucs) FAST_FUNC;
105 #  if ENABLE_UNICODE_BIDI_SUPPORT
106 #   undef unicode_bidi_isrtl
107 int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
108 #   if ENABLE_UNICODE_NEUTRAL_TABLE
109 #    undef unicode_bidi_is_neutral_wchar
110 int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
111 #   endif
112 #  endif
113
114
115 # endif /* !UNICODE_USING_LOCALE */
116
117 #endif /* UNICODE_SUPPORT */
118
119 POP_SAVED_FUNCTION_VISIBILITY
120
121 #endif