1119610Sache/* rlmbutil.h -- utility functions for multibyte characters. */ 2119610Sache 3119610Sache/* Copyright (C) 2001 Free Software Foundation, Inc. 4119610Sache 5119610Sache This file is part of the GNU Readline Library, a library for 6119610Sache reading lines of text with interactive input and history editing. 7119610Sache 8119610Sache The GNU Readline Library is free software; you can redistribute it 9119610Sache and/or modify it under the terms of the GNU General Public License 10119610Sache as published by the Free Software Foundation; either version 2, or 11119610Sache (at your option) any later version. 12119610Sache 13119610Sache The GNU Readline Library is distributed in the hope that it will be 14119610Sache useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15119610Sache of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16119610Sache GNU General Public License for more details. 17119610Sache 18119610Sache The GNU General Public License is often shipped with GNU software, and 19119610Sache is generally kept in a file called COPYING or LICENSE. If you do not 20119610Sache have a copy of the license, write to the Free Software Foundation, 21119610Sache 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 22119610Sache 23119610Sache#if !defined (_RL_MBUTIL_H_) 24119610Sache#define _RL_MBUTIL_H_ 25119610Sache 26119610Sache#include "rlstdc.h" 27119610Sache 28119610Sache/************************************************/ 29119610Sache/* check multibyte capability for I18N code */ 30119610Sache/************************************************/ 31119610Sache 32119610Sache/* For platforms which support the ISO C amendement 1 functionality we 33119610Sache support user defined character classes. */ 34119610Sache /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */ 35165670Sache#if defined (HAVE_WCTYPE_H) && defined (HAVE_WCHAR_H) && defined (HAVE_LOCALE_H) 36119610Sache# include <wchar.h> 37119610Sache# include <wctype.h> 38165670Sache# if defined (HAVE_ISWCTYPE) && \ 39165670Sache defined (HAVE_ISWLOWER) && \ 40165670Sache defined (HAVE_ISWUPPER) && \ 41165670Sache defined (HAVE_MBSRTOWCS) && \ 42165670Sache defined (HAVE_MBRTOWC) && \ 43165670Sache defined (HAVE_MBRLEN) && \ 44165670Sache defined (HAVE_TOWLOWER) && \ 45165670Sache defined (HAVE_TOWUPPER) && \ 46165670Sache defined (HAVE_WCHAR_T) && \ 47165670Sache defined (HAVE_WCWIDTH) 48136644Sache /* system is supposed to support XPG5 */ 49119610Sache# define HANDLE_MULTIBYTE 1 50119610Sache# endif 51119610Sache#endif 52119610Sache 53136644Sache/* If we don't want multibyte chars even on a system that supports them, let 54136644Sache the configuring user turn multibyte support off. */ 55136644Sache#if defined (NO_MULTIBYTE_SUPPORT) 56136644Sache# undef HANDLE_MULTIBYTE 57136644Sache#endif 58136644Sache 59119610Sache/* Some systems, like BeOS, have multibyte encodings but lack mbstate_t. */ 60119610Sache#if HANDLE_MULTIBYTE && !defined (HAVE_MBSTATE_T) 61119610Sache# define wcsrtombs(dest, src, len, ps) (wcsrtombs) (dest, src, len, 0) 62119610Sache# define mbsrtowcs(dest, src, len, ps) (mbsrtowcs) (dest, src, len, 0) 63119610Sache# define wcrtomb(s, wc, ps) (wcrtomb) (s, wc, 0) 64119610Sache# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0) 65119610Sache# define mbrlen(s, n, ps) (mbrlen) (s, n, 0) 66119610Sache# define mbstate_t int 67119610Sache#endif 68119610Sache 69119610Sache/* Make sure MB_LEN_MAX is at least 16 on systems that claim to be able to 70119610Sache handle multibyte chars (some systems define MB_LEN_MAX as 1) */ 71119610Sache#ifdef HANDLE_MULTIBYTE 72119610Sache# include <limits.h> 73119610Sache# if defined(MB_LEN_MAX) && (MB_LEN_MAX < 16) 74119610Sache# undef MB_LEN_MAX 75119610Sache# endif 76119610Sache# if !defined (MB_LEN_MAX) 77119610Sache# define MB_LEN_MAX 16 78119610Sache# endif 79119610Sache#endif 80119610Sache 81119610Sache/************************************************/ 82119610Sache/* end of multibyte capability checks for I18N */ 83119610Sache/************************************************/ 84119610Sache 85119610Sache/* 86119610Sache * Flags for _rl_find_prev_mbchar and _rl_find_next_mbchar: 87119610Sache * 88119610Sache * MB_FIND_ANY find any multibyte character 89119610Sache * MB_FIND_NONZERO find a non-zero-width multibyte character 90119610Sache */ 91119610Sache 92119610Sache#define MB_FIND_ANY 0x00 93119610Sache#define MB_FIND_NONZERO 0x01 94119610Sache 95119610Sacheextern int _rl_find_prev_mbchar PARAMS((char *, int, int)); 96119610Sacheextern int _rl_find_next_mbchar PARAMS((char *, int, int, int)); 97119610Sache 98119610Sache#ifdef HANDLE_MULTIBYTE 99119610Sache 100119610Sacheextern int _rl_compare_chars PARAMS((char *, int, mbstate_t *, char *, int, mbstate_t *)); 101119610Sacheextern int _rl_get_char_len PARAMS((char *, mbstate_t *)); 102119610Sacheextern int _rl_adjust_point PARAMS((char *, int, mbstate_t *)); 103119610Sache 104119610Sacheextern int _rl_read_mbchar PARAMS((char *, int)); 105119610Sacheextern int _rl_read_mbstring PARAMS((int, char *, int)); 106119610Sache 107119610Sacheextern int _rl_is_mbchar_matched PARAMS((char *, int, int, char *, int)); 108119610Sache 109157184Sacheextern wchar_t _rl_char_value PARAMS((char *, int)); 110157184Sacheextern int _rl_walphabetic PARAMS((wchar_t)); 111157184Sache 112157184Sache#define _rl_to_wupper(wc) (iswlower (wc) ? towupper (wc) : (wc)) 113157184Sache#define _rl_to_wlower(wc) (iswupper (wc) ? towlower (wc) : (wc)) 114157184Sache 115157184Sache#define MB_NEXTCHAR(b,s,c,f) \ 116157184Sache ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) \ 117157184Sache ? _rl_find_next_mbchar ((b), (s), (c), (f)) \ 118157184Sache : ((s) + (c))) 119157184Sache#define MB_PREVCHAR(b,s,f) \ 120157184Sache ((MB_CUR_MAX > 1 && rl_byte_oriented == 0) \ 121157184Sache ? _rl_find_prev_mbchar ((b), (s), (f)) \ 122157184Sache : ((s) - 1)) 123157184Sache 124136644Sache#define MB_INVALIDCH(x) ((x) == (size_t)-1 || (x) == (size_t)-2) 125136644Sache#define MB_NULLWCH(x) ((x) == 0) 126136644Sache 127119610Sache#else /* !HANDLE_MULTIBYTE */ 128119610Sache 129119610Sache#undef MB_LEN_MAX 130119610Sache#undef MB_CUR_MAX 131119610Sache 132119610Sache#define MB_LEN_MAX 1 133119610Sache#define MB_CUR_MAX 1 134119610Sache 135119610Sache#define _rl_find_prev_mbchar(b, i, f) (((i) == 0) ? (i) : ((i) - 1)) 136119610Sache#define _rl_find_next_mbchar(b, i1, i2, f) ((i1) + (i2)) 137119610Sache 138157184Sache#define _rl_char_value(buf,ind) ((buf)[(ind)]) 139157184Sache 140157184Sache#define _rl_walphabetic(c) (rl_alphabetic (c)) 141157184Sache 142157184Sache#define _rl_to_wupper(c) (_rl_to_upper (c)) 143157184Sache#define _rl_to_wlower(c) (_rl_to_lower (c)) 144157184Sache 145157184Sache#define MB_NEXTCHAR(b,s,c,f) ((s) + (c)) 146157184Sache#define MB_PREVCHAR(b,s,f) ((s) - 1) 147157184Sache 148136644Sache#define MB_INVALIDCH(x) (0) 149136644Sache#define MB_NULLWCH(x) (0) 150136644Sache 151119610Sache#endif /* !HANDLE_MULTIBYTE */ 152119610Sache 153119610Sacheextern int rl_byte_oriented; 154119610Sache 155119610Sache#endif /* _RL_MBUTIL_H_ */ 156