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 #include <errno.h>
26*16d86563SAlexander Pyhalov #include <stdlib.h>
27*16d86563SAlexander Pyhalov #include "common_han.h"
28*16d86563SAlexander Pyhalov #include "common_utf.h"
29*16d86563SAlexander Pyhalov #include "common_euc.h"
30*16d86563SAlexander Pyhalov #include "uni_uhang_table.h"
31*16d86563SAlexander Pyhalov /* #define DEBUG */
32*16d86563SAlexander Pyhalov /* #define DEBUG_C */
33*16d86563SAlexander Pyhalov
node_compare2(const void * node1,const void * node2)34*16d86563SAlexander Pyhalov static int node_compare2(const void *node1, const void *node2)
35*16d86563SAlexander Pyhalov {
36*16d86563SAlexander Pyhalov #ifdef DEBUG_C
37*16d86563SAlexander Pyhalov int ret;
38*16d86563SAlexander Pyhalov ret = (int)(((const hcode_table *)node1)->utf8.code) -(int)(((const hcode_table *)node2)->utf8.code);
39*16d86563SAlexander Pyhalov printf(" %d ",ret);
40*16d86563SAlexander Pyhalov return ret;
41*16d86563SAlexander Pyhalov #else
42*16d86563SAlexander Pyhalov /*
43*16d86563SAlexander Pyhalov return((int)(((const hcode_table *)node1)->utf8.code) -
44*16d86563SAlexander Pyhalov (int)(((const hcode_table *)node2)->utf8.code));
45*16d86563SAlexander Pyhalov */
46*16d86563SAlexander Pyhalov return((int)(((const hcode_table *)node1)->utf8.code) -
47*16d86563SAlexander Pyhalov (int)(((const hcode_table *)node2)->utf8.code));
48*16d86563SAlexander Pyhalov #endif
49*16d86563SAlexander Pyhalov }
50*16d86563SAlexander Pyhalov
51*16d86563SAlexander Pyhalov
52*16d86563SAlexander Pyhalov /**** _ U T F 8 _ T O _ UNIFIED HANGUL ****/
53*16d86563SAlexander Pyhalov
_utf8_to_unified_hangul(hcode_type utfcode)54*16d86563SAlexander Pyhalov hcode_type _utf8_to_unified_hangul(hcode_type utfcode)
55*16d86563SAlexander Pyhalov {
56*16d86563SAlexander Pyhalov hcode_table *node_ptr, node;
57*16d86563SAlexander Pyhalov hcode_type uhang;
58*16d86563SAlexander Pyhalov int udc_index;
59*16d86563SAlexander Pyhalov
60*16d86563SAlexander Pyhalov /* User Definable Area Check */
61*16d86563SAlexander Pyhalov if ((udc_index = _utf_to_udcidx(utfcode)) != IDX_UDC_ERROR) {
62*16d86563SAlexander Pyhalov if (udc_index < EUC_UDC_SEG_GAP) {
63*16d86563SAlexander Pyhalov uhang.byte.byte3 = EUC_UDC_SEG1;
64*16d86563SAlexander Pyhalov uhang.byte.byte4 = (unsigned int)(udc_index +
65*16d86563SAlexander Pyhalov EUC_UDC_OFFSET_START);
66*16d86563SAlexander Pyhalov } else {
67*16d86563SAlexander Pyhalov uhang.byte.byte3 = EUC_UDC_SEG2;
68*16d86563SAlexander Pyhalov uhang.byte.byte4 = EUC_UDC_OFFSET_START +
69*16d86563SAlexander Pyhalov (unsigned int)(udc_index - EUC_UDC_SEG_GAP);
70*16d86563SAlexander Pyhalov }
71*16d86563SAlexander Pyhalov
72*16d86563SAlexander Pyhalov return(uhang);
73*16d86563SAlexander Pyhalov }
74*16d86563SAlexander Pyhalov /*
75*16d86563SAlexander Pyhalov node.utf8 = utfcode;
76*16d86563SAlexander Pyhalov */
77*16d86563SAlexander Pyhalov
78*16d86563SAlexander Pyhalov if(utfcode.byte.byte1 ==0 && utfcode.byte.byte2 ==0 && utfcode.byte.byte3 ==0)
79*16d86563SAlexander Pyhalov return(utfcode);
80*16d86563SAlexander Pyhalov
81*16d86563SAlexander Pyhalov node.utf8 = _utf8_to_uni(utfcode);
82*16d86563SAlexander Pyhalov
83*16d86563SAlexander Pyhalov
84*16d86563SAlexander Pyhalov #ifdef DEBUG
85*16d86563SAlexander Pyhalov printf("*-> %2x %2x %2x*",node.utf8.unicode.data1,node.utf8.unicode.data2,node.utf8.unicode.data3);
86*16d86563SAlexander Pyhalov #endif
87*16d86563SAlexander Pyhalov
88*16d86563SAlexander Pyhalov node_ptr = bsearch( &node,
89*16d86563SAlexander Pyhalov uni_uhang_tbl, sizeof(uni_uhang_tbl)/sizeof(hcode_table),
90*16d86563SAlexander Pyhalov sizeof(hcode_table), node_compare2);
91*16d86563SAlexander Pyhalov
92*16d86563SAlexander Pyhalov uhang.code = NON_ID_CHAR; /* initial & default set to fail value */
93*16d86563SAlexander Pyhalov
94*16d86563SAlexander Pyhalov if (node_ptr != NULL)
95*16d86563SAlexander Pyhalov {
96*16d86563SAlexander Pyhalov uhang.word.low = node_ptr->code; /* Success */
97*16d86563SAlexander Pyhalov }
98*16d86563SAlexander Pyhalov #ifdef DEBUG
99*16d86563SAlexander Pyhalov else
100*16d86563SAlexander Pyhalov {
101*16d86563SAlexander Pyhalov printf("Fail in here.");
102*16d86563SAlexander Pyhalov }
103*16d86563SAlexander Pyhalov #endif
104*16d86563SAlexander Pyhalov
105*16d86563SAlexander Pyhalov return(uhang);
106*16d86563SAlexander Pyhalov
107*16d86563SAlexander Pyhalov
108*16d86563SAlexander Pyhalov } /* end of hcode_type _utf8_to_wansung(hcode_type utfcode) */
109