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) 1996 by Sun Microsystems, Inc.
23*16d86563SAlexander Pyhalov  */
24*16d86563SAlexander Pyhalov 
25*16d86563SAlexander Pyhalov 
26*16d86563SAlexander Pyhalov #include <errno.h>
27*16d86563SAlexander Pyhalov #include <stdlib.h>
28*16d86563SAlexander Pyhalov #include "common_han.h"
29*16d86563SAlexander Pyhalov #include "common_utf.h"
30*16d86563SAlexander Pyhalov #include "common_euc.h"
31*16d86563SAlexander Pyhalov #include "utf_euc_table.h"
32*16d86563SAlexander Pyhalov 
node_compare(const void * node1,const void * node2)33*16d86563SAlexander Pyhalov static int node_compare(const void *node1, const void *node2)
34*16d86563SAlexander Pyhalov {
35*16d86563SAlexander Pyhalov 	return((int)(((const hcode_table *)node1)->utf8.code) -
36*16d86563SAlexander Pyhalov 	       (int)(((const hcode_table *)node2)->utf8.code));
37*16d86563SAlexander Pyhalov }
38*16d86563SAlexander Pyhalov 
39*16d86563SAlexander Pyhalov 
40*16d86563SAlexander Pyhalov /****  _ U T F 8 _ T O _ W A N S U N G  ****/
41*16d86563SAlexander Pyhalov 
_utf8_to_wansung(hcode_type utfcode)42*16d86563SAlexander Pyhalov hcode_type _utf8_to_wansung(hcode_type utfcode)
43*16d86563SAlexander Pyhalov {
44*16d86563SAlexander Pyhalov         hcode_table *node_ptr, node;
45*16d86563SAlexander Pyhalov 	hcode_type wansung;
46*16d86563SAlexander Pyhalov 	int udc_index;
47*16d86563SAlexander Pyhalov 
48*16d86563SAlexander Pyhalov 	/* User Definable Area Check */
49*16d86563SAlexander Pyhalov 	if ((udc_index = _utf_to_udcidx(utfcode)) != IDX_UDC_ERROR) {
50*16d86563SAlexander Pyhalov 		if (udc_index < EUC_UDC_SEG_GAP) {
51*16d86563SAlexander Pyhalov 			wansung.byte.byte3 = EUC_UDC_SEG1;
52*16d86563SAlexander Pyhalov 			wansung.byte.byte4 = (unsigned int)(udc_index +
53*16d86563SAlexander Pyhalov 						EUC_UDC_OFFSET_START);
54*16d86563SAlexander Pyhalov 		} else {
55*16d86563SAlexander Pyhalov 			wansung.byte.byte3 = EUC_UDC_SEG2;
56*16d86563SAlexander Pyhalov 			wansung.byte.byte4 = EUC_UDC_OFFSET_START +
57*16d86563SAlexander Pyhalov 				(unsigned int)(udc_index - EUC_UDC_SEG_GAP);
58*16d86563SAlexander Pyhalov 		}
59*16d86563SAlexander Pyhalov 
60*16d86563SAlexander Pyhalov 		return(wansung);
61*16d86563SAlexander Pyhalov 	}
62*16d86563SAlexander Pyhalov 
63*16d86563SAlexander Pyhalov         node.utf8 = utfcode;
64*16d86563SAlexander Pyhalov 
65*16d86563SAlexander Pyhalov         node_ptr = bsearch( &node,
66*16d86563SAlexander Pyhalov                 utf2euc_tbl, sizeof(utf2euc_tbl)/sizeof(hcode_table),
67*16d86563SAlexander Pyhalov                 sizeof(hcode_table), node_compare);
68*16d86563SAlexander Pyhalov 
69*16d86563SAlexander Pyhalov 	wansung.code = NON_ID_CHAR; /* initial & default set to fail value */
70*16d86563SAlexander Pyhalov 
71*16d86563SAlexander Pyhalov         if (node_ptr != NULL)
72*16d86563SAlexander Pyhalov                 wansung.word.low = node_ptr->code; /* Success */
73*16d86563SAlexander Pyhalov         else {
74*16d86563SAlexander Pyhalov #ifdef NEVER_BOTHER
75*16d86563SAlexander Pyhalov 	  /*
76*16d86563SAlexander Pyhalov 	    failed, assign '??'  to fix bug
77*16d86563SAlexander Pyhalov 	    4294410 missing characters from dtmail's vacation message
78*16d86563SAlexander Pyhalov 	  */
79*16d86563SAlexander Pyhalov                 wansung.word.low = 0x3f3f;
80*16d86563SAlexander Pyhalov #endif
81*16d86563SAlexander Pyhalov 		/*
82*16d86563SAlexander Pyhalov 		  this function's responsibility is limitted to convert
83*16d86563SAlexander Pyhalov 		  find valid euc character corresponding to any given utf8
84*16d86563SAlexander Pyhalov 		  character. Bothering about 'NON_IDENTICAL' character should
85*16d86563SAlexander Pyhalov 		  be responsibilty of caller.
86*16d86563SAlexander Pyhalov 		 */
87*16d86563SAlexander Pyhalov 		wansung.code = 0x00;
88*16d86563SAlexander Pyhalov 	}
89*16d86563SAlexander Pyhalov 
90*16d86563SAlexander Pyhalov 
91*16d86563SAlexander Pyhalov         return(wansung);
92*16d86563SAlexander Pyhalov 
93*16d86563SAlexander Pyhalov 
94*16d86563SAlexander Pyhalov }  /* end of hcode_type _utf8_to_wansung(hcode_type utfcode) */
95