1*16d86563SAlexander Pyhalov /*
2*16d86563SAlexander Pyhalov * CDDL HEADER START
3*16d86563SAlexander Pyhalov *
4*16d86563SAlexander Pyhalov * The contents of this file are subject to the terms of the
5*16d86563SAlexander Pyhalov * Common Development and Distribution License (the "License").
6*16d86563SAlexander Pyhalov * You may not use this file except in compliance with the License.
7*16d86563SAlexander Pyhalov *
8*16d86563SAlexander Pyhalov * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
9*16d86563SAlexander Pyhalov * or http://www.opensolaris.org/os/licensing.
10*16d86563SAlexander Pyhalov * See the License for the specific language governing permissions
11*16d86563SAlexander Pyhalov * and limitations under the License.
12*16d86563SAlexander Pyhalov *
13*16d86563SAlexander Pyhalov * When distributing Covered Code, include this CDDL HEADER in each
14*16d86563SAlexander Pyhalov * file and include the License file at src/OPENSOLARIS.LICENSE.
15*16d86563SAlexander Pyhalov * If applicable, add the following below this CDDL HEADER, with the
16*16d86563SAlexander Pyhalov * fields enclosed by brackets "[]" replaced with your own identifying
17*16d86563SAlexander Pyhalov * information: Portions Copyright [yyyy] [name of copyright owner]
18*16d86563SAlexander Pyhalov *
19*16d86563SAlexander Pyhalov * CDDL HEADER END
20*16d86563SAlexander Pyhalov */
21*16d86563SAlexander Pyhalov /*
22*16d86563SAlexander Pyhalov * Copyright (c) 1999 by Sun Microsystems, Inc.
23*16d86563SAlexander Pyhalov */
24*16d86563SAlexander Pyhalov
25*16d86563SAlexander Pyhalov
26*16d86563SAlexander Pyhalov #include <errno.h>
27*16d86563SAlexander Pyhalov #include <stdio.h>
28*16d86563SAlexander Pyhalov #include <stdlib.h>
29*16d86563SAlexander Pyhalov #include "common_han.h"
30*16d86563SAlexander Pyhalov #include "common_utf.h"
31*16d86563SAlexander Pyhalov #include "common_euc.h"
32*16d86563SAlexander Pyhalov #include "uhang_uni_table.h"
33*16d86563SAlexander Pyhalov /* #define DEBUG */
34*16d86563SAlexander Pyhalov /* #define DEBUG_OLD */
35*16d86563SAlexander Pyhalov /* #define DEBUG_C */
36*16d86563SAlexander Pyhalov
node_compare(const void * node1,const void * node2)37*16d86563SAlexander Pyhalov static int node_compare(const void *node1, const void *node2)
38*16d86563SAlexander Pyhalov {
39*16d86563SAlexander Pyhalov #ifdef DEBUG_C
40*16d86563SAlexander Pyhalov int ret;
41*16d86563SAlexander Pyhalov ret = ((int)(((const hcode_table *)node1)->code) -(int)(((const hcode_table *)node2)->code));
42*16d86563SAlexander Pyhalov printf("/%d/",ret);
43*16d86563SAlexander Pyhalov return ret;
44*16d86563SAlexander Pyhalov #else
45*16d86563SAlexander Pyhalov return(((int)(((const hcode_table *)node1)->code) -
46*16d86563SAlexander Pyhalov (int)(((const hcode_table *)node2)->code)));
47*16d86563SAlexander Pyhalov #endif
48*16d86563SAlexander Pyhalov }
49*16d86563SAlexander Pyhalov
50*16d86563SAlexander Pyhalov /**** UNIFIED KO to UNICODE 2.0 to UTF-8 ****/
51*16d86563SAlexander Pyhalov
_unified_hangul_to_utf8(hcode_type euc_code)52*16d86563SAlexander Pyhalov hcode_type _unified_hangul_to_utf8(hcode_type euc_code)
53*16d86563SAlexander Pyhalov {
54*16d86563SAlexander Pyhalov hcode_table *node_ptr, node;
55*16d86563SAlexander Pyhalov hcode_type utf_code;
56*16d86563SAlexander Pyhalov int udc_index;
57*16d86563SAlexander Pyhalov
58*16d86563SAlexander Pyhalov /* User Definable Area Check */
59*16d86563SAlexander Pyhalov if ((EUC_UDC_SEG1 == euc_code.byte.byte3) ||
60*16d86563SAlexander Pyhalov (EUC_UDC_SEG2 == euc_code.byte.byte3)) {
61*16d86563SAlexander Pyhalov if ((euc_code.byte.byte4 < EUC_UDC_OFFSET_START) ||
62*16d86563SAlexander Pyhalov (EUC_UDC_OFFSET_END < euc_code.byte.byte4)) {
63*16d86563SAlexander Pyhalov /* beyond the UDC area */
64*16d86563SAlexander Pyhalov utf_code.code = 0;
65*16d86563SAlexander Pyhalov
66*16d86563SAlexander Pyhalov return(utf_code);
67*16d86563SAlexander Pyhalov }
68*16d86563SAlexander Pyhalov
69*16d86563SAlexander Pyhalov udc_index = (euc_code.byte.byte3 == EUC_UDC_SEG1) ?
70*16d86563SAlexander Pyhalov 0 : EUC_UDC_SEG_GAP;
71*16d86563SAlexander Pyhalov udc_index += (int)(euc_code.byte.byte4 - EUC_UDC_OFFSET_START);
72*16d86563SAlexander Pyhalov
73*16d86563SAlexander Pyhalov utf_code = _udcidx_to_utf(udc_index);
74*16d86563SAlexander Pyhalov
75*16d86563SAlexander Pyhalov if (utf_code.code == UTF_UDC_ERROR)
76*16d86563SAlexander Pyhalov utf_code.code = UTF8_NON_ID_CHAR; /* Failed */
77*16d86563SAlexander Pyhalov
78*16d86563SAlexander Pyhalov return(utf_code);
79*16d86563SAlexander Pyhalov }
80*16d86563SAlexander Pyhalov
81*16d86563SAlexander Pyhalov node.code = euc_code.word.low;
82*16d86563SAlexander Pyhalov
83*16d86563SAlexander Pyhalov node_ptr = bsearch( &node,
84*16d86563SAlexander Pyhalov uhang_uni_tbl, sizeof(uhang_uni_tbl)/sizeof(hcode_table),
85*16d86563SAlexander Pyhalov sizeof(hcode_table), node_compare);
86*16d86563SAlexander Pyhalov
87*16d86563SAlexander Pyhalov #ifdef DEBUG
88*16d86563SAlexander Pyhalov printf("*->%2x %2x %2x*",node_ptr->utf8.unicode.data1,node_ptr->utf8.unicode.data2,node_ptr->utf8.unicode.data3);
89*16d86563SAlexander Pyhalov #endif
90*16d86563SAlexander Pyhalov
91*16d86563SAlexander Pyhalov if (node_ptr != NULL) /* Success */
92*16d86563SAlexander Pyhalov {
93*16d86563SAlexander Pyhalov /*
94*16d86563SAlexander Pyhalov return(node_ptr->utf8);
95*16d86563SAlexander Pyhalov */
96*16d86563SAlexander Pyhalov
97*16d86563SAlexander Pyhalov utf_code = _uni_to_utf8(node_ptr->utf8);
98*16d86563SAlexander Pyhalov #ifdef DEBUG_OLD
99*16d86563SAlexander Pyhalov printf("*->%2x%2x%2x*",utf_code.byte.byte2,utf_code.byte.byte3,utf_code.byte.byte4);
100*16d86563SAlexander Pyhalov #endif
101*16d86563SAlexander Pyhalov
102*16d86563SAlexander Pyhalov return(utf_code);
103*16d86563SAlexander Pyhalov
104*16d86563SAlexander Pyhalov }
105*16d86563SAlexander Pyhalov else /* Failed */
106*16d86563SAlexander Pyhalov {
107*16d86563SAlexander Pyhalov utf_code.code = UTF8_NON_ID_CHAR;
108*16d86563SAlexander Pyhalov return(utf_code);
109*16d86563SAlexander Pyhalov }
110*16d86563SAlexander Pyhalov
111*16d86563SAlexander Pyhalov } /* end of hcode_type _unified_hangul_to_utf8(hcode_type euc_code) */
112