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_thai.h" 30 #include "ibm_thai_table.h" 31 #include "common_utf.h" 32 #include "common_euc.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 /**** IBM Cp874 to IBM Cp 838 ****/ 41 42 hcode_type _874_to_838(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 /* For Thai, this if statement will not be used.*/ 50 /* I retain them because it's the part of the */ 51 /* framework. To maintain, look down 21 lines. */ 52 53 if ((EUC_UDC_SEG1 == euc_code.byte.byte3) || 54 (EUC_UDC_SEG2 == euc_code.byte.byte3)) { 55 if ((euc_code.byte.byte4 < EUC_UDC_OFFSET_START) || 56 (EUC_UDC_OFFSET_END < euc_code.byte.byte4)) { 57 /* beyond the UDC area */ 58 utf_code.code = 0; 59 60 return(utf_code); 61 } 62 63 udc_index = (euc_code.byte.byte3 == EUC_UDC_SEG1) ? 64 0 : EUC_UDC_SEG_GAP; 65 udc_index += (int)(euc_code.byte.byte4 - EUC_UDC_OFFSET_START); 66 67 utf_code = _udcidx_to_utf(udc_index); 68 69 if (utf_code.code == UTF_UDC_ERROR) 70 utf_code.code = 0; /* Failed */ 71 72 return(utf_code); 73 } 74 75 /* For Thai, this function starts here */ 76 /* To change table, just change table */ 77 /* name 5 lines below. */ 78 79 node.code = euc_code.word.low; 80 81 node_ptr = bsearch( &node, 82 ibm874_838_tbl, sizeof(ibm874_838_tbl)/sizeof(hcode_table), 83 sizeof(hcode_table), node_compare); 84 85 if (node_ptr != NULL) /* Success */ 86 return(node_ptr->utf8); 87 else { /* Failed */ 88 utf_code.code = 0; 89 return(utf_code); 90 } 91 92 } /* end of hcode_type _874_to_838(hcode_type euc_code) */ 93