OSDN Git Service

f09fcdc18fec8d9f3d865676648c5101571f0255
[tamago-tsunagi/tamago-tsunagi.git] / egg / wnnrpc.el
1 ;;; egg/wnnrpc.el --- WNN Support (low level interface) in Egg
2 ;;;                   Input Method Architecture
3
4 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc
5
6 ;; Author: NIIBE Yutaka <gniibe@chroot.org>
7 ;;         KATAYAMA Yoshio <kate@pfu.co.jp> ; Korean, Chinese support.
8
9 ;; Maintainer: TOMURA Satoru <tomura@etl.go.jp>
10
11 ;; Keywords: mule, multilingual, input method
12
13 ;; This file is part of EGG.
14
15 ;; EGG is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; any later version.
19
20 ;; EGG is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 ;; GNU General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
29
30 ;;; Commentary:
31
32
33 ;;; Code:
34
35
36 (eval-when-compile
37   (require 'egg-com)
38   (defmacro wnn-file-string ()
39     (string-as-unibyte (decode-coding-string "\e$B#W#n#n$N%U%!%$%k\e(B" 'euc-jp)))
40   (defmacro wnn-const (c)
41     "Macro for WNN constants."
42     (cond ((eq c 'JS_VERSION)               0)
43           ((eq c 'JS_OPEN)                  1)
44           ((eq c 'JS_CLOSE)                 3)
45           ((eq c 'JS_CONNECT)               5)
46           ((eq c 'JS_DISCONNECT)            6)
47           ((eq c 'JS_ENV_EXIST)             7)
48           ((eq c 'JS_ENV_STICKY)            8)
49           ((eq c 'JS_ENV_UNSTICKY)          9)
50           ((eq c 'JS_KANREN)               17)
51           ((eq c 'JS_KANTAN_SHO)           18)
52           ((eq c 'JS_KANZEN_SHO)           19)
53           ((eq c 'JS_KANTAN_DAI)           20)
54           ((eq c 'JS_KANZEN_DAI)           21)
55           ((eq c 'JS_HINDO_SET)            24)
56           ((eq c 'JS_DIC_ADD)              33)
57           ((eq c 'JS_DIC_DELETE)           34)
58           ((eq c 'JS_DIC_USE)              35)
59           ((eq c 'JS_DIC_LIST)             36)
60           ((eq c 'JS_DIC_INFO)             37)
61           ((eq c 'JS_FUZOKUGO_SET)         41)
62           ((eq c 'JS_FUZOKUGO_GET)         48)
63           ((eq c 'JS_WORD_ADD)             49)
64           ((eq c 'JS_WORD_DELETE)          50)
65           ((eq c 'JS_WORD_SEARCH)          51)
66           ((eq c 'JS_WORD_SEARCH_BY_ENV)   52)
67           ((eq c 'JS_WORD_INFO)            53)
68           ((eq c 'JS_WORD_COMMENT_SET)     54)
69           ((eq c 'JS_PARAM_SET)            65)
70           ((eq c 'JS_PARAM_GET)            66)
71           ((eq c 'JS_MKDIR)                81)
72           ((eq c 'JS_ACCESS)               82)
73           ((eq c 'JS_WHO)                  83)
74           ((eq c 'JS_ENV_LIST)             85)
75           ((eq c 'JS_FILE_LIST_ALL)        86)
76           ((eq c 'JS_DIC_LIST_ALL)         87)
77           ((eq c 'JS_FILE_READ)            97)
78           ((eq c 'JS_FILE_WRITE)           98)
79           ((eq c 'JS_FILE_SEND)            99)
80           ((eq c 'JS_FILE_RECEIVE)        100)
81           ((eq c 'JS_HINDO_FILE_CREATE)   101)
82           ((eq c 'JS_DIC_FILE_CREATE)     102)
83           ((eq c 'JS_FILE_REMOVE)         103)
84           ((eq c 'JS_FILE_LIST)           104)
85           ((eq c 'JS_FILE_INFO)           105)
86           ((eq c 'JS_FILE_LOADED)         106)
87           ((eq c 'JS_FILE_LOADED_LOCAL)   107)
88           ((eq c 'JS_FILE_DISCARD)        108)
89           ((eq c 'JS_FILE_COMMENT_SET)    109)
90           ((eq c 'JS_FILE_PASSWORD_SET)   110)
91           ((eq c 'JS_FILE_STAT)           111)
92           ((eq c 'JS_KILL)                112)
93           ((eq c 'JS_HINSI_LIST)          114)
94           ((eq c 'JS_HINSI_NAME)          115)
95           ((eq c 'JS_HINSI_NUMBER)        116)
96           ((eq c 'JS_HINSI_DICTS)         117)
97           ((eq c 'JS_HINSI_TABLE_SET)     118)
98           ((eq c 'JS_ACCESS_ADD_HOST)         ?\xf00011)
99           ((eq c 'JS_ACCESS_ADD_USER)         ?\xf00012)
100           ((eq c 'JS_ACCESS_REMOVE_HOST)      ?\xf00013)
101           ((eq c 'JS_ACCESS_REMOVE_USER)      ?\xf00014)
102           ((eq c 'JS_ACCESS_ENABLE)           ?\xf00015)
103           ((eq c 'JS_ACCESS_DISABLE)          ?\xf00016)
104           ((eq c 'JS_ACCESS_GET_INFO)         ?\xf00017)
105           ((eq c 'JS_TEMPORARY_DIC_ADD)       ?\xf00021)
106           ((eq c 'JS_TEMPORARY_DIC_DELETE)    ?\xf00022)
107           ((eq c 'JS_AUTOLEARNING_WORD_ADD)   ?\xf00023)
108           ((eq c 'JS_SET_AUTOLEARNING_DIC)    ?\xf00024)
109           ((eq c 'JS_GET_AUTOLEARNING_DIC)    ?\xf00025)
110           ((eq c 'JS_IS_LOADED_TEMPORARY_DIC) ?\xf00026)
111           ((eq c 'JS_TEMPORARY_WORD_ADD)      ?\xf00027)
112           ((eq c 'JS_SET_HENKAN_ENV)          ?\xf00031)
113           ((eq c 'JS_GET_HENKAN_ENV)          ?\xf00032)
114           ((eq c 'JS_SET_HENKAN_HINSI)        ?\xf00033)
115           ((eq c 'JS_GET_HENKAN_HINSI)        ?\xf00034)
116           ((eq c 'JS_HENKAN_WITH_DATA)        ?\xf00035)
117           ((eq c 'JS_FI_DIC_ADD)              ?\xf00061)
118           ((eq c 'JS_FI_HINDO_FILE_CREATE)    ?\xf00062)
119           ((eq c 'JS_FI_KANREN)               ?\xf00065)
120           ((eq c 'JS_SET_FI_PRIORITY)         ?\xf00066)
121           ((eq c 'JS_OPTIMIZE_FI)             ?\xf00067)
122           ((eq c 'JS_HENKAN_IKEIJI)           ?\xf0006f)
123           ((eq c 'JS_LOCK)                    ?\xf00071)
124           ((eq c 'JS_UNLOCK)                  ?\xf00072)
125           ((eq c 'JS_FI_DIC_LIST)             ?\xf00081)
126           ((eq c 'JS_FI_DIC_LIST_ALL)         ?\xf00082)
127           ((eq c 'JS_FUZOKUGO_LIST)           ?\xf00083)
128
129           ((eq c 'JLIB_VERSION)       ?\x4003)
130           ((eq c 'JLIB_VERSION_WNN6)  ?\x4f00)
131
132           ((eq c 'WNN_C_LOCAL)            "!")
133           ((eq c 'WNN_FT_DICT_FILE)         1)
134           ((eq c 'WNN_FT_HINDO_FILE)        2)
135           ((eq c 'WNN_FILE_STRING)       (encode-coding-string
136                                           "\e$B#W#n#n$N%U%!%$%k\e(B" 'euc-jp))
137           ((eq c 'WNN_FILE_STRING_LEN)     16)
138           ((eq c 'WNN_PASSWD_LEN)          16)
139           ((eq c 'WNN_HOST_LEN)            16)
140           ((eq c 'WNN_UNIQ_LEN)            28)
141           ((eq c 'WNN_FILE_HEADER_LEN)    128)
142           ((eq c 'WNN_FILE_HEADER_PAD)     36)
143           ((eq c 'WNN_FILE_BODY_PAD)      116)
144           ((eq c 'WNN_ENVNAME_LEN)         32)
145           ((eq c 'WNN_MAX_ENV_OF_A_CLIENT) 32)
146           ((eq c 'WNN_MAX_DIC_OF_AN_ENV)   30)
147           ((eq c 'WNN_MAX_FILE_OF_AN_ENV)  60)
148
149           ((eq c 'WNN_ACK)                  0)
150           ((eq c 'WNN_NAK)                 -1)
151
152           ((eq c 'WNN_NO_EXIST)             1)
153           ((eq c 'WNN_OPENF_ERR)           16)
154           ((eq c 'WNN_JSERVER_DEAD)        70)
155           ((eq c 'WNN_BAD_VERSION)         73)
156           ((eq c 'WNN_FILE_READ_ERROR)     90)
157           ((eq c 'WNN_FILE_WRITE_ERROR)    91)
158           ((eq c 'WNN_INCORRECT_PASSWD)    94)
159           ((eq c 'WNN_FILE_IN_USE)         95)
160           ((eq c 'WNN_UNLINK)              96)
161           ((eq c 'WNN_FILE_CREATE_ERROR)   97)
162           ((eq c 'WNN_NOT_A_FILE)          98)
163           ((eq c 'WNN_INODE_CHECK_ERROR)   99)
164
165           ((eq c 'WNN_UD_DICT)              2)
166           ((eq c 'WNN_REV_DICT)             3)
167           ((eq c 'CWNN_REV_DICT)       ?\x103)
168           ((eq c 'BWNN_REV_DICT)       ?\x203)
169           ((eq c 'WNN_COMPACT_DICT)         5)
170           ((eq c 'WNN_FI_SYSTEM_DICT)       6)
171           ((eq c 'WNN_FI_USER_DICT)         7)
172           ((eq c 'WNN_FI_HINDO_FILE)        8)
173           ((eq c 'WNN_GROUP_DICT)           9)
174           ((eq c 'WNN_MERGE_DICT)          10)
175           ((eq c 'WNN_VECT_NO)             -1)
176           ((eq c 'WNN_VECT_BUNSETSU)        2)
177           ((eq c 'WNN_VECT_KANREN)          0)
178           ((eq c 'WNN_VECT_KANZEN)          1)
179           ((eq c 'WNN_VECT_KANTAN)          1))))
180
181 (defconst wnnrpc-error-message
182   '((Japanese .
183      [
184       nil
185       "\e$B%U%!%$%k$,B8:_$7$^$;$s\e(B"
186       nil
187       "\e$B%a%b%j\e(B allocation \e$B$G<:GT$7$^$7$?\e(B"
188       nil
189       "\e$B<-=q$G$O$"$j$^$;$s\e(B"
190       "\e$BIQEY%U%!%$%k$G$O$"$j$^$;$s\e(B"
191       "\e$BIUB08l%U%!%$%k$G$O$"$j$^$;$s\e(B"
192       nil
193       "\e$B<-=q%F!<%V%k$,0lGU$G$9\e(B"
194       "\e$BIQEY%U%!%$%k$,;XDj$5$l$?<-=q$NIQEY%U%!%$%k$G$O$"$j$^$;$s\e(B"
195       nil
196       nil
197       nil
198       nil
199       nil
200       "\e$B%U%!%$%k$,%*!<%W%s$G$-$^$;$s\e(B"
201       "\e$B@5$7$$IQEY%U%!%$%k$G$O$"$j$^$;$s\e(B"
202       "\e$B@5$7$$IUB08l%U%!%$%k$G$O$"$j$^$;$s\e(B"
203       "\e$BIUB08l$N8D?t\e(B, \e$B%Y%/%?D9$5$J$I$,B?2a$.$^$9\e(B"
204       "\e$B$=$NHV9f$N<-=q$O;H$o$l$F$$$^$;$s\e(B"
205       nil
206       nil
207       nil
208       "\e$BIUB08l%U%!%$%k$NFbMF$,@5$7$/$"$j$^$;$s\e(B"
209       "\e$B5?;wIJ;lHV9f$,0[>o$G$9\e(B(hinsi.data \e$B$,@5$7$/$"$j$^$;$s\e(B)"
210       "\e$BL$Dj5A$NIJ;l$,A0C<IJ;l$H$7$FDj5A$5$l$F$$$^$9\e(B"
211       "\e$BIUB08l%U%!%$%k$,FI$_9~$^$l$F$$$^$;$s\e(B"
212       nil
213       nil
214       "\e$B<-=q$N%(%$%s%H%j$,B?2a$.$^$9\e(B"
215       "\e$BJQ49$7$h$&$H$9$kJ8;zNs$,D92a$.$^$9\e(B"
216       "\e$BIUB08l2r@ONN0h$,ITB-$7$F$$$^$9\e(B"
217       nil
218       "\e$B<!8uJdNN0h$,ITB-$7$F$$$^$9\e(B"
219       "\e$B8uJd$,\e(B 1 \e$B$D$b:n$l$^$;$s$G$7$?\e(B"
220       nil
221       nil
222       nil
223       nil
224       "\e$BFI$_$,D92a$.$^$9\e(B"
225       "\e$B4A;z$,D92a$.$^$9\e(B"
226       "\e$B;XDj$5$l$?<-=q$OEPO?2DG=$G$O$"$j$^$;$s\e(B"
227       "\e$BFI$_$ND9$5$,\e(B 0 \e$B$G$9\e(B"
228       "\e$B;XDj$5$l$?<-=q$O5U0z$-2DG=$G$O$"$j$^$;$s\e(B"
229       "\e$B%j!<%I%*%s%j!<$N<-=q$KEPO?\e(B/\e$B:o=|$7$h$&$H$7$^$7$?\e(B"
230       "\e$B4D6-$KB8:_$7$J$$<-=q$KEPO?$7$h$&$H$7$^$7$?\e(B"
231       nil
232       nil
233       "\e$B%j!<%I%*%s%j!<$NIQEY$rJQ99$7$h$&$H$7$^$7$?\e(B"
234       "\e$B;XDj$5$l$?C18l$,B8:_$7$^$;$s\e(B"
235       nil
236       nil
237       nil
238       nil
239       nil
240       nil
241       nil
242       nil
243       nil
244       "\e$B%a%b%j\e(B allocation \e$B$G<:GT$7$^$7$?\e(B"
245       nil
246       nil
247       nil
248       nil
249       nil
250       nil
251       nil
252       "\e$B2?$+$N%(%i!<$,5/$3$j$^$7$?\e(B"
253       "\e$B%P%0$,H/@8$7$F$$$kLOMM$G$9\e(B"
254       "\e$B%5!<%P$,;`$s$G$$$^$9\e(B"
255       "allocation \e$B$K<:GT$7$^$7$?\e(B"
256       "\e$B%5!<%P$H@\B3$G$-$^$;$s$G$7$?\e(B"
257       "\e$BDL?.%W%m%H%3%k$N%P!<%8%g%s$,9g$C$F$$$^$;$s\e(B"
258       "\e$B%/%i%$%"%s%H$N@8@.$7$?4D6-$G$O$"$j$^$;$s\e(B"
259       nil
260       nil
261       nil
262       nil
263       nil
264       "\e$B%G%#%l%/%H%j$r:n$k$3$H$,$G$-$^$;$s\e(B"
265       nil
266       nil
267       nil
268       nil
269       nil
270       nil
271       nil
272       nil
273       nil
274       "\e$B%U%!%$%k$rFI$_9~$`$3$H$,$G$-$^$;$s\e(B"
275       "\e$B%U%!%$%k$r=q$-=P$9$3$H$,$G$-$^$;$s\e(B"
276       "\e$B%/%i%$%"%s%H$NFI$_9~$s$@%U%!%$%k$G$O$"$j$^$;$s\e(B"
277       "\e$B$3$l0J>e%U%!%$%k$rFI$_9~$`$3$H$,$G$-$^$;$s\e(B"
278       "\e$B%Q%9%o!<%I$,4V0c$C$F$$$^$9\e(B"
279       "\e$B%U%!%$%k$,FI$_9~$^$l$F$$$^$9\e(B"
280       "\e$B%U%!%$%k$,:o=|$G$-$^$;$s\e(B"
281       "\e$B%U%!%$%k$,:n@.=PMh$^$;$s\e(B"
282       "WNN \e$B$N%U%!%$%k$G$"$j$^$;$s\e(B"
283       "\e$B%U%!%$%k$N\e(B inode \e$B$H\e(B FILE_UNIQ \e$B$r0lCW$5$;$k;v$,$G$-$^$;$s\e(B"
284       "\e$BIJ;l%U%!%$%k$,Bg$-2a$.$^$9\e(B"
285       "\e$BIJ;l%U%!%$%k$,Bg$-2a$.$^$9\e(B"
286       "\e$BIJ;l%U%!%$%k$,B8:_$7$^$;$s\e(B"
287       "\e$BIJ;l%U%!%$%k$NFbMF$,4V0c$C$F$$$^$9\e(B"
288       nil
289       "\e$BIJ;l%U%!%$%k$,FI$_9~$^$l$F$$$^$;$s\e(B"
290       "\e$BIJ;lL>$,4V0c$C$F$$$^$9\e(B"
291       "\e$BIJ;lHV9f$,4V0c$C$F$$$^$9\e(B"
292       nil
293       "\e$B$=$NA`:n$O%5%]!<%H$5$l$F$$$^$;$s\e(B"
294       "\e$B%Q%9%o!<%I$NF~$C$F$$$k%U%!%$%k$,%*!<%W%s$G$-$^$;$s\e(B"
295       "uumrc \e$B%U%!%$%k$,B8:_$7$^$;$s\e(B"
296       "uumrc \e$B%U%!%$%k$N7A<0$,8m$C$F$$$^$9\e(B"
297       "\e$B$3$l0J>e4D6-$r:n$k$3$H$O$G$-$^$;$s\e(B"
298       "\e$B$3$N%/%i%$%"%s%H$,FI$_9~$s$@%U%!%$%k$G$"$j$^$;$s\e(B"
299       "\e$B<-=q$KIQEY%U%!%$%k$,$D$$$F$$$^$;$s\e(B"
300       "\e$B%Q%9%o!<%I$N%U%!%$%k$,:n@.=PMh$^$;$s\e(B"
301       ])
302     (Chinese-GB .
303      [
304       nil
305       "\e$AND<~2;4fTZ\e(B"
306       nil
307       "\e$ADZ4f\e(Balloc\e$AJ'0\\e(B"
308       nil
309       "\e$A2;JGWV5d\e(B"
310       "\e$A2;JGF56HND<~\e(B"
311       "\e$A2;JGND7(ND<~\e(B"
312       nil
313       "\e$AWV5d1m8qBz\e(B"
314       "\e$AF56HND<~#:2;JGV86(5DWV5d5DF56HND<~\e(B"
315       nil
316       nil
317       nil
318       nil
319       nil
320       "\e$AND<~2;D\4r?*\e(B"
321       "\e$A2;JGU}H75DF56HND<~\e(B"
322       "\e$A2;JGU}H75DND7(ND<~\e(B"
323       "\e$A8=JtSo5D8vJ}!"OrA?3$6H5H3,9}\e(B"
324       "\e$AUb8v:EBk5DWV5d!"C;SPJ9SC\e(B"
325       nil
326       nil
327       nil
328       "\e$AND7(ND<~5DDZH]2;U}H7\e(B"
329       "\e$APiDb4JPT:EBkRl3#\e(Bcixing.data\e$A2;U}H7\e(B"
330       "\e$AN46(Re5D4JPT!"6(ReAKG06K4JPT\e(B"
331       "\e$AND7(ND<~2;D\6AH!\e(B"
332       nil
333       nil
334       "\e$AWV5d5DOnJ}3,9}\e(B"
335       "\e$A1d;;:sWV7{4.5D3$6H3,9}\e(B"
336       "\e$A8=JtSo=bNvSr2;9;\e(B"
337       nil
338       "\e$A4N:n29Sr2;9;\e(B"
339       "\e$A:n29\e(B 1\e$A8vR2C;SP\e(B"
340       nil
341       nil
342       nil
343       nil
344       "\e$A6ARt3$6H3,9}\e(B"
345       "\e$A::WV3$6H3,9}\e(B"
346       "\e$AV86(5DWV5d!"2;D\5GB<\e(B"
347       "\e$A6ARt5D3$6HJG\e(B 0"
348       "\e$AV86(5DWV5d!"2;D\Df2i\e(B"
349       "\e$AV;6A5DWV5d!"5GB<\e(B/\e$AO{3}AK\e(B"
350       "\e$A;7>3VP2;4fTZ5DWV5d!"5GB<AK\e(B"
351       nil
352       nil
353       "\e$AV;6A5DF56H!"1d8|AK\e(B"
354       "\e$AV86(5D5%WV2;4fTZ\e(B"
355       nil
356       nil
357       nil
358       nil
359       nil
360       nil
361       nil
362       nil
363       nil
364       "\e$ADZ4f\e(Balloc\e$AJ'0\\e(B"
365       nil
366       nil
367       nil
368       nil
369       nil
370       nil
371       nil
372       "\e$ASP3v4m7"Iz\e(B"
373       "\e$A:COsSP#b#u#g7"Iz\e(B"
374       "server\e$AK@AK\e(B"
375       "alloc\e$AJ'0\AK\e(B"
376       "\e$A2;D\:M\e(Bserver\e$AA,=S\e(B"
377       "\e$AM(PE9f3L5D0f1>2;7{\e(B"
378       "\e$A2;JG#c#W#n#nSC;'Iz3I5D;7>3\e(B"
379       nil
380       nil
381       nil
382       nil
383       nil
384       "\e$AWSD?B<2;D\44=(\e(B"
385       nil
386       nil
387       nil
388       nil
389       nil
390       nil
391       nil
392       nil
393       nil
394       "\e$AND<~2;D\6AH!\e(B"
395       "\e$AND<~2;D\P43v\e(B"
396       "\e$A2;JG#c#W#n#nSC;'?I6AH!5DND<~\e(B"
397       "\e$ARTIO5DND<~2;D\6AH!\e(B"
398       "password\e$A2;6T\e(B"
399       "\e$AND<~U}TZ6AH!\e(B"
400       "\e$AND<~2;D\O{3}\e(B"
401       "\e$AND<~C;SP44=(3v@4\e(B"
402       "\e$A2;JG#c#W#n#n5DND<~\e(B"
403       "\e$AND<~5D\e(BI-node\e$A:M\e(BFILE_UNIQ\e$A2;D\R;VB\e(B"
404       "\e$A4JPTND<~L+4s\e(B"
405       "\e$A4JPTND<~L+4s\e(B"
406       "\e$A4JPTND<~2;4fTZ\e(B"
407       "\e$A4JPTND<~5DDZH]2;6T\e(B"
408       nil
409       "\e$A4JPTND<~2;D\6AH!\e(B"
410       "\e$A4JPTC{2;6T\e(B"
411       "\e$A4JPT:EBk2;6T\e(B"
412       nil
413       "\e$AUb8v2YWw2;V'3V\e(B"
414       "password\e$A5DJdHkND<~2;D\4r?*\e(B"
415       "uumrc\e$AND<~2;4fTZ\e(B"
416       "uumrc\e$AND<~5DPNJ=4mNs\e(B"
417       "\e$ARTIO;7>32;D\44=(\e(B"
418       "\e$AUb8v#c#W#n#nSC;'!"6AH!5DND<~C;SP\e(B"
419       "\e$AWV5d5DF56HND<~C;SP\e(B"
420       "password\e$A5DND<~C;SP44=(3v@4\e(B"
421       ])
422     (Chinese-CNS .
423      [
424       nil
425       "\e$(GEFG5DbGtGc\e(B"
426       nil
427       "\e$(GDyGt\e(Balloc\e$(GFBZu\e(B"
428       nil
429       "\e$(GDbQRGsL(\e(B"
430       "\e$(GDbQRs"PyEFG5\e(B"
431       "\e$(GDbQREFNNEFG5\e(B"
432       nil
433       "\e$(GGsL(OPV*iH\e(B"
434       "\e$(Gs"PyEFG5!3DbQRQ@LyN{GsL(N{s"PyEFG5\e(B"
435       nil
436       nil
437       nil
438       nil
439       nil
440       "\e$(GEFG5DbWdFTbd\e(B"
441       "\e$(GDbQRF_m}N{s"PyEFG5\e(B"
442       "\e$(GDbQRF_m}N{EFNNEFG5\e(B"
443       "\e$(GOazhk#N{T6m0!#GWbXO[Pya+b>g4\e(B"
444       "\e$(G]UT6f@n#N{GsL(!#JtH4KpFn\e(B"
445       nil
446       nil
447       nil
448       "\e$(GEFNNEFG5N{DyU)DbF_m}\e(B"
449       "\e$(Gapsib$MLf@n#\,Z&\e(Bcixing.data\e$(GDbF_m}\e(B"
450       "\e$(GF\LyexN{b$ML!#LyexD'P)j&b$ML\e(B"
451       "\e$(GEFNNEFG5DbWd{tL=\e(B"
452       nil
453       nil
454       "\e$(GGsL(N{bzm0b>g4\e(B"
455       "\e$(G|H_PG[Gs\JHkN{O[Pyb>g4\e(B"
456       "\e$(GOazhk#fXN5YQDbY\\e(B"
457       nil
458       "\e$(GH9OlfPYQDbY\\e(B"
459       "\e$(GOlfP\e(B 1\e$(GT6D>JtH4\e(B"
460       nil
461       nil
462       nil
463       nil
464       "\e$(G{tSvO[Pyb>g4\e(B"
465       "\e$(GiGGsO[Pyb>g4\e(B"
466       "\e$(GQ@LyN{GsL(!#DbWd`trg\e(B"
467       "\e$(G{tSvN{O[PyQR\e(B 0"
468       "\e$(GQ@LyN{GsL(!#DbWdXKQg\e(B"
469       "\e$(GF7{tN{GsL(!#`trg\e(B/\e$(GV<XfD'\e(B"
470       "\e$(Gt?h:DcDbGtGcN{GsL(!#`trgD'\e(B"
471       nil
472       nil
473       "\e$(GF7{tN{s"Py!#|HJUD'\e(B"
474       "\e$(GQ@LyN{^LGsDbGtGc\e(B"
475       nil
476       nil
477       nil
478       nil
479       nil
480       nil
481       nil
482       nil
483       nil
484       "\e$(GDyGt\e(Balloc\e$(GFBZu\e(B"
485       nil
486       nil
487       nil
488       nil
489       nil
490       nil
491       nil
492       "\e$(GH4Exrc`uFm\e(B"
493       "\e$(GGob/H4$\$o$a`uFm\e(B"
494       "server\e$(GH;D'\e(B"
495       "alloc\e$(GFBZuD'\e(B"
496       "\e$(GDbWdLO\e(Bserver\e$(G]YZY\e(B"
497       "\e$(G]WOj]=a#N{NjF[Db\J\e(B"
498       "\e$(GDbQR$]$q$h$hFnEBFmH)N{t?h:\e(B"
499       nil
500       nil
501       nil
502       nil
503       nil
504       "\e$(GDMFxrgDbWd^6Pz\e(B"
505       nil
506       nil
507       nil
508       nil
509       nil
510       nil
511       nil
512       nil
513       nil
514       "\e$(GEFG5DbWd{tL=\e(B"
515       "\e$(GEFG5DbWdlQEx\e(B"
516       "\e$(GDbQR$]$q$h$hFnEBF+{tL=N{EFG5\e(B"
517       "\e$(GEhD8N{EFG5DbWd{tL=\e(B"
518       "password\e$(GDbhW\e(B"
519       "\e$(GEFG5F_Gc{tL=\e(B"
520       "\e$(GEFG5DbWdV<Xf\e(B"
521       "\e$(GEFG5JtH4^6PzExKt\e(B"
522       "\e$(GDbQR$C$W$h$hN{EFG5\e(B"
523       "\e$(GEFG5N{\e(BI-node\e$(GLO\e(BFILE_UNIQ\e$(GDbWdD!S3\e(B"
524       "\e$(Gb$MLEFG5E4DK\e(B"
525       "\e$(Gb$MLEFG5E4DK\e(B"
526       "\e$(Gb$MLEFG5DbGtGc\e(B"
527       "\e$(Gb$MLEFG5N{DyU)DbhW\e(B"
528       nil
529       "\e$(Gb$MLEFG5DbWd{tL=\e(B"
530       "\e$(Gb$MLGXDbhW\e(B"
531       "\e$(Gb$MLf@n#DbhW\e(B"
532       nil
533       "\e$(G]UT6pgI"DbEEQ=\e(B"
534       "password\e$(GN{rSD+EFG5DbWdFTbd\e(B"
535       "cwnnrc\e$(GEFG5DbGtGc\e(B"
536       "cwnnrc\e$(GEFG5N{J0H"rck(\e(B"
537       "\e$(GEhD8t?h:DbWd^6Pz\e(B"
538       "\e$(G]UT6$C$W$h$hFnEB!#{tL=N{EFG5JtH4\e(B"
539       "\e$(GGsL(N{s"PyEFG5JtH4\e(B"
540       "password\e$(GN{EFG5JtH4^6PzExKt\e(B"
541       ])
542     (Korean .
543      [
544       nil
545       "\e$(CH-@O@L\e(B \e$(CA8@gGOAv\e(B \e$(C>J=@4O4Y\e(B"
546       nil
547       "\e$(C8^8p8.\e(B alloc \e$(C?!<-\e(B \e$(C=GFPG_@>4O4Y\e(B"
548       nil
549       "\e$(C;g@|@L\e(B \e$(C>F4U4O4Y\e(B"
550       "\e$(C:s55\e(B \e$(CH-@O@L\e(B \e$(C>F4U4O4Y\e(B"
551       "\e$(C:N<S>n\e(B \e$(CH-@O@L\e(B \e$(C>F4U4O4Y\e(B"
552       nil
553       "\e$(C;g@|\e(B \e$(CEW@L:m@L\e(B \e$(C2K\e(B \e$(CC!@>4O4Y\e(B"
554       "\e$(CAvA$5H\e(B \e$(C;g@|@G\e(B \e$(C:s55\e(B \e$(CH-@O@L\e(B \e$(C>F4U4O4Y\e(B"
555       nil
556       nil
557       nil
558       nil
559       nil
560       "\e$(CH-@O@;\e(B \e$(C?-\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
561       "\e$(C8B4B\e(B \e$(C:s55\e(B \e$(CH-@O@L\e(B \e$(C>F4U4O4Y\e(B"
562       "\e$(C8B4B\e(B \e$(C:N<S>n\e(B \e$(CH-@O@L\e(B \e$(C>F4U4O4Y\e(B"
563       "\e$(C:N<S>n@G\e(B \e$(C09<v0!\e(B \e$(C3J9+\e(B \e$(C890E3*\e(B \e$(C:$EM@G\e(B \e$(C1f@L0!\e(B \e$(C3J9+\e(B \e$(C1i4O4Y\e(B"
564       "\e$(C1W\e(B \e$(C9xH#@G\e(B \e$(C;g@|@:\e(B \e$(C;g?k5G0m\e(B \e$(C@VAv\e(B \e$(C>J=@4O4Y\e(B"
565       nil
566       nil
567       nil
568       "\e$(C:N<S>n\e(B \e$(CH-@O@G\e(B \e$(C3;?k@L\e(B \e$(C8BAv\e(B \e$(C>J=@4O4Y\e(B"
569       "\e$(C0!;s\e(B \e$(CG0;g@G\e(B \e$(C9xH#0!\e(B \e$(CF2834O4Y\e(B. hinsi.data \e$(C0!\e(B \e$(C8BAv\e(B \e$(C>J=@4O4Y\e(B"
570       "\e$(C9LA$@G@G\e(B \e$(CG0;g0!\e(B \e$(C@|4\\e(B \e$(CG0;g7N\e(B \e$(CA$@G5G>n\e(B \e$(C@V=@4O4Y\e(B"
571       "\e$(C:N<S>n\e(B \e$(CH-@O@L\e(B \e$(C@PGtA.\e(B \e$(C@VAv\e(B \e$(C>J=@4O4Y\e(B"
572       nil
573       nil
574       "\e$(C;g@|@G\e(B \e$(C?#F.8.0!\e(B \e$(C3J9+\e(B \e$(C89=@4O4Y\e(B"
575       "\e$(C:/H/GO7A4B\e(B \e$(C9.@Z?-@L\e(B \e$(C3J9+\e(B \e$(C1i4O4Y\e(B"
576       "\e$(C:N<S>n\e(B \e$(CGX<.\e(B \e$(C?5?*@L\e(B \e$(C:NA7GU4O4Y\e(B"
577       nil
578       "\e$(C4Y@=\e(B \e$(CHD:8\e(B \e$(C?5?*@L\e(B \e$(C:NA7GU4O4Y\e(B"
579       "\e$(CHD:80!\e(B \e$(C>x@>4O4Y\e(B"
580       nil
581       nil
582       nil
583       nil
584       "\e$(CGQ1[@L\e(B \e$(C3J9+\e(B \e$(C1i4O4Y\e(B"
585       "\e$(CGQ@Z0!\e(B \e$(C3J9+\e(B \e$(C1i4O4Y\e(B"
586       "\e$(CAvA$5H\e(B \e$(C;g@|@:\e(B \e$(C5n7O\e(B \e$(C:R0!4I@T4O4Y\e(B"
587       "\e$(CGQ1[@G\e(B \e$(C1f@L0!\e(B 0 \e$(C@T4O4Y\e(B"
588       "\e$(CAvA$5H\e(B \e$(C;g@|@:\e(B \e$(C?*B|A6\e(B \e$(C:R0!4I@T4O4Y\e(B"
589       "\e$(C@P1b@|?k\e(B \e$(C;g@|?!\e(B \e$(C5n7O\e(B/\e$(C<R0E\e(B \e$(CGO7A0m\e(B \e$(CG_@>4O4Y\e(B"
590       "\e$(CA8@gGOAv\e(B \e$(C>J4B\e(B \e$(C;g@|?!\e(B \e$(C5n7O\e(B \e$(CGO7A0m\e(B \e$(CG_@>4O4Y\e(B"
591       nil
592       nil
593       "\e$(C@P1b@|?k\e(B \e$(C:s558&\e(B \e$(C0f=E\e(B \e$(CGO7A0m\e(B \e$(CG_@>4O4Y\e(B"
594       "\e$(CAvA$5H\e(B \e$(C4\>n4B\e(B \e$(CA8@gGOAv\e(B \e$(C>J=@4O4Y\e(B"
595       nil
596       nil
597       nil
598       nil
599       nil
600       nil
601       nil
602       nil
603       nil
604       "\e$(C8^8p8.\e(B alloc \e$(C?!\e(B \e$(C=GFPG_@>4O4Y\e(B"
605       nil
606       nil
607       nil
608       nil
609       nil
610       nil
611       nil
612       "\e$(C?!7/0!\e(B \e$(C9_;}G_@>4O4Y\e(B"
613       "\e$(C9v1W\e(B(Bug)\e$(C0!\e(B \e$(C9_;}G_@>4O4Y\e(B"
614       "\e$(C<-9v\e(B(Server)\e$(C0!\e(B \e$(CAW>n\e(B \e$(C@V@>4O4Y\e(B"
615       "alloc\e$(C?!\e(B \e$(C=GFPG_@>4O4Y\e(B"
616       "\e$(C<-9v\e(B(Server) \e$(C?M\e(B \e$(CA"CKGR\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
617       "\e$(CEk=E\e(B \e$(CGA7NEdD]@G\e(B \e$(C9vA/@L\e(B \e$(C8BAv\e(B \e$(C>J=@4O4Y\e(B"
618       "\e$(CE,6s@L>HF.0!\e(B \e$(C;}<:GQ\e(B \e$(CH/0f@L\e(B \e$(C>F4U4O4Y\e(B"
619       nil
620       nil
621       nil
622       nil
623       nil
624       "\e$(C5p7:Ed8.8&\e(B \e$(C885i\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
625       nil
626       nil
627       nil
628       nil
629       nil
630       nil
631       nil
632       nil
633       nil
634       "\e$(CH-@O\e(B \e$(C@P1b?!\e(B \e$(C=GFPG_@>4O4Y\e(B"
635       "\e$(CH-@O\e(B \e$(C>21b?!\e(B \e$(C=GFPG_@>4O4Y\e(B"
636       "\e$(CE,6s@L>HF.0!\e(B \e$(C@P>n\e(B \e$(C5e80\e(B \e$(CH-@O@L\e(B \e$(C>F4U4O4Y\e(B"
637       "\e$(C4u\e(B \e$(C@L;s@G\e(B \e$(CH-@O@;\e(B \e$(C@P>n\e(B \e$(C5e81\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
638       "\e$(CFP=:?v5e0!\e(B \e$(CF2834O4Y\e(B"
639       "\e$(CH-@O@L\e(B \e$(C@PGtA.\e(B \e$(C@V@>4O4Y\e(B"
640       "\e$(CH-@O@;\e(B \e$(C<R0EGR\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
641       "\e$(CH-@O@;\e(B \e$(C@[<:GR\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
642       "kWnn\e$(C@G\e(B \e$(CH-@O@L\e(B \e$(C>F4U4O4Y\e(B"
643       "\e$(CH-@O@G\e(B I-node \e$(C?M\e(B FILE_UNIQ \e$(C8&\e(B \e$(C@OD!=CE3\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
644       "\e$(CG0;g\e(B \e$(CH-@O@G\e(B \e$(CE)1b0!\e(B \e$(C3J9+\e(B \e$(CE.4O4Y\e(B"
645       "\e$(CG0;g\e(B \e$(CH-@O@G\e(B \e$(CE)1b0!\e(B \e$(C3J9+\e(B \e$(CE.4O4Y\e(B"
646       "\e$(CG0;g\e(B \e$(CH-@O@L\e(B \e$(CA8@gGOAv\e(B \e$(C>J=@4O4Y\e(B"
647       "\e$(CG0;g\e(B \e$(CH-@O@G\e(B \e$(C3;?k@L\e(B \e$(CF2834O4Y\e(B"
648       nil
649       "\e$(CG0;g\e(B \e$(CH-@O@L\e(B \e$(C@PGtA.\e(B \e$(C@VAv\e(B \e$(C>J=@4O4Y\e(B"
650       "\e$(CG0;g\e(B \e$(C@L8'@L\e(B \e$(CF2834O4Y\e(B"
651       "\e$(CG0;g\e(B \e$(C9xH#0!\e(B \e$(CF2834O4Y\e(B"
652       nil
653       "\e$(C1W\e(B \e$(CA6@[@:\e(B \e$(CAv?x5GAv\e(B \e$(C>J=@4O4Y\e(B"
654       "\e$(CFP=:?v5e0!\e(B \e$(C5i>n@V4B\e(B \e$(CH-@O@;\e(B \e$(C?-\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
655       "uumrc \e$(C@L\e(B \e$(CA8@gGOAv\e(B \e$(C>J=@4O4Y\e(B"
656       "uumrc \e$(C@G\e(B \e$(CG|=D@L\e(B \e$(CF2834O4Y\e(B"
657       "\e$(C@L\e(B \e$(C@L;s\e(B \e$(CH/0f@;\e(B \e$(C@[<:GR\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
658       "\e$(CE)6s@L>HF.0!\e(B \e$(C@P>n\e(B \e$(C5e80\e(B \e$(CH-@O@L\e(B \e$(C>F4U4O4Y\e(B"
659       "\e$(C;g@|?!\e(B \e$(C:s55\e(B \e$(CH-@O@L\e(B \e$(CA8@gGOAv\e(B \e$(C>J=@4O4Y\e(B"
660       "\e$(CFP=:?v5e\e(B \e$(CH-@O@;\e(B \e$(C@[<:GR\e(B \e$(C<v\e(B \e$(C>x@>4O4Y\e(B"
661       ]))
662   "Array of WNN error messages.  Indexed by error code.")
663
664 (defvar wnnrpc-timeout 10)
665
666 (defun wnnrpc-message-language (lang)
667   (or (cdr (assq lang egg-message-language-alist)) lang))
668
669 (defun wnnrpc-get-error-message (errno)
670   "Return error message string specified by ERRNO."
671   (let ((msg (cdr (or (assq (wnnrpc-message-language egg-default-language)
672                             wnnrpc-error-message)
673                       (assq (wnnrpc-message-language its-current-language)
674                             wnnrpc-error-message)
675                       (assq 'Japanese wnnrpc-error-message)))))
676     (or (and (< errno (length msg)) (aref msg errno))
677         (format "#%d" errno))))
678
679 (defmacro wnnrpc-call-with-proc (proc vlist send-expr &rest receive-exprs)
680   `(comm-call-with-proc ,proc
681        ((zhuyin its-zhuyin)
682         (comm-accept-timeout wnnrpc-timeout)
683         ,@vlist)
684      ,send-expr ,@receive-exprs))
685
686 (defmacro wnnrpc-call-with-environment (env vlist send-expr &rest rcv-exprs)
687   `(comm-call-with-proc (wnnenv-get-proc ,env)
688        ((zhuyin its-zhuyin)
689         (comm-accept-timeout wnnrpc-timeout)
690         (env-id (wnnenv-get-env-id ,env))
691         ,@vlist)
692      ,send-expr ,@rcv-exprs))
693
694 (defmacro wnnrpc-get-result (&rest body)
695   `(let (result)
696      (comm-unpack (u) result)
697      (if (< result 0)
698        (progn
699          (comm-unpack (u) result)
700          (- result))
701      ,@(or body '(result)))))
702 \f
703 (defun wnnrpc-open-internal (proc version myhostname username)
704   "Open the session.  Return 0 on success, error code on failure."
705   (comm-call-with-proc proc ()
706     (comm-format (u u s s)
707                  (wnn-const JS_OPEN)
708                  version myhostname username)
709     (wnnrpc-get-result)))
710
711 (defun wnnrpc-open (proc myhostname username)
712   "Open the session.  Return wnn4 or wnn6 on success, NIL on failure."
713   (let ((type-list `((wnn6 . ,(wnn-const JLIB_VERSION_WNN6))
714                      (wnn4 . ,(wnn-const JLIB_VERSION))))
715         (result (- (wnn-const WNN_BAD_VERSION)))
716         type version)
717     (while (and type-list (= result (- (wnn-const WNN_BAD_VERSION))))
718       (setq type (caar type-list)
719             version (cdar type-list)
720             type-list (cdr type-list)
721             result (wnnrpc-open-internal proc version myhostname username)))
722     (if (zerop result)
723         type
724       result)))
725
726 (defun wnnrpc-connect (proc envname)
727   "Establish new `connection' and make an environment.
728 Return the identitifation of the environment on success, 
729 or negative error code on failure."
730   (comm-call-with-proc proc ()
731     (comm-format (u s) (wnn-const JS_CONNECT) envname)
732     (wnnrpc-get-result)))
733
734 (defun wnnrpc-file-read (env filename)
735   "Read the file FILENAME on the environment ENV
736 Return non-negative file ID on success, or negative error code on failure."
737   (wnnrpc-call-with-environment env ()
738     (comm-format (u u s) (wnn-const JS_FILE_READ) env-id filename)
739     (wnnrpc-get-result)))
740
741 (defun wnnrpc-set-fuzokugo-file (env fid)
742   "For PROC, on environment ENV-ID, 
743 Set Fuzokugo file specified by FID.
744 Return 0 on success, negate-encoded error code on failure."
745   (wnnrpc-call-with-environment env ()
746     (comm-format (u u i) (wnn-const JS_FUZOKUGO_SET) env-id fid)
747     (wnnrpc-get-result)))
748
749 (defun wnnrpc-set-dictionary (env dic-id freq-id priority dic-rw freq-rw
750                                   dic-passwd freq-passwd reverse)
751   "Set dictionary on server.
752 Return dictionary number on success, negate-encoded error code on faiulure."
753   (wnnrpc-call-with-environment env ()
754     (comm-format (u u i i i u u s s u) (wnn-const JS_DIC_ADD)
755                  env-id dic-id freq-id
756                  priority
757                  (if (numberp dic-rw) dic-rw (if dic-rw 0 1))
758                  (if (numberp freq-rw) freq-rw (if freq-rw 0 1))
759                  dic-passwd freq-passwd
760                  (if reverse 1 0))
761     (wnnrpc-get-result)))
762
763 (defun wnnrpc-set-fi-dictionary (env dic-id freq-id sys dic-rw freq-rw
764                                      dic-passwd freq-passwd)
765   "Set FI dictionary on the server.
766 Return 0 on success, negate-encoded error code on faiulure."
767   (wnnrpc-call-with-environment env ()
768     (comm-format (u u i i u u u s s) (wnn-const JS_FI_DIC_ADD)
769                  env-id dic-id freq-id
770                  (if sys
771                      (wnn-const WNN_FI_SYSTEM_DICT)
772                    (wnn-const WNN_FI_USER_DICT))
773                  (if (numberp dic-rw) dic-rw (if dic-rw 0 1))
774                  (if (numberp freq-rw) freq-rw (if freq-rw 0 1))
775                  dic-passwd freq-passwd)
776     (wnnrpc-get-result)))
777
778 (defun wnnrpc-get-autolearning-dic (env type)
779   "Get id of auto learning dictionary on the server.
780 Return dictionary id + 1 on success, 0 on no dictionary, negate-encoded
781 error code on faiulure."
782   (wnnrpc-call-with-environment env (result)
783     (comm-format (u u u) (wnn-const JS_GET_AUTOLEARNING_DIC)
784                  env-id type)
785     (wnnrpc-get-result
786       (comm-unpack (u) result)
787       (1+ result))))
788
789 (defun wnnrpc-set-autolearning-dic (env type dic-id)
790   "Set auto learning dictionary on the server.
791 Return 0 on success, negate-encoded error code on faiulure."
792   (wnnrpc-call-with-environment env ()
793     (comm-format (u u u i) (wnn-const JS_SET_AUTOLEARNING_DIC)
794                  env-id type dic-id)
795     (wnnrpc-get-result)))
796
797 (defun wnnrpc-version (proc)
798   "Return the version number of WNN server."
799   (comm-call-with-proc proc (result)
800     (comm-format (u) (wnn-const JS_VERSION))
801     (comm-unpack (u) result)
802     result))
803
804 (defun wnnrpc-access (env path mode) 
805   "Check the accessibility of file in the environment ENV.
806 Return 0 when the remote file (dictionary/frequency) of PATH on server
807 can be accessed in mode MODE.  Return Non-zero otherwise."
808   (wnnrpc-call-with-environment env (result)
809     (comm-format (u u u s) (wnn-const JS_ACCESS) env-id mode path)
810     (comm-unpack (u) result)
811     result))
812
813 (defun wnnrpc-mkdir (env path)
814   "Create directory specified by PATH."
815   (wnnrpc-call-with-environment env ()
816     (comm-format (u u s) (wnn-const JS_MKDIR) env-id path)
817     (wnnrpc-get-result)))
818
819 (defun wnnrpc-writable-dic-type (env fi rw)
820   (let ((server (wnnenv-get-server-type env)))
821     (cond (fi                        (wnn-const WNN_FI_USER_DICT))
822           ((or (eq server 'cserver)
823                (eq server 'tserver)) (wnn-const CWNN_REV_DICT))
824           ((eq rw 3)                 (wnn-const WNN_GROUP_DICT))
825           ((eq rw 4)                 (wnn-const WNN_MERGE_DICT))
826           (t                         (wnn-const WNN_REV_DICT)))))
827
828 (defun wnnrpc-dic-file-create (env dicname type comment passwd hpasswd)
829   "Create a dictionary on the server."
830   (wnnrpc-call-with-environment env ()
831     (comm-format (u u s S s s u) (wnn-const JS_DIC_FILE_CREATE)
832                  env-id dicname comment
833                  passwd hpasswd type)
834     (wnnrpc-get-result)))
835
836 (defun wnnrpc-hindo-file-create (env fi dic-id freqname comment passwd)
837   "Create a frequency file on the server."
838   (wnnrpc-call-with-environment env ()
839     (comm-format (u u u s S s)
840                  (if fi
841                      (wnn-const JS_FI_HINDO_FILE_CREATE)
842                    (wnn-const JS_HINDO_FILE_CREATE))
843                  env-id dic-id freqname comment passwd)
844     (wnnrpc-get-result)))
845
846 (defun wnnrpc-file-discard (env fid)
847   "Discard a file specified by FID.  Call this for already-opened file
848 before remove and create new file."
849   (wnnrpc-call-with-environment env ()
850     (comm-format (u u i) (wnn-const JS_FILE_DISCARD)
851                  env-id fid)
852     (wnnrpc-get-result)))
853
854 (defun wnnrpc-file-remove (proc filename passwd)
855   "Remove the file."
856   (comm-call-with-proc proc ()
857     (comm-format (u s s) (wnn-const JS_FILE_REMOVE)
858                  filename (or passwd ""))
859     (wnnrpc-get-result)))
860
861 (defun wnnrpc-set-conversion-parameter (env v)
862   "Set conversion parameter."
863   (wnnrpc-call-with-environment env ()
864     (comm-format (u u i i i i i i i i i i i i i i i i i)
865                  (wnn-const JS_PARAM_SET)
866                  env-id
867                  (aref v  0) (aref v  1) (aref v  2) (aref v  3) (aref v  4)
868                  (aref v  5) (aref v  6) (aref v  7) (aref v  8) (aref v  9)
869                  (aref v 10) (aref v 11) (aref v 12) (aref v 13) (aref v 14)
870                  (aref v 15) (aref v 16))
871     (wnnrpc-get-result)))
872
873 (defun wnnrpc-set-conversion-env-param (env mask v)
874   "Set Wnn6 conversion parameter."
875   (wnnrpc-call-with-environment env ()
876     (comm-format (u u u i i i i i i i i i i i i i i i i i i)
877                  (wnn-const JS_SET_HENKAN_ENV)
878                  env-id mask
879                  (aref v  0) (aref v  1) (aref v  2) (aref v  3) (aref v  4)
880                  (aref v  5) (aref v  6) (aref v  7) (aref v  8) (aref v  9)
881                  (aref v 10) (aref v 11) (aref v 12) (aref v 13) (aref v 14)
882                  (aref v 15) (aref v 16) (aref v 17))
883     (wnnrpc-get-result)))
884
885 (defun wnnrpc-temporary-dic-loaded (env)
886   "Ask to the server whether the temporary dictionary is loaded or not.
887 Return positive if loaded, zero if not, negative on failure."
888   (wnnrpc-call-with-environment env ()
889     (comm-format (u u) (wnn-const JS_IS_LOADED_TEMPORARY_DIC)
890                  env-id)
891     (wnnrpc-get-result)))
892
893 (defun wnnrpc-temporary-dic-add (env reverse)
894   "Add temporary dictionary on the server."
895   (wnnrpc-call-with-environment env ()
896     (comm-format (u u u) (wnn-const JS_TEMPORARY_DIC_ADD)
897                  env-id (if reverse 1 0))
898     (wnnrpc-get-result)))
899
900 (defun wnnrpc-receive-sho-bunsetsu-list (env n-bunsetsu)
901   (let ((proc (wnnenv-get-proc env))
902         slist
903         end start jiritsugo-end dic-no entry freq right-now
904         hinshi status status-backward kangovect evaluation
905         result source fuzokugo)
906     (while (> n-bunsetsu 0)
907       (comm-unpack (u u u u u u u u u u u u)
908                    end start jiritsugo-end
909                    dic-no entry freq right-now hinshi
910                    status status-backward kangovect evaluation)
911       (setq slist
912             (cons
913              (wnn-bunsetsu-create env (1+ (- jiritsugo-end start))
914                                   dic-no entry freq right-now hinshi
915                                   status status-backward kangovect evaluation)
916              slist))
917       (setq n-bunsetsu (1- n-bunsetsu)))
918     (prog1
919         (setq slist (nreverse slist))
920       (while slist
921         (comm-unpack (S S S) result source fuzokugo)
922         (wnn-bunsetsu-set-converted (car slist) result)
923         (wnn-bunsetsu-set-yomi (car slist) source)
924         (wnn-bunsetsu-set-fuzokugo (car slist) fuzokugo)
925         (setq slist (cdr slist))))))
926
927 (defun wnnrpc-receive-dai-bunsetsu-list (env n-dai separate)
928   (let ((proc (wnnenv-get-proc env))
929         n-bunstsu kanji-length dlist slist
930         end start n-sho evaluation
931         n retval)
932     (comm-unpack (u u) n-bunstsu kanji-length)
933     (while (> n-dai 0)
934       (comm-unpack (u u u u) end start n-sho evaluation)
935       (setq dlist (cons (cons n-sho evaluation) dlist)
936             n-dai (1- n-dai)))
937     (setq dlist (nreverse dlist)
938           slist (wnnrpc-receive-sho-bunsetsu-list env n-bunstsu))
939     (if (null separate)
940         (prog1
941             slist
942           (while dlist
943             (setq n (caar dlist))
944             (while (> n 0)
945               (wnn-bunsetsu-set-dai-evaluation (car slist) (cdar dlist))
946               (wnn-bunsetsu-set-dai-continue (car slist) (> n 1))
947               (setq slist (cdr slist)
948                     n (1- n)))
949             (setq dlist (cdr dlist))))
950       (while dlist
951         (setq retval (cons slist retval)
952               n (caar dlist))
953         (while (> n 1)
954           (wnn-bunsetsu-set-dai-evaluation (car slist) (cdar dlist))
955           (wnn-bunsetsu-set-dai-continue (car slist) t)
956           (setq slist (cdr slist)
957                 n (1- n)))
958         (wnn-bunsetsu-set-dai-evaluation (car slist) (cdar dlist))
959         (wnn-bunsetsu-set-dai-continue (car slist)
960                                        (wnn-bunsetsu-connect-next (car slist)))
961         (setq slist (prog1 (cdr slist) (setcdr slist nil))
962               dlist (cdr dlist)))
963       (nreverse retval))))
964
965 (defun wnnrpc-renbunsetsu-conversion (env yomi hinshi fuzokugo v)
966   "Convert YOMI string into Kanji.
967 HINSHI and FUZOKUGO are information of preceding bunsetsu."
968   (wnnrpc-call-with-environment env ()
969     (comm-format (u u S i S i i i) (wnn-const JS_KANREN)
970                  env-id yomi hinshi fuzokugo
971                  (or v (wnn-const WNN_VECT_KANREN))
972                  (if v (wnn-const WNN_VECT_KANREN) (wnn-const WNN_VECT_NO))
973                  (wnn-const WNN_VECT_BUNSETSU))
974      (wnnrpc-get-result
975       (wnnrpc-receive-dai-bunsetsu-list env result nil))))
976
977 (defun wnnrpc-fi-renbunsetsu-conversion (env yomi hinshi fuzokugo v context)
978   "Convert YOMI string into Kanji.
979 HINSHI and FUZOKUGO are information of preceding bunsetsu."
980   (wnnrpc-call-with-environment env (result)
981     (comm-format (u u S i S i i i i i i i S i i i i S) (wnn-const JS_FI_KANREN)
982                  env-id yomi hinshi fuzokugo
983                  (or v (wnn-const WNN_VECT_KANREN))
984                  (if v (wnn-const WNN_VECT_KANREN) (wnn-const WNN_VECT_NO))
985                  (wnn-const WNN_VECT_BUNSETSU)
986                  (wnn-context-dic-no (car context))
987                  (wnn-context-entry (car context))
988                  (wnn-context-jirilen (car context))
989                  (wnn-context-hinshi (car context))
990                  (wnn-context-fuzokugo (car context))
991                  (wnn-context-dic-no (nth 1 context))
992                  (wnn-context-entry (nth 1 context))
993                  (wnn-context-jirilen (nth 1 context))
994                  (wnn-context-hinshi (nth 1 context))
995                  (wnn-context-fuzokugo (nth 1 context)))
996     (setq result (wnnrpc-get-result
997                    (wnnrpc-receive-dai-bunsetsu-list env result nil)))
998     (prog1
999         result
1000       (unless (numberp result)
1001         (wnn-bunsetsu-set-fi-rel (car result)
1002                                  (wnnrpc-get-fi-relation-data env))
1003         (while result
1004           (wnn-bunsetsu-set-context (car result) context)
1005           (setq result (cdr result)))))))
1006
1007 (defun wnnrpc-get-fi-relation-data (env)
1008   "Receive FI relation data from the server."
1009   (let ((proc (wnnenv-get-proc env))
1010         fi-dic dic entry offset num result)
1011     (comm-unpack (i) num)
1012     (while (> num 0)
1013       (comm-unpack (u u u u) fi-dic dic entry offset)
1014       (setq result (cons (vector fi-dic dic entry offset -2 -4) result)
1015             num (1- num)))
1016     (nreverse result)))
1017
1018 (defun wnnrpc-tanbunsetsu-conversion (env yomi hinshi fuzoku v)
1019   ""
1020   (wnnrpc-call-with-environment env (kanji-length)
1021     (comm-format (u u S i S i i) (wnn-const JS_KANTAN_SHO)
1022                  env-id yomi hinshi fuzoku
1023                  (or v (wnn-const WNN_VECT_KANTAN))
1024                  (if v (wnn-const WNN_VECT_KANTAN) (wnn-const WNN_VECT_NO)))
1025     (wnnrpc-get-result
1026       (comm-unpack (u) kanji-length)    ; ignore kanji-length
1027       (wnnrpc-receive-sho-bunsetsu-list env result))))
1028
1029 (defun wnnrpc-get-bunsetsu-candidates (env yomi hinshi fuzoku v)
1030   ""
1031   (wnnrpc-call-with-environment env (kanji-length)
1032     (comm-format (u u S i S i i) (wnn-const JS_KANZEN_SHO)
1033                  env-id yomi hinshi fuzoku
1034                  (or v (wnn-const WNN_VECT_KANZEN))
1035                  (if v (wnn-const WNN_VECT_KANZEN) (wnn-const WNN_VECT_NO)))
1036     (wnnrpc-get-result
1037       (comm-unpack (u) kanji-length)    ; ignore kanji-length
1038       (mapcar (lambda (b)
1039                 (wnn-bunsetsu-set-dai-continue b (wnn-bunsetsu-connect-next b))
1040                 (list b))
1041               (wnnrpc-receive-sho-bunsetsu-list env result)))))
1042
1043 (defun wnnrpc-daibunsetsu-conversion (env yomi hinshi fuzoku v)
1044   ""
1045   (wnnrpc-call-with-environment env (n-sho-bunsetsu kanji-size)
1046     (comm-format (u u S i S i i) (wnn-const JS_KANTAN_DAI)
1047                  env-id yomi hinshi fuzoku
1048                  (or v (wnn-const WNN_VECT_KANTAN))
1049                  (if v (wnn-const WNN_VECT_KANTAN) (wnn-const WNN_VECT_NO)))
1050     (wnnrpc-get-result
1051       (wnnrpc-receive-dai-bunsetsu-list env result nil))))
1052
1053 (defun wnnrpc-get-daibunsetsu-candidates (env yomi hinshi fuzoku v)
1054   ""
1055   (wnnrpc-call-with-environment env (n-sho-bunsetsu kanji-size)
1056     (comm-format (u u S i S i i) (wnn-const JS_KANZEN_DAI)
1057                  env-id yomi hinshi fuzoku
1058                  (or v (wnn-const WNN_VECT_KANZEN))
1059                  (if v (wnn-const WNN_VECT_KANZEN) (wnn-const WNN_VECT_NO)))
1060     (wnnrpc-get-result
1061       (wnnrpc-receive-dai-bunsetsu-list env result t))))
1062
1063 (defun wnnrpc-set-frequency (env dicno entry ima hindo)
1064   ""
1065   (wnnrpc-call-with-environment env ()
1066     (comm-format (u u i i i i) (wnn-const JS_HINDO_SET)
1067                  env-id dicno entry ima hindo)
1068     (wnnrpc-get-result)))
1069
1070 (defun wnnrpc-set-fi-priority (env fi-rel)
1071   ""
1072   (wnnrpc-call-with-environment env ()
1073     (progn
1074       (comm-format (u u u) (wnn-const JS_SET_FI_PRIORITY)
1075                    env-id (length fi-rel))
1076       (while fi-rel
1077         (comm-format (i i i i i i)
1078                      (aref (car fi-rel) 0) (aref (car fi-rel) 1)
1079                      (aref (car fi-rel) 2) (aref (car fi-rel) 3)
1080                      (aref (car fi-rel) 4) (aref (car fi-rel) 5))
1081         (setq fi-rel (cdr fi-rel))))
1082     (wnnrpc-get-result)))
1083
1084 (defun wnnrpc-optimize-fi (env context)
1085   ""
1086   (wnnrpc-call-with-environment env (c)
1087     (progn
1088       (comm-format (u u u) (wnn-const JS_OPTIMIZE_FI)
1089                    env-id (length context))
1090       (while context
1091         (setq c (car context)
1092               context (cdr context))
1093         (comm-format (i i i i i S)
1094                      (wnn-context-dic-no c)
1095                      (wnn-context-entry c)
1096                      (wnn-context-right-now c)
1097                      (wnn-context-freq c)
1098                      (wnn-context-length c)
1099                      (concat (wnn-context-converted c)
1100                              (wnn-context-fuzokugo c)))))
1101     (wnnrpc-get-result)))
1102
1103 (defun wnnrpc-close (proc)
1104   ""
1105   (comm-call-with-proc proc ()
1106     (comm-format (u) (wnn-const JS_CLOSE))
1107     (wnnrpc-get-result)))
1108
1109 (defun wnnrpc-env-exist (proc envname)
1110   ""
1111   (comm-call-with-proc proc (result)
1112     (comm-format (u s) (wnn-const JS_ENV_EXIST) envname)
1113     (comm-unpack (u) result)
1114     result))
1115
1116 (defun wnnrpc-make-env-sticky (env)
1117   ""
1118   (wnnrpc-call-with-environment env ()
1119     (comm-format (u u) (wnn-const JS_ENV_STICKY) env-id)
1120     (wnnrpc-get-result)))
1121
1122 (defun wnnrpc-make-env-unsticky (env)
1123   ""
1124   (wnnrpc-call-with-environment env ()
1125     (comm-format (u u) (wnn-const JS_ENV_UNSTICKY) env-id)
1126     (wnnrpc-get-result)))
1127
1128 (defun wnnrpc-disconnect (env)
1129   ""
1130   (wnnrpc-call-with-environment env ()
1131     (comm-format (u u) (wnn-const JS_DISCONNECT) env-id)
1132     (wnnrpc-get-result)))
1133
1134 (defun wnnrpc-add-word (env dictionary yomi kanji comment hinshi initial-freq)
1135   ""
1136   (wnnrpc-call-with-environment env ()
1137     (comm-format (u u u S S S u u) (wnn-const JS_WORD_ADD)
1138                  env-id dictionary yomi kanji comment hinshi initial-freq)
1139     (wnnrpc-get-result)))
1140
1141 (defun wnnrpc-auto-learning (env type yomi kanji comment hinshi initial-freq)
1142   ""
1143   (wnnrpc-call-with-environment env ()
1144     (comm-format (u u u S S S u u) (wnn-const JS_AUTOLEARNING_WORD_ADD)
1145                  env-id type yomi kanji comment hinshi initial-freq)
1146     (wnnrpc-get-result)))
1147
1148 (defun wnnrpc-temporary-learning (env yomi kanji comment hinshi initial-freq)
1149   ""
1150   (wnnrpc-call-with-environment env ()
1151     (comm-format (u u S S S u u) (wnn-const JS_AUTOLEARNING_WORD_ADD)
1152                  env-id yomi kanji comment hinshi initial-freq)
1153     (wnnrpc-get-result)))
1154
1155 (defun wnnrpc-get-dictionary-list-with-environment (env)
1156   ""
1157   (wnnrpc-call-with-environment env (n-dic)
1158     (comm-format (u u) (wnn-const JS_DIC_LIST) env-id)
1159     (comm-unpack (u) n-dic)
1160     (wnnrpc-receive-dictionary-list proc n-dic)))
1161
1162 (defun wnnrpc-get-fi-dictionary-list-with-environment (env mask)
1163   ""
1164   (wnnrpc-call-with-environment env (n-dic)
1165     (comm-format (u u u) (wnn-const JS_FI_DIC_LIST) env-id mask)
1166     (comm-unpack (u) n-dic)
1167     (wnnrpc-receive-dictionary-list proc n-dic)))
1168
1169 (defun wnnrpc-receive-dictionary-list (proc n-dic)
1170   (let (entry dic freq dic-mode freq-mode enable-flag nice
1171         rev comment dicname freqname dic-passwd freq-passwd
1172         type gosuu dic-local-flag freq-local-flag retval)
1173     (while (> n-dic 0)
1174       (comm-unpack (u u u u u u u u S s s s s u u u u)
1175                    entry dic freq dic-mode freq-mode enable-flag nice
1176                    rev comment dicname freqname dic-passwd freq-passwd
1177                    type gosuu dic-local-flag freq-local-flag)
1178       (setq retval (cons
1179                     (vector entry dic freq dic-mode freq-mode enable-flag nice
1180                             rev comment dicname freqname dic-passwd freq-passwd
1181                             type gosuu dic-local-flag freq-local-flag)
1182                     retval)
1183             n-dic (1- n-dic)))
1184     (nreverse retval)))
1185
1186 (defsubst wnndic-get-id (dic) (aref dic 0))
1187 (defsubst wnndic-get-comment (dic) (aref dic 8))
1188 (defsubst wnndic-get-dictname (dic) (aref dic 9))
1189
1190 (defun wnnrpc-get-writable-dictionary-id-list (env)
1191   ""
1192   (wnnrpc-call-with-environment env (dic-list dic)
1193     (comm-format (u u i) (wnn-const JS_HINSI_DICTS) env-id -1)
1194     (wnnrpc-get-result
1195       (while (> result 0)
1196         (comm-unpack (u) dic)
1197         (setq dic-list (nconc dic-list (list dic))
1198               result (1- result)))
1199       dic-list)))
1200
1201 (defun wnnrpc-get-hinshi-list (env dic name)
1202   ""
1203   (wnnrpc-call-with-environment env (hinshi hinshi-list str-size)
1204     (comm-format (u u u S) (wnn-const JS_HINSI_LIST) env-id dic name)
1205     (wnnrpc-get-result
1206       (comm-unpack (u) str-size)        ; ignore
1207       (while (> result 0)
1208         (comm-unpack (S) hinshi)
1209         (setq hinshi-list (nconc hinshi-list (list hinshi))
1210               result (1- result)))
1211       hinshi-list)))
1212
1213 (defun wnnrpc-hinshi-number (proc name)
1214   ""
1215   (wnnrpc-call-with-proc proc ()
1216     (comm-format (u S) (wnn-const JS_HINSI_NUMBER) name)
1217     (wnnrpc-get-result)))
1218
1219 (defun wnnrpc-get-conversion-parameter (env)
1220   ""
1221   (wnnrpc-call-with-environment env (n nsho p1 p2 p3 p4 p5 p6 p7 p8 p9
1222                                      p10 p11 p12 p13 p14 p15)
1223     (comm-format (u u) (wnn-const JS_PARAM_GET) env-id)
1224     (wnnrpc-get-result
1225       (comm-unpack (u u  u u u u u  u u u u u  u u u u u)
1226                    n nsho p1 p2 p3 p4 p5 p6 p7 p8 p9
1227                    p10 p11 p12 p13 p14 p15)
1228       (vector n nsho p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15))))
1229
1230 (defun wnnrpc-get-conversion-env-param (env)
1231   ""
1232   (wnnrpc-call-with-environment env (p1 p2 p3 p4 p5 p6 p7 p8 p9
1233                                     p10 p11 p12 p13 p14 p15 p16 p17 p18)
1234     (comm-format (u u) (wnn-const JS_GET_HENKAN_ENV) env-id)
1235     (wnnrpc-get-result
1236       (comm-unpack (i i i i i i i i i i i i i i i i i i)
1237                    p1 p2 p3 p4 p5 p6 p7 p8 p9
1238                    p10 p11 p12 p13 p14 p15 p16 p17 p18)
1239       (vector p1 p2 p3 p4 p5 p6 p7 p8 p9
1240               p10 p11 p12 p13 p14 p15 p16 p17 p18))))
1241
1242 (defun wnnrpc-file-loaded (proc path)
1243   ""
1244   (comm-call-with-proc proc (result)
1245     (comm-format (u s) (wnn-const JS_FILE_LOADED) path)
1246     (comm-unpack (u) result)
1247     result))
1248
1249 (defun wnnrpc-write-file (env fid filename)
1250   (wnnrpc-call-with-environment env ()
1251     (comm-format (u u u s) (wnn-const JS_FILE_WRITE) env-id fid filename)
1252     (wnnrpc-get-result)))
1253
1254 (defun wnnrpc-get-fuzokugo-file (env)
1255   ""
1256   (wnnrpc-call-with-environment env ()
1257     (comm-format (u u) (wnn-const JS_FUZOKUGO_GET) env-id)
1258     (wnnrpc-get-result)))
1259
1260 (defsubst wnnrpc-receive-file-list (proc)
1261   (let ((i 0)
1262         flist
1263         nfiles fid local ref-count type name)
1264     (comm-unpack (u) nfiles)
1265     (while (> nfiles 0)
1266       (comm-unpack (u u u u s) fid local ref-count type name)
1267       (setq flist (nconc flist (list (vector fid local ref-count type name)))
1268             nfiles (1- nfiles)))
1269     flist))
1270
1271 (defun wnnrpc-get-file-list (proc)
1272   ""
1273   (comm-call-with-proc proc ()
1274     (comm-format (u) (wnn-const JS_FILE_LIST_ALL))
1275     (wnnrpc-receive-file-list proc)))
1276
1277 (defun wnnrpc-get-file-list-with-env (env)
1278   ""
1279   (wnnrpc-call-with-environment env ()
1280     (comm-format (u u) (wnn-const JS_FILE_LIST) env-id)
1281     (wnnrpc-receive-file-list proc)))
1282
1283 (defun wnnrpc-file-attribute (env path)
1284   "3: dictionary, 4: hindo file, 5: fuzokugo-file"
1285   (wnnrpc-call-with-environment env (result)
1286     (comm-format (u u s) (wnn-const JS_FILE_STAT) env-id path)
1287     (comm-unpack (u) result)
1288     result))
1289
1290 (defun wnnrpc-get-file-info (env fid)
1291   ""
1292   (wnnrpc-call-with-environment env (name local ref-count type)
1293     (comm-format (u u u) (wnn-const JS_FILE_INFO) env-id fid)
1294     (wnnrpc-get-result
1295       (comm-unpack (s u u u) name local ref-count type)
1296       (vector name local ref-count type))))
1297
1298 (defmacro wnnrpc-receive-vector (n)
1299   `(let ((v (make-vector ,n -1))
1300          (i 0)
1301          j)
1302      (while (< i ,n)
1303        (comm-unpack (u) j)
1304        (aset v i j)
1305        (setq i (1+ i)))
1306      v))
1307
1308 (defun wnnrpc-who (proc)
1309   ""
1310   (comm-call-with-proc proc (who socket username hostname)
1311     (comm-format (u) (wnn-const JS_WHO))
1312     (wnnrpc-get-result
1313       (while (> result 0)
1314         (comm-unpack (u s s) socket username hostname)
1315         (setq who (nconc who
1316                          (list (vector socket username hostname
1317                                        (wnnrpc-receive-vector
1318                                         (wnn-const WNN_MAX_ENV_OF_A_CLIENT)))))
1319               result (1- result)))
1320       who)))
1321
1322 (defun wnnrpc-get-env-list (proc)
1323   (comm-call-with-proc proc (envs id name count fuzokugo dic-max)
1324     (comm-format (u) (wnn-const JS_ENV_LIST))
1325     (wnnrpc-get-result
1326       (while (> result 0)
1327         (comm-unpack (u s u u u) id name count fuzokugo dic-max)
1328         (setq envs (nconc envs
1329                           (list (vector id name count fuzokugo dic-max
1330                                         (wnnrpc-receive-vector
1331                                          (wnn-const WNN_MAX_DIC_OF_AN_ENV))
1332                                         (wnnrpc-receive-vector
1333                                          (wnn-const WNN_MAX_FILE_OF_AN_ENV)))))
1334               result (1- result)))
1335         envs)))
1336
1337 (defun wnnrpc-kill (proc)
1338   ""
1339   (comm-call-with-proc proc (result)
1340     (comm-format (u) (wnn-const JS_KILL))
1341     (comm-unpack (u) result)
1342     result))
1343
1344 (defun wnnrpc-delete-dictionary (env dic)
1345   ""
1346   (wnnrpc-call-with-environment env ()
1347     (comm-format (u u u) (wnn-const JS_DIC_DELETE) env-id dic)
1348     (wnnrpc-get-result)))
1349
1350 (defun wnnrpc-set-flag-on-dictionary (env dic flag)
1351   ""
1352   (wnnrpc-call-with-environment env ()
1353     (comm-format (u u u u) (wnn-const JS_DIC_USE) env-id dic flag)
1354     (wnnrpc-get-result)))
1355
1356 (defun wnnrpc-get-dictionary-list (proc)
1357   ""
1358   (wnnrpc-call-with-proc proc (n-dic)
1359     (comm-format (u) (wnn-const JS_DIC_LIST_ALL))
1360     (comm-unpack (u) n-dic)
1361     (wnnrpc-receive-dictionary-list proc n-dic)))
1362
1363 (defun wnnrpc-delete-word (env dic entry)
1364   ""
1365   (wnnrpc-call-with-environment env ()
1366     (comm-format (u u u u) (wnn-const JS_WORD_DELETE) env-id dic entry)
1367     (wnnrpc-get-result)))
1368
1369 (defun wnnrpc-receive-word (proc yomi)
1370   (let (dic serial hinshi hindo right-now internal-hindo internal-right-now
1371         kanji comment l l1)
1372     (comm-unpack (u) dic)
1373     (while (>= dic 0)
1374       (comm-unpack (u u u u u u) serial hinshi hindo right-now
1375                    internal-hindo internal-right-now)
1376       (setq l (cons (vector dic serial hinshi hindo right-now
1377                             internal-hindo internal-right-now
1378                             yomi nil nil)
1379                     l))
1380       (comm-unpack (u) dic))
1381     (setq l (nreverse l)
1382           l1 l)
1383     (while l1
1384       (comm-unpack (S S) kanji comment)
1385       (aset (car l1) 8 kanji)
1386       (aset (car l1) 9 comment)
1387       (setq l1 (cdr l1)))
1388     l))
1389
1390 (defun wnnrpc-search-word-in-dictionary (env dic yomi)
1391   ""
1392   (wnnrpc-call-with-environment env (n-entries len)
1393     (comm-format (u u u S) (wnn-const JS_WORD_SEARCH) env-id dic yomi)
1394     (comm-unpack (u u) n-entries len)   ; ignore
1395     (wnnrpc-receive-word proc yomi)))
1396
1397 (defun wnnrpc-search-word (env yomi)
1398   ""
1399   (wnnrpc-call-with-environment env (n-entries len)
1400     (comm-format (u u S) (wnn-const JS_WORD_SEARCH_BY_ENV) env-id yomi)
1401     (comm-unpack (u u) n-entries len)   ; ignore
1402     (wnnrpc-receive-word proc yomi)))
1403
1404 (defun wnnrpc-get-word-info (env dic entry)
1405   ""
1406   (wnnrpc-call-with-environment env (n-entries len yomi)
1407     (comm-format (u u u u) (wnn-const JS_WORD_INFO) env-id dic entry)
1408     (wnnrpc-get-result
1409       (comm-unpack (S) yomi)
1410       (comm-unpack (u u) n-entries len) ; ignore
1411       (wnnrpc-receive-word proc yomi))))
1412
1413 (defun wnnrpc-set-comment-on-word (env dic entry comment)
1414   ""
1415   (wnnrpc-call-with-environment env ()
1416     (comm-format (u u u u S) (wnn-const JS_WORD_COMMENT_SET)
1417                  env-id dic entry comment)
1418     (wnnrpc-get-result)))
1419
1420 (defun wnnrpc-get-dictionary-info (env dic)
1421   ""
1422   (wnnrpc-call-with-environment env ()
1423     (comm-format (u u u) (wnn-const JS_DIC_INFO) env-id dic)
1424     (wnnrpc-get-result
1425       (wnnrpc-receive-dictionary-list proc 1))))
1426
1427 (defun wnnrpc-set-file-comment (env fid comment)
1428   ""
1429   (wnnrpc-call-with-environment env ()
1430     (comm-format (u u u S) (wnn-const JS_FILE_COMMENT_SET) env-id fid comment)
1431     (wnnrpc-get-result)))
1432
1433 (defun wnnrpc-hinshi-name (proc hinshi)
1434   ""
1435   (wnnrpc-call-with-proc proc ()
1436     (comm-format (u u) (wnn-const JS_HINSI_NAME) hinshi)
1437     (wnnrpc-get-result
1438       (comm-unpack (S) result)
1439       result)))
1440
1441 (defun wnnrpc-set-file-password (env fid which old new)
1442   "WHICH: 1: DIC, 2: HINDO, 3(0): Both"
1443   (wnnrpc-call-with-environment env ()
1444     (comm-format (u u u u s s) (wnn-const JS_FILE_PASSWORD_SET)
1445                  env-id fid which old new)
1446     (wnnrpc-get-result)))
1447
1448 (defun wnnrpc-set-hinshi-table (env dic hinshi-table)
1449   ""
1450   (wnnrpc-call-with-environment env ()
1451     (comm-format (u u u S) (wnn-const JS_HINSI_TABLE_SET)
1452                  env-id dic hinshi-table)
1453     (wnnrpc-get-result)))
1454 \f
1455 (defmacro wnnrpc-with-temp-buffer (&rest body)
1456   `(with-temp-buffer
1457      (let ((coding-system-for-read 'no-conversion)
1458            (coding-system-for-write 'no-conversion))
1459        (set-buffer-multibyte nil)
1460        ,@body)))
1461
1462 (defmacro wnnrpc-with-write-file (filename error-handler &rest body)
1463   `(condition-case error
1464        (with-temp-file ,filename
1465          (let ((coding-system-for-read 'no-conversion)
1466                (coding-system-for-write 'no-conversion))
1467            (set-buffer-multibyte nil)
1468            ,@body))
1469      (file-error ,error-handler)))
1470
1471 (defmacro wnnrpc-terminate-current-command (errno)
1472   `(progn
1473      (comm-call-with-proc-1 proc ()
1474        (comm-format (i) (wnn-const WNN_NAK)))
1475      (- (wnn-const ,errno))))
1476
1477 (defun wnnrpc-get-local-filename (name)
1478   (if (and (string-match (wnn-const WNN_C_LOCAL) name)
1479            (string= (substring name 0 (match-beginning 0)) wnn-system-name))
1480       (substring name (match-end 0))
1481     name))
1482
1483 ;; <header> ::= (<type> <uniq> <uniq> <passwd>)
1484 ;; <uniq>   ::= string
1485 ;; <passwd> ::= string
1486
1487 (defun wnnrpc-scan-file-header ()
1488   (let ((proc nil)
1489         type uniq1 uniq2 passwd)
1490     (if (and (> (point-max) (wnn-const WNN_FILE_HEADER_LEN))
1491              (equal (buffer-substring 1 (1+ (wnn-const WNN_FILE_STRING_LEN)))
1492                     (wnn-const WNN_FILE_STRING)))
1493         (progn
1494           (goto-char (1+ (wnn-const WNN_FILE_STRING_LEN)))
1495           (comm-unpack (u v v v)
1496                        type
1497                        uniq1 (wnn-const WNN_UNIQ_LEN)
1498                        uniq2 (wnn-const WNN_UNIQ_LEN)
1499                        passwd (wnn-const WNN_PASSWD_LEN))
1500           (list type uniq1 uniq2 passwd)))))
1501
1502 (defun wnnrpc-get-file-header (filename)
1503   (wnnrpc-with-temp-buffer
1504     (if (null (file-readable-p filename))
1505         (list nil (make-string (wnn-const WNN_UNIQ_LEN) 0) "" "")
1506       (insert-file-contents filename nil 0 (wnn-const WNN_FILE_HEADER_LEN))
1507       (wnnrpc-scan-file-header))))
1508
1509 (defun wnnrpc-check-local-file (path &optional preserve)
1510   (let ((header (wnnrpc-get-file-header path)))
1511     (cond ((null header)
1512            (- (wnn-const WNN_NOT_A_FILE)))
1513           ((null (car header))
1514            (if (file-exists-p path) 
1515                (- (wnn-const WNN_OPENF_ERR))
1516              (- (wnn-const WNN_NO_EXIST))))
1517           (t
1518            (if (wnnrpc-check-inode header path)
1519                header
1520              (if preserve
1521                  (- (wnn-const WNN_INODE_CHECK_ERROR))
1522                (wnnrpc-change-file-uniq header path)
1523                (wnnrpc-check-local-file path t)))))))
1524
1525 (defsubst wnnrpc-get-inode (uniq)
1526   (+ (lsh (aref uniq 8) 24)
1527      (lsh (aref uniq 9) 16)
1528      (lsh (aref uniq 10) 8)
1529      (aref uniq 11)))
1530
1531 (defun wnnrpc-check-inode (header path)
1532   (let ((inode (nth 10 (file-attributes path))))
1533     (and inode (= inode (wnnrpc-get-inode (nth 1 header))))))
1534
1535 (defun wnnrpc-make-uniq (attributes)
1536   (wnnrpc-with-temp-buffer
1537     (comm-format (U i u V)
1538                  (nth 6 attributes) (nth 11 attributes) (nth 10 attributes)
1539                  wnn-system-name (wnn-const WNN_HOST_LEN))
1540     (buffer-string)))
1541
1542 (defun wnnrpc-change-file-uniq (header path &optional new)
1543   (wnnrpc-with-write-file path
1544       nil
1545     (insert-file-contents path)
1546     (if (wnnrpc-scan-file-header)
1547         (let ((uniq (wnnrpc-make-uniq (file-attributes path))))
1548           (goto-char (1+ (wnn-const WNN_FILE_STRING_LEN)))
1549           (delete-region (point) (1+ (wnn-const WNN_FILE_HEADER_LEN)))
1550           (comm-format (u v v v v)
1551                        (car header)
1552                        uniq (wnn-const WNN_UNIQ_LEN)
1553                        (if new uniq (nth 1 header)) (wnn-const WNN_UNIQ_LEN)
1554                        (nth 3 header) (wnn-const WNN_PASSWD_LEN)
1555                        "" (wnn-const WNN_FILE_HEADER_PAD))
1556           t))))
1557
1558 (defun wnnrpc-check-passwd (proc passwd header)
1559   (let ((env-id -1))
1560     (unwind-protect
1561         (if (>= (setq env-id (wnnrpc-connect proc "")) 0)
1562             (wnnrpc-call-with-environment (wnnenv-create proc env-id)
1563                 (file-id)
1564               (comm-format (u u v) (wnn-const JS_FILE_SEND)
1565                            env-id
1566                            (nth 1 header) (wnn-const WNN_UNIQ_LEN))
1567               (comm-unpack (u) file-id)
1568               (if (>= file-id 0)
1569                   (progn
1570                     (wnnrpc-get-result) ; ignore result code
1571                     (- (wnn-const WNN_FILE_IN_USE)))
1572                 (wnnrpc-get-result
1573                   (comm-call-with-proc-1 proc ()
1574                     (comm-format (s B)
1575                                  (concat wnn-system-name "!TEMPFILE")
1576                                  (wnnrpc-make-dummy-dictionary header))
1577                     (wnnrpc-get-result
1578                       (let ((egg-fixed-euc (list egg-fixed-euc egg-fixed-euc)))
1579                         (wnnrpc-set-dictionary (wnnenv-create proc env-id)
1580                                                result -1 1 t t
1581                                                passwd "" nil))))))))
1582       (if (>= env-id 0)
1583           (wnnrpc-disconnect (wnnenv-create proc env-id))))))
1584
1585 (defun wnnrpc-make-dummy-dictionary (header)
1586   (wnnrpc-with-temp-buffer
1587     (comm-format (v u v v v v u v)
1588                  (wnn-const WNN_FILE_STRING) (wnn-const WNN_FILE_STRING_LEN)
1589                  (wnn-const WNN_FT_DICT_FILE)
1590                  (nth 1 header) (wnn-const WNN_UNIQ_LEN)
1591                  (nth 1 header) (wnn-const WNN_UNIQ_LEN)
1592                  (nth 3 header) (wnn-const WNN_PASSWD_LEN)
1593                  "" (wnn-const WNN_FILE_HEADER_PAD)
1594                  (wnn-const WNN_REV_DICT)
1595                  "" (wnn-const WNN_FILE_BODY_PAD))
1596     (buffer-string)))
1597
1598 (defun wnnrpc-file-loaded-local (proc path &optional preserve)
1599   ""
1600   (let ((header (wnnrpc-check-local-file path preserve)))
1601     (if (numberp header)
1602         -1
1603       (comm-call-with-proc proc (result)
1604         (comm-format (u v) (wnn-const JS_FILE_LOADED_LOCAL)
1605                      (nth 1 header) (wnn-const WNN_UNIQ_LEN))
1606         (comm-unpack (u) result)
1607         result))))
1608
1609 (defun wnnrpc-file-receive (env fid local-filename)
1610   ""
1611   (condition-case err
1612       (wnnrpc-call-with-environment env (filename)
1613         (comm-format (u u u) (wnn-const JS_FILE_RECEIVE)
1614                      env-id fid)
1615         (comm-unpack (s) filename)
1616         (if (null local-filename)
1617             (setq local-filename (wnnrpc-get-local-filename filename)))
1618         (let ((header (wnnrpc-get-file-header local-filename))
1619               contents)
1620           (if (null header)
1621               (wnnrpc-terminate-current-command WNN_NOT_A_FILE)
1622             (comm-call-with-proc-1 proc ()
1623               (comm-format (u v) (wnn-const WNN_ACK)
1624                            (nth 1 header) (wnn-const WNN_UNIQ_LEN)))
1625             (wnnrpc-get-result
1626               (cond
1627                ((= result 0) 0)
1628                ((null (file-writable-p local-filename))
1629                 (wnnrpc-terminate-current-command WNN_FILE_WRITE_ERROR))
1630                (t
1631                 (wnnrpc-with-write-file local-filename
1632                     (- (wnn-const WNN_FILE_WRITE_ERROR))            
1633                   (comm-call-with-proc proc ()
1634                     (comm-format (u) (wnn-const WNN_ACK))
1635                     (comm-unpack (B) contents))
1636                   (insert contents)
1637                   (if (= result 2)
1638                       (insert-file-contents local-filename nil (1- (point))))
1639                   (save-excursion
1640                     (set-buffer (process-buffer proc))
1641                     (wnnrpc-get-result)))))))))
1642     ((quit error)
1643      (wnnrpc-call-with-environment env ()
1644        (comm-format (i) (wnn-const WNN_NAK)))
1645      (signal (car err) (cdr err)))))
1646
1647 (defun wnnrpc-file-send (env filename)
1648   ""
1649   (let ((header (wnnrpc-check-local-file filename)))
1650     (if (numberp header)
1651         header
1652       (condition-case err
1653           (wnnrpc-call-with-environment env (file-id)
1654             (comm-format (u u v) (wnn-const JS_FILE_SEND)
1655                          env-id
1656                          (nth 1 header) (wnn-const WNN_UNIQ_LEN))
1657             (comm-unpack (u) file-id)
1658             (if (>= file-id 0)
1659                 (wnnrpc-get-result
1660                   (wnnenv-set-client-file env filename)
1661                   file-id)
1662               (wnnrpc-get-result
1663                 (comm-call-with-proc-1 proc ()
1664                   (comm-format (s B)
1665                                (concat wnn-system-name "!" filename)
1666                                (wnnrpc-with-temp-buffer
1667                                  (insert-file-contents filename)
1668                                  (buffer-string)))
1669                   (wnnrpc-get-result
1670                     (wnnenv-set-client-file env filename)
1671                     result)))))
1672         ((quit error)
1673          (wnnrpc-call-with-environment env ()
1674            (comm-format (s B B B B B B) "" "" "" "" "" "" ""))
1675          (signal (car err) (cdr err)))))))
1676
1677 (defun wnnrpc-file-remove-client (proc name passwd)
1678   (let (header)
1679     (cond
1680      ((/= (wnnrpc-file-loaded-local proc name) -1)
1681       (- (wnn-const WNN_FILE_IN_USE)))
1682      ((null (file-readable-p name))
1683       (- (wnn-const WNN_FILE_READ_ERROR)))
1684      ((null (numberp (car (setq header (wnnrpc-get-file-header name)))))
1685       (- (wnn-const WNN_NOT_A_FILE)))
1686      ((< (wnnrpc-check-passwd proc passwd header) 0)
1687       (- (wnn-const WNN_INCORRECT_PASSWD)))
1688      (t
1689       (condition-case nil
1690           (progn
1691             (delete-file name)
1692             0)
1693         (error (- (wnn-const WNN_UNLINK))))))))
1694
1695 (defun wnnrpc-dic-file-create-client (env dicname type comment passwd hpasswd)
1696   (if (and (null (file-exists-p dicname))
1697            (file-writable-p dicname)
1698            (or (eq type (wnn-const WNN_REV_DICT))
1699                (eq type (wnn-const CWNN_REV_DICT))
1700                (eq type (wnn-const BWNN_REV_DICT))
1701                (eq type (wnn-const WNN_UD_DICT))
1702                (and (wnnenv-is-wnn6 env)
1703                     (eq type (wnn-const WNN_FI_USER_DICT))))
1704            (wnnrpc-create-and-move-to-client env nil dicname type
1705                                              comment passwd hpasswd))
1706       0
1707     (- (wnn-const WNN_FILE_CREATE_ERROR))))
1708           
1709
1710 (defun wnnrpc-hindo-file-create-client (env fi dic-id freqname comment passwd)
1711   (if (and (null (file-exists-p freqname))
1712            (file-writable-p freqname)
1713            (wnnrpc-create-and-move-to-client env dic-id freqname fi
1714                                              comment passwd nil))
1715       0
1716     (- (wnn-const WNN_FILE_CREATE_ERROR))))
1717
1718 (defun wnnrpc-make-temp-name (env)
1719   (let ((n 0)
1720         (temp-form "usr/temp"))
1721     (while (= (wnnrpc-access env (concat temp-form n) 0) 0)
1722       (setq n (1+ n)))
1723     (concat temp-form n)))
1724
1725 (defun wnnrpc-create-and-move-to-client (env dic-id filename type
1726                                              comment passwd hpasswd)
1727   (let ((tempfile (wnnrpc-make-temp-name env))
1728         (created -1)
1729         (fid -1))
1730     (unwind-protect
1731         (progn
1732           (if (numberp type)
1733               (setq created (wnnrpc-dic-file-create env tempfile type
1734                                                     comment passwd hpasswd))
1735             (setq created (wnnrpc-hindo-file-create env type dic-id tempfile
1736                                                     comment passwd)))
1737           (if (and (>= created 0)
1738                    (>= (setq fid (wnnrpc-file-read env tempfile)) 0)
1739                    (>= (wnnrpc-file-receive env fid filename) 0))
1740               (wnnrpc-change-file-uniq (wnnrpc-get-file-header filename)
1741                                        filename t)
1742             (condition-case nil (delete-file filename) (error))
1743             nil))
1744       (if (>= fid 0)
1745           (wnnrpc-file-discard env fid))
1746       (if (>= created 0)
1747           (wnnrpc-file-remove (wnnenv-get-proc env) tempfile passwd)))))
1748
1749 (defun wnnrpc-read-passwd-file (filename)
1750   (cond
1751    ((null filename) "")
1752    ((null (file-readable-p filename)) (- (wnn-const WNN_FILE_READ_ERROR)))
1753    (t 
1754     (wnnrpc-with-temp-buffer
1755       (insert-file-contents filename nil 0 (1- (wnn-const WNN_PASSWD_LEN)))
1756       (goto-char 1)
1757       (if (and (search-forward-regexp "[\0\n]" nil 0)
1758                (= (preceding-char) 0))
1759           (backward-char))
1760       (buffer-substring 1 (point))))))
1761
1762 ;;; egg/wnnrpc.el ends here.