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