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) 1996 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 "euc_utf_table.h" 33 34 static int node_compare(const void *node1, const void *node2) 35 { 36 return(((int)(((const hcode_table *)node1)->code) - 37 (int)(((const hcode_table *)node2)->code))); 38 } 39 40 /**** _ W A N S U N G _ T O _ U T F 8 ****/ 41 42 hcode_type _wansung_to_utf8(hcode_type euc_code) 43 { 44 hcode_table *node_ptr, node; 45 hcode_type utf_code; 46 int udc_index; 47 48 /* User Definable Area Check */ 49 /* bugid 4701856 */ 50 /* characters from 0xc9fa to 0xc9fe are not part of UDC */ 51 /* Therefor, they need to be filtered out here... */ 52 if ( (euc_code.code < 0xc9fa || euc_code.code > 0xc9fe) 53 && ( (EUC_UDC_SEG1 == euc_code.byte.byte3) || 54 (EUC_UDC_SEG2 == euc_code.byte.byte3) ) 55 ){ 56 if ((euc_code.byte.byte4 < EUC_UDC_OFFSET_START) || 57 (EUC_UDC_OFFSET_END < euc_code.byte.byte4)) { 58 /* beyond the UDC area */ 59 utf_code.code = 0; 60 61 return(utf_code); 62 } 63 64 udc_index = (euc_code.byte.byte3 == EUC_UDC_SEG1) ? 65 0 : EUC_UDC_SEG_GAP; 66 udc_index += (int)(euc_code.byte.byte4 - EUC_UDC_OFFSET_START); 67 68 utf_code = _udcidx_to_utf(udc_index); 69 70 if (utf_code.code == UTF_UDC_ERROR) 71 utf_code.code = UTF8_NON_ID_CHAR; /* Failed */ 72 73 return(utf_code); 74 } 75 76 node.code = euc_code.word.low; 77 78 node_ptr = bsearch( &node, 79 euc2utf_tbl, sizeof(euc2utf_tbl)/sizeof(hcode_table), 80 sizeof(hcode_table), node_compare); 81 82 if (node_ptr != NULL) /* Success */ 83 return(node_ptr->utf8); 84 else { /* Failed */ 85 utf_code.code = UTF8_NON_ID_CHAR; 86 return(utf_code); 87 } 88 89 } /* end of hcode_type _wansung_to_utf8(hcode_type euc_code) */ 90