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