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	_UTF2NBYTE_H_
28 #define	_UTF2NBYTE_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 	enum { ASCII, WANSUNG }	state;
37 } _conv_desc;
38 
39 #define RESET_CONV_DESC()\
40 			cd->ci = cd->v = cd->cf = CVC_FILL; cd->prev_state = E;
41 #define PROCESS_PRIOR_CVC()\
42 	{\
43 		int		i;\
44 		register int	j;\
45 		char		c[5];\
46 		\
47 		if (cd->prev_state != E)\
48 		{\
49 			i = 0;\
50 			if ((cd->ci <= 18 || cd->ci == CVC_FILL) &&\
51 			    (cd->v <= 20 || cd->v == CVC_FILL) &&\
52 			    (cd->cf <= 28 || cd->cf == CVC_FILL))\
53 			{\
54 				c[i] = (char)Y19_32[cd->ci != CVC_FILL ?\
55 					cd->ci + 1 : 0] + '@';\
56 				if (c[i] > '@')\
57 					i++;\
58 				c[i] = (char)Y21_32[cd->v != CVC_FILL ? cd->v +\
59 					(short)(cd->v + 1) / 3 + 2 : 1] + '`';\
60 				if (c[i] > 'a')\
61 					echo_vowel(c, &i);\
62 				c[i] = (char)Y28_32[cd->cf != CVC_FILL ?\
63 					cd->cf - 1 : 0] + '@';\
64 				if (c[i] > '@')\
65 					echo_consonant(c, &i);\
66 				\
67 				if ((obtail - ob) < (i + (cd->state == ASCII ?\
68 								1 : 0)))\
69 				{\
70 					errno = E2BIG;\
71 					ret_val = (size_t)-1;\
72 					break;\
73 				}\
74 				if (cd->state == ASCII)\
75 				{\
76 					*ob++ = SO;\
77 					cd->state = WANSUNG;\
78 				}\
79 				for (j = 0; j < i; j++)\
80 					*ob++ = c[j];\
81 			}\
82 			else\
83 			{\
84 				/* Let's assume the code is non-identical. */\
85 				if (cd->state == WANSUNG)\
86 				{\
87 					if ((obtail - ob) < 3)\
88 					{\
89 						errno = E2BIG;\
90 						ret_val = (size_t)-1;\
91 						break;\
92 					}\
93 					*ob++ = SI;\
94 					cd->state = ASCII;\
95 				}\
96 				else if ((obtail - ob) < 2)\
97 				{\
98 					errno = E2BIG;\
99 					ret_val = (size_t)-1;\
100 					break;\
101 				}\
102 				*ob++ = NON_IDENTICAL;\
103 				*ob++ = NON_IDENTICAL;\
104 				ret_val += 2;\
105 			}\
106 			RESET_CONV_DESC();\
107 		}\
108 	}
109 
110 
111 #endif	/* _UTF2NBYTE_H_ */
112