blob: 4953a30dab3a237c56da537ed5f1f03c9458d1eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "common_thai.h"
#include "common_utf.h"
#include "common_euc.h"
#include "euc_utf_table.h"
static int node_compare(const void *node1, const void *node2)
{
return(((int)(((const hcode_table *)node1)->code) -
(int)(((const hcode_table *)node2)->code)));
}
/**** _ W A N S U N G _ T O _ U T F 8 ****/
hcode_type _eucTH_to_utf8(hcode_type euc_code)
{
hcode_table *node_ptr, node;
hcode_type utf_code;
int udc_index;
/* User Definable Area Check */
if ((EUC_UDC_SEG1 == euc_code.byte.byte3) ||
(EUC_UDC_SEG2 == euc_code.byte.byte3)) {
if ((euc_code.byte.byte4 < EUC_UDC_OFFSET_START) ||
(EUC_UDC_OFFSET_END < euc_code.byte.byte4)) {
/* beyond the UDC area */
utf_code.code = 0;
return(utf_code);
}
udc_index = (euc_code.byte.byte3 == EUC_UDC_SEG1) ?
0 : EUC_UDC_SEG_GAP;
udc_index += (int)(euc_code.byte.byte4 - EUC_UDC_OFFSET_START);
utf_code = _udcidx_to_utf(udc_index);
if (utf_code.code == UTF_UDC_ERROR)
utf_code.code = 0; /* Failed */
return(utf_code);
}
node.code = euc_code.word.low;
node_ptr = bsearch( &node,
euc2utf_tbl, sizeof(euc2utf_tbl)/sizeof(hcode_table),
sizeof(hcode_table), node_compare);
if (node_ptr != NULL) /* Success */
return(node_ptr->utf8);
else { /* Failed */
utf_code.code = 0;
return(utf_code);
}
} /* end of hcode_type _eucTH_to_utf8(hcode_type euc_code) */
|