rlmbutil.h revision 136644
1193323Sed/* rlmbutil.h -- utility functions for multibyte characters. */
2193323Sed
3193323Sed/* Copyright (C) 2001 Free Software Foundation, Inc.
4193323Sed
5193323Sed   This file is part of the GNU Readline Library, a library for
6193323Sed   reading lines of text with interactive input and history editing.
7193323Sed
8193323Sed   The GNU Readline Library is free software; you can redistribute it
9193323Sed   and/or modify it under the terms of the GNU General Public License
10193323Sed   as published by the Free Software Foundation; either version 2, or
11193323Sed   (at your option) any later version.
12218893Sdim
13218893Sdim   The GNU Readline Library is distributed in the hope that it will be
14218893Sdim   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15193323Sed   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16193323Sed   GNU General Public License for more details.
17193323Sed
18193323Sed   The GNU General Public License is often shipped with GNU software, and
19261991Sdim   is generally kept in a file called COPYING or LICENSE.  If you do not
20193323Sed   have a copy of the license, write to the Free Software Foundation,
21249423Sdim   59 Temple Place, Suite 330, Boston, MA 02111 USA. */
22193323Sed
23193323Sed#if !defined (_RL_MBUTIL_H_)
24193323Sed#define _RL_MBUTIL_H_
25249423Sdim
26249423Sdim#include "rlstdc.h"
27288943Sdim
28249423Sdim/************************************************/
29276479Sdim/* check multibyte capability for I18N code     */
30249423Sdim/************************************************/
31276479Sdim
32276479Sdim/* For platforms which support the ISO C amendement 1 functionality we
33249423Sdim   support user defined character classes.  */
34276479Sdim   /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.  */
35249423Sdim#if defined (HAVE_WCTYPE_H) && defined (HAVE_WCHAR_H)
36249423Sdim#  include <wchar.h>
37249423Sdim#  include <wctype.h>
38249423Sdim#  if defined (HAVE_MBSRTOWCS) && defined (HAVE_MBRTOWC) && defined (HAVE_MBRLEN) && defined (HAVE_WCWIDTH)
39288943Sdim     /* system is supposed to support XPG5 */
40249423Sdim#    define HANDLE_MULTIBYTE      1
41193323Sed#  endif
42193323Sed#endif
43193323Sed
44276479Sdim/* If we don't want multibyte chars even on a system that supports them, let
45276479Sdim   the configuring user turn multibyte support off. */
46193323Sed#if defined (NO_MULTIBYTE_SUPPORT)
47193323Sed#  undef HANDLE_MULTIBYTE
48193323Sed#endif
49193323Sed
50193323Sed/* Some systems, like BeOS, have multibyte encodings but lack mbstate_t.  */
51193323Sed#if HANDLE_MULTIBYTE && !defined (HAVE_MBSTATE_T)
52193323Sed#  define wcsrtombs(dest, src, len, ps) (wcsrtombs) (dest, src, len, 0)
53193323Sed#  define mbsrtowcs(dest, src, len, ps) (mbsrtowcs) (dest, src, len, 0)
54276479Sdim#  define wcrtomb(s, wc, ps) (wcrtomb) (s, wc, 0)
55193323Sed#  define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0)
56193323Sed#  define mbrlen(s, n, ps) (mbrlen) (s, n, 0)
57276479Sdim#  define mbstate_t int
58210299Sed#endif
59226633Sdim
60226633Sdim/* Make sure MB_LEN_MAX is at least 16 on systems that claim to be able to
61193323Sed   handle multibyte chars (some systems define MB_LEN_MAX as 1) */
62193323Sed#ifdef HANDLE_MULTIBYTE
63210299Sed#  include <limits.h>
64193323Sed#  if defined(MB_LEN_MAX) && (MB_LEN_MAX < 16)
65261991Sdim#    undef MB_LEN_MAX
66226633Sdim#  endif
67226633Sdim#  if !defined (MB_LEN_MAX)
68193323Sed#    define MB_LEN_MAX 16
69193323Sed#  endif
70224145Sdim#endif
71224145Sdim
72224145Sdim/************************************************/
73224145Sdim/* end of multibyte capability checks for I18N  */
74224145Sdim/************************************************/
75276479Sdim
76224145Sdim/*
77224145Sdim * Flags for _rl_find_prev_mbchar and _rl_find_next_mbchar:
78224145Sdim *
79224145Sdim * MB_FIND_ANY		find any multibyte character
80276479Sdim * MB_FIND_NONZERO	find a non-zero-width multibyte character
81224145Sdim */
82224145Sdim
83224145Sdim#define MB_FIND_ANY	0x00
84224145Sdim#define MB_FIND_NONZERO	0x01
85224145Sdim
86193323Sedextern int _rl_find_prev_mbchar PARAMS((char *, int, int));
87193323Sedextern int _rl_find_next_mbchar PARAMS((char *, int, int, int));
88193323Sed
89210299Sed#ifdef HANDLE_MULTIBYTE
90193323Sed
91193323Sedextern int _rl_compare_chars PARAMS((char *, int, mbstate_t *, char *, int, mbstate_t *));
92193323Sedextern int _rl_get_char_len PARAMS((char *, mbstate_t *));
93193323Sedextern int _rl_adjust_point PARAMS((char *, int, mbstate_t *));
94193323Sed
95193323Sedextern int _rl_read_mbchar PARAMS((char *, int));
96261991Sdimextern int _rl_read_mbstring PARAMS((int, char *, int));
97261991Sdim
98261991Sdimextern int _rl_is_mbchar_matched PARAMS((char *, int, int, char *, int));
99261991Sdim
100261991Sdim#define MB_INVALIDCH(x)		((x) == (size_t)-1 || (x) == (size_t)-2)
101261991Sdim#define MB_NULLWCH(x)		((x) == 0)
102261991Sdim
103261991Sdim#else /* !HANDLE_MULTIBYTE */
104261991Sdim
105261991Sdim#undef MB_LEN_MAX
106261991Sdim#undef MB_CUR_MAX
107261991Sdim
108261991Sdim#define MB_LEN_MAX	1
109261991Sdim#define MB_CUR_MAX	1
110276479Sdim
111276479Sdim#define _rl_find_prev_mbchar(b, i, f)		(((i) == 0) ? (i) : ((i) - 1))
112261991Sdim#define _rl_find_next_mbchar(b, i1, i2, f)	((i1) + (i2))
113276479Sdim
114276479Sdim#define MB_INVALIDCH(x)		(0)
115261991Sdim#define MB_NULLWCH(x)		(0)
116261991Sdim
117261991Sdim#endif /* !HANDLE_MULTIBYTE */
118261991Sdim
119261991Sdimextern int rl_byte_oriented;
120261991Sdim
121261991Sdim#endif /* _RL_MBUTIL_H_ */
122261991Sdim