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) 1999 by Sun Microsystems, Inc. 23 */ 24 25 26 #include <errno.h> 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include "common_han.h" 30 #include "common_utf.h" 31 #include "common_euc.h" 32 #include "uhang_uni_table.h" 33 34 static int 35 node_compare (const void *node1, const void *node2) 36 { 37 return(((int)(((const hcode_table *)node1)->code) - 38 (int)(((const hcode_table *)node2)->code))); 39 } 40 41 42 43 hcode_type 44 _unified_hangul_to_UCS2LE (hcode_type euc_code) 45 { 46 hcode_table *node_ptr, node; 47 hcode_type utf_code; 48 int udc_index; 49 50 /* User Definable Area Check */ 51 if ((EUC_UDC_SEG1 == euc_code.byte.byte3) || 52 (EUC_UDC_SEG2 == euc_code.byte.byte3)) { 53 if ((euc_code.byte.byte4 < EUC_UDC_OFFSET_START) || 54 (EUC_UDC_OFFSET_END < euc_code.byte.byte4)) { 55 /* beyond the UDC area */ 56 utf_code.code = 0; 57 58 return(utf_code); 59 } 60 61 udc_index = (euc_code.byte.byte3 == EUC_UDC_SEG1) ? 62 0 : EUC_UDC_SEG_GAP; 63 udc_index += (int)(euc_code.byte.byte4 - EUC_UDC_OFFSET_START); 64 65 utf_code = _udcidx_to_utf(udc_index); 66 67 if (utf_code.code == UTF_UDC_ERROR) 68 utf_code.code = UTF8_NON_ID_CHAR; /* Failed */ 69 70 return(utf_code); 71 } 72 73 node.code = euc_code.word.low; 74 75 node_ptr = bsearch( &node, 76 uhang_uni_tbl, sizeof(uhang_uni_tbl)/sizeof(hcode_table), 77 sizeof(hcode_table), node_compare); 78 79 if (node_ptr != NULL) /* Success */ 80 utf_code = node_ptr->utf8; 81 else /* Failed */ 82 utf_code.code = UTF8_NON_ID_CHAR; 83 return(utf_code); 84 } 85