2009-07-11 19:36:13 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
2009-07-11 19:36:13 +00:00
|
|
|
*/
|
|
|
|
#ifndef UNICODE_H
|
|
|
|
#define UNICODE_H 1
|
|
|
|
|
2010-03-26 13:06:56 +00:00
|
|
|
#if ENABLE_UNICODE_USING_LOCALE
|
2010-02-19 07:47:17 +00:00
|
|
|
# include <wchar.h>
|
|
|
|
# include <wctype.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-02 11:45:38 +00:00
|
|
|
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
|
|
|
|
|
2010-01-04 19:49:58 +00:00
|
|
|
enum {
|
|
|
|
UNICODE_UNKNOWN = 0,
|
|
|
|
UNICODE_OFF = 1,
|
2014-11-01 14:46:02 +00:00
|
|
|
UNICODE_ON = 2
|
2010-01-04 19:49:58 +00:00
|
|
|
};
|
|
|
|
|
2010-03-26 12:13:24 +00:00
|
|
|
#define unicode_bidi_isrtl(wc) 0
|
|
|
|
#define unicode_bidi_is_neutral_wchar(wc) (wc <= 126 && !isalpha(wc))
|
2010-03-18 17:35:37 +00:00
|
|
|
|
2010-03-26 13:06:56 +00:00
|
|
|
#if !ENABLE_UNICODE_SUPPORT
|
2009-07-11 19:36:13 +00:00
|
|
|
|
2010-06-01 06:33:18 +00:00
|
|
|
# define unicode_strlen(string) strlen(string)
|
|
|
|
# define unicode_strwidth(string) strlen(string)
|
2010-01-04 19:49:58 +00:00
|
|
|
# define unicode_status UNICODE_OFF
|
|
|
|
# define init_unicode() ((void)0)
|
2011-03-23 16:59:27 +00:00
|
|
|
# define reinit_unicode(LANG) ((void)0)
|
2009-07-11 19:36:13 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2010-03-18 17:35:37 +00:00
|
|
|
# if CONFIG_LAST_SUPPORTED_WCHAR < 126 || CONFIG_LAST_SUPPORTED_WCHAR >= 0x30000
|
2010-05-16 19:15:03 +00:00
|
|
|
# undef CONFIG_LAST_SUPPORTED_WCHAR
|
|
|
|
# define CONFIG_LAST_SUPPORTED_WCHAR 0x2ffff
|
2010-03-18 17:35:37 +00:00
|
|
|
# endif
|
|
|
|
|
2010-05-16 19:15:03 +00:00
|
|
|
# if CONFIG_LAST_SUPPORTED_WCHAR < 0x300
|
2010-05-16 18:46:53 +00:00
|
|
|
# undef ENABLE_UNICODE_COMBINING_WCHARS
|
|
|
|
# define ENABLE_UNICODE_COMBINING_WCHARS 0
|
|
|
|
# endif
|
|
|
|
|
2010-05-16 19:15:03 +00:00
|
|
|
# if CONFIG_LAST_SUPPORTED_WCHAR < 0x1100
|
2010-05-16 18:46:53 +00:00
|
|
|
# undef ENABLE_UNICODE_WIDE_WCHARS
|
|
|
|
# define ENABLE_UNICODE_WIDE_WCHARS 0
|
|
|
|
# endif
|
|
|
|
|
2010-05-16 19:15:03 +00:00
|
|
|
# if CONFIG_LAST_SUPPORTED_WCHAR < 0x590
|
2010-03-18 17:35:37 +00:00
|
|
|
# undef ENABLE_UNICODE_BIDI_SUPPORT
|
|
|
|
# define ENABLE_UNICODE_BIDI_SUPPORT 0
|
|
|
|
# endif
|
|
|
|
|
2010-06-01 06:33:18 +00:00
|
|
|
/* Number of unicode chars. Falls back to strlen() on invalid unicode */
|
2010-01-24 06:44:03 +00:00
|
|
|
size_t FAST_FUNC unicode_strlen(const char *string);
|
2010-06-01 06:33:18 +00:00
|
|
|
/* Width on terminal */
|
|
|
|
size_t FAST_FUNC unicode_strwidth(const char *string);
|
2010-01-30 22:16:21 +00:00
|
|
|
enum {
|
2014-11-01 14:46:02 +00:00
|
|
|
UNI_FLAG_PAD = (1 << 0)
|
2010-01-30 22:16:21 +00:00
|
|
|
};
|
|
|
|
//UNUSED: unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
|
|
|
|
//UNUSED: char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags);
|
|
|
|
char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src);
|
2011-01-11 12:08:28 +00:00
|
|
|
//UNUSED: char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth);
|
|
|
|
char* FAST_FUNC unicode_conv_to_printable_fixedwidth(/*uni_stat_t *stats,*/ const char *src, unsigned width);
|
2009-07-11 20:26:48 +00:00
|
|
|
|
2010-03-26 13:06:56 +00:00
|
|
|
# if ENABLE_UNICODE_USING_LOCALE
|
2009-07-11 19:36:13 +00:00
|
|
|
|
2010-01-04 19:49:58 +00:00
|
|
|
extern uint8_t unicode_status;
|
|
|
|
void init_unicode(void) FAST_FUNC;
|
2011-03-23 16:59:27 +00:00
|
|
|
void reinit_unicode(const char *LANG) FAST_FUNC;
|
2009-07-11 19:36:13 +00:00
|
|
|
|
|
|
|
# else
|
|
|
|
|
2010-01-24 06:44:03 +00:00
|
|
|
/* Homegrown Unicode support. It knows only C and Unicode locales. */
|
2009-07-11 20:26:48 +00:00
|
|
|
|
2009-07-11 19:36:13 +00:00
|
|
|
# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
|
2010-01-04 19:49:58 +00:00
|
|
|
# define unicode_status UNICODE_ON
|
|
|
|
# define init_unicode() ((void)0)
|
2011-03-23 16:59:27 +00:00
|
|
|
# define reinit_unicode(LANG) ((void)0)
|
2009-07-11 19:36:13 +00:00
|
|
|
# else
|
2010-01-04 19:49:58 +00:00
|
|
|
extern uint8_t unicode_status;
|
|
|
|
void init_unicode(void) FAST_FUNC;
|
2011-03-23 16:59:27 +00:00
|
|
|
void reinit_unicode(const char *LANG) FAST_FUNC;
|
2009-07-11 19:36:13 +00:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# undef MB_CUR_MAX
|
|
|
|
# define MB_CUR_MAX 6
|
|
|
|
|
|
|
|
/* Prevent name collisions */
|
|
|
|
# define wint_t bb_wint_t
|
|
|
|
# define mbstate_t bb_mbstate_t
|
|
|
|
# define mbstowcs bb_mbstowcs
|
|
|
|
# define wcstombs bb_wcstombs
|
|
|
|
# define wcrtomb bb_wcrtomb
|
|
|
|
# define iswspace bb_iswspace
|
|
|
|
# define iswalnum bb_iswalnum
|
|
|
|
# define iswpunct bb_iswpunct
|
2010-01-24 06:44:03 +00:00
|
|
|
# define wcwidth bb_wcwidth
|
2009-07-11 19:36:13 +00:00
|
|
|
|
|
|
|
typedef int32_t wint_t;
|
|
|
|
typedef struct {
|
|
|
|
char bogus;
|
|
|
|
} mbstate_t;
|
|
|
|
|
|
|
|
size_t mbstowcs(wchar_t *dest, const char *src, size_t n) FAST_FUNC;
|
|
|
|
size_t wcstombs(char *dest, const wchar_t *src, size_t n) FAST_FUNC;
|
|
|
|
size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) FAST_FUNC;
|
|
|
|
int iswspace(wint_t wc) FAST_FUNC;
|
|
|
|
int iswalnum(wint_t wc) FAST_FUNC;
|
|
|
|
int iswpunct(wint_t wc) FAST_FUNC;
|
2010-05-16 18:46:53 +00:00
|
|
|
int wcwidth(unsigned ucs) FAST_FUNC;
|
2010-03-18 17:35:37 +00:00
|
|
|
# if ENABLE_UNICODE_BIDI_SUPPORT
|
2010-03-26 12:13:24 +00:00
|
|
|
# undef unicode_bidi_isrtl
|
|
|
|
int unicode_bidi_isrtl(wint_t wc) FAST_FUNC;
|
|
|
|
# if ENABLE_UNICODE_NEUTRAL_TABLE
|
|
|
|
# undef unicode_bidi_is_neutral_wchar
|
|
|
|
int unicode_bidi_is_neutral_wchar(wint_t wc) FAST_FUNC;
|
|
|
|
# endif
|
2010-03-18 17:35:37 +00:00
|
|
|
# endif
|
2009-07-11 19:36:13 +00:00
|
|
|
|
2010-01-18 00:55:00 +00:00
|
|
|
|
2010-03-26 13:06:56 +00:00
|
|
|
# endif /* !UNICODE_USING_LOCALE */
|
2009-07-11 19:36:13 +00:00
|
|
|
|
2010-03-26 13:06:56 +00:00
|
|
|
#endif /* UNICODE_SUPPORT */
|
2009-07-11 19:36:13 +00:00
|
|
|
|
2010-02-02 11:45:38 +00:00
|
|
|
POP_SAVED_FUNCTION_VISIBILITY
|
|
|
|
|
2009-07-11 19:36:13 +00:00
|
|
|
#endif
|