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 #include <errno.h> 26 #include <stdlib.h> 27 #include "common_han.h" 28 #include "common_utf.h" 29 #include "common_euc.h" 30 #include "uni_uhang_table.h" 31 /* #define DEBUG */ 32 /* #define DEBUG_C */ 33 34 static int node_compare2(const void *node1, const void *node2) 35 { 36 #ifdef DEBUG_C 37 int ret; 38 ret = (int)(((const hcode_table *)node1)->utf8.code) -(int)(((const hcode_table *)node2)->utf8.code); 39 printf(" %d ",ret); 40 return ret; 41 #else 42 /* 43 return((int)(((const hcode_table *)node1)->utf8.code) - 44 (int)(((const hcode_table *)node2)->utf8.code)); 45 */ 46 return((int)(((const hcode_table *)node1)->utf8.code) - 47 (int)(((const hcode_table *)node2)->utf8.code)); 48 #endif 49 } 50 51 52 /**** _ U T F 8 _ T O _ UNIFIED HANGUL ****/ 53 54 hcode_type _utf8_to_unified_hangul(hcode_type utfcode) 55 { 56 hcode_table *node_ptr, node; 57 hcode_type uhang; 58 int udc_index; 59 60 /* User Definable Area Check */ 61 if ((udc_index = _utf_to_udcidx(utfcode)) != IDX_UDC_ERROR) { 62 if (udc_index < EUC_UDC_SEG_GAP) { 63 uhang.byte.byte3 = EUC_UDC_SEG1; 64 uhang.byte.byte4 = (unsigned int)(udc_index + 65 EUC_UDC_OFFSET_START); 66 } else { 67 uhang.byte.byte3 = EUC_UDC_SEG2; 68 uhang.byte.byte4 = EUC_UDC_OFFSET_START + 69 (unsigned int)(udc_index - EUC_UDC_SEG_GAP); 70 } 71 72 return(uhang); 73 } 74 /* 75 node.utf8 = utfcode; 76 */ 77 78 if(utfcode.byte.byte1 ==0 && utfcode.byte.byte2 ==0 && utfcode.byte.byte3 ==0) 79 return(utfcode); 80 81 node.utf8 = _utf8_to_uni(utfcode); 82 83 84 #ifdef DEBUG 85 printf("*-> %2x %2x %2x*",node.utf8.unicode.data1,node.utf8.unicode.data2,node.utf8.unicode.data3); 86 #endif 87 88 node_ptr = bsearch( &node, 89 uni_uhang_tbl, sizeof(uni_uhang_tbl)/sizeof(hcode_table), 90 sizeof(hcode_table), node_compare2); 91 92 uhang.code = NON_ID_CHAR; /* initial & default set to fail value */ 93 94 if (node_ptr != NULL) 95 { 96 uhang.word.low = node_ptr->code; /* Success */ 97 } 98 #ifdef DEBUG 99 else 100 { 101 printf("Fail in here."); 102 } 103 #endif 104 105 return(uhang); 106 107 108 } /* end of hcode_type _utf8_to_wansung(hcode_type utfcode) */ 109