comparison lib/Xatoklib/buffer.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: buffer.c,v 1.3 1999/08/24 09:05:26 ishisone Exp $" ;
20 #endif /* !lint */
21
22 #include <stdio.h>
23 #include <X11/IntrinsicP.h>
24 #include <X11/StringDefs.h>
25 #include <X11/Xmu/Atoms.h>
26 #include <X11/keysym.h>
27
28
29 #include <Xatoklib.h>
30
31
32 /* Page */
33 /*
34 * [$B4X?tL>(B]
35 * XatokClearBuffer( )
36 * [$BI=Bj(B]
37 * kinput2$BMQJQ49%P%C%U%!$K%/%j%"(B
38 * [$B8F=P7A<0(B]
39 * int XatokClearBuffer( _XatokRecPtr acomm )
40 *
41 * [$B0z?t(B]
42 * $B7?(B : $BL>(B $B>N(B : I O : $B@b(B $BL@(B
43 * _XatokRecPtr : acomm : i/o : kinput2$BMQJQ49%P%C%U%!(B
44 *
45 * [$BJV$jCM(B]
46 * $B$J$7(B
47 *
48 * [$B;HMQ4X?t(B]
49 * $B$J$7(B
50 * [$B5!G=(B]
51 * $B3NJ]$5$l$?(B kinput2$BMQJQ49%P%C%U%!$r%/%j%"$9$k!#(B
52 */
53 void XatokClearBuffer(abuf)
54 _XatokRecPtr abuf;
55 {
56 int i, n ;
57
58 for( i = 0 ; i < abuf->nbr_of_seg ; i++ ) {
59 /* XatokFreeSegement( abuf->segments[i] ) ; */
60 }
61 abuf->cur_seg = 0 ;
62 abuf->nbr_of_seg = 0 ;
63
64 }
65
66 /* Page */
67 /*
68 * [$B4X?tL>(B]
69 * XatokBufferConvert( )
70 * [$BI=Bj(B]
71 * $B%(%s%8%sJQ497k2L%G!<%?$N%3%s%P!<%H(B
72 * [$B8F=P7A<0(B]
73 * int XatokBufferConvert( _XatokRecPtr acomm,
74 * WORD ceCmd, AtokRsltPacket *result, int *status,
75 * int *enable, int *change, int *elseEvent )
76 * [$B0z?t(B]
77 * $B7?(B : $BL>(B $B>N(B : I O : $B@b(B $BL@(B
78 * _XatokRecPtr : acomm : i/o : kinput2$BMQJQ49%P%C%U%!(B
79 * WORD ceCmd,
80 * AtokRsltPacket *result,
81 * int *status,
82 * int *enable,
83 * int *change,
84 * int *elseEvent
85 *
86 *
87 * [$BJV$jCM(B]
88 * $B3NDjJ8;zNs$ND9$5(B
89 * [$B;HMQ4X?t(B]
90 * ucs2euc( )
91 * es = euc2wcs( )
92 * s2e( )
93 * XatokCompStr( )
94 *
95 * [$B5!G=(B]
96 * ATOK12X $B$X$N(BREQUEST$B$h$j(B $BLa$C$FMh$?%G!<%?$r%A%'%C%/$7!"(B
97 * kinput2 $B$N(B ATOK CLASS$B$G;HMQ$G$-$k%G!<%?7A<0$KJQ49$9$k!#(B
98 *
99 */
100 int XatokBufferConvert(acomm, ceCmd, result, status, enable, change, elseEvent)
101 _XatokRecPtr acomm;
102 WORD ceCmd;
103 AtokRsltPacket *result;
104 int *status;
105 int *enable;
106 int *change;
107 int *elseEvent;
108 {
109 char euc[BUFSIZ*4] ; /* $BFI$_I=<($N$?$a$N%P%C%U%!(B */
110 int es ; /* euc $BJ8;zNs$ND9$5(B */
111 unsigned char *sp, *sp1, *uni2euc( ) ;
112 wchar *wbuf ; /* $B3NDjJ8;zNs(B */
113 char *wrbuf ; /* $B3NDjFI$_J8;zNs(B */
114
115 int length = 0 ; /* $B3NDjJ8;zNs$ND9$5(B */
116 int i, n, ksize ; /* WORK */
117 AtokRsltHdr *hdr ; /* WORK */
118 int wsize ; /* WORK */
119 static int euclen = 1 ;
120
121 wsize = sizeof( wchar ) ;
122 wbuf = acomm->wbuf ;
123 wrbuf = acomm->wrbuf ;
124
125 hdr = &acomm->NETrslt.header ;
126
127 /*
128 * $B%b!<%IJ8;zNs$N@_Dj(B
129 * $B%b!<%IJ8;zNs$N@hF,$K6uGr$,B8:_$9$k$N$G:o=|$9$k!#(B
130 */
131 #ifdef ATOK_DEBUG
132 printf( "buffer conv \245\342\241\274\245\311LEN %d\n"/*=buffer conv $B%b!<%I(BLEN %d\n=*/, hdr->modeLen ) ;
133 #endif /* ATOK_DEBUG */
134 if ( hdr->modeLen > 0 ) {
135 es = hdr->modeLen * 3 ;
136 sp = ( unsigned char * )malloc( es ) ;
137 bzero( sp, es ) ;
138 ucs2euc( hdr->modePtr, hdr->modeLen, sp, es, 0x0000a2ae ) ;
139 sp1 = sp ;
140 while( *sp1 == 0x20 ) sp1++ ; /* SPACE */
141 es = strlen( sp1 ) ;
142 es = euc2wcs( sp1, es, acomm->mode.name ) ;
143 #ifdef ATOK_DEBUG
144 printf( "\245\342\241\274\245\311\312\270\273\372\316\363 [%s]\n"/*=$B%b!<%IJ8;zNs(B [%s]\n=*/, sp ) ;
145 #endif /* ATOK_DEBUG */
146 acomm->mode.length = hdr->modeLen ;
147 acomm->mode.length = es ;
148 free( sp ) ;
149 /* acomm->mode.changes = 1 ; */
150 }
151
152 /*
153 * $B3NDjJ8;zNs$,B8:_$9$k>l9g$K$O!"(Bwbuf $B$K3NDjJ8;zNs$r@_Dj$7!"(B
154 * $B%j%?!<%sCM$G$"$k3NDjJ8;zNs$ND9$5$r@_Dj$9$k!#(B
155 * wrbuf $B$K$OFI$_J8;zNs$r@_Dj$9$k!#(B
156 */
157 if ( hdr->resultStrLen ) {
158 es = hdr->resultStrLen * 3 ;
159 sp = ( unsigned char * )malloc( es ) ;
160 bzero( sp, es ) ;
161 ucs2euc( hdr->resultStrPtr, hdr->resultStrLen, sp, es, 0x0000a2ae ) ;
162
163 es = strlen( sp ) ;
164 es = euc2wcs( sp, es, wbuf ) ;
165 length = hdr->resultStrLen ;
166 free( sp ) ;
167
168 /*
169 * $B$h$_J8;zNs(B
170 */
171 bzero( acomm->wrbuf, sizeof( acomm->wrbuf )) ;
172 es = hdr->resultReadLen ;
173 s2e( hdr->resultReadPtr, es, wrbuf, sizeof( acomm->wrbuf )) ;
174
175 #ifdef ATOK_DEBUG
176 printf( "=== buffer.c \263\316\304\352EUC [%s] === \n"/*==== buffer.c $B3NDj(BEUC [%s] === \n=*/, sp ) ;
177 printf( "=== buffer.c \263\316\304\352 READ EUC [%s] === \n"/*==== buffer.c $B3NDj(B READ EUC [%s] === \n=*/, acomm->wrbuf ) ;
178 #endif /* ATOK_DEBUG */
179
180 }
181 /*
182 * $BL$3NDjJ8;zNs$,$"$C$?>l9g$K$O!"(B
183 * $BL$3NDjJ8;zNs$r(BUNICODE$B$+$i(BEUC$B$KJQ49$7!"(B
184 * $BH?E>I=<(Ey$N0LCV$r5a$a$k!#(B
185 * $BL$3NDjJ8;zNs$ND9$5$HL$3NDjJ8;zNsB0@-$ND9$5$O(B
186 * $BF1$8$J$N$G(B if $BJ8$O$^$H$a$F=hM}$9$k!#(B
187 */
188 if ( hdr->compStrLen ) {
189 es = hdr->compStrLen * wsize ;
190 es = hdr->compStrLen * 3 ;
191 sp = ( unsigned char * )malloc( es ) ;
192 bzero( sp, es ) ;
193
194 ucs2euc( hdr->compStrPtr, hdr->compStrLen, sp, es, 0x0000a2ae ) ;
195 es = strlen( sp ) ;
196
197 acomm->echoLen = euc2wcs( sp, es, acomm->echoStr ) ;
198 /*
199 * $B$3$3$GH?E>I=<($N%3%a%s%H$b:n@.$9$k!#(B
200 */
201 XatokCompStr( hdr->compStrPtr, hdr->compAttrPtr,
202 hdr->compStrLen, &acomm->revPos, &acomm->revLen ) ;
203 #ifdef ATOK_DEBUG
204 /* printf( "$BL$3NDjJ8;zNs(B[%s]\n", sp ) ; */
205 printf( "EUC CODE\n" ) ;
206 for( i = 0 ; sp[i] ; i++ ) {
207 printf( "0x%x ", sp[i] ) ;
208 }
209 printf( "\n" ) ;
210
211 printf( "== DEBUG \314\244\263\316\304\352\311\275\274\250:\n"/*=== DEBUG $BL$3NDjI=<((B:\n=*/ ) ;
212 printf( "==> [%s]\n", sp ) ;
213 printf( "==> [----+----1----+----2----+----3]\n" ) ;
214 printf( "==> [" ) ;
215 for( i = 0 ; i < acomm->revPos ; i++ ) {
216 printf( "\241\373"/*=$B!{(B=*/ ) ;
217 }
218 for( i = 0 ; i < acomm->revLen ; i++ ) {
219 printf( "\241\374"/*=$B!|(B=*/ ) ;
220 }
221 for( i = acomm->revPos + acomm->revLen ; i < hdr->compStrLen ; i++ ) {
222 printf( "\241\373"/*=$B!{(B=*/ ) ;
223 }
224 printf( "-]\n" ) ;
225 printf( "revPos %d, revLen %d\n", acomm->revPos, acomm->revLen ) ;
226 #endif /* ATOK_DEBUG */
227
228 free( sp ) ;
229 }
230 else {
231 acomm->echoLen = 0 ;
232 acomm->echoStr[0] = 0 ;
233 }
234
235 /*
236 * $B8uJdJ8;zNs(B
237 */
238 #ifdef ATOK_DEBUG
239 printf( "\270\365\312\344\277\364\241\242 %d, \270\365\312\344\245\265\245\244\245\272 %d\n"/*=$B8uJd?t!"(B %d, $B8uJd%5%$%:(B %d\n=*/, hdr->kohoNum, hdr->kohoStrLen ) ;
240 #endif /* ATOK_DEBUG */
241
242 acomm->kohoNum = 0 ;
243 if ( hdr->kohoNum > 0 && hdr->kohoStrLen > 0 ) {
244 n = hdr->kohoNum ;
245 ksize = hdr->kohoStrLen ;
246 if ( acomm->kohoSize == 0 ) {
247 acomm->kohoStrPtr = ( WCHAR * )malloc( ksize * sizeof( WCHAR )) ;
248 acomm->kohoLenPtr = ( BYTE * )malloc( n * sizeof( BYTE )) ;
249 acomm->kohoSfxPtr = ( BYTE * )malloc( n * sizeof( BYTE )) ;
250 acomm->kohoSize = n ;
251 acomm->kohoStrLen = ksize ;
252 }
253 /*
254 * $BJ8;zNsD9!"B0@-$O!"8uJd?t$@$13NJ](B
255 * $B8uJd?t$O(B kohoSize $B$K(B $B@_Dj$7$F$"$k!#(B
256 */
257 if ( acomm->kohoSize < n ) {
258
259 acomm->kohoLenPtr = ( BYTE * )realloc( acomm->kohoLenPtr, n * sizeof( BYTE )) ;
260 acomm->kohoSfxPtr = ( BYTE * )realloc( acomm->kohoSfxPtr, n * sizeof( BYTE )) ;
261 acomm->kohoSize = n ;
262 }
263 if ( acomm->kohoStrLen < ksize ) {
264 acomm->kohoStrPtr = ( WCHAR * )realloc( acomm->kohoStrPtr, ksize * sizeof( WCHAR )) ;
265 acomm->kohoStrLen = ksize ;
266 }
267
268 memcpy( acomm->kohoStrPtr, hdr->kohoStrPtr, ksize * sizeof( WCHAR)) ;
269 memcpy( acomm->kohoLenPtr, hdr->kohoLenPtr, n * sizeof( BYTE )) ;
270 memcpy( acomm->kohoSfxPtr, hdr->kohoSfxPtr, n * sizeof( BYTE )) ;
271 acomm->kohoNum = n ;
272 acomm->kohoPos = hdr->kohoPos ;
273
274 #ifdef ATOK_DEBUG
275 {
276 int kk ;
277 char *eep ;
278 kk = ksize * sizeof( WCHAR );
279 eep = uni2euc( acomm->kohoStrPtr, &kk ) ;
280 printf( "\270\365\312\344 [%s]\n"/*=$B8uJd(B [%s]\n=*/, eep ) ;
281 for ( i = 0 ; i < n ; i++ ) {
282 printf( "%d ", acomm->kohoLenPtr[i] ) ;
283 }
284 printf( "\304\271\244\265\n"/*=$BD9$5(B\n=*/ ) ;
285 }
286 #endif /* ATOK_DEBUG */
287 }
288
289 /*
290 * $B%7%9%F%`9T%G!<%?(B
291 */
292 if ( hdr->sysStrLen ) {
293 es = hdr->sysStrLen * 3 ;
294 sp = ( unsigned char * )malloc( es ) ;
295 bzero( sp, es ) ;
296 ucs2euc( hdr->sysStrPtr, hdr->sysStrLen, sp, es, 0x0000a2ae ) ;
297 es = strlen( sp ) ;
298 es = euc2wcs( sp, es, acomm->sysLineStr ) ;
299 acomm->sysLineLen = hdr->sysStrLen ;
300 #ifdef ATOK_DEBUG
301 printf( "SYS LINE LEN in buffer.c (%d)\n", hdr->sysStrLen ) ;
302 #endif /* ATOK_DEBUG */
303 if ( acomm->sysLineSize == 0 ) {
304 acomm->sysAttrPtr = ( WORD * )malloc( sizeof( WORD ) *
305 hdr->sysStrLen ) ;
306 acomm->sysLineSize = hdr->sysStrLen ;
307 }
308 else if ( acomm->sysLineSize < hdr->sysStrLen ) {
309 acomm->sysAttrPtr = ( WORD * )malloc( sizeof( WORD ) *
310 hdr->sysStrLen ) ;
311 acomm->sysLineSize = hdr->sysStrLen ;
312 }
313 memcpy( acomm->sysAttrPtr, hdr->sysAttrPtr, sizeof( WORD ) * hdr->sysStrLen ) ;
314
315 free( sp ) ;
316 }
317 if ( hdr->guideStrLen ) {
318 es = hdr->guideStrLen * 3 ;
319 sp = ( unsigned char * )malloc( es ) ;
320 bzero( sp, es ) ;
321 ucs2euc( hdr->guideStrPtr, hdr->guideStrLen, sp, es, 0x0000a2ae ) ;
322 free( sp ) ;
323 }
324 acomm->kohoNum = hdr->kohoNum ;
325
326 acomm->guide_openEventIndex = hdr->CEGuideOpenEventIndx ;
327 acomm->guide_closeEventIndex = hdr->CEGuideCloseEventIndx ;
328 acomm->guide_OpenIndex = hdr->CEGuideOpenIndx ;
329
330 *status = hdr->CEOutinf ;
331 *enable = hdr->StatusEnableFlag ;
332 *change = hdr->DispChangeStatus ;
333 *elseEvent = hdr->StatusElseEvent ;
334
335 return length ;
336 }
337 /* End of buffer.c */