xref: /freebsd/contrib/nvi/common/conv.h (revision 2008043f386721d58158e37e0d7e50df8095942d)
1 /*-
2  * Copyright (c) 1992, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1992, 1993, 1994, 1995, 1996
5  *	Keith Bostic.  All rights reserved.
6  * Copyright (c) 2011, 2012
7  *	Zhihao Yuan.  All rights reserved.
8  *
9  * See the LICENSE file for redistribution information.
10  */
11 
12 #ifdef USE_ICONV
13 #include <iconv.h>
14 #ifdef ICONV_TRADITIONAL
15 typedef char **		iconv_src_t;
16 #else
17 typedef char const **	iconv_src_t;
18 #endif
19 #else
20 typedef int	iconv_t;
21 #endif
22 
23 /*
24  * XXX
25  * We can not use MB_CUR_MAX here, since UTF-8 may report it as 6, but
26  * a sequence longer than 4 is deprecated by RFC 3629.
27  */
28 #define KEY_NEEDSWIDE(sp, ch)						\
29 	(INTISWIDE(ch) && KEY_LEN(sp, ch) <= 4)
30 #define KEY_COL(sp, ch)							\
31 	(KEY_NEEDSWIDE(sp, ch) ? XCHAR_WIDTH(sp, ch) : KEY_LEN(sp, ch))
32 
33 enum { IC_FE_CHAR2INT, IC_FE_INT2CHAR, IC_IE_CHAR2INT, IC_IE_TO_UTF16 };
34 
35 struct _conv_win {
36 	union {
37 		char 	*c;
38 		CHAR_T	*wc;
39 	}	bp1;
40 	size_t	blen1;
41 };
42 
43 typedef int (*char2wchar_t)
44     (SCR *, const char *, ssize_t, struct _conv_win *, size_t *, CHAR_T **);
45 typedef int (*wchar2char_t)
46     (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *, char **);
47 
48 struct _conv {
49 	char2wchar_t	sys2int;
50 	wchar2char_t	int2sys;
51 	char2wchar_t	file2int;
52 	wchar2char_t	int2file;
53 	char2wchar_t	input2int;
54 	iconv_t		id[IC_IE_TO_UTF16 + 1];
55 };
56