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_thai.h"
29 #include "common_utf.h"
30 #include "common_euc.h"
31 #include "utf_euc_table.h"
32
node_compare(const void * node1,const void * node2)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
_utf8_to_eucTH(hcode_type utfcode)42 hcode_type _utf8_to_eucTH(hcode_type utfcode)
43 {
44 hcode_table *node_ptr, node;
45 hcode_type eucTH;
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 eucTH.byte.byte3 = EUC_UDC_SEG1;
52 eucTH.byte.byte4 = (unsigned int)(udc_index +
53 EUC_UDC_OFFSET_START);
54 } else {
55 eucTH.byte.byte3 = EUC_UDC_SEG2;
56 eucTH.byte.byte4 = EUC_UDC_OFFSET_START +
57 (unsigned int)(udc_index - EUC_UDC_SEG_GAP);
58 }
59
60 return(eucTH);
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 eucTH.code = 0; /* initial & default set to fail value */
70
71 if (node_ptr != NULL)
72 eucTH.word.low = node_ptr->code; /* Success */
73
74 return(eucTH);
75
76
77 } /* end of hcode_type _utf8_to_eucTH(hcode_type utfcode) */
78