Mercurial > kinput2.yaz
comparison lib/Xatoklib/misc.c @ 0:92745d501b9a
initial import from kinput2-v3.1
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 08 Mar 2010 04:44:30 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:92745d501b9a |
---|---|
1 /* | |
2 * Copyright 1999 Justsystem Corporation, Japan. | |
3 * | |
4 * Permission to use, copy, modify, and distribute this software and its | |
5 * documentation for any purpose and without fee is hereby granted, | |
6 * provided that the above copyright notice appear in all copies and that | |
7 * both that copyright notice and this permission notice appear in | |
8 * supporting documentation, and that the name of Justsystem Corporation | |
9 * not be used in advertising or publicity pertaining to distribution | |
10 * of the software without specific, written prior permission. Justsystem | |
11 * Corporation makes no representations about the suitability of this | |
12 * software for any purpose. It is provided "as is" without express | |
13 * or implied warranty. | |
14 * | |
15 * Author: Atsushi Irisawa | |
16 */ | |
17 | |
18 #ifndef lint | |
19 static char rcsid[] = "$Id: misc.c,v 1.2 1999/08/24 09:01:09 ishisone Exp $" ; | |
20 #endif /* !lint */ | |
21 | |
22 #include <Xatoklib.h> | |
23 | |
24 /* Page */ | |
25 /* | |
26 * [$B4X?tL>(B] | |
27 * wcs2euc( ) | |
28 * [$BI=Bj(B] | |
29 * WCHAR $B7?$+$i(BEUC$BJ8;zNs$X$NJQ49(B | |
30 * [$B8F=P7A<0(B] | |
31 * int wcs2euc( wchar *wbuf, int wlen, unsigned char *euc ) | |
32 * | |
33 * [$B0z?t(B] | |
34 * $B7?(B : $BL>(B $B>N(B : I O : $B@b(B $BL@(B | |
35 * wchar : *wbuf : i : WCHAR $B7?J8;zNs(B | |
36 * int : wlen : i : wchar $B7?J8;zNs$ND9$5(B | |
37 * unsigned char : *euc : o : EUC $BJ8;zNs3JG<NN0h(B | |
38 * | |
39 * [$BJV$jCM(B] | |
40 * EUC $BJ8;zNs$ND9$5(B | |
41 * | |
42 * [$B;HMQ4X?t(B] | |
43 * $B$J$7(B | |
44 * [$B5!G=(B] | |
45 * wchar $B7?J8;zNs$+$i(B unsigined char $B$N(BEUC$BJ8;zNs$KJQ49$9$k!#(B | |
46 * | |
47 */ | |
48 | |
49 int wcs2euc(wbuf, wlen, euc) | |
50 wchar *wbuf; | |
51 int wlen; | |
52 unsigned char *euc; | |
53 { | |
54 int i ; | |
55 int n = 0 ; | |
56 unsigned char c ; | |
57 for( i = 0 ; i < wlen ; i++ ) { | |
58 c = ( *wbuf & 0xff00 ) >> 8 ; | |
59 if ( c ) { | |
60 *euc++ = c ; | |
61 n++ ; | |
62 } | |
63 else if (( *wbuf & 0xff ) & 0x80 ) { | |
64 *euc++ = 0x8e ; | |
65 n++ ; | |
66 } | |
67 *euc++ = *wbuf & 0xff ; | |
68 wbuf++ ; | |
69 n++ ; | |
70 } | |
71 *euc = 0 ; | |
72 | |
73 return n ; | |
74 } | |
75 /* Page */ | |
76 /* | |
77 * [$B4X?tL>(B] | |
78 * euc2wcs( ) | |
79 * [$BI=Bj(B] | |
80 * EUC$BJ8;zNs$+$i(B wchar $B7?J8;zNs$X$NJQ49(B | |
81 * [$B8F=P7A<0(B] | |
82 * int euc2wcs( unsigned char *euc, int elen, wchar *wbuf ) | |
83 * | |
84 * [$B0z?t(B] | |
85 * $B7?(B : $BL>(B $B>N(B : I O : $B@b(B $BL@(B | |
86 * unsigned char : *euc : i : EUC $BJ8;zNs(B | |
87 * int : elen : i : EUC $BJ8;zNs$ND9$5(B | |
88 * wchar : *wbuf : o : wchar $B7?J8;zNs3JG<NN0h(B | |
89 * | |
90 * [$BJV$jCM(B] | |
91 * 1 : $B>o$K#1(B | |
92 * | |
93 * [$B;HMQ4X?t(B] | |
94 * $B$J$7(B | |
95 * [$B5!G=(B] | |
96 * unsigined char $B7?$N(BEUC $BJ8;zNs$r(Bwchar $B7?$KJQ49$9$k!#(B | |
97 * EUC $BJ8;zNs$K$O!"(B0x8f $B$NFCJL$J%3!<%I$,4^$^$l$F$$$k$N$G(B | |
98 * wchar $B$KJQ49$9$k;~$K8DJL=hM}$r$9$k!#(B | |
99 */ | |
100 int euc2wcs(euc, elen, wbuf) | |
101 unsigned char *euc; | |
102 int elen; | |
103 wchar *wbuf; | |
104 { | |
105 int lb = 0, hb = 0 ; | |
106 int i ; | |
107 int n = 0 ; | |
108 int isSkip ; | |
109 | |
110 for( i = 0 ; i < elen ; i++ ) { | |
111 isSkip = 0 ; | |
112 if ( *euc == 0x8e ) { | |
113 euc++ ; | |
114 hb = *euc ; | |
115 lb = 0 ; | |
116 i++ ; | |
117 } | |
118 else if ( *euc & 0x80 ) { | |
119 if ( *euc == 0x8f ) { | |
120 isSkip=1 ; | |
121 } | |
122 else { | |
123 lb = *euc ; | |
124 euc++ ; | |
125 hb = *euc ; | |
126 i++ ; | |
127 } | |
128 } | |
129 else { | |
130 hb = *euc ; | |
131 lb = 0 ; | |
132 } | |
133 euc++ ; | |
134 if ( !isSkip ) { | |
135 *wbuf = (( lb << 8 ) | hb ) & 0xffff ; | |
136 wbuf++ ; | |
137 n++ ; | |
138 } | |
139 } | |
140 | |
141 *wbuf = 0 ; | |
142 return n ; | |
143 } | |
144 /* End of misc.c */ |