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 /* Copyright 1995 by Sun Microsystems, Inc.
22 * All rights are reserved.
23 */
24
25 #include <stdio.h>
26 #include <signal.h>
27 #include "kdefs.h"
28 #include "ktable.h"
29
30 struct _cv_state {
31 char **my_outbuf;
32 size_t *my_outbytesleft;
33 int invalid;
34 int flush_obuf;
35 char temp_obuf[5];
36 int temp_obuf_cnt;
37 };
38
39 void AddChar (char Char, struct _cv_state *st);
40 void echo_conso(char code, struct _cv_state *st);
41 void echo_vowel(char code, struct _cv_state *st);
42
43
44 /* write Hangul 7-bit Standard code sequences (KSC 5601)
45 * from Standard 2-byte Combination code(87-3).
46 * also handles Hangul and English display modes */
47
48 int
write_21(code_2,st)49 write_21(code_2, st)
50 KCHAR code_2;
51 struct _cv_state *st;
52 {
53 register KCHAR buffer; /* buffer for Hangul code conversion */
54 register char code_1; /* 1-byte code converted */
55
56 buffer = Y19_32[(short)INITIAL_SOUND(code_2) - 0x09] + BEG_OF_CONSO;
57 code_1 = (char) buffer;
58 if(code_1 != BEG_OF_CONSO)
59 AddChar(code_1, st);
60
61 buffer = Y21_32[(short)MIDDLE_SOUND(code_2)] + BEG_OF_VOW;
62 code_1 = (char) buffer;
63 if(code_1 != BEG_OF_VOW)
64 echo_vowel(code_1, st);
65
66 buffer = Y28_32[FINAL_SOUND(code_2) - 0x01] + BEG_OF_CONSO;
67 code_1 = (char) buffer;
68 if(code_1 != BEG_OF_CONSO)
69 echo_conso(code_1, st);
70
71 return(1);
72 }
73
74 void
echo_vowel(char code,struct _cv_state * st)75 echo_vowel(char code, struct _cv_state* st)
76 {
77 switch (code) {
78 case O_A: /* o-a 0x6d */
79 AddChar(O, st);
80 AddChar(A, st);
81 break;
82
83 case O_AE: /* o-ae 0x6e */
84 AddChar(O, st);
85 AddChar(AE, st);
86 break;
87
88 case O_I: /* o-i 0x6f */
89 AddChar(O, st);
90 AddChar(I, st);
91 break;
92
93 case U_E: /* u-e 0x74 */
94 AddChar(U, st);
95 AddChar(E, st);
96 break;
97
98 case U_EA: /* u-ea 0x75 */
99 AddChar(U, st);
100 AddChar(EA, st);
101 break;
102
103 case U_I: /* u-i 0x75 */
104 AddChar(U, st);
105 AddChar(I, st);
106 break;
107
108 case EU_I: /* eu-i 0x7b */
109 AddChar(EU, st);
110 AddChar(I, st);
111 break;
112
113 default:
114 AddChar(code, st);
115 break;
116
117 }
118 }
119
120 void
echo_conso(char code,struct _cv_state * st)121 echo_conso(char code, struct _cv_state *st)
122 {
123 switch (code) {
124 case GIUG_SIOD: /* gi-ug and si-od 0x43 */
125 AddChar(GI_UG, st);
126 AddChar(SI_OD, st);
127 break;
128
129 case NIUN_JIUD: /* ni-un and ji-ud 0x45 */
130 AddChar(NI_UN, st);
131 AddChar(JI_UD, st);
132 break;
133
134 case NIUN_HIUD: /* ni-un and hi-ud 0x46 */
135 AddChar(NI_UN, st);
136 AddChar(HI_UD, st);
137 break;
138
139 case RIUL_GIUG: /* ri-ul and gi_ug 0x4a */
140 AddChar(RI_UL, st);
141 AddChar(GI_UG, st);
142 break;
143
144 case RIUL_MIUM: /* ri-ul and mi_um 0x4b */
145 AddChar(RI_UL, st);
146 AddChar(MI_UM, st);
147 break;
148
149 case RIUL_BIUB: /* ri-ul and bi_ub 0x4c */
150 AddChar(RI_UL, st);
151 AddChar(BI_UB, st);
152 break;
153
154 case RIUL_SIOD: /* ri-ul and si-od 0x4d */
155 AddChar(RI_UL, st);
156 AddChar(SI_OD, st);
157 break;
158
159 case RIUL_TIGUT: /* ri-ul and ti-gut 0x4e */
160 AddChar(RI_UL, st);
161 AddChar(TI_GUT, st);
162 break;
163
164 case RIUL_PIUP: /* ri-ul and pi-up 0x4f */
165 AddChar(RI_UL, st);
166 AddChar(PI_UP, st);
167 break;
168
169 case RIUL_HIUD: /* ri-ul and hi-ud 0x50 */
170 AddChar(RI_UL, st);
171 AddChar(HI_UD, st);
172 break;
173
174 case BIUB_SIOD: /* bi-ub and si-od 0x54 */
175 AddChar(BI_UB, st);
176 AddChar(SI_OD, st);
177 break;
178
179 default :
180 AddChar(code, st);
181 break;
182 }
183 }
184
185 #ifdef TESTPRINT
main(argc,argv)186 main(argc,argv) /* Hangul 2-byte Combination code files
187 to 7-bit ASCII file conversion */
188 int argc;
189 char *argv[];
190 {
191 int fd,i,n;
192 char *myname;
193 short buf[BUFSIZ];
194
195 myname = argv[0];
196 if(argc == 1){
197 printf("usage: %s file ...\n",myname);
198 exit(0);
199 } else {
200 while(--argc > 0){
201 if((fd = open(*++argv,0)) == -1){
202 printf("%s: can't open %s\n",myname,*argv);
203 } else {
204 while ((n = read(fd,buf,bufsize)) > 0){
205 for (i = 0; i < n/2; i++)
206 write_21(buf[i]);
207 }
208 close(fd);
209 }
210 }
211 }
212 }
213 #endif
214