xref: /freebsd/contrib/nvi/common/conv.h (revision bc96366c864c07ef352edb92017357917c75b36c)
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  *	$Id: conv.h,v 2.32 2013/03/11 01:20:53 zy Exp $
12  */
13 
14 #ifdef USE_ICONV
15 #include <iconv.h>
16 #ifdef ICONV_TRADITIONAL
17 typedef char **		iconv_src_t;
18 #else
19 typedef char const **	iconv_src_t;
20 #endif
21 #else
22 typedef int	iconv_t;
23 #endif
24 
25 /*
26  * XXX
27  * We can not use MB_CUR_MAX here, since UTF-8 may report it as 6, but
28  * a sequence longer than 4 is deprecated by RFC 3629.
29  */
30 #define KEY_NEEDSWIDE(sp, ch)						\
31 	(INTISWIDE(ch) && KEY_LEN(sp, ch) <= 4)
32 #define KEY_COL(sp, ch)							\
33 	(KEY_NEEDSWIDE(sp, ch) ? CHAR_WIDTH(sp, ch) : KEY_LEN(sp, ch))
34 
35 enum { IC_FE_CHAR2INT, IC_FE_INT2CHAR, IC_IE_CHAR2INT, IC_IE_TO_UTF16 };
36 
37 struct _conv_win {
38 	union {
39 		char 	*c;
40 		CHAR_T	*wc;
41 	}	bp1;
42 	size_t	blen1;
43 };
44 
45 typedef int (*char2wchar_t)
46     (SCR *, const char *, ssize_t, struct _conv_win *, size_t *, CHAR_T **);
47 typedef int (*wchar2char_t)
48     (SCR *, const CHAR_T *, ssize_t, struct _conv_win *, size_t *, char **);
49 
50 struct _conv {
51 	char2wchar_t	sys2int;
52 	wchar2char_t	int2sys;
53 	char2wchar_t	file2int;
54 	wchar2char_t	int2file;
55 	char2wchar_t	input2int;
56 	iconv_t		id[IC_IE_TO_UTF16 + 1];
57 };
58