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) 1994 by Sun Microsystems, Inc. 23 */ 24 25 26 27 #ifndef _NBYTE2UTF_H_ 28 #define _NBYTE2UTF_H_ 29 30 31 #include "hangulcode.h" 32 33 typedef struct __conv_desc { 34 int cur_stat; 35 int cur_act; 36 char hbuf[5]; 37 } _conv_desc; 38 39 int next_stat[14][21]={ /* next state table[current state][input] */ 40 /* input 41 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 */ 42 /*state*/ 43 /* 0 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 44 /* 1 */ { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1}, 45 /* 2 */ { 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 1, 2}, 46 /* 3 */ { 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 1, 2}, 47 /* 4 */ { 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2}, 48 /* 5 */ { 0, 4, 9,10,11,12,13,13,13,13,13, 3, 8, 3, 8, 3, 3, 3, 2, 1, 2}, 49 /* 6 */ { 0, 4, 9,10,11,12,13,13,13,13,13, 3, 3, 8, 8, 3, 3, 3, 2, 1, 2}, 50 /* 7 */ { 0, 4, 9,10,11,12,13,13,13,13,13, 3, 3, 3, 8, 3, 3, 3, 2, 1, 2}, 51 /* 8 */ { 0, 4, 9,10,11,12,13,13,13,13,13, 3, 3, 3, 3, 3, 3, 3, 2, 1, 2}, 52 /* 9 */ { 0, 4, 4, 4, 4, 4, 4,13, 4, 4, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2}, 53 /*10 */ { 0, 4, 4, 4, 4, 4, 4, 4,13,13, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2}, 54 /*11 */ { 0, 4,13, 4, 4,13, 4,13, 4,13,13, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2}, 55 /*12 */ { 0, 4, 4, 4, 4, 4, 4,13, 4, 4, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2}, 56 /*13 */ { 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 5, 6, 7, 2, 1, 2} 57 }; 58 59 int next_act[14][21]={ /* next action table[current state][input] */ 60 /*input 61 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 */ 62 /*state*/ 63 /* 0 */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 64 /* 1 */ { 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4}, 65 /* 2 */ { 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,15,15,15,15,15,15,15, 1, 3, 4}, 66 /* 3 */ { 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,15,15,15,15,15,15,15, 1, 3, 4}, 67 /* 4 */ { 0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 6, 6, 6, 6,16,12,13}, 68 /* 5 */ { 0, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7,10,14,10,14,10,10,10,16,12,13}, 69 /* 6 */ { 0, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7,10,10,14,14,10,10,10,16,12,13}, 70 /* 7 */ { 0, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7,10,10,10,14,10,10,10,16,12,13}, 71 /* 8 */ { 0, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7,10,10,10,10,10,10,10,16,12,13}, 72 /* 9 */ { 0, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,17,17,17,17,17,17,17,16,12,13}, 73 /*10 */ { 0, 9, 9, 9, 9, 9, 9, 9, 8, 8, 9,17,17,17,17,17,17,17,16,12,13}, 74 /*11 */ { 0, 9, 8, 9, 9, 8, 9, 8, 9, 8, 8,17,17,17,17,17,17,17,16,12,13}, 75 /*12 */ { 0, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,17,17,17,17,17,17,17,16,12,13}, 76 /*13 */ { 0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,17,17,17,17,17,17,17,16,12,13} 77 }; 78 79 #define ADD_CONVERTED_CODE(K, ADD)\ 80 {\ 81 char temp[5];\ 82 \ 83 temp[1] = cd->hbuf[1];\ 84 temp[2] = cd->hbuf[2];\ 85 temp[3] = cd->hbuf[3];\ 86 temp[4] = cd->hbuf[4];\ 87 if ((result = _johap_to_utf8(&ci, &v, &cf,\ 88 make_johap_code((K), temp))) == HANGUL)\ 89 {\ 90 if ((obtail - ob) < ((cf ? 9 : 6) + (ADD)))\ 91 {\ 92 errno = E2BIG;\ 93 ret_val = (size_t)-1;\ 94 break;\ 95 }\ 96 cd->hbuf[1] = temp[1];\ 97 cd->hbuf[2] = temp[2];\ 98 cd->hbuf[3] = temp[3];\ 99 cd->hbuf[4] = temp[4];\ 100 *ob++ = (char)((ci >> 16) & 0xFF);\ 101 *ob++ = (char)((ci >> 8) & 0xFF);\ 102 *ob++ = (char)(ci & 0xFF);\ 103 *ob++ = (char)((v >> 16) & 0xFF);\ 104 *ob++ = (char)((v >> 8) & 0xFF);\ 105 *ob++ = (char)(v & 0xFF);\ 106 if (cf)\ 107 {\ 108 *ob++ = (char)((cf >> 16) & 0xFF);\ 109 *ob++ = (char)((cf >> 8) & 0xFF);\ 110 *ob++ = (char)(cf & 0xFF);\ 111 }\ 112 }\ 113 else if (result == FAILED)\ 114 {\ 115 if ((obtail - ob) < 3)\ 116 {\ 117 errno = E2BIG;\ 118 ret_val = (size_t)-1;\ 119 break;\ 120 }\ 121 *ob++ = UTF8_NON_ID_CHAR1;\ 122 *ob++ = UTF8_NON_ID_CHAR2;\ 123 *ob++ = UTF8_NON_ID_CHAR3;\ 124 ret_val += 3;\ 125 }\ 126 else /* result == ILLEGAL_SEQ */\ 127 {\ 128 errno = EILSEQ;\ 129 ret_val = (size_t)-1;\ 130 break;\ 131 }\ 132 } 133 134 135 #endif /* _NBYTE2UTF_H_ */ 136