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 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* 28 * $Id: comp_to_pack.c,v 1.13 1997/10/31 16:16:56 binz Exp $ SMI ALE. 29 */ 30 31 #include <stdio.h> 32 #include <ctype.h> 33 #include "kctype.h" 34 #include "kdefs.h" 35 #include "ktable.h" 36 #ifdef TESTP 37 #include <widec.h> 38 #include <locale.h> 39 #endif 40 41 KCHAR c2p(); 42 43 KCHAR comptopack(comp) 44 KCHAR comp; 45 { 46 int c; 47 KCHAR code; 48 unsigned char cnv_buf[2]; 49 50 #ifdef TESTP 51 setlocale (LC_CTYPE, ""); 52 #endif 53 54 #if defined(i386) || defined(__ppc) 55 c = comp & 0x00ff; 56 #else 57 c = comp>>8 & 0x00ff; 58 #endif 59 if (iskorea1 (c)) { /* output completion code */ 60 #if defined(i386) || defined(__ppc) 61 code = (comp >> 8 & 0x00ff) | (((comp & 0x00ff) << 8) & 0xff00); 62 #else 63 code = comp; 64 #endif 65 if (iskorea2(code&BYTE_MASK)) { 66 /* Output hangul character */ 67 if (ishangul(c)) { 68 if ((code = c2p(code)) == K_ILLEGAL) { 69 return(K_ILLEGAL); 70 } else { 71 cnv_buf[0] = code>>8; 72 cnv_buf[1] = code&BYTE_MASK; 73 } 74 75 /* output initial sound only case */ 76 } else if (ishaninit(code)) { 77 if (X32_19[code - 0xa4a0] == -1) { 78 return(K_ILLEGAL); 79 } else { 80 cnv_buf[0] = (X32_19[code - 0xa4a0]<<2)|0x80; 81 cnv_buf[1] = 0x21; /* mid,last Fill */ 82 } 83 84 /* output middle sound only case */ 85 } else if (ishanmid(code)) { 86 code -= 0xa4be; 87 code = ((code + code/3 + 1)<<5)|0xa401; 88 /* a401 is first,last Fill */ 89 cnv_buf[0] = code>>8; 90 cnv_buf[1] = code&BYTE_MASK; 91 92 /* output hanja character */ 93 } else if (ishanja (c)) { 94 return(K_ILLEGAL); 95 96 /* other case */ 97 } else { 98 return(K_ILLEGAL); 99 /* 100 cnv_buf[0] = c; 101 cnv_buf[1] = code&BYTE_MASK; 102 */ 103 } 104 105 } else { 106 return(K_ILLEGAL); 107 } 108 109 } else { 110 /* output normal Ascii code */ 111 return(comp); 112 } 113 #if defined(i386) || defined(__ppc) 114 return(cnv_buf[1] << 8 | cnv_buf[0]); 115 #else 116 return(cnv_buf[0] << 8 | cnv_buf[1]); 117 #endif 118 } 119 120 #ifdef TESTP 121 main() /* This main portion is just for test */ 122 { 123 unsigned int comp2; 124 unsigned short comb2; 125 unsigned int wc; 126 127 for(;;) { 128 wc = getwchar(); 129 wctomb((char *)&comb2, wc); 130 comp2 = comptopack(comb2); 131 printf("completion, combination = 0x%x 0x%x\n", 132 comb2, comp2); 133 } 134 } 135 #endif 136