xref: /illumos-gate/usr/src/lib/iconv_modules/ko/common/utf_johap.h (revision 4db555a5389470c6f15aa8b50a38ca5d533d0641)
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  * Copyright (c) 1994 by Sun Microsystems, Inc.
23  */
24 
25 
26 
27 #ifndef	_UTF2JOHAP_H_
28 #define	_UTF2JOHAP_H_
29 
30 
31 #include "hangulcode.h"
32 
33 typedef struct __conv_desc {
34 	unsigned short          ci, v, cf;
35 	enum { E, CI, V, CF }   prev_state;
36 } _conv_desc;
37 
38 #define RESET_CONV_DESC()\
39 			cd->ci = cd->v = cd->cf = CVC_FILL; cd->prev_state = E;
40 #define PROCESS_PRIOR_CVC()\
41 	{\
42 		unsigned short code;\
43 		\
44 		if (cd->prev_state != E)\
45 		{\
46 			if ((obtail - ob) < 2)\
47 			{\
48 				errno = E2BIG;\
49 				ret_val = (size_t)-1;\
50 				break;\
51 			}\
52 			\
53 			if ((cd->ci <= 18 || cd->ci == CVC_FILL) &&\
54 			    (cd->v <= 20 || cd->v == CVC_FILL) &&\
55 			    (cd->cf <= 28 || cd->cf == CVC_FILL))\
56 			{\
57 				code = (cd->ci == CVC_FILL) ? 9 :\
58 					cd->ci + 0xA;\
59 				code = (code<<5) | ((unsigned short)(cd->v ==\
60 					CVC_FILL) ? 1 : cd->v + \
61 					(short)(cd->v + 1) / 3 + 2);\
62 				code = (code<<5) | ((cd->cf == CVC_FILL) ? 1 : \
63 					cd->cf) | 0x8000;\
64 			}\
65 			else\
66 			{\
67 				/* Let's assume the code is non-identical. */\
68 				code = (((unsigned short)NON_IDENTICAL) << 8) |\
69 					((unsigned short)NON_IDENTICAL);\
70 				ret_val += 2;\
71 			}\
72 			*ob++ = (char)((code >> 8) & 0xFF);\
73 			*ob++ = (char)(code & 0xFF);\
74 			RESET_CONV_DESC();\
75 		}\
76 	}
77 
78 
79 #endif	/* _UTF2JOHAP_H_ */
80