Mercurial > hg > xemacs-beta
comparison lisp/egg/egg-sj3-client.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | |
children | 262b8bb4a523 |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
1 ;; Sj3 server interface for Egg | |
2 ;; Coded by K.Ishii, Sony Corp. (kiyoji@sm.sony.co.jp) | |
3 | |
4 ;; This file is part of Egg on Mule (Multilingual Environment) | |
5 | |
6 ;; Egg is distributed in the forms of patches to GNU | |
7 ;; Emacs under the terms of the GNU EMACS GENERAL PUBLIC | |
8 ;; LICENSE which is distributed along with GNU Emacs by the | |
9 ;; Free Software Foundation. | |
10 | |
11 ;; Egg is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY; without even the implied | |
13 ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
14 ;; PURPOSE. See the GNU EMACS GENERAL PUBLIC LICENSE for | |
15 ;; more details. | |
16 | |
17 ;; You should have received a copy of the GNU EMACS GENERAL | |
18 ;; PUBLIC LICENSE along with Nemacs; see the file COPYING. | |
19 ;; If not, write to the Free Software Foundation, 675 Mass | |
20 ;; Ave, Cambridge, MA 02139, USA. | |
21 | |
22 ;;; | |
23 ;;; Mule - Sj3 server interface in elisp | |
24 ;;; | |
25 | |
26 (provide 'sj3-client) | |
27 | |
28 ;;;; $B=$@5%a%b!(!((B | |
29 | |
30 ;;; Aug-4-94 by K.Ishii | |
31 ;;; Bug fixed in sj3-put-kata. | |
32 | |
33 ;;; Apr-6-94 by N.Tanaka | |
34 ;;; Add version 2(japanese EUC) protocol | |
35 | |
36 ;;; Jun-16-93 by H.Shirasaki <sirasaki@rd.ecip.osaka-u.ac.jp> | |
37 ;;; In sj3-bunsetu-yomi-equal, typo fixed. | |
38 | |
39 ;;; Apr-6-93 by T.Saneto <sanewo@pdp.crl.sony.co.jp> | |
40 ;;; Bug fixed in sj3-bunsetu-yomi-equal. | |
41 | |
42 ;;; Mar-19-93 by K.Ishii | |
43 ;;; Changed sj3-server-dict-info for edit-dict | |
44 | |
45 ;;; Aug-6-92 by K.Ishii | |
46 ;;; $BF|K\8lH=Dj$K(B lc-jp $B$r;H$&$h$&$KJQ99(B | |
47 | |
48 ;;; Jul-30-92 by K.Ishii | |
49 ;;; $BD9$$J8>O$rJQ49$9$k$H$-$K5/$3$k(B "Args out of range" $B%(%i!<$N=$@5(B | |
50 ;;; $BEPO?$7$?F0;l$N:o=|$,$G$-$k$h$&$K(B sj3-server-dict-info $B$N=$@5(B | |
51 ;;; sj3serv $B$KEO$9%W%m%0%i%`L>$NJQ99(B | |
52 | |
53 ;;; Jun-2-92 by K.Ishii | |
54 ;;; Mule $BMQ$KJQ99(B | |
55 | |
56 ;;; Dec-12-91 by K.Ishii | |
57 ;;; $BJ8@a3X=,$,$&$^$/$G$-$J$$$3$H$,$"$k$?$a!"(Bsj3-result-buffer $B$rJQ99(B | |
58 ;;; | |
59 ;;; sj3-get-stdy $B$G(B "Count exceed." $B%(%i!<$rNI$/5/$3$9$N$G:o=|(B | |
60 | |
61 ;;; Nov-26-91 by K.Ishii | |
62 ;;; sj3-server-open $B$G(B host_name $B$H(B user_name $B$rEO$9=gHV$N=$@5(B | |
63 ;;; | |
64 ;;; sj3-server-henkan-next $B$r<B9T$7$F$h$/5/$3$k(B "Count exceed." $B$H$$$&(B | |
65 ;;; $B%P%0$N=$@5(B | |
66 ;;; | |
67 ;;; sj3-server-henkan-next $B$G0l3gJQ49$HJ8@aJQ49$GBh0l8uJd$,0c$C$?>l9g(B | |
68 ;;; $B$K5/$3$k%P%0$N=$@5(B($B$3$l$KH<$$J8@a3X=,(B sj3-server-b-study $B$N=$@5(B) | |
69 | |
70 ;;; | |
71 ;;; Sj3 deamon command constants | |
72 ;;; | |
73 | |
74 (defconst SJ3_OPEN 1 "$BMxMQ<TEPO?(B") | |
75 (defconst SJ3_CLOSE 2 "$BMxMQ<T:o=|(B") | |
76 ;;; | |
77 (defconst SJ3_DICADD 11 "$B<-=qDI2C(B") | |
78 (defconst SJ3_DICDEL 12 "$B<-=q:o=|(B") | |
79 ;;; | |
80 (defconst SJ3_OPENSTDY 21 "$B3X=,%U%!%$%k%*!<%W%s(B") | |
81 (defconst SJ3_CLOSESTDY 22 "$B3X=,%U%!%$%k%/%m!<%:(B") | |
82 (defconst SJ3_STDYSIZE 23 "") | |
83 ;;; | |
84 (defconst SJ3_LOCK 31 "$B<-=q%m%C%/(B") | |
85 (defconst SJ3_UNLOCK 32 "$B<-=q%"%s%m%C%/(B") | |
86 ;;; | |
87 (defconst SJ3_BEGIN 41 "$BJQ493+;O(B") | |
88 (defconst SJ3_BEGIN_EUC 111 "$BJQ493+;O(B") | |
89 ;;; | |
90 (defconst SJ3_TANCONV 51 "$B:FJQ49!JJ8@a?-=L!K(B") | |
91 (defconst SJ3_TANCONV_EUC 112 "$B:FJQ49!JJ8@a?-=L!K(B") | |
92 (defconst SJ3_KOUHO 54 "$B8uJd(B") | |
93 (defconst SJ3_KOUHO_EUC 115 "$B8uJd(B") | |
94 (defconst SJ3_KOUHOSU 55 "$B8uJd?t(B") | |
95 (defconst SJ3_KOUHOSU_EUC 116 "$B8uJd?t(B") | |
96 ;;; | |
97 (defconst SJ3_STDY 61 "$BJ8@a3X=,(B") | |
98 (defconst SJ3_END 62 "$BJ8@aD93X=,(B") | |
99 (defconst SJ3_END_EUC 117 "$BJ8@aD93X=,(B") | |
100 ;;; | |
101 (defconst SJ3_WREG 71 "$BC18lEPO?(B") | |
102 (defconst SJ3_WREG_EUC 118 "$BC18lEPO?(B") | |
103 (defconst SJ3_WDEL 72 "$BC18l:o=|(B") | |
104 (defconst SJ3_WDEL_EUC 119 "$BC18l:o=|(B") | |
105 ;;; | |
106 (defconst SJ3_MKDIC 81 "") | |
107 (defconst SJ3_MKSTDY 82 "") | |
108 (defconst SJ3_MKDIR 83 "") | |
109 (defconst SJ3_ACCESS 84 "") | |
110 ;;; | |
111 (defconst SJ3_WSCH 91 "$BC18l8!:w(B") | |
112 (defconst SJ3_WSCH_EUC 120 "$BC18l8!:w(B") | |
113 (defconst SJ3_WNSCH 92 "") | |
114 (defconst SJ3_WNSCH_EUC 121 "") | |
115 ;;; | |
116 (defconst SJ3_VERSION 103 "") | |
117 | |
118 ;;; Sj3 server version error | |
119 (defconst SJ3_DifferentVersion 11 "") | |
120 (defvar *sj3-current-server-version* nil) | |
121 | |
122 (defvar sj3-server-buffer nil "Buffer associated with Sj3 server process.") | |
123 | |
124 (defvar sj3-server-process nil "Sj3 Kana Kanji hankan process.") | |
125 | |
126 (defvar sj3-command-tail-position nil) | |
127 (defvar sj3-command-buffer nil) | |
128 | |
129 (defvar sj3-result-buffer nil) | |
130 (defvar sj3-henkan-string nil) | |
131 (defvar sj3-bunsetu-suu nil) | |
132 | |
133 (defvar sj3-return-code nil) | |
134 (defvar sj3-error-code nil) | |
135 | |
136 (defvar sj3-stdy-size nil) | |
137 (defvar sj3-user-dict-list nil) | |
138 (defvar sj3-sys-dict-list nil) | |
139 (defvar sj3-yomi-llist nil) | |
140 ;;; | |
141 ;;; Put data into buffer | |
142 ;;; | |
143 | |
144 (defun sj3-put-4byte (integer) | |
145 (insert (logand 255 (ash integer -24)) | |
146 (logand 255 (ash integer -16)) | |
147 (logand 255 (ash integer -8)) | |
148 (logand 255 (ash integer 0)) )) | |
149 | |
150 (defun sj3-put-string (str) | |
151 (insert str 0)) | |
152 | |
153 (defun sj3-put-string* (str) | |
154 (let ((sstr (if (= *sj3-current-server-version* 2) | |
155 (code-convert-string str *internal* *euc-japan*) | |
156 (code-convert-string str *internal* *sjis*)))) | |
157 (insert sstr 0))) | |
158 | |
159 ;;; | |
160 ;;; Get data from buffer | |
161 ;;; | |
162 | |
163 (defun sj3-get-4byte () | |
164 | |
165 (let ((c 0) (point (point))) | |
166 ;;;(goto-char (point-min)) | |
167 (while (< (point-max) (+ point 4)) | |
168 (accept-process-output) | |
169 (if (= c 10) (if t (progn (sit-for 0) (setq c 0)) (error "Count exceed."))) | |
170 (setq c (1+ c))) | |
171 (goto-char point)) | |
172 | |
173 (let ((point (point))) | |
174 (if (not (or (and (= (char-after point) 0) | |
175 (< (char-after (+ point 1)) 128)) | |
176 (and (= (char-after point) 255) | |
177 (<= 128 (char-after (+ point 1)))))) | |
178 (error "sj3-get-4byte: integer range overflow.")) | |
179 (prog1 | |
180 (logior | |
181 (lsh (char-after point) 24) | |
182 (lsh (char-after (+ point 1)) 16) | |
183 (lsh (char-after (+ point 2)) 8) | |
184 (lsh (char-after (+ point 3)) 0)) | |
185 (goto-char (+ (point) 4))))) | |
186 | |
187 (defun sj3-get-byte () | |
188 (let ((c 0) (point (point))) | |
189 (while (< (point-max) (1+ point)) | |
190 (accept-process-output) | |
191 (if (= c 10) (if t (progn (sit-for 0) (setq c 0)) (error "Count exceed."))) | |
192 (setq c (1+ c))) | |
193 (goto-char point) | |
194 (prog1 | |
195 (lsh (char-after point) 0) | |
196 (forward-char 1)))) | |
197 | |
198 (defun sj3-get-string () | |
199 (let ((point (point))) | |
200 (skip-chars-forward "^\0") | |
201 (let ((c 0)) | |
202 (while (eobp) | |
203 (accept-process-output) | |
204 (if (= c 10) (if t (progn (sit-for 0) (setq c 0)) (error "Count exceed"))) | |
205 (setq c (1+ c)) | |
206 (skip-chars-forward "^\0"))) | |
207 (prog1 | |
208 (buffer-substring point (point)) | |
209 (forward-char 1)))) | |
210 | |
211 (defun sj3-get-string* () | |
212 (let ((point (point))) | |
213 (sj3-get-convert-string) | |
214 (buffer-substring point (1- (point))))) | |
215 | |
216 (defun sj3-get-convert-string () | |
217 (let ((point (point)) (c 0) str) | |
218 (while (not (search-forward "\0" nil t)) | |
219 (accept-process-output) | |
220 (goto-char point) | |
221 (if (= c 10) (if t (progn (sit-for 0) (setq c 0)) (error "Count exceed"))) | |
222 (setq c (1+ c))) | |
223 (setq str (buffer-substring point (1- (point)))) | |
224 (delete-region point (point)) | |
225 (insert (if (= *sj3-current-server-version* 2) | |
226 (code-convert-string str *euc-japan* *internal*) | |
227 (code-convert-string str *sjis* *internal*)) 0))) | |
228 | |
229 (defun sj3-get-stdy () | |
230 (let ((c 0) (point (point))) | |
231 (while (< (point-max) (+ point sj3-stdy-size)) | |
232 (accept-process-output) | |
233 (if (>= c 10) (progn (sit-for 0) (setq c 0))) ;;; delete error | |
234 (setq c (1+ c))) | |
235 (goto-char (+ point sj3-stdy-size)))) | |
236 | |
237 ;;; | |
238 ;;; Sj3 Server Command Primitives | |
239 ;;; | |
240 | |
241 (defun sj3-command-start (command) | |
242 (set-buffer sj3-command-buffer) | |
243 (goto-char (point-min)) | |
244 (if (not (= (point-max) (+ sj3-command-tail-position 1024))) | |
245 (error "sj3 command start error")) | |
246 (delete-region (point-min) sj3-command-tail-position) | |
247 (sj3-put-4byte command)) | |
248 | |
249 (defun sj3-command-reset () | |
250 (save-excursion | |
251 (progn | |
252 ;;; for Mule | |
253 (if (fboundp 'set-process-coding-system) | |
254 (set-process-coding-system sj3-server-process *noconv* *noconv*)) | |
255 ;;; for Nemacs 3.0 and later | |
256 ;; (if (fboundp 'set-process-kanji-code) | |
257 ;; (set-process-kanji-code sj3-server-process 0)) | |
258 (set-buffer sj3-command-buffer) | |
259 (setq mc-flag nil) ;;; for Mule | |
260 ;; (setq kanji-flag nil) | |
261 ;; (setq kanji-fileio-code 0) ;;; for Nemacs 2.1 | |
262 (buffer-disable-undo sj3-command-buffer) | |
263 (erase-buffer) | |
264 (setq sj3-command-tail-position (point-min)) | |
265 (let ((max 1024) (i 0)) | |
266 (while (< i max) | |
267 (insert 0) | |
268 (setq i (1+ i))))))) | |
269 | |
270 (defun sj3-command-end () | |
271 (set-buffer sj3-server-buffer) | |
272 (erase-buffer) | |
273 (set-buffer sj3-command-buffer) | |
274 (setq sj3-command-tail-position (point)) | |
275 ;; (process-send-region sj3-server-process (point-min) | |
276 ;; (+ (point-min) (lsh (1+ (lsh (- (point) (point-min)) -10)) 10))) | |
277 (process-send-region sj3-server-process (point-min) (1+ (point))) | |
278 ) | |
279 | |
280 ;;; | |
281 ;;; Sj3 Server Reply primitives | |
282 ;;; | |
283 | |
284 (defun sj3-get-result () | |
285 (set-buffer sj3-server-buffer) | |
286 (condition-case () | |
287 (accept-process-output sj3-server-process) | |
288 (error nil)) | |
289 (goto-char (point-min))) | |
290 | |
291 (defun sj3-get-return-code () | |
292 (setq sj3-return-code (sj3-get-4byte)) | |
293 (setq sj3-error-code (if (= sj3-return-code 0) nil | |
294 (sj3-error-symbol sj3-return-code))) | |
295 (if sj3-error-code nil | |
296 sj3-return-code)) | |
297 | |
298 ;;; | |
299 ;;; Sj3 Server Interface: sj3-server-open | |
300 ;;; | |
301 | |
302 ;(defvar *sj3-server-max-kana-string-length* 1000) | |
303 ;(defvar *sj3-server-max-bunsetu-suu* 1000) | |
304 | |
305 (defvar *sj3-server-version* 2) | |
306 (setq *sj3-server-version* 2) | |
307 (defvar *sj3-program-name* "sj3-egg-m") | |
308 (defvar *sj3-service-name* "sj3") | |
309 | |
310 (defun sj3-server-open (server-host-name login-name) | |
311 (if (sj3-server-active-p) t | |
312 (let ((server_version *sj3-server-version*) | |
313 (sj3serv_name | |
314 (if (or (null server-host-name) | |
315 (equal server-host-name "") | |
316 (equal server-host-name "unix")) | |
317 (system-name) | |
318 server-host-name)) | |
319 (user_name | |
320 (if (or (null login-name) (equal login-name "")) | |
321 (user-login-name) | |
322 login-name)) | |
323 (host_name (system-name)) | |
324 (program_name | |
325 (format "%d.%s" | |
326 (string-to-int (substring (make-temp-name "") 1 6)) | |
327 *sj3-program-name*))) | |
328 (setq sj3-server-process | |
329 (condition-case var | |
330 (open-network-stream "Sj3" " [Sj3 Output Buffer] " | |
331 sj3serv_name *sj3-service-name* ) | |
332 (error | |
333 (cond((string-match "Unknown host" (car (cdr var))) | |
334 (setq sj3-error-code (list ':SJ3_UNKNOWN_HOST | |
335 sj3serv_name))) | |
336 ((string-match "Unknown service" (car (cdr var))) | |
337 (setq sj3-error-code (list ':SJ3_UNKNOWN_SERVICE | |
338 *sj3-service-name*))) | |
339 (t ;;; "Host ... not respoding" | |
340 (setq sj3-error-code ':SJ3_SOCK_OPEN_FAIL))) | |
341 nil))) | |
342 (if (null sj3-server-process) nil | |
343 (process-kill-without-query sj3-server-process) | |
344 (setq sj3-server-buffer (get-buffer " [Sj3 Output Buffer] ")) | |
345 (setq sj3-command-buffer (get-buffer-create " [Sj3 Command Buffer] ")) | |
346 (setq sj3-result-buffer (get-buffer-create " [Sj3 Result Buffer] ")) | |
347 | |
348 (save-excursion | |
349 ;;; for Mule | |
350 (if (fboundp 'set-process-coding-system) | |
351 (set-process-coding-system | |
352 sj3-server-process *noconv* *noconv*)) | |
353 ;;; for Nemacs 3.0 | |
354 ;; (if (fboundp 'set-process-kanji-code) | |
355 ;; (set-process-kanji-code sj3-server-process 0)) | |
356 (progn | |
357 (set-buffer sj3-server-buffer) | |
358 (setq mc-flag nil) ;;; for Mule | |
359 ;; (setq kanji-flag nil) | |
360 ;;; for Nemacs 2.1 | |
361 ;; (setq kanji-fileio-code 0) | |
362 (buffer-disable-undo sj3-server-buffer) | |
363 ) | |
364 (progn | |
365 (set-buffer sj3-result-buffer) | |
366 (setq mc-flag nil) ;;; for Mule | |
367 ;; (setq kanji-flag nil) | |
368 ;;; for Nemacs 2.1 | |
369 ;; (setq kanji-fileio-code 0) | |
370 (buffer-disable-undo sj3-result-buffer)) | |
371 (progn | |
372 (set-buffer sj3-command-buffer) | |
373 (setq mc-flag nil) ;;; for Mule | |
374 ;; (setq kanji-flag nil) | |
375 ;;; for Nemacs 2.1 | |
376 ;; (setq kanji-fileio-code 0) | |
377 (buffer-disable-undo sj3-command-buffer) | |
378 (erase-buffer) | |
379 (setq sj3-command-tail-position (point-min)) | |
380 (let ((max 1024) (i 0)) | |
381 (while (< i max) | |
382 (insert 0) | |
383 (setq i (1+ i))))) | |
384 (sj3-clear-dict-list) | |
385 (sj3-command-start SJ3_OPEN) | |
386 (sj3-put-4byte server_version) | |
387 (sj3-put-string host_name) | |
388 (sj3-put-string user_name) | |
389 (sj3-put-string program_name) | |
390 (sj3-command-end) | |
391 (sj3-get-result) | |
392 (sj3-get-return-code) | |
393 (if (= sj3-return-code SJ3_DifferentVersion) | |
394 (progn (sj3-command-start SJ3_OPEN) | |
395 (sj3-put-4byte 1) | |
396 (sj3-put-string host_name) | |
397 (sj3-put-string user_name) | |
398 (sj3-put-string program_name) | |
399 (sj3-command-end) | |
400 (sj3-get-result) | |
401 (sj3-get-return-code) | |
402 (if (not (= sj3-return-code 0)) | |
403 (sj3-connection-error) | |
404 nil) | |
405 ) | |
406 nil) | |
407 (if (or (= sj3-return-code 0) (> -1 sj3-return-code)) | |
408 (progn (setq *sj3-current-server-version* 1) | |
409 (if (not (= sj3-return-code 0)) | |
410 (setq *sj3-current-server-version* (- 0 sj3-return-code)) | |
411 nil) | |
412 (sj3-get-stdy-size) | |
413 ) | |
414 nil) | |
415 ))))) | |
416 | |
417 (defun sj3-server-active-p () | |
418 (and sj3-server-process | |
419 (eq (process-status sj3-server-process) 'open))) | |
420 | |
421 (defun sj3-connection-error () | |
422 (setq sj3-error-code ':sj3-no-connection) | |
423 (setq sj3-return-code -1) | |
424 nil) | |
425 | |
426 (defun sj3-zero-arg-command (op) | |
427 (if (sj3-server-active-p) | |
428 (progn | |
429 (sj3-command-start op) | |
430 (sj3-command-end) | |
431 (sj3-get-result) | |
432 (sj3-get-return-code)) | |
433 (sj3-connection-error))) | |
434 | |
435 (defun sj3-server-close () | |
436 (let (dict-no) | |
437 (while (and (sj3-server-active-p) (setq dict-no (car sj3-sys-dict-list))) | |
438 (sj3-server-close-dict dict-no) | |
439 (setq sj3-sys-dict-list (cdr sj3-sys-dict-list))) | |
440 (while (and (sj3-server-active-p) (setq dict-no (car sj3-user-dict-list))) | |
441 (sj3-server-close-dict dict-no) | |
442 (setq sj3-user-dict-list (cdr sj3-user-dict-list))) | |
443 (sj3-clear-dict-list)) | |
444 (sj3-server-close-stdy) | |
445 (sj3-zero-arg-command SJ3_CLOSE) | |
446 (if (sj3-server-active-p) | |
447 (delete-process sj3-server-process)) | |
448 (if sj3-server-buffer | |
449 (kill-buffer sj3-server-buffer)) | |
450 (if sj3-command-buffer | |
451 (kill-buffer sj3-command-buffer)) | |
452 (if sj3-result-buffer | |
453 (kill-buffer sj3-result-buffer)) | |
454 (setq sj3-server-process nil) | |
455 (setq sj3-server-buffer nil) | |
456 (setq sj3-command-buffer nil) | |
457 (setq sj3-result-buffer nil)) | |
458 | |
459 (defun sj3-clear-dict-list () | |
460 (setq sj3-sys-dict-list nil) | |
461 (setq sj3-user-dict-list nil)) | |
462 | |
463 (or (fboundp 'si:kill-emacs) | |
464 (fset 'si:kill-emacs (symbol-function 'kill-emacs))) | |
465 | |
466 (defun kill-emacs (&optional arg) | |
467 (interactive "P") | |
468 (if (sj3-server-active-p) | |
469 (progn | |
470 (sj3-server-close))) | |
471 (si:kill-emacs arg)) | |
472 | |
473 (defun sj3-get-stdy-size () | |
474 (sj3-zero-arg-command SJ3_STDYSIZE) | |
475 (if (not (= sj3-return-code 0)) nil | |
476 (setq sj3-stdy-size (sj3-get-4byte)))) | |
477 | |
478 (defun sj3-put-stdy-dmy () | |
479 (let ((i 0)) | |
480 (while (< i sj3-stdy-size) | |
481 (insert 0) | |
482 (setq i (1+ i))))) | |
483 | |
484 ;;; Sj3 Result Buffer's layout: | |
485 ;;; | |
486 ;;; { length:4 kana 0 kouhoSuu:4 kouhoNo:4 | |
487 ;;; {studyData kanji 0 } ... | |
488 ;;; } | |
489 ;;; 0 0 0 0 | |
490 | |
491 (defun sj3-skip-length () | |
492 (goto-char (+ (point) 4))) | |
493 | |
494 (defun sj3-skip-4byte () | |
495 (goto-char (+ (point) 4))) | |
496 | |
497 (defun sj3-skip-yomi () | |
498 (skip-chars-forward "^\0") (forward-char 1)) | |
499 | |
500 (defun sj3-skip-stdy () | |
501 (goto-char (+ (point) sj3-stdy-size))) | |
502 | |
503 ;;; | |
504 ;;; entry function | |
505 ;;; | |
506 (defun sj3-server-henkan-begin (henkan-string) | |
507 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
508 (let ((inhibit-quit t) mb-str) | |
509 (save-excursion | |
510 (setq sj3-henkan-string henkan-string) | |
511 (if (= *sj3-current-server-version* 2) | |
512 (setq mb-str (code-convert-string henkan-string *internal* *euc-japan*)) | |
513 (setq mb-str (code-convert-string henkan-string *internal* *sjis*)) | |
514 ) | |
515 (set-buffer sj3-result-buffer) | |
516 (erase-buffer) | |
517 (setq sj3-bunsetu-suu 0) | |
518 (setq sj3-yomi-llist nil) | |
519 (goto-char (point-min)) | |
520 (if (= *sj3-current-server-version* 2) | |
521 (sj3-command-start SJ3_BEGIN_EUC) | |
522 (sj3-command-start SJ3_BEGIN) | |
523 ) | |
524 (sj3-put-string mb-str) | |
525 (sj3-command-end) | |
526 (sj3-get-result) | |
527 (sj3-get-return-code) | |
528 (if (not (= sj3-return-code 0)) nil | |
529 (let ((yp 0) p0 yl offset) | |
530 (sj3-get-4byte) | |
531 (set-buffer sj3-result-buffer) | |
532 (delete-region (point) (point-max)) | |
533 (setq p0 (point)) | |
534 (insert sj3-henkan-string 0 0 0 0) | |
535 (goto-char p0) | |
536 (set-buffer sj3-server-buffer) | |
537 (while (> (setq yl (sj3-get-byte)) 0) | |
538 (let ((startp (point)) | |
539 (ystr (substring mb-str yp (+ yp yl))) | |
540 endp) | |
541 (setq yp (+ yp yl)) | |
542 (if (= *sj3-current-server-version* 2) | |
543 (setq yl (length (code-convert-string ystr *euc-japan* *internal*))) | |
544 (setq yl (length (code-convert-string ystr *sjis* *internal*))) | |
545 ) | |
546 (sj3-get-stdy) ;;; skip study-data | |
547 (sj3-get-convert-string) | |
548 (setq endp (point)) | |
549 (set-buffer sj3-result-buffer) | |
550 (setq p0 (point)) | |
551 (forward-char yl) | |
552 (setq sj3-yomi-llist (append sj3-yomi-llist (list yl))) | |
553 (insert 0) ;;; yomi | |
554 (sj3-put-4byte 1) ;;; kouho suu | |
555 (sj3-put-4byte 0) ;;; current kouho number | |
556 (insert-buffer-substring sj3-server-buffer startp endp) | |
557 ;;; insert study data and kanji strings | |
558 (setq offset (- (point) p0)) | |
559 (goto-char p0) (sj3-put-4byte offset) | |
560 (goto-char (+ (point) offset)) | |
561 (setq sj3-return-code (1+ sj3-return-code)) | |
562 (set-buffer sj3-server-buffer))) | |
563 (setq sj3-bunsetu-suu sj3-return-code))))))) | |
564 ;;; | |
565 ;;; entry function | |
566 ;;; | |
567 (defun sj3-server-henkan-quit () t) | |
568 | |
569 (defun sj3-get-yomi-suu-org () | |
570 (if (setq sj3-yomi-llist (cdr sj3-yomi-llist)) | |
571 (car sj3-yomi-llist) | |
572 0)) | |
573 | |
574 ;;; | |
575 ;;; entry function | |
576 ;;; | |
577 (defun sj3-server-henkan-end (bunsetu-no) | |
578 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
579 (let ((inhibit-quit t)) | |
580 (save-excursion | |
581 (let (length ystr len kouho-no kouho-suu p0 (ylist nil)) | |
582 (set-buffer sj3-result-buffer) | |
583 (goto-char (point-min)) | |
584 (let ((max (if (and (integerp bunsetu-no) | |
585 (<= 0 bunsetu-no) | |
586 (<= bunsetu-no sj3-bunsetu-suu)) | |
587 bunsetu-no | |
588 sj3-bunsetu-suu)) | |
589 (i 0)) | |
590 (while (< i max) | |
591 (setq length (sj3-get-4byte)) | |
592 (setq p0 (point)) | |
593 (setq ystr (sj3-get-string)) | |
594 (setq len (1- (- (point) p0))) | |
595 (setq kouho-suu (sj3-get-4byte)) ;;; kouho suu | |
596 (setq kouho-no (sj3-get-4byte)) | |
597 (if (and (> kouho-no 0) | |
598 (< kouho-no (- kouho-suu 2)) | |
599 (> kouho-suu 3)) | |
600 (sj3-server-b-study kouho-no)) | |
601 (setq ylist (cons (list len ystr kouho-suu (point)) ylist)) | |
602 (goto-char (+ p0 length)) | |
603 (setq i (1+ i))) | |
604 (setq ylist (nreverse ylist)) | |
605 (setq i 1) | |
606 (let ((yp 0) (op 0) (ydata (car ylist)) (ol (car sj3-yomi-llist))) | |
607 (while (< i max) | |
608 (let ((yl (nth 0 ydata))) | |
609 (setq ylist (cdr ylist)) | |
610 (if (and (= yp op) (= yl ol)) | |
611 (let ((pp (+ yp yl))) | |
612 (setq yp pp) | |
613 (setq op pp) | |
614 (setq ydata (car ylist)) | |
615 (setq ol (sj3-get-yomi-suu-org))) | |
616 (let ((str (nth 1 ydata)) | |
617 (ent (nth 2 ydata))) | |
618 (setq ydata (car ylist)) | |
619 (setq yp (+ yp yl)) | |
620 (while (< op yp) | |
621 (setq op (+ op ol)) | |
622 (setq ol (sj3-get-yomi-suu-org))) | |
623 (if (or (= ent 2) (= (nth 2 ydata) 2)) nil | |
624 (let ((sub (- op yp)) (yl1 (nth 0 ydata))) | |
625 (set-buffer sj3-result-buffer) | |
626 (goto-char (nth 3 ydata)) | |
627 (sj3-server-cl-study str (nth 1 ydata)) | |
628 (if (and (not (= sub yl1)) (not (= sub (- yl1 ol)))) | |
629 nil | |
630 (setq i (1+ i)) | |
631 (setq ylist (cdr ylist)) | |
632 (setq ydata (car ylist)) | |
633 (if (= sub yl1) nil | |
634 (setq op (+ op ol)) | |
635 (setq ol (sj3-get-yomi-suu-org)))))))) | |
636 (setq i (1+ i)))) | |
637 (if (or (null ydata) (= (nth 0 ydata) ol) (= (nth 2 ydata) 2)) | |
638 sj3-return-code | |
639 (goto-char (nth 3 ydata)) | |
640 (sj3-server-cl-study (nth 1 ydata) ""))))))))) | |
641 | |
642 (defun sj3-server-cl-study (str1 str2) | |
643 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
644 (save-excursion | |
645 (if (= *sj3-current-server-version* 2) | |
646 (sj3-command-start SJ3_END_EUC) | |
647 (sj3-command-start SJ3_END)) | |
648 (sj3-put-string* str1) | |
649 (sj3-put-string* str2) | |
650 (if (string= str2 "") (sj3-put-stdy-dmy) | |
651 (let (p0) | |
652 (set-buffer sj3-result-buffer) | |
653 (setq p0 (point)) | |
654 (set-buffer sj3-command-buffer) | |
655 (insert-buffer-substring sj3-result-buffer p0 (+ p0 sj3-stdy-size)))) | |
656 (sj3-command-end) | |
657 (sj3-get-result) | |
658 (sj3-get-return-code)))) | |
659 | |
660 (defun sj3-server-b-study (no) | |
661 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
662 (save-excursion | |
663 (let ((i 0) p0) | |
664 (set-buffer sj3-result-buffer) | |
665 (while (< i no) | |
666 (sj3-skip-stdy) | |
667 (sj3-skip-yomi) | |
668 (setq i (1+ i))) | |
669 (setq p0 (point)) | |
670 (sj3-command-start SJ3_STDY) | |
671 (insert-buffer-substring sj3-result-buffer p0 (+ p0 sj3-stdy-size)) | |
672 (sj3-command-end) | |
673 (sj3-get-result) | |
674 (sj3-get-return-code))))) | |
675 | |
676 (defun sj3-result-goto-bunsetu (bunsetu-no) | |
677 (goto-char (point-min)) | |
678 (let (length (i 0)) | |
679 (while (< i bunsetu-no) | |
680 (setq length (sj3-get-4byte)) | |
681 (goto-char (+ (point) length)) | |
682 (setq i (1+ i))))) | |
683 | |
684 ;;; | |
685 ;;; entry function | |
686 ;;; | |
687 (defun sj3-server-henkan-kakutei (bunsetu-no jikouho-no) | |
688 (cond((not (sj3-server-active-p)) (sj3-connection-error)) | |
689 ((or (< bunsetu-no 0) (<= sj3-bunsetu-suu bunsetu-no)) | |
690 nil) | |
691 (t | |
692 (let ((inhibit-quit t)) | |
693 (save-excursion | |
694 (set-buffer sj3-result-buffer) | |
695 (let (kouho-suu) | |
696 (sj3-result-goto-bunsetu bunsetu-no) | |
697 (sj3-skip-length) | |
698 (sj3-skip-yomi) | |
699 (setq kouho-suu (sj3-get-4byte)) | |
700 (if (or (< jikouho-no 0) (<= kouho-suu jikouho-no)) nil | |
701 (delete-char 4) (sj3-put-4byte jikouho-no) | |
702 t))))))) | |
703 | |
704 ;;; | |
705 ;;; entry function | |
706 ;;; | |
707 (defun sj3-server-henkan-next (bunsetu-no) | |
708 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
709 (let ((inhibit-quit t)) | |
710 (save-excursion | |
711 (let (p0 p1 kouho-suu length ystr) | |
712 (set-buffer sj3-result-buffer) | |
713 (sj3-result-goto-bunsetu bunsetu-no) | |
714 (sj3-skip-length) | |
715 (setq p0 (point)) | |
716 (setq ystr (sj3-get-string)) | |
717 (setq p1 (point)) | |
718 (setq kouho-suu (sj3-get-4byte)) | |
719 (if (> kouho-suu 1) t | |
720 (let ((ksuu (sj3-server-henkan-kouho ystr)) (startp 0) endp) | |
721 (if (< ksuu 0) sj3-return-code | |
722 (let (kanji) | |
723 (set-buffer sj3-result-buffer) | |
724 (sj3-skip-4byte) | |
725 (sj3-skip-stdy) | |
726 (setq kanji (sj3-get-string)) | |
727 (if (> ksuu 1) | |
728 (let ((i 1)) | |
729 (set-buffer sj3-server-buffer) | |
730 (sj3-get-4byte) | |
731 (setq startp (point)) | |
732 (sj3-get-stdy) | |
733 (let ((kkanji (sj3-get-string*))) | |
734 (if (equal kanji kkanji) | |
735 (setq startp (point)) | |
736 (setq ksuu (1+ ksuu)) | |
737 (setq i (1+ i)))) | |
738 (while (< i ksuu) | |
739 (sj3-get-4byte) | |
740 (delete-char -4) | |
741 (sj3-get-stdy) | |
742 (sj3-get-convert-string) | |
743 (setq i (1+ i))) | |
744 (setq endp (point)))) | |
745 (set-buffer sj3-result-buffer) | |
746 (if (> startp 0) | |
747 (insert-buffer-substring sj3-server-buffer startp endp)) | |
748 (sj3-put-kata ystr) | |
749 (insert ystr 0) | |
750 (setq length (- (point) p0)) | |
751 (goto-char p1) | |
752 (delete-char 4) | |
753 (if (<= ksuu 0)(sj3-put-4byte 3) ;;; | |
754 (sj3-put-4byte (+ ksuu 2))) ;;; put kouho-suu | |
755 (goto-char p0) | |
756 (delete-char -4) | |
757 (sj3-put-4byte length)) | |
758 t)))))))) | |
759 | |
760 (defun sj3-server-henkan-kouho (str) | |
761 (if (not (sj3-server-active-p)) -1 | |
762 (let ((mb-str (if (= *sj3-current-server-version* 2) | |
763 (code-convert-string str *internal* *euc-japan*) | |
764 (code-convert-string str *internal* *sjis*))) | |
765 len kouho-suu) | |
766 (setq len (length mb-str)) | |
767 (setq kouho-suu (sj3-server-henkan-kouho-suu len mb-str)) | |
768 (if (<= kouho-suu 0) nil | |
769 (if (= *sj3-current-server-version* 2) | |
770 (sj3-command-start SJ3_KOUHO_EUC) | |
771 (sj3-command-start SJ3_KOUHO)) | |
772 (sj3-put-4byte len) | |
773 (sj3-put-string mb-str) | |
774 (sj3-command-end) | |
775 (sj3-get-result) | |
776 (sj3-get-return-code) | |
777 (if (not (= sj3-return-code 0)) -1)) | |
778 kouho-suu))) | |
779 | |
780 (defun sj3-put-kata (str) | |
781 (setq str (copy-sequence str)) | |
782 (let ((i 0) (len (length str))) | |
783 (while (< i len) | |
784 (if (/= (aref str i) lc-jp) | |
785 (setq i (1+ i)) | |
786 (if (= (aref str (1+ i)) ?\244) | |
787 (aset str (1+ i) ?\245)) | |
788 (setq i (+ i 3))))) | |
789 (insert str 0)) | |
790 | |
791 (defun sj3-server-henkan-kouho-suu (yomi-length yomi) | |
792 (if (not (sj3-server-active-p)) -1 | |
793 (save-excursion | |
794 (if (= *sj3-current-server-version* 2) | |
795 (sj3-command-start SJ3_KOUHOSU_EUC) | |
796 (sj3-command-start SJ3_KOUHOSU)) | |
797 (sj3-put-4byte yomi-length) | |
798 (sj3-put-string yomi) | |
799 (sj3-command-end) | |
800 (sj3-get-result) | |
801 (sj3-get-return-code) | |
802 (if (not (= sj3-return-code 0)) -1 | |
803 (sj3-get-4byte))))) | |
804 | |
805 ;;; | |
806 ;;; entry function | |
807 ;;; | |
808 (defun sj3-server-bunsetu-henkou (bunsetu-no bunsetu-length) | |
809 (cond((not (sj3-server-active-p)) (sj3-connection-error)) | |
810 ((or (< bunsetu-no 0) (<= sj3-bunsetu-suu bunsetu-no)) | |
811 nil) | |
812 (t | |
813 (let ((inhibit-quit t)) | |
814 (save-excursion | |
815 (let (yp0 p0 p1 str len1 len2 bunsetu-suu (bno bunsetu-no)) | |
816 (set-buffer sj3-result-buffer) | |
817 (setq yp0 (sj3-yomi-point bunsetu-no)) | |
818 (setq p0 (point)) | |
819 (setq str (sj3-get-yomi* yp0 bunsetu-length)) | |
820 (setq len1 (length str)) | |
821 (setq bunsetu-suu sj3-bunsetu-suu) | |
822 (let (point length) | |
823 (setq len2 len1) | |
824 (while (and (< bno sj3-bunsetu-suu) (> len2 0)) | |
825 (setq length (sj3-get-4byte)) | |
826 (setq point (point)) | |
827 (skip-chars-forward "^\0") | |
828 (setq len2 (- len2 (- (point) point))) | |
829 (goto-char (+ point length)) | |
830 (setq bno (1+ bno)))) | |
831 (setq p1 (point)) | |
832 (delete-region p0 p1) | |
833 (setq sj3-bunsetu-suu (- sj3-bunsetu-suu (- bno bunsetu-no))) | |
834 (if (= (sj3-put-tanconv str) 0) | |
835 (if (not (= len2 0)) | |
836 (let ((len (- 0 len2)) (yp1 (+ yp0 len1)) | |
837 ystr mb-str) | |
838 (if (or (> bno (1+ bunsetu-no)) (= bno bunsetu-suu)) | |
839 (setq ystr (sj3-get-yomi yp1 len)) | |
840 (let (ll length i) | |
841 (set-buffer sj3-result-buffer) | |
842 (setq p0 (point)) | |
843 (setq length (sj3-get-4byte)) | |
844 (skip-chars-forward "^\0") | |
845 (setq ll (+ len (- (point) (+ p0 4)))) | |
846 (setq p1 (+ p0 (+ length 4))) | |
847 (setq ystr (sj3-get-yomi yp1 ll)) | |
848 (setq mb-str (if (= *sj3-current-server-version* 2) | |
849 (code-convert-string ystr *internal* *euc-japan*) | |
850 (code-convert-string ystr *internal* *sjis*))) | |
851 (setq i (sj3-server-henkan-kouho-suu | |
852 (length mb-str) mb-str)) | |
853 (set-buffer sj3-result-buffer) | |
854 (if (= i 0) (setq ystr (sj3-get-yomi yp1 len)) | |
855 (delete-region p0 p1) | |
856 (setq sj3-bunsetu-suu (1- sj3-bunsetu-suu)) | |
857 (setq len ll)) | |
858 (goto-char p0))) | |
859 (sj3-put-tanconv ystr)))) | |
860 (if (= sj3-return-code -1) nil | |
861 sj3-bunsetu-suu))))))) | |
862 | |
863 (defun sj3-put-tanconv (str) | |
864 (let ((point (point)) len ksuu | |
865 (mb-str (if (= *sj3-current-server-version* 2) | |
866 (code-convert-string str *internal* *euc-japan*) | |
867 (code-convert-string str *internal* *sjis*)))) | |
868 (setq len (length mb-str)) | |
869 (setq ksuu (sj3-server-henkan-kouho-suu len mb-str)) | |
870 (if (>= ksuu 0) | |
871 (let (offset) | |
872 (set-buffer sj3-result-buffer) | |
873 (insert str 0) | |
874 (if (or (= ksuu 0) | |
875 (not (sj3-server-tanconv len mb-str))) | |
876 (put-kata-and-hira str) | |
877 (let (p0 p1) | |
878 (set-buffer sj3-result-buffer) | |
879 (sj3-put-4byte 1) | |
880 (sj3-put-4byte 0) | |
881 (set-buffer sj3-server-buffer) | |
882 (sj3-get-4byte) | |
883 (setq p0 (point)) | |
884 (sj3-get-stdy) | |
885 (sj3-get-convert-string) | |
886 (setq p1 (point)) | |
887 (set-buffer sj3-result-buffer) | |
888 (insert-buffer-substring sj3-server-buffer p0 p1))) | |
889 (set-buffer sj3-result-buffer) | |
890 (setq offset (- (point) point)) | |
891 (goto-char point) (sj3-put-4byte offset) | |
892 (goto-char (+ (point) offset)) | |
893 (setq sj3-bunsetu-suu (1+ sj3-bunsetu-suu)))) | |
894 sj3-return-code)) | |
895 | |
896 (defun sj3-server-tanconv (len str) | |
897 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
898 (let ((inhibit-quit t)) | |
899 (if (= *sj3-current-server-version* 2) | |
900 (sj3-command-start SJ3_TANCONV_EUC) | |
901 (sj3-command-start SJ3_TANCONV)) | |
902 (sj3-put-4byte len) | |
903 (sj3-put-string str) | |
904 (sj3-command-end) | |
905 (sj3-get-result) | |
906 (sj3-get-return-code)))) | |
907 | |
908 (defun put-kata-and-hira (str) | |
909 (sj3-put-4byte 2) | |
910 (sj3-put-4byte 0) | |
911 (sj3-put-stdy-dmy) | |
912 (sj3-put-kata str) | |
913 (insert str 0)) | |
914 | |
915 (defun sj3-get-yomi (offset length) | |
916 (substring sj3-henkan-string offset (+ offset length))) | |
917 | |
918 (defun sj3-get-yomi* (offset bunsetu-length) | |
919 (let ((i 0) (c offset)) | |
920 (while (< i bunsetu-length) | |
921 (let ((ch (substring sj3-henkan-string c (1+ c)))) | |
922 (if (string= ch "\222");;lc-jp | |
923 (setq c (+ 3 c)) | |
924 (setq c (1+ c))) | |
925 (setq i (1+ i)))) | |
926 (substring sj3-henkan-string offset c))) | |
927 | |
928 (defun sj3-bunsetu-suu () sj3-bunsetu-suu) | |
929 | |
930 (defun sj3-bunsetu-kanji (bunsetu-no &optional buffer) | |
931 (let ((savebuffer (current-buffer))) | |
932 (unwind-protect | |
933 (progn | |
934 (set-buffer sj3-result-buffer) | |
935 (if (or (< bunsetu-no 0) | |
936 (<= sj3-bunsetu-suu bunsetu-no)) | |
937 nil | |
938 (sj3-result-goto-bunsetu bunsetu-no) | |
939 (sj3-skip-length) | |
940 (sj3-skip-yomi) | |
941 | |
942 (let ((i 0) | |
943 (rksuu (- (sj3-get-4byte) 2)) ;;; real kouho-suu | |
944 (max (sj3-get-4byte))) ;;; kouho-number | |
945 (sj3-skip-stdy) | |
946 (while (< i max) | |
947 (sj3-skip-yomi) | |
948 (setq i (1+ i)) | |
949 (if (< i rksuu) | |
950 (sj3-skip-stdy)))) | |
951 | |
952 (let ( p1 p2 ) | |
953 (setq p1 (point)) | |
954 (skip-chars-forward "^\0") (setq p2 (point)) | |
955 (forward-char 1) | |
956 (if (null buffer) | |
957 (concat (buffer-substring p1 p2)) | |
958 (set-buffer buffer) | |
959 (insert-buffer-substring sj3-result-buffer p1 p2) | |
960 nil)))) | |
961 (set-buffer savebuffer)))) | |
962 | |
963 (defun sj3-bunsetu-kanji-length (bunsetu-no) | |
964 (save-excursion | |
965 (set-buffer sj3-result-buffer) | |
966 (if (or (< bunsetu-no 0) | |
967 (<= sj3-bunsetu-suu bunsetu-no)) | |
968 nil | |
969 (sj3-result-goto-bunsetu bunsetu-no) | |
970 (sj3-skip-length) | |
971 (sj3-skip-yomi) | |
972 | |
973 (let ((i 0) | |
974 (rksuu (- (sj3-get-4byte) 2)) ;;; real kouho-suu | |
975 (max (sj3-get-4byte))) ;;; kouho-number | |
976 (sj3-skip-stdy) | |
977 (while (< i max) | |
978 (sj3-skip-yomi) | |
979 (setq i (1+ i)) | |
980 (if (< i rksuu) | |
981 (sj3-skip-stdy)))) | |
982 | |
983 (let ( p1 p3 ) | |
984 (setq p1 (point)) | |
985 (skip-chars-forward "^\0") | |
986 (setq p3 (point)) | |
987 (- p3 p1))))) | |
988 | |
989 (defun sj3-bunsetu-yomi-moji-suu (bunsetu-no) | |
990 (save-excursion | |
991 (set-buffer sj3-result-buffer) | |
992 (if (or (< bunsetu-no 0) | |
993 (<= sj3-bunsetu-suu bunsetu-no)) | |
994 nil | |
995 (sj3-result-goto-bunsetu bunsetu-no) | |
996 (sj3-skip-length) | |
997 (let ((c 0) ch) | |
998 (while (not (zerop (setq ch (following-char)))) | |
999 (if (= ch lc-jp) | |
1000 (forward-char 3) | |
1001 (forward-char 1)) | |
1002 (setq c (1+ c))) | |
1003 c)))) | |
1004 | |
1005 (defun sj3-yomi-point (bunsetu-no) | |
1006 (let ((i 0) (len 0) point length) | |
1007 (goto-char (point-min)) | |
1008 (while (< i bunsetu-no) | |
1009 (setq length (sj3-get-4byte)) | |
1010 (setq point (point)) | |
1011 (skip-chars-forward "^\0") | |
1012 (setq len (+ len (- (point) point))) | |
1013 (goto-char (+ point length)) | |
1014 (setq i (1+ i))) | |
1015 len)) | |
1016 | |
1017 (defun sj3-bunsetu-yomi (bunsetu-no &optional buffer) | |
1018 (let ((savebuff (current-buffer))) | |
1019 (unwind-protect | |
1020 (progn | |
1021 (set-buffer sj3-result-buffer) | |
1022 (if (or (< bunsetu-no 0) | |
1023 (<= sj3-bunsetu-suu bunsetu-no)) | |
1024 nil | |
1025 (sj3-result-goto-bunsetu bunsetu-no) | |
1026 (sj3-skip-length) | |
1027 (let (p1 p2 ) | |
1028 (setq p1 (point)) | |
1029 (skip-chars-forward "^\0") | |
1030 (if (null buffer ) (buffer-substring p1 (point)) | |
1031 (setq p2 (point)) | |
1032 (set-buffer buffer) | |
1033 (insert-buffer-substring sj3-result-buffer p1 p2) | |
1034 t)))) | |
1035 (set-buffer savebuff)))) | |
1036 | |
1037 (defun sj3-bunsetu-yomi-equal (bunsetu-no yomi) | |
1038 (save-excursion | |
1039 (set-buffer sj3-result-buffer) | |
1040 (if (or (< bunsetu-no 0) | |
1041 (<= sj3-bunsetu-suu bunsetu-no)) | |
1042 nil | |
1043 (sj3-result-goto-bunsetu bunsetu-no) | |
1044 (sj3-skip-length) | |
1045 (looking-at (regexp-quote yomi))))) ;93.4.6 by T.Saneto | |
1046 | |
1047 (defun sj3-bunsetu-kouho-suu (bunsetu-no) | |
1048 (save-excursion | |
1049 (set-buffer sj3-result-buffer) | |
1050 (if (or (< bunsetu-no 0) | |
1051 (<= sj3-bunsetu-suu bunsetu-no)) | |
1052 nil | |
1053 (sj3-result-goto-bunsetu bunsetu-no) | |
1054 (sj3-skip-length) | |
1055 (sj3-skip-yomi) | |
1056 (sj3-get-4byte)))) | |
1057 | |
1058 (defun sj3-bunsetu-kouho-list (bunsetu-no) | |
1059 (save-excursion | |
1060 (set-buffer sj3-result-buffer) | |
1061 (if (or (< bunsetu-no 0) | |
1062 (<= sj3-bunsetu-suu bunsetu-no)) | |
1063 nil | |
1064 (sj3-result-goto-bunsetu bunsetu-no) | |
1065 (sj3-skip-length) | |
1066 (sj3-skip-yomi) | |
1067 (let ((max (sj3-get-4byte)) (i 0) (result nil) p0) | |
1068 (sj3-skip-4byte) ;;; current kouhou number | |
1069 (sj3-skip-stdy) | |
1070 (while (< i max) | |
1071 (setq p0 (point)) | |
1072 (skip-chars-forward "^\0") | |
1073 (setq result | |
1074 (cons (concat (buffer-substring p0 (point))) | |
1075 result)) | |
1076 (forward-char 1) | |
1077 (setq i (1+ i)) | |
1078 (if (< i (- max 2)) | |
1079 (sj3-skip-stdy))) | |
1080 (nreverse result))))) | |
1081 | |
1082 (defun sj3-bunsetu-kouho-number (bunsetu-no) | |
1083 (save-excursion | |
1084 (set-buffer sj3-result-buffer) | |
1085 (if (or (< bunsetu-no 0) | |
1086 (<= sj3-bunsetu-suu bunsetu-no)) | |
1087 nil | |
1088 (sj3-result-goto-bunsetu bunsetu-no) | |
1089 (sj3-skip-length) | |
1090 (sj3-skip-yomi) | |
1091 (sj3-skip-4byte) | |
1092 (sj3-get-4byte))) | |
1093 ) | |
1094 | |
1095 (defun sj3-simple-command (op arg) | |
1096 (if (sj3-server-active-p) | |
1097 (let ((inhibit-quit t)) | |
1098 (progn | |
1099 (sj3-command-start op) | |
1100 (sj3-put-4byte arg) | |
1101 (sj3-command-end) | |
1102 (sj3-get-result) | |
1103 (sj3-get-return-code))) | |
1104 (sj3-connection-error))) | |
1105 | |
1106 (defun sj3-server-open-dict (dict-file-name password) | |
1107 (if (not (sj3-server-active-p))(sj3-connection-error) | |
1108 (let ((inhibit-quit t)) | |
1109 (save-excursion | |
1110 (sj3-command-start SJ3_DICADD) | |
1111 (sj3-put-string dict-file-name) | |
1112 (if (stringp password) | |
1113 (sj3-put-string password) | |
1114 (sj3-put-string 0)) | |
1115 (sj3-command-end) | |
1116 (sj3-get-result) | |
1117 (sj3-get-return-code) | |
1118 (if (not (= sj3-return-code 0)) nil | |
1119 (let ((dict-no (sj3-get-4byte))) | |
1120 (if (stringp password) | |
1121 (setq sj3-user-dict-list | |
1122 (append sj3-user-dict-list (list dict-no))) | |
1123 (setq sj3-sys-dict-list | |
1124 (append sj3-sys-dict-list (list dict-no)))) | |
1125 dict-no)))))) | |
1126 | |
1127 (defun sj3-server-close-dict (dict-no) | |
1128 (if (not (sj3-server-active-p))(sj3-connection-error) | |
1129 (let ((inhibit-quit t)) | |
1130 (save-excursion | |
1131 (sj3-command-start SJ3_DICDEL) | |
1132 (sj3-put-4byte dict-no) | |
1133 (sj3-command-end) | |
1134 (sj3-get-result) | |
1135 (sj3-get-return-code))))) | |
1136 | |
1137 (defun sj3-server-make-dict (dict-file-name) | |
1138 (if (not (sj3-server-active-p))(sj3-connection-error) | |
1139 (let ((inhibit-quit t)) | |
1140 (save-excursion | |
1141 (sj3-command-start SJ3_MKDIC) | |
1142 (sj3-put-string dict-file-name) | |
1143 (sj3-put-4byte 2048) ;;; Index length | |
1144 (sj3-put-4byte 2048) ;;; Length | |
1145 (sj3-put-4byte 256) ;;; Number | |
1146 (sj3-command-end) | |
1147 (sj3-get-result) | |
1148 (sj3-get-return-code))))) | |
1149 | |
1150 (defun sj3-server-open-stdy (stdy-file-name) | |
1151 (if (not (sj3-server-active-p))(sj3-connection-error) | |
1152 (let ((inhibit-quit t)) | |
1153 (save-excursion | |
1154 (sj3-command-start SJ3_OPENSTDY) | |
1155 (sj3-put-string stdy-file-name) | |
1156 (sj3-put-string 0) | |
1157 (sj3-command-end) | |
1158 (sj3-get-result) | |
1159 (sj3-get-return-code))))) | |
1160 | |
1161 (defun sj3-server-close-stdy () | |
1162 (sj3-zero-arg-command SJ3_CLOSESTDY)) | |
1163 | |
1164 (defun sj3-server-make-stdy (stdy-file-name) | |
1165 (if (not (sj3-server-active-p))(sj3-connection-error) | |
1166 (let ((inhibit-quit t)) | |
1167 (save-excursion | |
1168 (sj3-command-start SJ3_MKSTDY) | |
1169 (sj3-put-string stdy-file-name) | |
1170 (sj3-put-4byte 2048) ;;; Number | |
1171 (sj3-put-4byte 1) ;;; Step | |
1172 (sj3-put-4byte 2048) ;;; Length | |
1173 (sj3-command-end) | |
1174 (sj3-get-result) | |
1175 (sj3-get-return-code))))) | |
1176 | |
1177 (defun sj3-server-dict-add (dictno kanji yomi bunpo) | |
1178 (if (not (sj3-server-active-p))(sj3-connection-error) | |
1179 (let ((inhibit-quit t)) | |
1180 (save-excursion | |
1181 (if (= *sj3-current-server-version* 2) | |
1182 (sj3-command-start SJ3_WREG_EUC) | |
1183 (sj3-command-start SJ3_WREG)) | |
1184 (sj3-put-4byte dictno) | |
1185 (sj3-put-string* yomi) | |
1186 (sj3-put-string* kanji) | |
1187 (sj3-put-4byte bunpo) | |
1188 (sj3-command-end) | |
1189 (sj3-get-result) | |
1190 (sj3-get-return-code))))) | |
1191 | |
1192 (defun sj3-server-dict-delete (dictno kanji yomi bunpo) | |
1193 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
1194 (let ((inhibit-quit t)) | |
1195 (save-excursion | |
1196 (if (= *sj3-current-server-version* 2) | |
1197 (sj3-command-start SJ3_WDEL_EUC) | |
1198 (sj3-command-start SJ3_WDEL)) | |
1199 (sj3-put-4byte dictno) | |
1200 (sj3-put-string* yomi) | |
1201 (sj3-put-string* kanji) | |
1202 (sj3-put-4byte bunpo) | |
1203 (sj3-command-end) | |
1204 (sj3-get-result) | |
1205 (sj3-get-return-code))))) | |
1206 | |
1207 (defun sj3-server-dict-info (dict-no) | |
1208 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
1209 (let ((inhibit-quit t)) | |
1210 (save-excursion | |
1211 (let ((result nil)) | |
1212 (set-buffer sj3-server-buffer) | |
1213 (if (= *sj3-current-server-version* 2) | |
1214 (sj3-simple-command SJ3_WSCH_EUC dict-no) | |
1215 (sj3-simple-command SJ3_WSCH dict-no)) | |
1216 (while (= sj3-return-code 0) | |
1217 ;;; (sj3-get-4byte) | |
1218 (setq result (cons (list (sj3-get-string*) | |
1219 (sj3-get-string*) (sj3-get-4byte)) result)) | |
1220 (if (= *sj3-current-server-version* 2) | |
1221 (sj3-simple-command SJ3_WNSCH_EUC dict-no) | |
1222 (sj3-simple-command SJ3_WNSCH dict-no))) | |
1223 (if (= sj3-return-code 111) | |
1224 (setq sj3-error-code nil)) | |
1225 (nreverse result)))))) | |
1226 | |
1227 (defun sj3-server-make-directory (dir-name) | |
1228 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
1229 (let ((inhibit-quit t)) | |
1230 (save-excursion | |
1231 (sj3-command-start SJ3_MKDIR) | |
1232 (sj3-put-string dir-name) | |
1233 (sj3-command-end) | |
1234 (sj3-get-result) | |
1235 (sj3-get-return-code))))) | |
1236 | |
1237 (defun sj3-server-file-access (file-name access-mode) | |
1238 (if (not (sj3-server-active-p)) (sj3-connection-error) | |
1239 (let ((inhibit-quit t)) | |
1240 (save-excursion | |
1241 (sj3-command-start SJ3_ACCESS) | |
1242 (sj3-put-string file-name) | |
1243 (sj3-put-4byte access-mode) | |
1244 (sj3-command-end) | |
1245 (sj3-get-result) | |
1246 (setq sj3-error-code nil) | |
1247 (sj3-get-4byte))))) | |
1248 | |
1249 (defun sj3_lock () | |
1250 (sj3-zero-arg-command SJ3_LOCK)) | |
1251 | |
1252 (defun sj3_unlock () | |
1253 (sj3-zero-arg-command SJ3_UNLOCK)) | |
1254 | |
1255 (defun sj3_version () | |
1256 (sj3-zero-arg-command SJ3_VERSION)) | |
1257 | |
1258 (defconst *sj3-error-alist* | |
1259 '( | |
1260 (1 :SJ3_SERVER_DEAD | |
1261 "$B%5!<%P$,;`$s$G$$$^$9!#(B") | |
1262 (2 :SJ3_SOCK_OPEN_FAIL | |
1263 "socket$B$N(Bopen$B$K<:GT$7$^$7$?!#(B") | |
1264 (6 :SJ3_ALLOC_FAIL | |
1265 "$B%a%b%j(Balloc$B$G<:GT$7$^$7$?!#(B") | |
1266 (7 :SJ3_ILLEGAL_COMMAND | |
1267 "$B%3%^%s%I$,4V0c$C$F$$$k(B") | |
1268 (12 :SJ3_BAD_HOST | |
1269 " $B%[%9%HL>$,$J$$(B ") | |
1270 (13 :SJ3_BAD_USER | |
1271 " $B%f!<%6L>$,$J$$(B ") | |
1272 (31 :SJ3_NOT_A_DICT | |
1273 "$B@5$7$$<-=q$G$O$"$j$^$;$s!#(B") | |
1274 (35 :SJ3_NO_EXIST | |
1275 "$B%U%!%$%k$,B8:_$7$^$;$s!#(B") | |
1276 (37 :SJ3_OPENF_ERR | |
1277 "$B%U%!%$%k$,%*!<%W%s$G$-$^$;$s!#(B") | |
1278 (39 :SJ3_PARAMR | |
1279 "$B%U%!%$%k$NFI$_9~$_8"8B$,$"$j$^$;$s!#(B") | |
1280 (40 :SJ3_PARAMW | |
1281 "$B%U%!%$%k$N=q$-9~$_8"8B$,$"$j$^$;$s!#(B") | |
1282 (71 :SJ3_NOT_A_USERDICT | |
1283 "$B;XDj$5$l$F<-=q$O!"%f!<%6!<<-=q$G$O$"$j$^$;$s!#(B") | |
1284 (72 :SJ3_RDONLY | |
1285 "$B%j!<%I%*%s%j!<$N<-=q$KEPO?$7$h$&$H$7$^$7$?!#(B") | |
1286 (74 :SJ3_BAD_YOMI | |
1287 "$BFI$_$KITE,Ev$JJ8;z$,4^$^$l$F$$$^$9!#(B") | |
1288 (75 :SJ3_BAD_KANJI | |
1289 "$B4A;z$KITE,Ev$JJ8;z$,4^$^$l$F$$$^$9!#(B") | |
1290 (76 :SJ3_BAD_HINSHI | |
1291 "$B;XDj$5$l$?IJ;lHV9f$,$"$j$^$;$s!#(B") | |
1292 (82 :SJ3_WORD_ALREADY_EXIST | |
1293 "$B;XDj$5$l$?C18l$O$9$G$KB8:_$7$F$$$^$9!#(B") | |
1294 (84 :SJ3_JISHOTABLE_FULL | |
1295 "$B<-=q%F!<%V%k$,0lGU$G$9!#(B") | |
1296 (92 :SJ3_WORD_NO_EXIST | |
1297 "$B;XDj$5$l$?C18l$,B8:_$7$^$;$s!#(B") | |
1298 (102 :SJ3_MKDIR_FAIL | |
1299 " $B%G%#%l%/%H%j$r:n$jB;$J$C$?(B ") | |
1300 )) | |
1301 | |
1302 (defun sj3-error-symbol (code) | |
1303 (let ((pair (assoc code *sj3-error-alist*))) | |
1304 (if (null pair) | |
1305 (list ':sj3-unknown-error-code code) | |
1306 (car (cdr pair))))) | |
1307 |