1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1997, by Sun Microsystems, Inc.
23  * All rights reserved.
24  */
25 
26 
27 /*
28     Header file for converting iso2022-CN-EXT to cns11643 and big5
29 */
30 
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 
35 #define MSB		0x80	/* Most significant bit */
36 #define MBYTE		0x8e	/* multi-byte (4 byte character) */
37 #define PMASK		0xa0	/* plane number mask */
38 #define ONEBYTE		0xff	/* The right most byte */
39 
40 #define SI		0x0f	/* shift in */
41 #define SO		0x0e	/* shift out */
42 #define ESC		0x1b	/* escape */
43 
44 #define SS2LOW		0x4e	/* SS2 escape sequence low byte */
45 #define SS3LOW		0x4f	/* SS3 escape sequence low byte */
46 
47 #define NON_ID_CHAR	'_'		/* non-identified character */
48 
49 typedef struct _icv_state {
50 	char	Sfunc;		/* Current shift function SI or SO. Also the current
51 				   state of the ISO state machine */
52 	short	SSfunc;		/* Current single shift function NONE, SS2, SS3 */
53 	short	ESCstate;	/* State of the ESC seq processing sub-machine. State
54 				   can be OFF, E0, E1, E2, E3, E4 */
55 	int	firstbyte;	/* False if waiting for second Chinese byte */
56 	char	keepc[2];	/* For the 2-byte Chinese character code */
57 	char	savbuf[4];	/* Save Esc seq here in the ESC seq processing
58 				   sub-machine. If illegal ESC seq and if
59 				   insufficient space to output it, these are processed
60 				   before any byte from the inbuf when _icv_iconv is
61 				   called again with more output space. In state SO an
62 				   illegal ESC sequence causes _icv_iconv()
63 				   to return with EILSEQ error. See processESCseq()
64 				   to know what is an illegal ESC sequence. */
65 	int	numsav;		/* The number of bytes saved in savbuf */
66 	char	SOcharset;	/* The current SO designation */
67 	char	SS2charset;	/* The current SS2 designation */
68 	char	SS3charset;	/* The current SS3 designation */
69 	size_t	nonidcount;	/* Keeps track of skipped input bytes in convertion */
70 	int	_errno;		/* Internal error number */
71 } _iconv_st;
72 
73 enum	_ssfunc		{ NONE, SS2, SS3 };
74 enum	_escstate	{ OFF, E0, E1, E2, E3, E4 };
75 enum	_retProcESC 	{ NEEDMORE, DONE, INVALID };
76 enum	_truefalse	{ True, False };
77 
78 void*	iso2022_icv_open();
79 void	iso2022_icv_close(_iconv_st*);
80 size_t	iso2022_icv_iconv(_iconv_st*, char**, size_t*, unsigned char**, size_t*, int (*)(_iconv_st*, unsigned char**, size_t*, int));
81