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 #include <errno.h>
27 #include "ktable.h"
28 #include "hangulcode.h"
29 
30 
31 /****  _ J O H A P _ T O _ U T F 8  ****/
32 
_johap_to_utf8(unsigned long * chosung,unsigned long * joongsung,unsigned long * jongsung,unsigned short wcode)33 char _johap_to_utf8(unsigned long* chosung, unsigned long* joongsung,
34 				unsigned long* jongsung, unsigned short wcode)
35 {
36 	register short	h, i, j, l;
37 	short		ci, v, cf;
38 
39 	/* Hangul only conversion. */
40 	if (wcode < 0xA421 || wcode > 0xF3BC)
41 		return(FAILED);
42 
43 	ci = CHOSUNG(wcode) - 0x0A;
44 	v = JOONGSUNG(wcode) - ((short)JOONGSUNG(wcode) / 4 + 2);
45 	cf = JONGSUNG(wcode);
46 	if (ci > 18 || v > 20 || cf > 28)
47 		return(ILLEGAL_SEQ);
48 
49 	*chosung = (ci < 0) ? 0xE1859F : 0xE18480 + ci;
50 	*joongsung = (v < 0) ? 0xE185A0 : 0xE185A1 + v;
51 	*jongsung = (cf < 2) ? 0 : (cf + ((cf > 25) ? 0xE18766 : 0xE186A6));
52 	return(HANGUL);
53 }  /* end of char _johap_to_utf8(unsigned long*, unsigned long*,
54 				unsigned long*, unsigned short). */
55