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 <stdlib.h> 28 #include "common_han.h" 29 #include "common_utf.h" 30 #include "common_euc.h" 31 #include "utf_euc_table.h" 32 33 static int node_compare(const void *node1, const void *node2) 34 { 35 return((int)(((const hcode_table *)node1)->utf8.code) - 36 (int)(((const hcode_table *)node2)->utf8.code)); 37 } 38 39 40 /**** _ U T F 8 _ T O _ W A N S U N G ****/ 41 42 hcode_type _utf8_to_wansung(hcode_type utfcode) 43 { 44 hcode_table *node_ptr, node; 45 hcode_type wansung; 46 int udc_index; 47 48 /* User Definable Area Check */ 49 if ((udc_index = _utf_to_udcidx(utfcode)) != IDX_UDC_ERROR) { 50 if (udc_index < EUC_UDC_SEG_GAP) { 51 wansung.byte.byte3 = EUC_UDC_SEG1; 52 wansung.byte.byte4 = (unsigned int)(udc_index + 53 EUC_UDC_OFFSET_START); 54 } else { 55 wansung.byte.byte3 = EUC_UDC_SEG2; 56 wansung.byte.byte4 = EUC_UDC_OFFSET_START + 57 (unsigned int)(udc_index - EUC_UDC_SEG_GAP); 58 } 59 60 return(wansung); 61 } 62 63 node.utf8 = utfcode; 64 65 node_ptr = bsearch( &node, 66 utf2euc_tbl, sizeof(utf2euc_tbl)/sizeof(hcode_table), 67 sizeof(hcode_table), node_compare); 68 69 wansung.code = NON_ID_CHAR; /* initial & default set to fail value */ 70 71 if (node_ptr != NULL) 72 wansung.word.low = node_ptr->code; /* Success */ 73 else { 74 #ifdef NEVER_BOTHER 75 /* 76 failed, assign '??' to fix bug 77 4294410 missing characters from dtmail's vacation message 78 */ 79 wansung.word.low = 0x3f3f; 80 #endif 81 /* 82 this function's responsibility is limitted to convert 83 find valid euc character corresponding to any given utf8 84 character. Bothering about 'NON_IDENTICAL' character should 85 be responsibilty of caller. 86 */ 87 wansung.code = 0x00; 88 } 89 90 91 return(wansung); 92 93 94 } /* end of hcode_type _utf8_to_wansung(hcode_type utfcode) */ 95