OSDN Git Service

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