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