comparison lib/Xrubylib/misc.c @ 16:598fcbe482b5

imported patch 19_kinput2-v3.1-ruby.patch
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 08 Mar 2010 20:38:17 +0900
parents
children
comparison
equal deleted inserted replaced
15:89750191b165 16:598fcbe482b5
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 2003/06/10 02:11:27 komatsu Exp $" ;
20 #endif /* !lint */
21 #include "WStr.h"
22
23 /* Page */
24 /*
25 * [$B4X?tL>(B]
26 * wcs2euc( )
27 * [$BI=Bj(B]
28 * WCHAR $B7?$+$i(BEUC$BJ8;zNs$X$NJQ49(B
29 * [$B8F=P7A<0(B]
30 * int wcs2euc( wchar *wbuf, int wlen, unsigned char *euc )
31 *
32 * [$B0z?t(B]
33 * $B7?(B : $BL>(B $B>N(B : I O : $B@b(B $BL@(B
34 * wchar : *wbuf : i : WCHAR $B7?J8;zNs(B
35 * int : wlen : i : wchar $B7?J8;zNs$ND9$5(B
36 * unsigned char : *euc : o : EUC $BJ8;zNs3JG<NN0h(B
37 *
38 * [$BJV$jCM(B]
39 * EUC $BJ8;zNs$ND9$5(B
40 *
41 * [$B;HMQ4X?t(B]
42 * $B$J$7(B
43 * [$B5!G=(B]
44 * wchar $B7?J8;zNs$+$i(B unsigined char $B$N(BEUC$BJ8;zNs$KJQ49$9$k!#(B
45 *
46 */
47
48 int wcs2euc(wbuf, wlen, euc)
49 wchar *wbuf;
50 int wlen;
51 unsigned char *euc;
52 {
53 int i ;
54 int n = 0 ;
55 unsigned char c ;
56 for( i = 0 ; i < wlen ; i++ ) {
57 c = ( *wbuf & 0xff00 ) >> 8 ;
58 if ( c ) {
59 *euc++ = c ;
60 n++ ;
61 }
62 else if (( *wbuf & 0xff ) & 0x80 ) {
63 *euc++ = 0x8e ;
64 n++ ;
65 }
66 *euc++ = *wbuf & 0xff ;
67 wbuf++ ;
68 n++ ;
69 }
70 *euc = 0 ;
71
72 return n ;
73 }
74 /* Page */
75 /*
76 * [$B4X?tL>(B]
77 * euc2wcs( )
78 * [$BI=Bj(B]
79 * EUC$BJ8;zNs$+$i(B wchar $B7?J8;zNs$X$NJQ49(B
80 * [$B8F=P7A<0(B]
81 * int euc2wcs( unsigned char *euc, int elen, wchar *wbuf )
82 *
83 * [$B0z?t(B]
84 * $B7?(B : $BL>(B $B>N(B : I O : $B@b(B $BL@(B
85 * unsigned char : *euc : i : EUC $BJ8;zNs(B
86 * int : elen : i : EUC $BJ8;zNs$ND9$5(B
87 * wchar : *wbuf : o : wchar $B7?J8;zNs3JG<NN0h(B
88 *
89 * [$BJV$jCM(B]
90 * 1 : $B>o$K#1(B
91 *
92 * [$B;HMQ4X?t(B]
93 * $B$J$7(B
94 * [$B5!G=(B]
95 * unsigined char $B7?$N(BEUC $BJ8;zNs$r(Bwchar $B7?$KJQ49$9$k!#(B
96 * EUC $BJ8;zNs$K$O!"(B0x8f $B$NFCJL$J%3!<%I$,4^$^$l$F$$$k$N$G(B
97 * wchar $B$KJQ49$9$k;~$K8DJL=hM}$r$9$k!#(B
98 */
99 int euc2wcs(euc, elen, wbuf)
100 unsigned char *euc;
101 int elen;
102 wchar *wbuf;
103 {
104 int lb = 0, hb = 0 ;
105 int i ;
106 int n = 0 ;
107 int isSkip ;
108
109 for( i = 0 ; i < elen ; i++ ) {
110 isSkip = 0 ;
111 if ( *euc == 0x8e ) {
112 euc++ ;
113 hb = *euc ;
114 lb = 0 ;
115 i++ ;
116 }
117 else if ( *euc & 0x80 ) {
118 if ( *euc == 0x8f ) {
119 isSkip=1 ;
120 }
121 else {
122 lb = *euc ;
123 euc++ ;
124 hb = *euc ;
125 i++ ;
126 }
127 }
128 else {
129 hb = *euc ;
130 lb = 0 ;
131 }
132 euc++ ;
133 if ( !isSkip ) {
134 *wbuf = (( lb << 8 ) | hb ) & 0xffff ;
135 wbuf++ ;
136 n++ ;
137 }
138 }
139
140 *wbuf = 0 ;
141 return n ;
142 }
143 /* End of misc.c */