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_han.h"
30 #include "common_utf.h"
31 #include "common_euc.h"
32 #include "uhang_uni_table.h"
33 /* #define DEBUG */
34 /* #define DEBUG_OLD */
35 /* #define DEBUG_C */
36
node_compare(const void * node1,const void * node2)37 static int node_compare(const void *node1, const void *node2)
38 {
39 #ifdef DEBUG_C
40 int ret;
41 ret = ((int)(((const hcode_table *)node1)->code) -(int)(((const hcode_table *)node2)->code));
42 printf("/%d/",ret);
43 return ret;
44 #else
45 return(((int)(((const hcode_table *)node1)->code) -
46 (int)(((const hcode_table *)node2)->code)));
47 #endif
48 }
49
50 /**** UNIFIED KO to UNICODE 2.0 to UTF-8 ****/
51
_unified_hangul_to_utf8(hcode_type euc_code)52 hcode_type _unified_hangul_to_utf8(hcode_type euc_code)
53 {
54 hcode_table *node_ptr, node;
55 hcode_type utf_code;
56 int udc_index;
57
58 /* User Definable Area Check */
59 if ((EUC_UDC_SEG1 == euc_code.byte.byte3) ||
60 (EUC_UDC_SEG2 == euc_code.byte.byte3)) {
61 if ((euc_code.byte.byte4 < EUC_UDC_OFFSET_START) ||
62 (EUC_UDC_OFFSET_END < euc_code.byte.byte4)) {
63 /* beyond the UDC area */
64 utf_code.code = 0;
65
66 return(utf_code);
67 }
68
69 udc_index = (euc_code.byte.byte3 == EUC_UDC_SEG1) ?
70 0 : EUC_UDC_SEG_GAP;
71 udc_index += (int)(euc_code.byte.byte4 - EUC_UDC_OFFSET_START);
72
73 utf_code = _udcidx_to_utf(udc_index);
74
75 if (utf_code.code == UTF_UDC_ERROR)
76 utf_code.code = UTF8_NON_ID_CHAR; /* Failed */
77
78 return(utf_code);
79 }
80
81 node.code = euc_code.word.low;
82
83 node_ptr = bsearch( &node,
84 uhang_uni_tbl, sizeof(uhang_uni_tbl)/sizeof(hcode_table),
85 sizeof(hcode_table), node_compare);
86
87 #ifdef DEBUG
88 printf("*->%2x %2x %2x*",node_ptr->utf8.unicode.data1,node_ptr->utf8.unicode.data2,node_ptr->utf8.unicode.data3);
89 #endif
90
91 if (node_ptr != NULL) /* Success */
92 {
93 /*
94 return(node_ptr->utf8);
95 */
96
97 utf_code = _uni_to_utf8(node_ptr->utf8);
98 #ifdef DEBUG_OLD
99 printf("*->%2x%2x%2x*",utf_code.byte.byte2,utf_code.byte.byte3,utf_code.byte.byte4);
100 #endif
101
102 return(utf_code);
103
104 }
105 else /* Failed */
106 {
107 utf_code.code = UTF8_NON_ID_CHAR;
108 return(utf_code);
109 }
110
111 } /* end of hcode_type _unified_hangul_to_utf8(hcode_type euc_code) */
112