ls: unicode fixes
[platform/upstream/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 enum {
9         UNICODE_UNKNOWN = 0,
10         UNICODE_OFF = 1,
11         UNICODE_ON = 2,
12 };
13
14 #if !ENABLE_FEATURE_ASSUME_UNICODE
15
16 # define unicode_strlen(string) strlen(string)
17 # define unicode_status UNICODE_OFF
18 # define init_unicode() ((void)0)
19
20 #else
21
22 size_t FAST_FUNC unicode_strlen(const char *string);
23 enum {
24         UNI_FLAG_PAD = (1 << 0),
25 };
26 //UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
27 //UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
28 char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
29 char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
30 char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width);
31
32 # if ENABLE_LOCALE_SUPPORT
33
34 #  include <wchar.h>
35 #  include <wctype.h>
36 extern uint8_t unicode_status;
37 void init_unicode(void) FAST_FUNC;
38
39 # else
40
41 /* Homegrown Unicode support. It knows only C and Unicode locales. */
42
43 #  if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
44 #   define unicode_status UNICODE_ON
45 #   define init_unicode() ((void)0)
46 #  else
47 extern uint8_t unicode_status;
48 void init_unicode(void) FAST_FUNC;
49 #  endif
50
51 #  undef MB_CUR_MAX
52 #  define MB_CUR_MAX 6
53
54 /* Prevent name collisions */
55 #  define wint_t    bb_wint_t
56 #  define mbstate_t bb_mbstate_t
57 #  define mbstowcs  bb_mbstowcs
58 #  define wcstombs  bb_wcstombs
59 #  define wcrtomb   bb_wcrtomb
60 #  define iswspace  bb_iswspace
61 #  define iswalnum  bb_iswalnum
62 #  define iswpunct  bb_iswpunct
63 #  define wcwidth   bb_wcwidth
64
65 typedef int32_t wint_t;
66 typedef struct {
67         char bogus;
68 } mbstate_t;
69
70 size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
71 size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
72 size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
73 int iswspace(wint_t wc) FAST_FUNC;
74 int iswalnum(wint_t wc) FAST_FUNC;
75 int iswpunct(wint_t wc) FAST_FUNC;
76
77
78 # endif /* !LOCALE_SUPPORT */
79
80 #endif /* FEATURE_ASSUME_UNICODE */
81
82 #endif