xref: /titanic_50/usr/src/lib/iconv_modules/ko/common/Cp933_to_UTF8.c (revision 880d797826457b77414b37d531cc3e1aa166ecbe)
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 /*
23  * Copyright (c) 1997, by Sun Microsystems, Inc.
24  * All rights reserved.
25  *
26  * $Id: Cp933_to_UTF8.c,v 1.4 2004/03/21 23:14:51 fzhang Exp $ SMI
27  *
28  */
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <errno.h>
33 #include <sys/types.h>
34 
35 #include "tab_lookup.h"   	/* table lookup data types */
36 #include "cp933_ucs2.h"   	/* Cp933 to Unicode mapping table */
37 
38 
39 /*
40  * Open; called from iconv_open()
41  */
42 void *
_icv_open()43 _icv_open()
44 {
45 
46         _icv_state *st;
47 
48         if ((st = (_icv_state *)malloc(sizeof(_icv_state))) == NULL) {
49                 errno = ENOMEM;
50                 return ((void *) -1);
51         }
52 
53         st->left_to_right = B_FALSE;
54         st->right_to_left = B_TRUE;
55         st->left_code_size = 2; /* byte */
56         st->right_code_size = 2; /* byte */
57         st->table = &cp933_ucs2_tab[0];
58         st->table_size =  MAX_UCS_NUM;
59 	st->shift = SHIFT_IN;
60 
61 	st->ustate = 0;
62 	st->_errno = 0;
63         return ((void *)st);
64 }
65 
66 
67 /*
68  * Close; called from iconv_close()
69  */
70 void
_icv_close(_icv_state * st)71 _icv_close(_icv_state *st)
72 {
73         if (st == NULL)
74                 errno = EBADF;
75         else
76                 free(st);
77 }
78 
79 
80 #ifdef TEST
81 
82 /* test case 1 */
83 /*
84 char ibuf1[] = {0x0e, 0x57, 0x6c, 0x0f, 0x0e, 0x55, 0x67, 0x0f, 0x0e, 0x5a, 0x62, 0x57};
85 char obuf1[20];
86 */
87 
88 unsigned char ibuf1[] = {0x00, 0x6d, 0x00, 0x83, 0x00, 0xa2, 0x00, 0x89, 0x00, 0x6d, 0x00, 0xa4, 0x00, 0x83, 0x00, 0xa2, 0x00, 0xf2, 0x00, 0xa4, 0x00, 0xa3, 0x00, 0x86};
89 unsigned char obuf1[48];
90 
main()91 main()
92 {
93         int i;
94         struct _icv_state *st;
95         size_t oleft, ileft;
96         unsigned char *ip1 = &ibuf1[0], *op1 = &obuf1[0];
97 
98         /****************************** test case 1 *************************/
99 
100         ileft = sizeof(ibuf1);
101         oleft = sizeof(obuf1);
102 
103         st = (_icv_state *)_icv_open();
104 
105         printf("TEST 1\n INPUT BUFFER: ");
106         for (i = 0; i < ileft ; i++) {
107             printf("%x ", 0xff&ibuf1[i]);
108         }
109         printf("\n");
110         printf("OUTPUT: return value \n");
111         printf("OUTPUT: return value %d ",
112                 _icv_iconv(st, &ip1, &ileft, &op1, &oleft));
113 
114         printf("OUTPUT BUFFER: ");
115         for (i = 0; i < (sizeof(obuf1) - oleft) ; i++) {
116             printf("%x ", 0xff&obuf1[i]);
117         }
118         printf("\n\n\n");
119         _icv_close(st);
120 
121 }
122 
123 #endif /* TEST */
124