Mercurial > freewnn
annotate Wnn/jlib/js.c @ 23:e1aadb6dcbd4
- fixed the build rule for build_stamp.h. keywords in template for hg tip should surrounded by curly braces instead of hash marks.
- fixed usage of libtool in building jlib.V3. newer libtool does not work without mode specifier.
- replaced some libtool related files. (should remove these?)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 23 Jan 2009 16:36:13 +0900 |
parents | 1f16ab4b33e5 |
children | a7ccf412ba02 |
rev | line source |
---|---|
0 | 1 /* |
2 * $Id: js.c,v 1.16 2005/04/10 15:26:37 aonoto Exp $ | |
3 */ | |
4 | |
5 /* | |
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system. | |
7 * This file is part of FreeWnn. | |
8 * | |
9 * Copyright Kyoto University Research Institute for Mathematical Sciences | |
10 * 1987, 1988, 1989, 1990, 1991, 1992 | |
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999 | |
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992 | |
13 * Copyright FreeWnn Project 1999, 2000, 2001, 2002, 2003 | |
14 * | |
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp> | |
16 * | |
17 * This library is free software; you can redistribute it and/or | |
18 * modify it under the terms of the GNU Lesser General Public | |
19 * License as published by the Free Software Foundation; either | |
20 * version 2 of the License, or (at your option) any later version. | |
21 * | |
22 * This library is distributed in the hope that it will be useful, | |
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
25 * Lesser General Public License for more details. | |
26 * | |
27 * You should have received a copy of the GNU Lesser General Public | |
28 * License along with this library; if not, write to the | |
29 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
30 * Boston, MA 02111-1307, USA. | |
31 */ | |
32 | |
33 /* | |
34 Nihongo Henkan Library | |
35 */ | |
36 /* | |
37 entry functions | |
38 | |
39 js_open_lang js_close | |
40 js_change_current_jserver | |
41 js_connect_lang js_disconnect | |
42 js_isconnect | |
43 | |
44 js_param_get js_param_set | |
45 | |
46 js_access js_mkdir | |
47 | |
48 js_get_lang js_set_lang | |
49 | |
50 | |
51 extern Variables | |
52 int wnn_errorno; | |
53 */ | |
54 | |
55 #if defined(HAVE_CONFIG_H) | |
56 #include <config.h> | |
57 #endif | |
58 | |
59 #include <stdio.h> | |
60 #include <ctype.h> | |
61 #include <errno.h> | |
62 #include <signal.h> | |
63 #if STDC_HEADERS | |
64 # include <stdlib.h> | |
65 # include <string.h> | |
66 #else | |
67 # if HAVE_MALLOC_H | |
68 # include <malloc.h> | |
69 # endif | |
70 # if HAVE_STRINGS_H | |
71 # include <strings.h> | |
72 # endif | |
73 #endif /* STDC_HEADERS */ | |
74 #if HAVE_FCNTL_H | |
75 # include <fcntl.h> | |
76 #endif | |
77 #include <pwd.h> | |
78 #if HAVE_UNISTD_H | |
79 # include <unistd.h> | |
80 #endif | |
81 #include <sys/stat.h> | |
82 #include <sys/types.h> | |
83 | |
84 #include "jd_sock.h" | |
85 #include "commonhd.h" | |
86 #include "demcom.h" | |
87 #include "wnn_config.h" | |
88 | |
89 #include "wnnerror.h" | |
90 #include "jslib.h" | |
91 #include "jh.h" | |
92 | |
93 #include "msg.h" | |
94 | |
95 #define JS /* For include ../etc/bdic.c */ | |
96 #include "../etc/bdic.c" | |
97 #include "../etc/pwd.c" | |
98 | |
99 /* defined in wnn_os.h & should be modified in the future */ | |
100 /* #define bzero(adr,n) memset((adr),0,(n)) */ | |
101 | |
102 int wnn_errorno = 0; | |
103 struct msg_cat *wnn_msg_cat = NULL; | |
104 | |
105 /* j Lib. */ | |
106 | |
107 static int current_sd; /** ¥½¥±¥Ã¥Èfd **/ | |
108 static WNN_JSERVER_ID *current_js = NULL; | |
109 | |
110 | |
111 /* Packet Buffers */ | |
112 static unsigned char snd_buf[S_BUF_SIZ]; /** Á÷¿® **/ | |
113 static int sbp = 0; /** Á÷¿®¥Ð¥Ã¥Õ¥¡¡¼¥Ý¥¤¥ó¥¿¡¼ **/ | |
114 static int rbc = -1; /** ¼õ¿®¥Ð¥Ã¥Õ¥¡¡¼¥Ý¥¤¥ó¥¿¡¼ **/ | |
115 | |
116 #if defined(EAGAIN) | |
117 # if defined(EWOULDBLOCK) | |
118 # define ERRNO_CHECK(no) ((no) == EAGAIN || (no) == EWOULDBLOCK) | |
119 # else /* defined(EWOULDBLOCK) */ | |
120 # define ERRNO_CHECK(no) ((no) == EAGAIN) | |
121 # endif /* defined(EWOULDBLOCK) */ | |
122 #else /* defined(EAGAIN) */ | |
123 # if defined(EWOULDBLOCK) | |
124 # define ERRNO_CHECK(no) ((no) == EWOULDBLOCK) | |
125 # else /* defined(EWOULDBLOCK) */ | |
126 # define ERRNO_CHECK(no) (0) | |
127 # endif /* defined(EWOULDBLOCK) */ | |
128 #endif /* defined(EAGAIN) */ | |
129 | |
130 static void connect_timeout (); | |
131 static int _get_server_name (); | |
132 static int writen (); | |
133 static char *get_unixdomain_of_serv_defs (), *get_service_of_serv_defs (); | |
134 static int get_port_num_of_serv_defs (); | |
135 #if DEBUG | |
136 void xerror (); | |
137 #endif | |
138 | |
139 /********* V4 *****************/ | |
140 /*** | |
141 jserver_dead Macro | |
142 ***/ | |
143 | |
144 static jmp_buf current_jserver_dead; | |
145 | |
146 #define handler_of_jserver_dead(err_val) \ | |
147 { \ | |
148 if (current_js) { \ | |
149 if(current_js->js_dead){wnn_errorno=WNN_JSERVER_DEAD;return err_val;}\ | |
150 if(setjmp(current_jserver_dead)){ \ | |
151 wnn_errorno=WNN_JSERVER_DEAD; \ | |
152 return err_val; \ | |
153 } \ | |
154 wnn_errorno = 0; /* here initialize wnn_errorno; */ \ | |
155 } \ | |
156 } | |
157 | |
158 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
159 set_current_js (register WNN_JSERVER_ID *server) |
0 | 160 { |
161 current_js = server; | |
162 current_sd = current_js->sd; | |
163 } | |
164 | |
165 /** ¥Ç¡¼¥â¥ó¤¬»à¤ó¤À»þ¤Î¤¿¤á¤Î¸å»ÏËö **/ | |
166 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
167 daemon_dead (void) |
0 | 168 { |
169 current_js->js_dead = -1; | |
170 wnn_errorno = WNN_JSERVER_DEAD; | |
171 shutdown (current_sd, 2); | |
172 #ifdef HAVE_CLOSESOCKET | |
173 closesocket (current_sd); | |
174 #else | |
175 close (current_sd); | |
176 #endif | |
177 #if DEBUG | |
178 fprintf (stderr, "jslib:JSERVER %s is Dead\n", current_js->js_name); | |
179 #endif | |
180 if (current_js->js_dead_env_flg) | |
181 { | |
182 longjmp (current_js->js_dead_env, 666); | |
183 } | |
184 longjmp (current_jserver_dead, 666); | |
185 /* never reach */ | |
186 } | |
187 | |
188 | |
189 /** | |
190 ¥½¥±¥Ã¥È¤ò¥ª¡¼¥×¥ó¤·¤Æcurrent_sd¤Ë¥½¥±¥Ã¥Èfd¤òÊÖ¤¹ | |
191 (cd¤È¤¤¤¦¤Î¤Ï¥³¥ß¥å¥Ë¥±¡¼¥·¥ç¥ó¥Ç¥Ð¥¤¥¹¤Î̾»Ä) | |
192 **/ | |
193 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
194 cd_open_un (register char *lang) |
0 | 195 { |
196 #ifdef AF_UNIX | |
197 int sd; | |
198 struct sockaddr_un saddr; /** ¥½¥±¥Ã¥È **/ | |
199 char *sock_name = NULL; | |
200 saddr.sun_family = AF_UNIX; | |
201 | |
202 /* find socket name from table by lang */ | |
203 if (lang && *lang) | |
204 { | |
205 if ((sock_name = get_unixdomain_of_serv_defs (lang)) == NULL) | |
206 { | |
207 sock_name = sockname; | |
208 } | |
209 } | |
210 else | |
211 { | |
212 sock_name = sockname; /* Jserver */ | |
213 } | |
214 strcpy (saddr.sun_path, sock_name); | |
215 | |
216 if ((sd = socket (AF_UNIX, SOCK_STREAM, 0)) == ERROR) | |
217 { | |
218 #if DEBUG | |
219 xerror ("jslib:Can't create unix domain socket.\n"); | |
220 #endif | |
221 return -1; | |
222 } | |
223 | |
224 #if !defined(SUN_LEN) | |
225 # define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) | |
226 #endif | |
227 if (connect (sd, (struct sockaddr *) &saddr, SUN_LEN (&saddr)) == ERROR) | |
228 { | |
229 | |
230 #if DEBUG | |
231 xerror ("jslib:Can't connect unix domain socket.\n"); | |
232 #endif | |
233 close (sd); | |
234 return -1; | |
235 } | |
236 return sd; | |
237 #else | |
238 return -1; | |
239 #endif | |
240 } | |
241 | |
242 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
243 cd_open_in (register char *server, register char *lang, register int timeout) |
0 | 244 { |
245 int sd; | |
246 #ifdef INET6 | |
247 struct addrinfo hints, *res, *res0; | |
248 int error; | |
249 char sport[6]; | |
250 #else | |
251 struct sockaddr_in saddr_in; /** ¥½¥±¥Ã¥È **/ | |
252 register struct hostent *hp; | |
253 #endif | |
254 struct servent *sp = NULL; | |
255 int serverNO, port_num; | |
256 int ret; | |
257 char pserver[64]; | |
258 char sserver[64]; | |
259 char *serv_name = NULL; | |
260 | |
261 serverNO = _get_server_name (server, pserver); | |
262 | |
263 /* find service name from table by lang */ | |
264 if (lang && *lang) | |
265 { | |
266 if ((serv_name = get_service_of_serv_defs (lang)) == NULL) | |
267 { | |
268 strcpy (sserver, SERVERNAME); | |
269 } | |
270 else | |
271 { | |
272 strcpy (sserver, serv_name); | |
273 } | |
274 } | |
275 else | |
276 { | |
277 /* | |
278 serv_name = SERVERNAME; | |
279 */ | |
280 strcpy (sserver, SERVERNAME); | |
281 } | |
282 /* | |
283 if ((sp = getservbyname(serv_name,"tcp")) != NULL) { | |
284 */ | |
285 if ((sp = getservbyname (sserver, "tcp")) != NULL) | |
286 { | |
287 serverNO += ntohs (sp->s_port); | |
288 } | |
289 else | |
290 { | |
291 if ((port_num = get_port_num_of_serv_defs (lang)) == -1) | |
292 { | |
293 serverNO += WNN_PORT_IN; | |
294 } | |
295 else | |
296 { | |
297 serverNO += port_num; | |
298 } | |
299 } | |
300 #ifdef INET6 | |
301 memset(&hints, 0, sizeof(hints)); | |
302 hints.ai_family = PF_UNSPEC; | |
303 hints.ai_socktype = SOCK_STREAM; | |
304 sprintf(sport, "%d", serverNO); | |
305 error = getaddrinfo(pserver, sport, &hints, &res0); | |
306 if (error) | |
307 { | |
308 #if DEBUG | |
309 xerror (gai_strerror(error)); | |
310 #endif | |
311 return -1; | |
312 } | |
313 for (res = res0; res ; res = res->ai_next) { | |
314 if (res->ai_family == AF_INET || res->ai_family == AF_INET6){ | |
315 if ((sd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) != ERROR){ | |
316 #else | |
317 if ((hp = gethostbyname (pserver)) == NULL) | |
318 { | |
319 return -1; | |
320 } | |
321 bzero ((char *) &saddr_in, sizeof (saddr_in)); | |
322 bcopy (hp->h_addr, (char *) &saddr_in.sin_addr, hp->h_length); | |
323 saddr_in.sin_family = AF_INET; | |
324 saddr_in.sin_port = htons (serverNO); | |
325 if ((sd = socket (AF_INET, SOCK_STREAM, 0)) == ERROR) | |
326 { | |
327 #if DEBUG | |
328 xerror ("jslib:Can't create inet socket.\n"); | |
329 #endif | |
330 return -1; | |
331 } | |
332 #endif | |
333 | |
334 if (timeout != 0 && timeout > 0) | |
335 { | |
336 signal (SIGALRM, connect_timeout); | |
337 alarm (timeout); | |
338 } | |
339 #ifdef INET6 | |
340 ret = connect (sd, res->ai_addr, res->ai_addrlen); | |
341 #else | |
342 ret = connect (sd, (struct sockaddr *) &saddr_in, sizeof (saddr_in)); | |
343 #endif | |
344 if (timeout != 0 && timeout > 0) | |
345 { | |
346 alarm (0); | |
347 signal (SIGALRM, SIG_IGN); | |
348 } | |
349 if (ret == ERROR) | |
350 { | |
351 #if DEBUG | |
352 #ifdef INET6 | |
353 if (res->ai_family == AF_INET) | |
354 xerror ("jslib:Can't connect inet socket.\n"); | |
355 else if (res->ai_family == AF_INET6) | |
356 xerror ("jslib:Can't connect inet6 socket.\n"); | |
357 #else | |
358 xerror ("jslib:Can't connect inet socket.\n"); | |
359 #endif | |
360 #endif | |
361 #ifdef HAVE_CLOSESOCKET | |
362 closesocket (sd); | |
363 #else | |
364 close (sd); | |
365 #endif | |
366 #ifdef INET6 | |
367 sd = ERROR; | |
368 } else | |
369 break; | |
370 } else { | |
371 #if DEBUG | |
372 if (res->ai_family == AF_INET) | |
373 xerror ("jslib:Can't create inet socket.\n"); | |
374 else if (res->ai_family == AF_INET6) | |
375 xerror ("jslib:Can't create inet6 socket.\n"); | |
376 #endif | |
377 } | |
378 } | |
379 } | |
380 freeaddrinfo(res0); | |
381 if (sd == ERROR) { | |
382 #endif | |
383 return -1; | |
384 } | |
385 return sd; | |
386 } | |
387 | |
388 static void | |
389 connect_timeout () | |
390 { | |
391 } | |
392 | |
393 /* get server name and return serverNo */ | |
394 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
395 _get_server_name (char *server, char *pserver) |
0 | 396 { |
397 register char *p; | |
398 #ifdef INET6 | |
399 int len; | |
400 | |
401 if (server[0] == '[') { | |
402 p = strchr(server++, ']'); | |
403 if (p) { | |
404 len = p-server<64-1?p-server:64-1; | |
405 strncpy(pserver, server, len); | |
406 pserver[len] = '\0'; | |
407 } else | |
408 pserver[0] = '\0'; | |
409 } else { | |
410 #endif | |
411 /* Workaround for pserver buffer overrun : Nov 11,1999 by T.Aono */ | |
412 /* assumes pserver[64]. variable length string is not supported. */ | |
413 strncpy(pserver, server, 64-1); | |
414 pserver[64-1] = '\0'; | |
415 p = pserver; | |
416 #ifdef INET6 | |
417 } | |
418 #endif | |
419 for (; *p && *p != ':'; p++); | |
420 if (!*p) | |
421 return (0); /* does not have a colon */ | |
422 *p = 0; | |
423 return (atoi (++p)); | |
424 } | |
425 | |
426 /* Packet SND/RCV subroutines */ | |
427 static void put4com (); | |
428 | |
429 /** ¥Ñ¥±¥Ã¥È¤Î¥Ø¥Ã¥À¡¼¤òÁ÷¤ë **/ | |
430 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
431 snd_head (int cmd) |
0 | 432 { |
433 sbp = 0; | |
434 put4com (cmd); | |
435 rbc = -1; | |
436 } | |
437 | |
438 /** ¥Ñ¥±¥Ã¥È¤Î¥Ø¥Ã¥À¡¼¤òÁ÷¤ë **/ | |
439 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
440 snd_env_head (register struct wnn_env *env, int cmd) |
0 | 441 { |
442 snd_head (cmd); | |
443 put4com (env->env_id); | |
444 return 0; | |
445 } | |
446 | |
447 /** ¥Ñ¥±¥Ã¥È¤Î¥Ø¥Ã¥À¡¼¤òÁ÷¤ë **/ | |
448 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
449 snd_server_head (register WNN_JSERVER_ID *server, int cmd) |
0 | 450 { |
451 snd_head (cmd); | |
452 return 0; | |
453 } | |
454 | |
455 /** Á÷¿®¥Ð¥Ã¥Õ¥¡¤ò¥Õ¥é¥Ã¥·¥å¤¹¤ë **/ | |
456 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
457 snd_flush (void) |
0 | 458 { |
459 if (sbp == 0) | |
460 return (-1); | |
461 writen (sbp); | |
462 sbp = 0; | |
463 return (0); | |
464 } | |
465 | |
466 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
467 writen (int n) |
0 | 468 { |
469 int cc, x; | |
470 for (cc = 0; cc < n;) | |
471 { | |
472 errno = 0; | |
473 #ifdef HAVE_SEND | |
474 x = send (current_sd, &snd_buf[cc], n - cc, 0); | |
475 #else | |
476 x = write (current_sd, &snd_buf[cc], n - cc); | |
477 #endif | |
478 if (x < 0) | |
479 { | |
480 if (ERRNO_CHECK (errno) || errno == EINTR) | |
481 { | |
482 continue; | |
483 } | |
484 else | |
485 { | |
486 daemon_dead (); | |
487 return -1; | |
488 } | |
489 } | |
490 cc += x; | |
491 } | |
492 #if DEBUG | |
493 fprintf (stderr, "jslib:writen=%d\n", x); | |
494 /* dmp(snd_buf,x); */ | |
495 #endif | |
496 return (0); | |
497 } | |
498 | |
499 /** ¥µ¡¼¥Ð¤Ø1¥Ð¥¤¥ÈÁ÷¤ë **/ | |
500 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
501 put1com (int c) |
0 | 502 { |
503 snd_buf[sbp++] = c; | |
504 if (sbp >= S_BUF_SIZ) | |
505 { | |
506 writen (S_BUF_SIZ); | |
507 sbp = 0; | |
508 } | |
509 } | |
510 | |
511 /** ¥µ¡¼¥Ð¤Ø2¥Ð¥¤¥ÈÁ÷¤ë **/ | |
512 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
513 put2com (int c) |
0 | 514 { |
515 put1com (c >> (8 * 1)); | |
516 put1com (c); | |
517 } | |
518 | |
519 /** ¥µ¡¼¥Ð¤Ø4¥Ð¥¤¥ÈÁ÷¤ë **/ | |
520 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
521 put4com (int c) |
0 | 522 { |
523 put1com (c >> (8 * 3)); | |
524 put1com (c >> (8 * 2)); | |
525 put1com (c >> (8 * 1)); | |
526 put1com (c); | |
527 } | |
528 | |
529 /** ¥µ¡¼¥Ð¤Øʸ»úÎó¤òÁ÷¤ë **/ | |
530 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
531 putwscom (register w_char *p) |
0 | 532 { |
533 if (p == NULL) | |
534 { | |
535 put2com (0); | |
536 return; | |
537 } | |
538 while (*p) | |
539 put2com (*p++); | |
540 put2com (0); | |
541 } | |
542 | |
543 /** ¥µ¡¼¥Ð¤Øʸ»úÎó¤òÁ÷¤ë **/ | |
544 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
545 putscom (register char *p) |
0 | 546 { |
547 if (p == NULL) | |
548 { | |
549 put1com (0); | |
550 return; | |
551 } | |
552 while (*p) | |
553 put1com (*p++); | |
554 put1com (0); | |
555 } | |
556 | |
557 /** ¥µ¡¼¥Ð¤«¤é1¥Ð¥¤¥È¼õ¤±¤ë **/ | |
558 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
559 get1com (void) |
0 | 560 { |
561 static int rbp; | |
562 static unsigned char rcv_buf[R_BUF_SIZ]; /** ¼õ¿® **/ | |
563 if (rbc <= 0) | |
564 { | |
565 while (1) | |
566 { | |
567 errno = 0; | |
568 #ifdef HAVE_RECV | |
569 rbc = recv (current_sd, rcv_buf, R_BUF_SIZ, 0); | |
570 #else | |
571 rbc = read (current_sd, rcv_buf, R_BUF_SIZ); | |
572 #endif | |
573 if (rbc <= 0) | |
574 { | |
575 if (ERRNO_CHECK (errno)) | |
576 { | |
577 continue; | |
578 } | |
579 else if (rbc == 0) | |
580 { | |
581 daemon_dead (); | |
582 return -1; | |
583 } | |
584 else | |
585 { /* cc == -1 */ | |
586 if (errno != EINTR) | |
587 { | |
588 daemon_dead (); | |
589 return -1; | |
590 } | |
591 continue; | |
592 } | |
593 } | |
594 rbp = 0; | |
595 #if DEBUG | |
596 fprintf (stderr, "jslib:read:rbc=%d\n", rbc); | |
597 /* dmp(rcv_buf,rbc); */ | |
598 #endif | |
599 break; | |
600 } | |
601 } | |
602 rbc--; | |
603 return rcv_buf[rbp++] & 0xFF; | |
604 } | |
605 | |
606 /** ¥µ¡¼¥Ð¤«¤é2¥Ð¥¤¥È¼õ¤±¤ë **/ | |
607 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
608 get2com (void) |
0 | 609 { |
610 register int h; | |
611 h = get1com (); | |
612 return (h << 8) | get1com (); | |
613 } | |
614 | |
615 /** ¥µ¡¼¥Ð¤«¤é4¥Ð¥¤¥È¼õ¤±¤ë **/ | |
616 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
617 get4com (void) |
0 | 618 { |
619 register int h1, h2, h3; | |
620 h1 = get1com () << 24; | |
621 h2 = get1com () << 16; | |
622 h3 = get1com () << 8; | |
623 return h1 | h2 | h3 | get1com (); | |
624 } | |
625 | |
626 /** ¥µ¡¼¥Ð¤Øʸ»úÎó¤òÁ÷¤ë **/ | |
627 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
628 getscom (register char *p) |
0 | 629 { |
5 | 630 while ((*p++ = get1com ())) |
0 | 631 ; |
632 } | |
633 | |
634 /** ¥µ¡¼¥Ð¤Øʸ»úÎó¤òÁ÷¤ë **/ | |
635 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
636 getwscom (w_char register *p) |
0 | 637 { |
5 | 638 while ((*p++ = get2com ())) |
0 | 639 ; |
640 } | |
641 | |
642 #ifdef nodef | |
643 /* Moved from ../etc/string.c */ | |
644 /** **/ | |
645 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
646 Strlen (register w_char *s) |
0 | 647 { |
648 register int n; | |
649 | |
650 for (n = 0; *s++ != 0; n++); | |
651 return n; | |
652 } | |
653 | |
654 /** **/ | |
655 static w_char * | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
656 Strcpy (register w_char *s1, register w_char *s2) |
0 | 657 { |
658 register w_char *d; | |
659 | |
660 for (d = s1; (*d++ = *s2++) != 0;); | |
661 return s1; | |
662 } | |
663 #endif | |
664 | |
665 | |
666 /* Debug Subroutines */ | |
667 #if DEBUG | |
668 void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
669 xerror (char *s) |
0 | 670 { |
671 fprintf (stderr, "%s\n", s); | |
672 } | |
673 | |
674 void | |
675 dmp (p, c) | |
676 char *p; | |
677 { | |
678 int i, j; | |
679 for (i = 0;; i += 16) | |
680 { | |
681 for (j = 0; j < 16; j++) | |
682 { | |
683 if (c <= 0) | |
684 { | |
685 fprintf (stderr, "\n"); | |
686 return; | |
687 } | |
688 fprintf (stderr, "%02x ", p[i + j] & 0xFF); | |
689 c--; | |
690 } | |
691 fprintf (stderr, "\n"); | |
692 } | |
693 } | |
694 | |
695 #endif | |
696 | |
697 /* get login name form /etc/passwd file */ | |
698 static char * | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
699 getlogname (void) |
0 | 700 { |
701 struct passwd *getpwuid (); | |
702 return getpwuid (getuid ())->pw_name; | |
703 } | |
704 | |
705 | |
706 | |
707 | |
708 /* | |
709 * Lib. Functions | |
710 * raw lib. | |
711 */ | |
712 | |
713 /*** | |
714 js | |
715 ¡¦global | |
716 ***/ | |
717 | |
718 /** jserver ¤ÈÀܳ¤¹¤ë¡£jserver_id ¤òÊÖ¤¹¡£ **/ | |
719 WNN_JSERVER_ID * | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
720 js_open_lang (register char *server, register char *lang, register int timeout) |
0 | 721 { |
722 char *new_js; | |
723 char host[WNN_HOSTLEN], user[WNN_ENVNAME_LEN]; | |
724 int x; | |
725 | |
726 if (wnn_msg_cat == NULL) | |
727 { | |
728 char nlspath[MAXPATHLEN]; | |
729 strcpy (nlspath, LIBDIR); | |
730 strcat (nlspath, "/%L/%N"); | |
731 wnn_msg_cat = msg_open ("libwnn.msg", nlspath, lang); | |
732 if (wnn_msg_cat == NULL) | |
733 { | |
734 fprintf (stderr, "libwnn: Cannot open message file for libwnn.a\n"); | |
735 } | |
736 } | |
737 sbp = 0; /* init sndBufPointer */ | |
738 if (!(new_js = (char *) malloc (sizeof (WNN_JSERVER_ID)))) | |
739 { | |
740 wnn_errorno = WNN_ALLOC_FAIL; | |
741 return NULL; | |
742 } | |
743 current_js = (WNN_JSERVER_ID *) new_js; | |
744 if (server == NULL) | |
745 { | |
746 current_js->js_name[0] = '\0'; | |
747 } | |
748 else | |
749 { | |
750 strncpy (current_js->js_name, server, sizeof (current_js->js_name) - 1); | |
751 current_js->js_name[sizeof (current_js->js_name) - 1] = '\0'; | |
752 } | |
753 current_js->js_dead = 0; | |
754 current_js->js_dead_env_flg = 0; | |
755 /* | |
756 if(user == NULL || 0==strcmp(user,"")) | |
757 */ | |
758 strncpy (user, getlogname (), WNN_ENVNAME_LEN); | |
759 user[WNN_ENVNAME_LEN - 1] = '\0'; /* truncate by WNN_ENVNAME_LEN */ | |
760 if (server == NULL || 0 == strcmp (server, "") || 0 == strcmp (server, "unix")) | |
761 { | |
762 strcpy (host, "unix"); | |
763 if ((current_sd = cd_open_un (lang)) == -1) | |
764 { | |
765 wnn_errorno = WNN_SOCK_OPEN_FAIL; | |
766 free ((char *) current_js); | |
767 current_js = NULL; | |
768 return NULL; | |
769 } | |
770 } | |
771 else | |
772 { | |
773 gethostname (host, WNN_HOSTLEN); | |
774 host[WNN_HOSTLEN - 1] = '\0'; /* truncate by WNN_HOSTLEN */ | |
775 if ((current_sd = cd_open_in (server, lang, timeout)) == -1) | |
776 { | |
777 wnn_errorno = WNN_SOCK_OPEN_FAIL; | |
778 free ((char *) current_js); | |
779 current_js = NULL; | |
780 return NULL; | |
781 } | |
782 } | |
783 current_js->sd = current_sd; | |
784 handler_of_jserver_dead (NULL); | |
785 snd_head (JS_OPEN); | |
786 put4com (JLIB_VERSION); /* H.T. */ | |
787 putscom (host); | |
788 putscom (user); | |
789 snd_flush (); | |
790 if (get4com () == -1) | |
791 { | |
792 x = wnn_errorno = get4com (); | |
793 js_close (current_js); /* H.T. */ | |
794 current_js = NULL; | |
795 wnn_errorno = x; | |
796 return NULL; | |
797 } | |
798 return current_js; | |
799 } | |
800 | |
801 | |
802 /** ¥½¥±¥Ã¥È¤ò¥¯¥í¡¼¥º¤¹¤ë **/ | |
803 /** jserver ¤È¤ÎÀܳ¤ò close ¤¹¤ë¡£ **/ | |
804 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
805 js_close (WNN_JSERVER_ID *server) |
0 | 806 { |
807 register int x; | |
808 WNN_JSERVER_ID tmp_js_id; | |
809 if (server == 0) | |
810 return (-1); | |
811 tmp_js_id = *server; | |
812 free ((char *) server); | |
813 current_js = &tmp_js_id; | |
814 current_sd = current_js->sd; | |
815 /* handler of jserver dead */ | |
816 handler_of_jserver_dead (-1); | |
817 snd_head (JS_CLOSE); | |
818 snd_flush (); | |
819 x = get4com (); | |
820 if (x == -1) | |
821 wnn_errorno = get4com (); | |
822 #ifdef HAVE_CLOSESOCKET | |
823 closesocket (current_sd); | |
824 #else | |
825 close (current_sd); | |
826 #endif | |
827 return x; | |
828 } | |
829 | |
830 | |
831 /* | |
832 jserver ¤È¤Î´Ö¤Ë connection ¤òÄ¥¤ê¡¢Æ±»þ¤Ë jserver ¤ÎÆâÉô¤Ë´Ä | |
833 ¶¤òºî¤ë¡£env_name ¤Ë´û¤Ë¸ºß¤¹¤ë´Ä¶¤ò»ØÄꤷ¤¿»þ¤Ë¤Ï¤½¤Î´Ä¶¤ò | |
834 ÊÖ¤·¡¢NULL ¤ò»ØÄꤷ¤¿»þ¤Ë¤Ï¿·¤·¤¤´Ä¶¤òºî¤Ã¤ÆÊÖ¤¹¡£ | |
835 */ | |
836 | |
837 struct wnn_env * | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
838 js_connect_lang (WNN_JSERVER_ID *server, register char *env_name, char *lang) |
0 | 839 { |
840 register int e_id; | |
841 register struct wnn_env *env; | |
842 void js_set_lang (); | |
843 | |
844 set_current_js (server); | |
845 if (!(env = (struct wnn_env *) malloc (sizeof (struct wnn_env)))) | |
846 { | |
847 wnn_errorno = WNN_ALLOC_FAIL; | |
848 return NULL; | |
849 } | |
850 handler_of_jserver_dead (NULL); | |
851 snd_head (JS_CONNECT); | |
852 putscom (env_name); | |
853 snd_flush (); | |
854 e_id = get4com (); | |
855 if (e_id == -1) | |
856 { | |
857 wnn_errorno = get4com (); | |
858 free (env); | |
859 return NULL; | |
860 } | |
861 env->env_id = e_id; | |
862 env->js_id = server; | |
863 strcpy (env->lang, lang); /* set language name */ | |
864 return env; | |
865 } | |
866 | |
867 #ifdef nodef | |
868 /* set language value to env */ | |
869 void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
870 js_set_lang (struct wnn_env *env, register char *lang) |
0 | 871 { |
872 register char *p; | |
873 extern char *getenv (); | |
874 | |
875 /* if not specified language , use $LANG */ | |
876 if (lang == 0 || *lang == 0) | |
877 lang = getenv ("LANG"); | |
878 if (lang == 0 || *lang == 0) | |
879 lang = WNN_DEFAULT_LANG; | |
880 for (p = env->lang; *lang != '.' && *lang != '@' && *lang != 0; lang++, p++) | |
881 *p = *lang; | |
882 *p = 0; | |
883 } | |
884 #endif | |
885 | |
886 /* get language value from env */ | |
887 char * | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
888 js_get_lang (struct wnn_env *env) |
0 | 889 { |
890 return (env->lang); | |
891 } | |
892 | |
893 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
894 js_env_exist (register WNN_JSERVER_ID *server, register char *env_name) |
0 | 895 { |
896 set_current_js (server); | |
897 handler_of_jserver_dead (-1); | |
898 snd_head (JS_ENV_EXIST); | |
899 putscom (env_name); | |
900 snd_flush (); | |
901 return (get4com ()); | |
902 } | |
903 | |
904 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
905 js_env_sticky (register struct wnn_env *env) |
0 | 906 { |
907 if (env == 0) | |
908 return (-1); | |
909 set_current_js (env->js_id); | |
910 handler_of_jserver_dead (-1); | |
911 snd_env_head (env, JS_ENV_STICKY); | |
912 snd_flush (); | |
913 return (get4com ()); | |
914 } | |
915 | |
916 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
917 js_env_un_sticky (register struct wnn_env *env) |
0 | 918 { |
919 if (env == 0) | |
920 return (-1); | |
921 set_current_js (env->js_id); | |
922 handler_of_jserver_dead (-1); | |
923 snd_env_head (env, JS_ENV_UN_STICKY); | |
924 snd_flush (); | |
925 return (get4com ()); | |
926 } | |
927 | |
928 /** | |
929 env ¤Ç¼¨¤µ¤ì¤ë´Ä¶¤ò̵¤¯¤¹¡£ | |
930 **/ | |
931 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
932 js_disconnect (register struct wnn_env *env) |
0 | 933 { |
934 register int x; | |
935 struct wnn_env tmp_env; | |
936 if (env == 0) | |
937 return (-1); | |
938 tmp_env = *env; | |
939 /* ËÜÍè¤Ï¡¢free ¤·¤Ê¤¤ã¤¢¤«¤ó¤Î¤À¤±¤É¡¢¥ê¥½¡¼¥¹´ÉÍý¤¬½ÐÍè¤Ê¤¤¤·¡¢ | |
940 ¤Þ¤¢¡¢8¥Ð¥¤¥È¤À¤«¤é¡¢¥´¥ß¤¬»Ä¤ë¤±¤É¤¤¤¤¤À¤í¤¦¡£ | |
941 free((char *)env); | |
942 */ | |
943 set_current_js (env->js_id); | |
1 | 944 handler_of_jserver_dead (0); |
0 | 945 snd_env_head (&tmp_env, JS_DISCONNECT); |
946 snd_flush (); | |
947 x = get4com (); | |
948 if (x == -1) | |
949 { | |
950 wnn_errorno = get4com (); | |
951 } | |
952 return x; | |
953 } | |
954 | |
955 /** ¥µ¡¼¥Ð¤È¥³¥Í¥¯¥È¤·¤Æ¤¤¤ë¤« **/ | |
956 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
957 js_isconnect (register struct wnn_env *env) |
0 | 958 { |
959 if (env && env->js_id) | |
960 return (env->js_id->js_dead); | |
961 return (-1); | |
962 } | |
963 | |
964 /** | |
965 env ¤Î ´Ä¶ ¤È¤ÎÄÌ¿®¥Ð¥Ã¥Õ¥¡¤ò flush ¤¹¤ë¡£ | |
966 **/ | |
967 void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
968 js_flush (struct wnn_env *env) |
0 | 969 { |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
970 /* no operation */ |
0 | 971 } |
972 | |
973 | |
974 | |
975 /* Parameter set/get */ | |
976 /** ÊÑ´¹ parameter ¤òÀßÄꤹ¤ë¡£ **/ | |
977 /** js_param_set **/ | |
978 int | |
979 js_param_set (env, para) | |
980 struct wnn_env *env; | |
981 register struct wnn_param *para; | |
982 { | |
983 register int x; | |
984 if (env == 0) | |
985 return (-1); | |
986 set_current_js (env->js_id); | |
987 handler_of_jserver_dead (-1); | |
988 snd_env_head (env, JS_PARAM_SET); | |
989 put4com (para->n); /* £Î(Âç)ʸÀá²òÀϤΣΠ*/ | |
990 put4com (para->nsho); /* ÂçʸÀáÃæ¤Î¾®Ê¸Àá¤ÎºÇÂç¿ô */ | |
991 put4com (para->p1); /* ´´¸ì¤ÎÉÑÅ٤Υѥé¥á¡¼¥¿ */ | |
992 put4com (para->p2); /* ¾®Ê¸ÀáĹ¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
993 put4com (para->p3); /* ´´¸ìĹ¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
994 put4com (para->p4); /* º£»È¤Ã¤¿¤è¥Ó¥Ã¥È¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
995 put4com (para->p5); /* ¼½ñ¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
996 put4com (para->p6); /* ¾®Ê¸Àá¤Îɾ²ÁÃͤΥѥé¥á¡¼¥¿ */ | |
997 put4com (para->p7); /* ÂçʸÀáĹ¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
998 put4com (para->p8); /* ¾®Ê¸Àá¿ô¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
999 | |
1000 put4com (para->p9); /* µ¿»÷ÉÊ»ì ¿ô»ú¤ÎÉÑÅÙ */ | |
1001 put4com (para->p10); /* µ¿»÷ÉÊ»ì ¥«¥Ê¤ÎÉÑÅÙ *//* CWNN ±Ñ¿ô¤ÎÉÑÅÙ */ | |
1002 put4com (para->p11); /* µ¿»÷ÉÊ»ì ±Ñ¿ô¤ÎÉÑÅÙ *//* CWNN µ¹æ¤ÎÉÑÅÙ */ | |
1003 put4com (para->p12); /* µ¿»÷ÉÊ»ì µ¹æ¤ÎÉÑÅÙ *//* CWNN ³«³ç¸Ì¤ÎÉÑÅÙ */ | |
1004 put4com (para->p13); /* µ¿»÷ÉÊ»ì Êijç¸Ì¤ÎÉÑÅÙ *//* CWNN Êijç¸Ì¤ÎÉÑÅÙ */ | |
1005 put4com (para->p14); /* µ¿»÷ÉÊ»ì ÉÕ°¸ì¤ÎÉÑÅÙ *//* BWNN No of koho */ | |
1006 put4com (para->p15); /* µ¿»÷ÉÊ»ì ³«³ç¸Ì¤ÎÉÑÅÙ *//* CWNN Not used */ | |
1007 | |
1008 snd_flush (); | |
1009 x = get4com (); | |
1010 if (x == -1) | |
1011 { | |
1012 wnn_errorno = get4com (); | |
1013 return -1; | |
1014 } | |
1015 return 0; | |
1016 } | |
1017 | |
1018 /** js_param_get **/ | |
1019 /** env ¤Ç¼¨¤µ¤ì¤ë´Ä¶¤ÎÊÑ´¹ parameter ¤ò¼è¤ê½Ð¤¹¡£ **/ | |
1020 int | |
1021 js_param_get (env, para) | |
1022 struct wnn_env *env; | |
1023 register struct wnn_param *para; | |
1024 { | |
1025 if (env == 0) | |
1026 return (-1); | |
1027 set_current_js (env->js_id); | |
1028 handler_of_jserver_dead (-1); | |
1029 snd_env_head (env, JS_PARAM_GET); | |
1030 snd_flush (); | |
1031 if (get4com () == -1) | |
1032 { | |
1033 wnn_errorno = get4com (); | |
1034 return -1; | |
1035 } | |
1036 para->n = get4com (); /* £Î(Âç)ʸÀá²òÀϤΣΠ*/ | |
1037 para->nsho = get4com (); /* ÂçʸÀáÃæ¤Î¾®Ê¸Àá¤ÎºÇÂç¿ô */ | |
1038 para->p1 = get4com (); /* ´´¸ì¤ÎÉÑÅ٤Υѥé¥á¡¼¥¿ */ | |
1039 para->p2 = get4com (); /* ¾®Ê¸ÀáĹ¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
1040 para->p3 = get4com (); /* ´´¸ìĹ¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
1041 para->p4 = get4com (); /* º£»È¤Ã¤¿¤è¥Ó¥Ã¥È¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
1042 para->p5 = get4com (); /* ¼½ñ¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
1043 para->p6 = get4com (); /* ¾®Ê¸Àá¤Îɾ²ÁÃͤΥѥé¥á¡¼¥¿ */ | |
1044 para->p7 = get4com (); /* ÂçʸÀáĹ¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
1045 para->p8 = get4com (); /* ¾®Ê¸Àá¿ô¤Î¥Ñ¥é¥á¡¼¥¿ */ | |
1046 para->p9 = get4com (); /* µ¿»÷ÉÊ»ì ¿ô»ú¤ÎÉÑÅÙ */ | |
1047 para->p10 = get4com (); /* µ¿»÷ÉÊ»ì ¥«¥Ê¤ÎÉÑÅÙ */ | |
1048 para->p11 = get4com (); /* µ¿»÷ÉÊ»ì ±Ñ¿ô¤ÎÉÑÅÙ */ | |
1049 para->p12 = get4com (); /* µ¿»÷ÉÊ»ì µ¹æ¤ÎÉÑÅÙ */ | |
1050 para->p13 = get4com (); /* µ¿»÷ÉÊ»ì Êijç¸Ì¤ÎÉÑÅÙ */ | |
1051 para->p14 = get4com (); /* µ¿»÷ÉÊ»ì ÉÕ°¸ì¤ÎÉÑÅÙ */ | |
1052 para->p15 = get4com (); /* µ¿»÷ÉÊ»ì ³«³ç¸Ì¤ÎÉÑÅÙ */ | |
1053 | |
1054 return 0; | |
1055 } | |
1056 | |
1057 /* | |
1058 global File Operation | |
1059 */ | |
1060 /** js_mkdir **/ | |
1061 int | |
1062 js_mkdir (env, path) | |
1063 struct wnn_env *env; | |
1064 char *path; | |
1065 { | |
1066 register int x; | |
1067 if (env == 0) | |
1068 return (-1); | |
1069 set_current_js (env->js_id); | |
1070 handler_of_jserver_dead (-1); | |
1071 snd_env_head (env, JS_MKDIR); | |
1072 putscom (path); | |
1073 snd_flush (); | |
1074 x = get4com (); | |
1075 if (x == -1) | |
1076 wnn_errorno = get4com (); | |
1077 return x; | |
1078 } | |
1079 | |
1080 /** js_access **/ | |
1081 int | |
1082 js_access (env, path, amode) | |
1083 struct wnn_env *env; | |
1084 char *path; | |
1085 int amode; | |
1086 { | |
1087 register int x; | |
1088 if (env == 0) | |
1089 return (-1); | |
1090 set_current_js (env->js_id); | |
1091 handler_of_jserver_dead (-1); | |
1092 snd_env_head (env, JS_ACCESS); | |
1093 put4com (amode); | |
1094 putscom (path); | |
1095 snd_flush (); | |
1096 x = get4com (); | |
1097 return x; | |
1098 } | |
1099 | |
1100 /** js_file_list_all **/ | |
1101 static int rcv_file_list (); | |
1102 | |
1103 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1104 js_file_list_all (WNN_JSERVER_ID *server, struct wnn_ret_buf *ret) |
0 | 1105 { |
1106 set_current_js (server); | |
1107 handler_of_jserver_dead (-1); | |
1108 snd_server_head (server, JS_FILE_LIST_ALL); | |
1109 snd_flush (); | |
1110 return rcv_file_list (ret); | |
1111 } | |
1112 | |
1113 | |
1114 /** js_file_list **/ | |
1115 int | |
1116 js_file_list (env, ret) | |
1117 struct wnn_env *env; | |
1118 struct wnn_ret_buf *ret; | |
1119 { | |
1120 if (env == 0) | |
1121 return (-1); | |
1122 set_current_js (env->js_id); | |
1123 handler_of_jserver_dead (-1); | |
1124 snd_env_head (env, JS_FILE_LIST); | |
1125 snd_flush (); | |
1126 return rcv_file_list (ret); | |
1127 } | |
1128 | |
1129 static void re_alloc (); | |
1130 | |
1131 static int | |
1132 rcv_file_list (ret) | |
1133 struct wnn_ret_buf *ret; | |
1134 { | |
1135 register int i, count; | |
1136 WNN_FILE_INFO_STRUCT *files; | |
1137 count = get4com (); | |
1138 re_alloc (ret, sizeof (WNN_FILE_INFO_STRUCT) * count); | |
1139 files = (WNN_FILE_INFO_STRUCT *) ret->buf; | |
1140 for (i = 0; i < count; i++) | |
1141 { | |
1142 files->fid = get4com (); | |
1143 files->localf = get4com (); | |
1144 files->ref_count = get4com (); | |
1145 files->type = get4com (); | |
1146 getscom (files->name); | |
1147 files++; | |
1148 } | |
1149 return count; | |
1150 } | |
1151 | |
1152 /** js_file_stat **/ | |
1153 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1154 js_file_stat (struct wnn_env *env, char *path, WNN_FILE_STAT *s) |
0 | 1155 { |
1156 register int x; | |
1157 if (env == 0) | |
1158 return (-1); | |
1159 set_current_js (env->js_id); | |
1160 handler_of_jserver_dead (-1); | |
1161 snd_env_head (env, JS_FILE_STAT); | |
1162 putscom (path); | |
1163 snd_flush (); | |
1164 x = get4com (); | |
1165 s->type = x; | |
1166 return x; | |
1167 } | |
1168 | |
1169 | |
1170 /** js_file_info **/ | |
1171 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1172 js_file_info (struct wnn_env *env, int fid, register WNN_FILE_INFO_STRUCT *file) |
0 | 1173 { |
1174 register int x; | |
1175 if (env == 0) | |
1176 return (-1); | |
1177 set_current_js (env->js_id); | |
1178 handler_of_jserver_dead (-1); | |
1179 snd_env_head (env, JS_FILE_INFO); | |
1180 put4com (fid); | |
1181 snd_flush (); | |
1182 file->fid = fid; | |
1183 x = get4com (); | |
1184 if (x == -1) | |
1185 { | |
1186 wnn_errorno = get4com (); | |
1187 return (-1); | |
1188 } | |
1189 getscom (file->name); | |
1190 file->localf = get4com (); | |
1191 file->ref_count = get4com (); | |
1192 file->type = get4com (); | |
1193 return 0; | |
1194 } | |
1195 | |
1196 /** js_file_loaded **/ | |
1197 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1198 js_file_loaded (WNN_JSERVER_ID *server, char *path) |
0 | 1199 { |
1200 register int x; | |
1201 set_current_js (server); | |
1202 handler_of_jserver_dead (-1); | |
1203 snd_server_head (server, JS_FILE_LOADED); | |
1204 putscom (path); | |
1205 snd_flush (); | |
1206 x = get4com (); | |
1207 return x; | |
1208 } | |
1209 | |
1210 /** js_file_loaded_local **/ | |
1211 static int check_local_file (); | |
1212 static int file_loaded_local (); | |
1213 | |
1214 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1215 js_file_loaded_local (WNN_JSERVER_ID *server, char *path) |
0 | 1216 { |
1217 int x; | |
1218 set_current_js (server); | |
1219 handler_of_jserver_dead (-1); | |
1220 | |
1221 if (check_local_file (path) == -1) | |
1222 return (-1); | |
1223 snd_server_head (server, JS_FILE_LOADED_LOCAL); | |
1224 x = file_loaded_local (path); | |
1225 if (x == -1) | |
1226 { | |
1227 return -1; | |
1228 } | |
1229 return x; | |
1230 } | |
1231 | |
1232 static int | |
1233 check_local_file (path) | |
1234 char *path; | |
1235 { | |
1236 register FILE *f; | |
1237 register int x; | |
1238 struct wnn_file_head fh; | |
1239 | |
1240 #ifdef WRITE_CHECK | |
1241 check_backup (path); | |
1242 #endif /* WRITE_CHECK */ | |
1243 f = fopen (path, "r"); | |
1244 if (f == NULL) | |
1245 { | |
1246 wnn_errorno = WNN_OPENF_ERR; | |
1247 return -1; | |
1248 } | |
1249 x = input_file_header (f, &fh); | |
1250 if (x == -1) | |
1251 { | |
1252 fclose (f); | |
1253 wnn_errorno = WNN_NOT_A_FILE; | |
1254 return -1; | |
1255 } | |
1256 if (check_inode (f, &fh) == -1) | |
1257 { | |
1258 change_file_uniq (&fh, path); | |
1259 #ifdef WRITE_CHECK | |
1260 fclose (f); | |
1261 f = fopen (path, "r"); | |
1262 if (f == NULL) | |
1263 { | |
1264 wnn_errorno = WNN_OPENF_ERR; | |
1265 return (-1); | |
1266 } | |
1267 #endif /* WRITE_CHECK */ | |
1268 if (check_inode (f, &fh) == -1) | |
1269 { | |
1270 fclose (f); | |
1271 wnn_errorno = WNN_INODE_CHECK_ERROR; | |
1272 return (-1); | |
1273 } | |
1274 } | |
1275 fclose (f); | |
1276 return 0; | |
1277 } | |
1278 | |
1279 | |
1280 static int | |
1281 file_loaded_local (path) | |
1282 char *path; | |
1283 { | |
1284 register int x, i; | |
1285 FILE *f; | |
1286 struct wnn_file_head fh; | |
1287 | |
1288 #ifdef WRITE_CHECK | |
1289 check_backup (path); | |
1290 #endif /* WRITE_CHECK */ | |
1291 f = fopen (path, "r"); | |
1292 if (f == NULL) | |
1293 { | |
1294 wnn_errorno = WNN_OPENF_ERR; | |
1295 return -1; | |
1296 } | |
1297 x = input_file_header (f, &fh); | |
1298 if (x == -1) | |
1299 { | |
1300 fclose (f); | |
1301 wnn_errorno = WNN_NOT_A_FILE; | |
1302 return -1; | |
1303 } | |
1304 put4com (fh.file_uniq.time); | |
1305 put4com (fh.file_uniq.dev); | |
1306 put4com (fh.file_uniq.inode); | |
1307 for (i = 0; i < WNN_HOSTLEN; i++) | |
1308 { | |
1309 put1com (fh.file_uniq.createhost[i]); | |
1310 } | |
1311 | |
1312 snd_flush (); | |
1313 x = get4com (); | |
1314 fclose (f); | |
1315 return x; | |
1316 } | |
1317 | |
1318 | |
1319 /** js_hindo_file_create **/ | |
1320 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1321 js_hindo_file_create (struct wnn_env *env, int fid, char *fn, w_char *comment, char *hpasswd) |
0 | 1322 { |
1323 register int x; | |
1324 if (env == 0) | |
1325 return (-1); | |
1326 set_current_js (env->js_id); | |
1327 handler_of_jserver_dead (-1); | |
1328 snd_env_head (env, JS_HINDO_FILE_CREATE); | |
1329 put4com (fid); | |
1330 putscom (fn); | |
1331 putwscom (comment); | |
1332 putscom (hpasswd); | |
1333 snd_flush (); | |
1334 x = get4com (); | |
1335 if (x == -1) | |
1336 wnn_errorno = get4com (); | |
1337 return x; | |
1338 } | |
1339 | |
1340 /** js_dic_file_create **/ | |
1341 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1342 js_dic_file_create (struct wnn_env *env, char *fn, int type, w_char *comment, char *passwd, char *hpasswd) |
0 | 1343 { |
1344 register int x; | |
1345 if (env == 0) | |
1346 return (-1); | |
1347 set_current_js (env->js_id); | |
1348 handler_of_jserver_dead (-1); | |
1349 snd_env_head (env, JS_DIC_FILE_CREATE); | |
1350 putscom (fn); | |
1351 putwscom (comment); | |
1352 putscom (passwd); | |
1353 putscom (hpasswd); | |
1354 put4com (type); | |
1355 snd_flush (); | |
1356 x = get4com (); | |
1357 if (x == -1) | |
1358 wnn_errorno = get4com (); | |
1359 return x; | |
1360 } | |
1361 | |
1362 | |
1363 /** js_file_discard **/ | |
1364 int | |
1365 js_file_discard (env, fid) | |
1366 struct wnn_env *env; | |
1367 int fid; | |
1368 { | |
1369 register int x; | |
1370 if (env == 0) | |
1371 return (-1); | |
1372 set_current_js (env->js_id); | |
1373 handler_of_jserver_dead (-1); | |
1374 snd_env_head (env, JS_FILE_DISCARD); | |
1375 put4com (fid); | |
1376 snd_flush (); | |
1377 x = get4com (); | |
1378 if (x == -1) | |
1379 wnn_errorno = get4com (); | |
1380 return x; | |
1381 } | |
1382 | |
1383 /** js_file_read **/ | |
1384 int | |
1385 js_file_read (env, fn) | |
1386 struct wnn_env *env; | |
1387 char *fn; | |
1388 { | |
1389 register int x; | |
1390 if (env == 0) | |
1391 return (-1); | |
1392 set_current_js (env->js_id); | |
1393 handler_of_jserver_dead (-1); | |
1394 snd_env_head (env, JS_FILE_READ); | |
1395 putscom (fn); | |
1396 snd_flush (); | |
1397 x = get4com (); | |
1398 if (x == -1) | |
1399 wnn_errorno = get4com (); | |
1400 return x; | |
1401 } | |
1402 | |
1403 /** js_file_write **/ | |
1404 int | |
1405 js_file_write (env, fid, fn) | |
1406 struct wnn_env *env; | |
1407 int fid; | |
1408 char *fn; | |
1409 { | |
1410 register int x; | |
1411 if (env == 0) | |
1412 return (-1); | |
1413 set_current_js (env->js_id); | |
1414 handler_of_jserver_dead (-1); | |
1415 snd_env_head (env, JS_FILE_WRITE); | |
1416 put4com (fid); | |
1417 putscom (fn); | |
1418 snd_flush (); | |
1419 x = get4com (); | |
1420 if (x == -1) | |
1421 wnn_errorno = get4com (); | |
1422 return x; | |
1423 } | |
1424 | |
1425 /** js_file_receive **/ | |
1426 static int xget1com (); | |
1427 static void xput1com (); | |
1428 | |
1429 int | |
1430 js_file_receive (env, fid, fn) | |
1431 struct wnn_env *env; | |
1432 int fid; | |
1433 char *fn; | |
1434 { | |
1435 register int mode, x; | |
1436 char file_name[1024]; | |
1437 char buf[1024]; | |
1438 FILE *f; | |
1439 int n; | |
1440 struct wnn_file_head fh; | |
1441 int i; | |
1442 #ifdef WRITE_CHECK | |
1443 char *tmp, *backup = NULL, tmp_x; | |
1444 int tmp_err = 0; | |
1445 #endif /* WRITE_CHECK */ | |
1446 | |
1447 if (env == 0) | |
1448 return (-1); | |
1449 set_current_js (env->js_id); | |
1450 handler_of_jserver_dead (-1); | |
1451 snd_env_head (env, JS_FILE_RECEIVE); | |
1452 put4com (fid); | |
1453 snd_flush (); | |
1454 /**/ getscom (file_name); | |
1455 if (fn == NULL || strcmp (fn, "") == 0) | |
1456 { | |
1457 gethostname (buf, 1024); | |
1458 n = strlen (buf); | |
1459 buf[n] = C_LOCAL; | |
1460 buf[n + 1] = 0; | |
1461 if (strncmp (buf, file_name, n + 1) == 0) | |
1462 { | |
1463 fn = file_name + n + 1; | |
1464 } | |
1465 } | |
1466 #ifdef WRITE_CHECK | |
1467 check_backup (fn); | |
1468 #endif /* WRITE_CHECK */ | |
1469 if ((f = fopen (fn, "r")) == NULL) | |
1470 { /* New File */ | |
1471 fh.file_uniq.time = fh.file_uniq.dev = fh.file_uniq.inode = 0; | |
1472 } | |
1473 else | |
1474 { /* Old File Exists */ | |
1475 if (input_file_header (f, &fh) == -1) | |
1476 { | |
1477 wnn_errorno = WNN_NOT_A_FILE; | |
1478 fclose (f); | |
1479 put4com (-1); | |
1480 snd_flush (); | |
1481 sleep (1); /* enssure handshake */ | |
1482 return (-1); | |
1483 } | |
1484 fclose (f); | |
1485 } | |
1486 put4com (0); /* Ack */ | |
1487 put4com (fh.file_uniq.time); | |
1488 put4com (fh.file_uniq.dev); | |
1489 put4com (fh.file_uniq.inode); | |
1490 for (i = 0; i < WNN_HOSTLEN; i++) | |
1491 { | |
1492 put1com (fh.file_uniq.createhost[i]); | |
1493 } | |
1494 | |
1495 snd_flush (); | |
1496 | |
1497 if ((mode = get4com ()) == -1) | |
1498 { /* check stat */ | |
1499 wnn_errorno = get4com (); | |
1500 return -1; | |
1501 } | |
1502 else if (mode == 0) | |
1503 { | |
1504 return 0; /* need not saving */ | |
1505 } | |
1506 else if (mode == 1 || mode == 3) | |
1507 { /* mode == 3 means the file is a new one. */ | |
1508 #ifdef WRITE_CHECK | |
1509 backup = make_backup_file (fn); | |
1510 if ((tmp = make_tmp_file (fn, 0, &f)) == NULL) | |
1511 { | |
1512 delete_tmp_file (backup); | |
1513 #else /* WRITE_CHECK */ | |
1514 if ((f = fopen (fn, "w+")) == NULL) | |
1515 { | |
1516 #endif /* WRITE_CHECK */ | |
1517 wnn_errorno = WNN_FILE_WRITE_ERROR; | |
1518 put4com (-1); | |
1519 snd_flush (); | |
1520 sleep (1); /* enssure handshake */ | |
1521 return (-1); | |
1522 } | |
1523 } | |
1524 else if (mode == 2) | |
1525 { | |
1526 #ifdef WRITE_CHECK | |
1527 backup = make_backup_file (fn); | |
1528 if ((tmp = make_tmp_file (fn, 1, &f)) == NULL) | |
1529 { | |
1530 delete_tmp_file (backup); | |
1531 #else /* WRITE_CHECK */ | |
1532 if ((f = fopen (fn, "r+")) == NULL) | |
1533 { /* New File */ | |
1534 #endif /* WRITE_CHECK */ | |
1535 wnn_errorno = WNN_FILE_WRITE_ERROR; | |
1536 put4com (-1); | |
1537 snd_flush (); | |
1538 sleep (1); /* enssure handshake */ | |
1539 return (-1); | |
1540 } | |
1541 } | |
1542 put4com (0); | |
1543 snd_flush (); /* ACK */ | |
1544 for (;;) | |
1545 { | |
1546 if ((x = xget1com ()) == -1) | |
1547 break; /* EOF */ | |
1548 #ifdef WRITE_CHECK | |
1549 tmp_x = (char) x; | |
1550 if (fwrite (&tmp_x, sizeof (char), 1, f) == -1) | |
1551 tmp_err = 1; | |
1552 #else /* WRITE_CHECK */ | |
1553 fputc (x, f); | |
1554 #endif /* WRITE_CHECK */ | |
1555 } | |
1556 fclose (f); | |
1557 #ifdef WRITE_CHECK | |
1558 if (tmp_err == 0) | |
1559 { | |
1560 move_tmp_to_org (tmp, fn, 1); | |
1561 } | |
1562 else | |
1563 { | |
1564 delete_tmp_file (tmp); | |
1565 } | |
1566 delete_tmp_file (backup); | |
1567 #endif /* WRITE_CHECK */ | |
1568 | |
1569 x = get4com (); | |
1570 if (x == -1) | |
1571 wnn_errorno = get4com (); | |
1572 #ifdef WRITE_CHECK | |
1573 if (tmp_err) | |
1574 { | |
1575 wnn_errorno = WNN_FILE_WRITE_ERROR; | |
1576 return (-1); | |
1577 } | |
1578 #endif /* WRITE_CHECK */ | |
1579 | |
1580 return x; | |
1581 } | |
1582 | |
1583 static int | |
1584 xget1com () | |
1585 { | |
1586 register int x; | |
1587 if ((x = get1com ()) != 0xFF) | |
1588 return x; | |
1589 if (get1com () == 0xFF) | |
1590 return -1; /* EOF */ | |
1591 return 0xFF; | |
1592 } | |
1593 | |
1594 /** js_file_send **/ | |
1595 int | |
1596 js_file_send (env, fn) | |
1597 struct wnn_env *env; | |
1598 char *fn; | |
1599 { | |
1600 register int x; | |
1601 FILE *f; | |
1602 int n; | |
1603 char buf[1024], *b; | |
1604 register int cc, i; | |
1605 if (env == 0) | |
1606 return (-1); | |
1607 set_current_js (env->js_id); | |
1608 handler_of_jserver_dead (-1); | |
1609 | |
1610 if (check_local_file (fn) == -1) | |
1611 return (-1); | |
1612 | |
1613 snd_env_head (env, JS_FILE_SEND); | |
1614 x = file_loaded_local (fn); | |
1615 if (x != -1) | |
1616 { /* file is already loaded */ | |
1617 if (get4com () == -1) | |
1618 { | |
1619 wnn_errorno = get4com (); | |
1620 return (-1); | |
1621 } | |
1622 return x; | |
1623 } | |
1624 | |
1625 x = get4com (); | |
1626 if (x == -1) | |
1627 { | |
1628 wnn_errorno = get4com (); | |
1629 return -1; | |
1630 } | |
1631 | |
1632 gethostname (buf, 1024); | |
1633 n = strlen (buf); | |
1634 buf[n] = C_LOCAL; | |
1635 strcpy (buf + n + 1, fn); | |
1636 putscom (buf); | |
1637 | |
1638 #ifdef WRITE_CHECK | |
1639 check_backup (fn); | |
1640 #endif /* WRITE_CHECK */ | |
1641 if ((f = fopen (fn, "r")) == NULL) | |
1642 { | |
1643 xput1com (-1); /* EOF */ | |
1644 return -1; | |
1645 } | |
1646 | |
1647 /* send contents of file */ | |
1648 for (;;) | |
1649 { | |
1650 cc = fread (buf, 1, 1024, f); | |
1651 if (cc <= 0) | |
1652 break; /* EOF */ | |
1653 for (b = buf, i = 0; i < cc; i++) | |
1654 { | |
1655 xput1com ((int) *b++ & 0xff); | |
1656 } | |
1657 } | |
1658 fclose (f); | |
1659 xput1com (-1); /* EOF */ | |
1660 snd_flush (); | |
1661 x = get4com (); | |
1662 if (x == -1) | |
1663 wnn_errorno = get4com (); | |
1664 return x; | |
1665 } | |
1666 | |
1667 static void | |
1668 xput1com (d) | |
1669 int d; | |
1670 { | |
1671 if (d == -1) | |
1672 { | |
1673 put1com (0xFF); | |
1674 put1com (0xFF); | |
1675 return; /* EOF */ | |
1676 } | |
1677 put1com (d); | |
1678 if (d == 0xFF) | |
1679 { | |
1680 put1com (0x00); | |
1681 } | |
1682 } | |
1683 | |
1684 | |
1685 /*** Dic. Operation for Env. ***/ | |
1686 | |
1687 /** js_dic_add **/ | |
1688 int | |
1689 js_dic_add (env, fid, hfid, rev, jnice, rw, hrw, pw1, pw2) | |
1690 struct wnn_env *env; | |
1691 int fid, hfid, rev, jnice, rw, hrw; | |
1692 char *pw1, *pw2; | |
1693 { | |
1694 register int x; | |
1695 if (env == 0) | |
1696 return (-1); | |
1697 set_current_js (env->js_id); | |
1698 handler_of_jserver_dead (-1); | |
1699 snd_env_head (env, JS_DIC_ADD); | |
1700 put4com (fid); | |
1701 put4com (hfid); | |
1702 put4com (jnice); | |
1703 put4com (rw); | |
1704 put4com (hrw); | |
1705 putscom (pw1); | |
1706 putscom (pw2); | |
1707 put4com (rev); /* rev is to add it as reverse dict */ | |
1708 snd_flush (); | |
1709 x = get4com (); | |
1710 if (x == -1) | |
1711 wnn_errorno = get4com (); | |
1712 return x; | |
1713 } | |
1714 | |
1715 /** js_dic_delete **/ | |
1716 int | |
1717 js_dic_delete (env, dicno) | |
1718 struct wnn_env *env; | |
1719 int dicno; | |
1720 { | |
1721 register int x; | |
1722 if (env == 0) | |
1723 return (-1); | |
1724 set_current_js (env->js_id); | |
1725 handler_of_jserver_dead (-1); | |
1726 snd_env_head (env, JS_DIC_DELETE); | |
1727 put4com (dicno); | |
1728 snd_flush (); | |
1729 x = get4com (); | |
1730 if (x == -1) | |
1731 wnn_errorno = get4com (); | |
1732 return x; | |
1733 } | |
1734 | |
1735 /** js_dic_use **/ | |
1736 int | |
1737 js_dic_use (env, dic_no, flag) | |
1738 struct wnn_env *env; | |
1739 int dic_no, flag; | |
1740 { | |
1741 register int x; | |
1742 if (env == 0) | |
1743 return (-1); | |
1744 set_current_js (env->js_id); | |
1745 handler_of_jserver_dead (-1); | |
1746 snd_env_head (env, JS_DIC_USE); | |
1747 put4com (dic_no); | |
1748 put4com (flag); | |
1749 snd_flush (); | |
1750 x = get4com (); | |
1751 if (x == -1) | |
1752 wnn_errorno = get4com (); | |
1753 return x; | |
1754 } | |
1755 | |
1756 /** js_fuzokugo_set **/ | |
1757 int | |
1758 js_fuzokugo_set (env, fid) | |
1759 struct wnn_env *env; | |
1760 int fid; | |
1761 { | |
1762 register int x; | |
1763 if (env == 0) | |
1764 return (-1); | |
1765 set_current_js (env->js_id); | |
1766 handler_of_jserver_dead (-1); | |
1767 snd_env_head (env, JS_FUZOKUGO_SET); | |
1768 put4com (fid); | |
1769 snd_flush (); | |
1770 x = get4com (); | |
1771 if (x == -1) | |
1772 wnn_errorno = get4com (); | |
1773 return x; | |
1774 } | |
1775 | |
1776 /** js_fuzokugo_get **/ | |
1777 int | |
1778 js_fuzokugo_get (env) | |
1779 struct wnn_env *env; | |
1780 { | |
1781 register int x; | |
1782 if (env == 0) | |
1783 return (-1); | |
1784 set_current_js (env->js_id); | |
1785 handler_of_jserver_dead (-1); | |
1786 snd_env_head (env, JS_FUZOKUGO_GET); | |
1787 snd_flush (); | |
1788 x = get4com (); | |
1789 if (x == -1) | |
1790 wnn_errorno = get4com (); | |
1791 return x; | |
1792 } | |
1793 | |
1794 /** js_dic_list_all **/ | |
1795 static int rcv_dic_list (); | |
1796 static void get_dic_info (); | |
1797 | |
1798 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1799 js_dic_list_all (WNN_JSERVER_ID *server, struct wnn_ret_buf *ret) |
0 | 1800 { |
1801 set_current_js (server); | |
1802 handler_of_jserver_dead (-1); | |
1803 snd_server_head (server, JS_DIC_LIST_ALL); | |
1804 snd_flush (); | |
1805 return rcv_dic_list (ret); | |
1806 } | |
1807 | |
1808 | |
1809 /** js_dic_list **/ | |
1810 int | |
1811 js_dic_list (env, ret) | |
1812 struct wnn_env *env; | |
1813 struct wnn_ret_buf *ret; | |
1814 { | |
1815 if (env == 0) | |
1816 return (-1); | |
1817 set_current_js (env->js_id); | |
1818 handler_of_jserver_dead (-1); | |
1819 snd_env_head (env, JS_DIC_LIST); | |
1820 snd_flush (); | |
1821 return rcv_dic_list (ret); | |
1822 } | |
1823 | |
1824 static int | |
1825 rcv_dic_list (ret) | |
1826 struct wnn_ret_buf *ret; | |
1827 { | |
1828 register int i, count; | |
1829 register WNN_DIC_INFO *dic; | |
1830 count = get4com (); | |
1831 re_alloc (ret, sizeof (WNN_DIC_INFO) * (count + 1)); | |
1832 | |
1833 dic = (WNN_DIC_INFO *) ret->buf; | |
1834 for (i = 0; i < count; i++) | |
1835 { | |
1836 get_dic_info (dic); | |
1837 dic++; | |
1838 } | |
1839 dic->dic_no = -1; | |
1840 return count; | |
1841 } | |
1842 | |
1843 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1844 get_dic_info (register WNN_DIC_INFO *dic) |
0 | 1845 { |
1846 dic->dic_no = get4com (); /* dic_No */ | |
1847 dic->body = get4com (); /* body fid */ | |
1848 dic->hindo = get4com (); /* hindo fid */ | |
1849 dic->rw = get4com (); /* r/w */ | |
1850 dic->hindo_rw = get4com (); /* hindo r/w */ | |
1851 dic->enablef = get4com (); /* enable/disable */ | |
1852 dic->nice = get4com (); /* nice */ | |
1853 dic->rev = get4com (); | |
1854 /* added H.T */ | |
1855 getwscom (dic->comment); | |
1856 getscom (dic->fname); | |
1857 getscom (dic->hfname); | |
1858 getscom (dic->passwd); | |
1859 getscom (dic->hpasswd); | |
1860 dic->type = get4com (); | |
1861 dic->gosuu = get4com (); | |
1862 dic->localf = get4com (); | |
1863 dic->hlocalf = get4com (); | |
1864 } | |
1865 | |
1866 /*** Dic. Operation by dic_No. ***/ | |
1867 | |
1868 /** js_word_add **/ | |
1869 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1870 js_word_add (struct wnn_env *env, int dic_no, w_char *yomi, w_char *kanji, w_char *comment, int hinshi, int init_hindo) |
0 | 1871 { |
1872 register int x; | |
1873 if (env == 0) | |
1874 return (-1); | |
1875 set_current_js (env->js_id); | |
1876 handler_of_jserver_dead (-1); | |
1877 snd_env_head (env, JS_WORD_ADD); | |
1878 put4com (dic_no); | |
1879 putwscom (yomi); | |
1880 putwscom (kanji); | |
1881 putwscom (comment); | |
1882 put4com (hinshi); | |
1883 put4com (init_hindo); | |
1884 snd_flush (); | |
1885 x = get4com (); | |
1886 if (x == -1) | |
1887 wnn_errorno = get4com (); | |
1888 return x; | |
1889 } | |
1890 | |
1891 /** js_word_delete **/ | |
1892 int | |
1893 js_word_delete (env, dic_no, entry) | |
1894 struct wnn_env *env; | |
1895 int dic_no; | |
1896 int entry; | |
1897 { | |
1898 register int x; | |
1899 if (env == 0) | |
1900 return (-1); | |
1901 set_current_js (env->js_id); | |
1902 handler_of_jserver_dead (-1); | |
1903 snd_env_head (env, JS_WORD_DELETE); | |
1904 put4com (dic_no); | |
1905 put4com (entry); | |
1906 snd_flush (); | |
1907 x = get4com (); | |
1908 if (x == -1) | |
1909 wnn_errorno = get4com (); | |
1910 return x; | |
1911 } | |
1912 | |
1913 | |
1914 /** js_word_search **/ | |
1915 static int rcv_word_data (); | |
1916 | |
1917 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1918 js_word_search (struct wnn_env *env, int dic_no, w_char *yomi, struct wnn_ret_buf *ret) |
0 | 1919 { |
1920 if (env == 0) | |
1921 return (-1); | |
1922 set_current_js (env->js_id); | |
1923 handler_of_jserver_dead (-1); | |
1924 snd_env_head (env, JS_WORD_SEARCH); | |
1925 put4com (dic_no); | |
1926 putwscom (yomi); | |
1927 snd_flush (); | |
1928 | |
1929 return (rcv_word_data (ret, yomi)); | |
1930 } | |
1931 | |
1932 /** js_word_search_by_env **/ | |
1933 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1934 js_word_search_by_env (struct wnn_env *env, w_char *yomi, struct wnn_ret_buf *ret) |
0 | 1935 { |
1936 if (env == 0) | |
1937 return (-1); | |
1938 set_current_js (env->js_id); | |
1939 handler_of_jserver_dead (-1); | |
1940 snd_env_head (env, JS_WORD_SEARCH_BY_ENV); | |
1941 putwscom (yomi); | |
1942 snd_flush (); | |
1943 | |
1944 return (rcv_word_data (ret, yomi)); | |
1945 } | |
1946 | |
1947 /** js_word_info **/ | |
1948 int | |
1949 js_word_info (env, dic_no, entry, ret) | |
1950 struct wnn_env *env; | |
1951 int dic_no, entry; | |
1952 struct wnn_ret_buf *ret; | |
1953 { | |
1954 register int x; | |
1955 w_char yomi[LENGTHYOMI]; | |
1956 | |
1957 if (env == 0) | |
1958 return (-1); | |
1959 set_current_js (env->js_id); | |
1960 handler_of_jserver_dead (-1); | |
1961 snd_env_head (env, JS_WORD_INFO); | |
1962 put4com (dic_no); | |
1963 put4com (entry); | |
1964 snd_flush (); | |
1965 x = get4com (); | |
1966 if (x == -1) | |
1967 { | |
1968 wnn_errorno = get4com (); | |
1969 return (-1); | |
1970 } | |
1971 getwscom (yomi); | |
1972 rcv_word_data (ret, yomi); | |
1973 return (0); | |
1974 } | |
1975 | |
1976 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
1977 js_word_comment_set (struct wnn_env *env, int dic_no, int entry, w_char *comment) |
0 | 1978 { |
1979 register int x; | |
1980 if (env == 0) | |
1981 return (-1); | |
1982 set_current_js (env->js_id); | |
1983 handler_of_jserver_dead (-1); | |
1984 snd_env_head (env, JS_WORD_COMMENT_SET); | |
1985 put4com (dic_no); | |
1986 put4com (entry); | |
1987 putwscom (comment); | |
1988 snd_flush (); | |
1989 x = get4com (); | |
1990 if (x == -1) | |
1991 { | |
1992 wnn_errorno = get4com (); | |
1993 return (-1); | |
1994 } | |
1995 return (0); | |
1996 } | |
1997 | |
1998 /** rcv for word_search **/ | |
1999 static int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2000 rcv_word_data (struct wnn_ret_buf *ret, w_char *yomi) |
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2001 /* Yomi is not sent from server (at least for the time being). */ |
0 | 2002 { |
2003 register int x, j_c, k_c; | |
2004 w_char *k; | |
2005 register struct wnn_jdata *jd; | |
2006 register int cnt; | |
2007 | |
2008 j_c = get4com (); | |
2009 k_c = get4com (); | |
2010 re_alloc (ret, sizeof (struct wnn_jdata) * (j_c + 1) + sizeof (w_char) * (k_c + j_c * 3 + j_c * wnn_Strlen (yomi))); | |
2011 jd = (struct wnn_jdata *) ret->buf; | |
2012 for (cnt = 0;; cnt++) | |
2013 { | |
2014 jd->dic_no = x = get4com (); | |
2015 if (x == -1) | |
2016 break; | |
2017 jd->serial = get4com (); | |
2018 jd->hinshi = get4com (); | |
2019 jd->hindo = get4com (); | |
2020 jd->ima = get4com (); | |
2021 jd->int_hindo = get4com (); | |
2022 jd->int_ima = get4com (); | |
2023 jd++; | |
2024 } | |
2025 jd++; | |
2026 k = (w_char *) jd; | |
2027 jd = (struct wnn_jdata *) ret->buf; | |
2028 for (;;) | |
2029 { | |
2030 if (jd->dic_no == -1) | |
2031 break; | |
2032 | |
2033 jd->yomi = k; /* Copy Yomi */ | |
2034 wnn_Strcpy (k, yomi); | |
2035 k += wnn_Strlen (k) + 1; | |
2036 | |
2037 jd->kanji = k; /* Get Kanji */ | |
2038 getwscom (k); | |
2039 k += wnn_Strlen (k) + 1; | |
2040 | |
2041 jd->com = k; /* Get Comment */ | |
2042 getwscom (k); | |
2043 k += wnn_Strlen (k) + 1; | |
2044 jd++; | |
2045 } | |
2046 return cnt; | |
2047 } | |
2048 | |
2049 | |
2050 /** js_dic_info **/ | |
2051 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2052 js_dic_info (struct wnn_env *env, int dic_no, register WNN_DIC_INFO *ret) |
0 | 2053 { |
2054 register int x; | |
2055 if (env == 0) | |
2056 return (-1); | |
2057 set_current_js (env->js_id); | |
2058 handler_of_jserver_dead (-1); | |
2059 snd_env_head (env, JS_DIC_INFO); | |
2060 put4com (dic_no); | |
2061 snd_flush (); | |
2062 x = get4com (); | |
2063 if (x == -1) | |
2064 { | |
2065 return get4com (); | |
2066 } | |
2067 get_dic_info (ret); | |
2068 return dic_no; | |
2069 } | |
2070 | |
2071 | |
2072 /** js_who **/ | |
2073 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2074 js_who (WNN_JSERVER_ID *server, struct wnn_ret_buf *ret) |
0 | 2075 { |
2076 register int i, j, c; | |
2077 WNN_JWHO *w; | |
2078 set_current_js (server); | |
2079 handler_of_jserver_dead (-1); | |
2080 snd_server_head (server, JS_WHO); | |
2081 snd_flush (); | |
2082 | |
2083 c = get4com (); | |
2084 if (c == -1) | |
2085 { | |
2086 wnn_errorno = get4com (); | |
2087 return -1; | |
2088 } | |
2089 | |
2090 re_alloc (ret, sizeof (WNN_JWHO) * c); | |
2091 w = (WNN_JWHO *) ret->buf; | |
2092 for (i = 0; i < c; i++) | |
2093 { | |
2094 w->sd = get4com (); | |
2095 getscom (w->user_name); | |
2096 getscom (w->host_name); | |
2097 for (j = 0; j < WNN_MAX_ENV_OF_A_CLIENT; j++) | |
2098 { | |
2099 (w->env)[j] = get4com (); | |
2100 } | |
2101 w++; | |
2102 } | |
2103 return (c); | |
2104 } | |
2105 | |
2106 /** jserver Ãæ¤ÎÁ´¤Æ¤Î´Ä¶¤Ë´Ø¤¹¤ë¾ðÊó¤òÆÀ¤ë¡£ | |
2107 (¥¦¥éµ») | |
2108 **/ | |
2109 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2110 js_env_list (WNN_JSERVER_ID *server, struct wnn_ret_buf *ret) |
0 | 2111 { |
2112 register int i, j, c; | |
2113 WNN_ENV_INFO *w; | |
2114 set_current_js (server); | |
2115 handler_of_jserver_dead (-1); | |
2116 snd_server_head (server, JS_ENV_LIST); | |
2117 snd_flush (); | |
2118 | |
2119 c = get4com (); | |
2120 if (c == -1) | |
2121 { | |
2122 wnn_errorno = get4com (); | |
2123 return -1; | |
2124 } | |
2125 | |
2126 re_alloc (ret, sizeof (WNN_ENV_INFO) * c); | |
2127 w = (WNN_ENV_INFO *) ret->buf; | |
2128 for (i = 0; i < c; i++) | |
2129 { | |
2130 w->env_id = get4com (); | |
2131 getscom (w->env_name); | |
2132 w->ref_count = get4com (); | |
2133 w->fzk_fid = get4com (); | |
2134 w->jishomax = get4com (); | |
2135 for (j = 0; j < WNN_MAX_JISHO_OF_AN_ENV; j++) | |
2136 { | |
2137 (w->jisho)[j] = get4com (); | |
2138 } | |
2139 for (j = 0; j < WNN_MAX_FILE_OF_AN_ENV; j++) | |
2140 { | |
2141 (w->file)[j] = get4com (); | |
2142 } | |
2143 w++; | |
2144 } | |
2145 return (c); | |
2146 } | |
2147 | |
2148 /**** | |
2149 | |
2150 ****/ | |
2151 int | |
2152 js_hindo_set (env, dic, entry, ima, hindo) | |
2153 struct wnn_env *env; | |
2154 int dic, entry, ima, hindo; | |
2155 { | |
2156 register int x; | |
2157 if (env == 0) | |
2158 return (-1); | |
2159 set_current_js (env->js_id); | |
2160 handler_of_jserver_dead (-1); | |
2161 snd_env_head (env, JS_HINDO_SET); | |
2162 | |
2163 put4com (dic); | |
2164 put4com (entry); | |
2165 put4com (ima); | |
2166 put4com (hindo); | |
2167 snd_flush (); | |
2168 if ((x = get4com ()) == -1) | |
2169 { | |
2170 wnn_errorno = get4com (); | |
2171 return -1; | |
2172 } | |
2173 return x; | |
2174 } | |
2175 | |
2176 | |
2177 /**** | |
2178 Henkan | |
2179 ****/ | |
2180 | |
2181 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2182 put_fzk_vec (int hinsi, w_char *fzk, int vec, int vec1) |
0 | 2183 { |
2184 put4com (hinsi); | |
2185 putwscom (fzk); | |
2186 put4com (vec); | |
2187 put4com (vec1); | |
2188 } | |
2189 | |
2190 /** | |
2191 kanren | |
2192 **/ | |
2193 static int rcv_dai (); | |
2194 static void rcv_sho_x (); | |
2195 static void rcv_sho_kanji (); | |
2196 | |
2197 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2198 js_kanren (struct wnn_env *env, w_char *yomi, int hinsi, w_char *fzk, int vec, int vec1, int vec2, struct wnn_ret_buf *rb) |
0 | 2199 { |
2200 if (env == 0) | |
2201 return (-1); | |
2202 set_current_js (env->js_id); | |
2203 handler_of_jserver_dead (-1); | |
2204 | |
2205 snd_env_head (env, JS_KANREN); | |
2206 putwscom (yomi); | |
2207 put_fzk_vec (hinsi, fzk, vec, vec1); | |
2208 put4com (vec2); | |
2209 snd_flush (); | |
2210 return rcv_dai (rb); | |
2211 } | |
2212 | |
2213 /* rcv dai */ | |
2214 static int | |
2215 rcv_dai (ret) | |
2216 struct wnn_ret_buf *ret; | |
2217 { | |
2218 int dai_cnt, sho_sum, kanji_sum, d_size, s_size, k_size, x; | |
2219 register int i; | |
2220 struct wnn_dai_bunsetsu *dai_list; | |
2221 register struct wnn_dai_bunsetsu *dp; | |
2222 struct wnn_sho_bunsetsu *sho_list; | |
2223 register struct wnn_sho_bunsetsu *sp; | |
2224 w_char *kanji, *kp; | |
2225 | |
2226 dai_cnt = get4com (); | |
2227 if (dai_cnt == -1) | |
2228 { /* error dayo */ | |
2229 wnn_errorno = get4com (); | |
2230 return -1; | |
2231 } | |
2232 sho_sum = get4com (); | |
2233 kanji_sum = get4com (); | |
2234 | |
2235 d_size = sizeof (struct wnn_dai_bunsetsu) * dai_cnt; | |
2236 s_size = sizeof (struct wnn_sho_bunsetsu) * sho_sum; | |
2237 k_size = sizeof (w_char) * kanji_sum; | |
2238 | |
2239 /* re_alloc(ret, d_size+s_size+k_size); Seems This cause Bug?? H.T.*/ | |
2240 re_alloc (ret, d_size + s_size + k_size); | |
2241 | |
2242 dai_list = (struct wnn_dai_bunsetsu *) ret->buf; | |
2243 sho_list = (struct wnn_sho_bunsetsu *) ((char *) ret->buf + d_size); | |
2244 kanji = (w_char *) ((char *) ret->buf + d_size + s_size); | |
2245 | |
2246 for (dp = dai_list, i = 0; i < dai_cnt; i++) | |
2247 { | |
2248 dp->end = get4com (); | |
2249 dp->start = get4com (); | |
2250 dp->sbncnt = get4com (); | |
2251 dp->hyoka = get4com (); | |
2252 dp++; | |
2253 } | |
2254 | |
2255 for (dp = dai_list, sp = sho_list, i = 0; i < dai_cnt; i++) | |
2256 { | |
2257 dp->sbn = sp; | |
2258 x = dp->sbncnt; | |
2259 rcv_sho_x (sp, x); | |
2260 sp += x; | |
2261 dp++; | |
2262 } | |
2263 | |
2264 for (dp = dai_list, kp = kanji, i = 0; i < dai_cnt; i++) | |
2265 { | |
2266 rcv_sho_kanji (dp->sbn, dp->sbncnt, &kp); | |
2267 dp++; | |
2268 } | |
2269 return dai_cnt; | |
2270 } | |
2271 | |
2272 /* rcv sho routines */ | |
2273 static void | |
2274 rcv_sho_x (sho_list, sho_cnt) | |
2275 register struct wnn_sho_bunsetsu *sho_list; | |
2276 int sho_cnt; | |
2277 { | |
2278 register int i; | |
2279 for (i = 0; i < sho_cnt; i++) | |
2280 { | |
2281 sho_list->end = get4com (); | |
2282 sho_list->start = get4com (); | |
2283 sho_list->jiriend = get4com (); | |
2284 sho_list->dic_no = get4com (); | |
2285 sho_list->entry = get4com (); | |
2286 sho_list->hindo = get4com (); | |
2287 sho_list->ima = get4com (); | |
2288 sho_list->hinsi = get4com (); | |
2289 sho_list->status = get4com (); | |
2290 sho_list->status_bkwd = get4com (); | |
2291 sho_list->kangovect = get4com (); | |
2292 sho_list->hyoka = get4com (); | |
2293 sho_list++; | |
2294 } | |
2295 } | |
2296 | |
2297 static void | |
2298 rcv_sho_kanji (sho_list, sho_cnt, kanji) | |
2299 struct wnn_sho_bunsetsu *sho_list; | |
2300 int sho_cnt; | |
2301 w_char **kanji; | |
2302 { | |
2303 register w_char *k; | |
2304 register int i, x; | |
2305 k = *kanji; | |
2306 for (i = 0; i < sho_cnt; i++) | |
2307 { | |
2308 sho_list->kanji = k; | |
2309 getwscom (k); | |
2310 x = wnn_Strlen (k); | |
2311 k += x + 1; | |
2312 | |
2313 sho_list->yomi = k; | |
2314 getwscom (k); | |
2315 x = wnn_Strlen (k); | |
2316 k += x + 1; | |
2317 | |
2318 sho_list->fuzoku = k; | |
2319 getwscom (k); | |
2320 x = wnn_Strlen (k); | |
2321 k += x + 1; | |
2322 sho_list++; | |
2323 } | |
2324 *kanji = k; | |
2325 } | |
2326 | |
2327 | |
2328 static int | |
2329 rcv_sho (ret) | |
2330 struct wnn_ret_buf *ret; | |
2331 { | |
2332 register int sho_sum, kanji_sum, s_size, k_size; | |
2333 struct wnn_sho_bunsetsu *sho_list; | |
2334 w_char *kanji, *kp; | |
2335 | |
2336 sho_sum = get4com (); | |
2337 if (sho_sum == -1) | |
2338 { /* error dayo */ | |
2339 wnn_errorno = get4com (); | |
2340 return -1; | |
2341 } | |
2342 kanji_sum = get4com (); | |
2343 | |
2344 s_size = sizeof (struct wnn_sho_bunsetsu) * sho_sum; | |
2345 k_size = sizeof (w_char) * kanji_sum; | |
2346 | |
2347 re_alloc (ret, s_size + k_size); | |
2348 | |
2349 sho_list = (struct wnn_sho_bunsetsu *) ((char *) ret->buf); | |
2350 kanji = (w_char *) ((char *) ret->buf + s_size); | |
2351 | |
2352 rcv_sho_x (sho_list, sho_sum); | |
2353 kp = kanji; | |
2354 rcv_sho_kanji (sho_list, sho_sum, &kp); | |
2355 return sho_sum; | |
2356 } | |
2357 | |
2358 /** | |
2359 kantan | |
2360 **/ | |
2361 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2362 js_kantan_dai (struct wnn_env *env, w_char *yomi, int hinsi, w_char *fzk, int vec, int vec1, struct wnn_ret_buf *rb) |
0 | 2363 { |
2364 if (env == 0) | |
2365 return (-1); | |
2366 set_current_js (env->js_id); | |
2367 handler_of_jserver_dead (-1); | |
2368 | |
2369 snd_env_head (env, JS_KANTAN_DAI); | |
2370 putwscom (yomi); | |
2371 put_fzk_vec (hinsi, fzk, vec, vec1); | |
2372 snd_flush (); | |
2373 | |
2374 return rcv_dai (rb); | |
2375 } | |
2376 | |
2377 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2378 js_kantan_sho (struct wnn_env *env, w_char *yomi, int hinsi, w_char *fzk, int vec, int vec1, struct wnn_ret_buf *rb) |
0 | 2379 { |
2380 int sbncnt; | |
2381 if (env == 0) | |
2382 return (-1); | |
2383 set_current_js (env->js_id); | |
2384 handler_of_jserver_dead (-1); | |
2385 | |
2386 snd_env_head (env, JS_KANTAN_SHO); | |
2387 putwscom (yomi); | |
2388 put_fzk_vec (hinsi, fzk, vec, vec1); | |
2389 snd_flush (); | |
2390 | |
2391 sbncnt = rcv_sho (rb); | |
2392 return sbncnt; | |
2393 } | |
2394 | |
2395 /** | |
2396 kanzen | |
2397 **/ | |
2398 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2399 js_kanzen_dai (struct wnn_env *env, w_char *yomi, int hinsi, w_char *fzk, int vec, int vec1, struct wnn_ret_buf *rb) |
0 | 2400 { |
2401 if (env == 0) | |
2402 return (-1); | |
2403 set_current_js (env->js_id); | |
2404 handler_of_jserver_dead (-1); | |
2405 snd_env_head (env, JS_KANZEN_DAI); | |
2406 putwscom (yomi); | |
2407 put_fzk_vec (hinsi, fzk, vec, vec1); | |
2408 snd_flush (); | |
2409 | |
2410 return rcv_dai (rb); | |
2411 } | |
2412 | |
2413 | |
2414 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2415 js_kanzen_sho (struct wnn_env *env, w_char *yomi, int hinsi, w_char *fzk, int vec, int vec1, struct wnn_ret_buf *rb) |
0 | 2416 { |
2417 int sbncnt; | |
2418 if (env == 0) | |
2419 return (-1); | |
2420 set_current_js (env->js_id); | |
2421 handler_of_jserver_dead (-1); | |
2422 snd_env_head (env, JS_KANZEN_SHO); | |
2423 putwscom (yomi); | |
2424 put_fzk_vec (hinsi, fzk, vec, vec1); | |
2425 snd_flush (); | |
2426 | |
2427 sbncnt = rcv_sho (rb); | |
2428 return sbncnt; | |
2429 } | |
2430 | |
2431 /** js_version **/ | |
2432 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2433 js_version (WNN_JSERVER_ID *server, int *serv, int *libv) |
0 | 2434 { |
2435 set_current_js (server); | |
2436 handler_of_jserver_dead (-1); | |
2437 snd_server_head (server, JS_VERSION); | |
2438 snd_flush (); | |
2439 *libv = JLIB_VERSION; | |
2440 return *serv = get4com (); | |
2441 } | |
2442 | |
2443 static void | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2444 re_alloc (register struct wnn_ret_buf *ret, int size) |
0 | 2445 { |
2446 if (ret->size < size) | |
2447 { | |
2448 if (ret->buf) | |
2449 free ((char *) ret->buf); | |
2450 ret->buf = malloc (size); | |
2451 ret->size = size; | |
2452 } | |
2453 } | |
2454 | |
2455 | |
2456 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2457 js_kill (WNN_JSERVER_ID *server) |
0 | 2458 { |
2459 int x; | |
2460 set_current_js (server); | |
2461 handler_of_jserver_dead (-1); | |
2462 snd_server_head (server, JS_KILL); | |
2463 snd_flush (); | |
2464 x = get4com (); | |
2465 return (x); | |
2466 } | |
2467 | |
2468 | |
2469 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2470 js_file_remove (WNN_JSERVER_ID *server, char *n, char *pwd) |
0 | 2471 { |
2472 register int x; | |
2473 set_current_js (server); | |
2474 handler_of_jserver_dead (-1); | |
2475 snd_server_head (server, JS_FILE_REMOVE); | |
2476 putscom (n); | |
2477 putscom (pwd); | |
2478 snd_flush (); | |
2479 if ((x = get4com ()) == -1) | |
2480 { | |
2481 wnn_errorno = get4com (); | |
2482 return -1; | |
2483 } | |
2484 return (x); | |
2485 } | |
2486 | |
2487 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2488 js_file_remove_client (WNN_JSERVER_ID *server, char *n, char *pwd) |
0 | 2489 { |
2490 struct wnn_file_head fh; | |
2491 register FILE *fp; | |
2492 set_current_js (server); | |
2493 handler_of_jserver_dead (-1); | |
2494 if (js_file_loaded_local (server, n) != -1) | |
2495 { | |
2496 wnn_errorno = WNN_FILE_IN_USE; | |
2497 return (-1); | |
2498 } | |
2499 #ifdef WRITE_CHECK | |
2500 check_backup (n); | |
2501 #endif /* WRITE_CHECK */ | |
2502 if ((fp = fopen (n, "r")) == NULL) | |
2503 { | |
2504 wnn_errorno = WNN_FILE_READ_ERROR; | |
2505 return (-1); | |
2506 } | |
2507 if (input_file_header (fp, &fh) == -1) | |
2508 { | |
2509 fclose (fp); | |
2510 wnn_errorno = WNN_NOT_A_FILE; | |
2511 return (-1); | |
2512 } | |
2513 fclose (fp); | |
2514 if (!check_pwd (pwd, fh.file_passwd)) | |
2515 { | |
2516 wnn_errorno = WNN_INCORRECT_PASSWD; | |
2517 return (-1); | |
2518 } | |
2519 if (unlink (n) == -1) | |
2520 { | |
2521 wnn_errorno = WNN_UNLINK; | |
2522 return (-1); | |
2523 } | |
2524 return (0); | |
2525 } | |
2526 | |
2527 /** js_dic_file_create_client **/ | |
2528 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2529 js_dic_file_create_client (struct wnn_env *env, char *fn, int type, w_char *com, char *passwd, char *hpasswd) |
0 | 2530 { |
2531 int x; | |
2532 if (type != WNN_REV_DICT && type != CWNN_REV_DICT && type != BWNN_REV_DICT && type != WNN_UD_DICT) | |
2533 { | |
2534 wnn_errorno = WNN_NOT_A_UD; | |
2535 return (-1); | |
2536 } | |
2537 x = create_null_dic (fn, com, passwd, hpasswd, type); | |
2538 if (x == -1) | |
2539 { | |
2540 wnn_errorno = WNN_FILE_CREATE_ERROR; | |
2541 return (-1); | |
2542 } | |
2543 return (0); | |
2544 } | |
2545 | |
2546 | |
2547 /** js_hindo_file_create_client **/ | |
2548 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2549 js_hindo_file_create_client (struct wnn_env *env, int fid, char *fn, w_char *com, char *hpasswd) |
0 | 2550 { |
2551 register int x; | |
2552 struct wnn_file_uniq funiq; | |
2553 int serial; | |
2554 register int i; | |
2555 | |
2556 if (env == 0) | |
2557 return (-1); | |
2558 set_current_js (env->js_id); | |
2559 handler_of_jserver_dead (-1); | |
2560 snd_env_head (env, JS_HINDO_FILE_CREATE_CLIENT); | |
2561 put4com (fid); | |
2562 snd_flush (); | |
2563 x = get4com (); | |
2564 if (x == -1) | |
2565 { | |
2566 wnn_errorno = get4com (); | |
2567 return (-1); | |
2568 } | |
2569 serial = get4com (); | |
2570 funiq.time = get4com (); | |
2571 funiq.dev = get4com (); | |
2572 funiq.inode = get4com (); | |
2573 for (i = 0; i < WNN_HOSTLEN; i++) | |
2574 { | |
2575 funiq.createhost[i] = get1com (); | |
2576 } | |
2577 /* getscom(funiq.createhost); */ | |
2578 if (create_hindo_file (&funiq, fn, com, hpasswd, serial) == -1) | |
2579 { | |
2580 wnn_errorno = WNN_FILE_CREATE_ERROR; | |
2581 return (-1); | |
2582 } | |
2583 return (0); | |
2584 } | |
2585 | |
2586 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2587 js_file_comment_set (struct wnn_env *env, int fid, w_char *comment) |
0 | 2588 { |
2589 register int x; | |
2590 if (env == 0) | |
2591 return (-1); | |
2592 set_current_js (env->js_id); | |
2593 handler_of_jserver_dead (-1); | |
2594 snd_env_head (env, JS_FILE_COMMENT_SET); | |
2595 put4com (fid); | |
2596 putwscom (comment); | |
2597 snd_flush (); | |
2598 x = get4com (); | |
2599 if (x == -1) | |
2600 { | |
2601 wnn_errorno = get4com (); | |
2602 return (-1); | |
2603 } | |
2604 return (0); | |
2605 } | |
2606 | |
2607 | |
2608 /* | |
2609 * Hinsi Primitives | |
2610 */ | |
2611 | |
2612 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2613 js_hinsi_name (WNN_JSERVER_ID *server, int no, struct wnn_ret_buf *rb) |
0 | 2614 { |
2615 register int size; | |
2616 | |
2617 set_current_js (server); | |
2618 handler_of_jserver_dead (-1); | |
2619 snd_server_head (server, JS_HINSI_NAME); | |
2620 put4com (no); | |
2621 snd_flush (); | |
2622 if ((size = get4com ()) == -1) | |
2623 { | |
2624 wnn_errorno = get4com (); | |
2625 return (-1); | |
2626 } | |
2627 re_alloc (rb, sizeof (w_char) * (size + 1)); | |
2628 getwscom ((w_char *) rb->buf); | |
2629 return (0); | |
2630 } | |
2631 | |
2632 | |
2633 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2634 js_hinsi_number (WNN_JSERVER_ID *server, w_char *name) |
0 | 2635 { |
2636 register int no; | |
2637 | |
2638 set_current_js (server); | |
2639 handler_of_jserver_dead (-1); | |
2640 snd_server_head (server, JS_HINSI_NUMBER); | |
2641 putwscom (name); | |
2642 snd_flush (); | |
2643 if ((no = get4com ()) == -1) | |
2644 { | |
2645 wnn_errorno = get4com (); | |
2646 return (-1); | |
2647 } | |
2648 return (no); | |
2649 } | |
2650 | |
2651 | |
2652 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2653 js_hinsi_list (struct wnn_env *env, int dic_no, w_char *name, struct wnn_ret_buf *rb) |
0 | 2654 { |
2655 int size; | |
2656 int count; | |
2657 register w_char *s; | |
2658 register w_char **r; | |
2659 register int k; | |
2660 | |
2661 if (env == 0) | |
2662 return (-1); | |
2663 set_current_js (env->js_id); | |
2664 handler_of_jserver_dead (-1); | |
2665 snd_env_head (env, JS_HINSI_LIST); | |
2666 put4com (dic_no); | |
2667 putwscom (name); | |
2668 snd_flush (); | |
2669 if ((count = get4com ()) == -1) | |
2670 { | |
2671 wnn_errorno = get4com (); | |
2672 return (-1); | |
2673 } | |
2674 size = get4com (); | |
2675 re_alloc (rb, sizeof (w_char) * (size + 1) + count * sizeof (w_char *)); | |
2676 r = (w_char **) rb->buf; | |
2677 s = (w_char *) ((w_char **) rb->buf + count); | |
2678 for (k = 0; k < count; k++) | |
2679 { | |
2680 *r++ = s; | |
2681 getwscom (s); | |
2682 s += wnn_Strlen (s) + 1; | |
2683 } | |
2684 return (count); | |
2685 } | |
2686 | |
2687 | |
2688 int | |
2689 js_hinsi_dicts (env, no, rb) | |
2690 struct wnn_env *env; | |
2691 int no; | |
2692 struct wnn_ret_buf *rb; | |
2693 { | |
2694 register int k, count; | |
2695 int *p; | |
2696 | |
2697 if (env == 0) | |
2698 return (-1); | |
2699 set_current_js (env->js_id); | |
2700 handler_of_jserver_dead (-1); | |
2701 snd_env_head (env, JS_HINSI_DICTS); | |
2702 put4com (no); | |
2703 snd_flush (); | |
2704 if ((count = get4com ()) == -1) | |
2705 { | |
2706 wnn_errorno = get4com (); | |
2707 return (-1); | |
2708 } | |
2709 re_alloc (rb, sizeof (int) * (count + 1)); | |
2710 p = (int *) rb->buf; | |
2711 | |
2712 for (k = 0; k < count; k++) | |
2713 { | |
2714 *p++ = get4com (); | |
2715 } | |
2716 return (count); | |
2717 } | |
2718 | |
2719 | |
2720 char *wnn_dic_types[] = { "", "¸ÇÄê", "ÅÐÏ¿", "µÕ°ú", "Àµµ¬" }; | |
2721 | |
2722 char *cwnn_dic_types[] = { "", "¹Ì¶¨", "µÇ¼", "Æ´Òô", "Õý¹æ" }; | |
2723 char *bwnn_dic_types[] = { "", "¹Ì¶¨", "µÇ¼", "±ÊÐÍ", "Õý¹æ" }; | |
2724 | |
2725 char *kwnn_dic_types[] = { "", "°íÁ¤", "µî·Ï", "¿ª¿ë", "Á¤±Ô" }; | |
2726 /* ͳïÒ ÔôÖâ æ½ìÚ ïáЮ */ | |
2727 | |
2728 /* New primitives 9/8 */ | |
2729 | |
2730 int | |
2731 js_file_password_set (env, fid, which, old, new) | |
2732 struct wnn_env *env; | |
2733 int fid; | |
2734 int which; /* 1 for dic, 2 for hindo 3(0) for both */ | |
2735 char *old, *new; | |
2736 { | |
2737 register int x; | |
2738 if (env == 0) | |
2739 return (-1); | |
2740 set_current_js (env->js_id); | |
2741 handler_of_jserver_dead (-1); | |
2742 snd_env_head (env, JS_FILE_PASSWORD_SET); | |
2743 put4com (fid); | |
2744 put4com (which); | |
2745 putscom (old); | |
2746 putscom (new); | |
2747 snd_flush (); | |
2748 x = get4com (); | |
2749 if (x == -1) | |
2750 { | |
2751 wnn_errorno = get4com (); | |
2752 return (-1); | |
2753 } | |
2754 return (0); | |
2755 } | |
2756 | |
2757 int | |
12
1f16ab4b33e5
add prototypes for functions to jslib.h
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
5
diff
changeset
|
2758 js_hinsi_table_set (struct wnn_env *env, int dic_no, w_char *hinsi_table) |
0 | 2759 { |
2760 int x; | |
2761 if (env == 0) | |
2762 return (-1); | |
2763 set_current_js (env->js_id); | |
2764 handler_of_jserver_dead (-1); | |
2765 snd_env_head (env, JS_HINSI_TABLE_SET); | |
2766 put4com (dic_no); | |
2767 putwscom (hinsi_table); | |
2768 snd_flush (); | |
2769 x = get4com (); | |
2770 if (x == -1) | |
2771 { | |
2772 wnn_errorno = get4com (); | |
2773 return (-1); | |
2774 } | |
2775 return (0); | |
2776 } | |
2777 | |
2778 #define SERVERDEFS_FILE "/serverdefs" | |
2779 | |
2780 #define MACHINE_NAME 1 | |
2781 #define UNIXDOMAIN_NAME 2 | |
2782 #define SERVICE_NAME 3 | |
2783 #define SERVICE_PORT_NUM 4 | |
2784 | |
2785 static char * | |
2786 get_serv_defs (lang, cnt) | |
2787 char *lang; | |
2788 int cnt; | |
2789 { | |
2790 FILE *fp; | |
2791 static char s[7][EXPAND_PATH_LENGTH]; | |
2792 char serv_defs[EXPAND_PATH_LENGTH]; | |
2793 char data[1024]; | |
2794 int num; | |
2795 | |
2796 strcpy (serv_defs, LIBDIR); | |
2797 strcat (serv_defs, SERVERDEFS_FILE); | |
2798 if ((fp = fopen (serv_defs, "r")) == NULL) | |
2799 { | |
2800 return (NULL); | |
2801 } | |
2802 while (fgets (data, 1024, fp) != NULL) | |
2803 { | |
2804 num = sscanf (data, "%s %s %s %s %s %s %s", s[0], s[1], s[2], s[3], s[4], s[5], s[6]); | |
2805 if ((num < 4) || s[0][0] == ';') | |
2806 { | |
2807 continue; | |
2808 } | |
2809 if (!strncmp (lang, s[0], strlen (s[0]))) | |
2810 { | |
2811 fclose (fp); | |
2812 if (cnt == SERVICE_PORT_NUM && num < 5) | |
2813 return (NULL); | |
2814 if (strlen (s[cnt]) == strlen ("NULL") && !strcmp (s[cnt], "NULL")) | |
2815 { | |
2816 return (NULL); | |
2817 } | |
2818 else | |
2819 { | |
2820 return (s[cnt]); | |
2821 } | |
2822 } | |
2823 } | |
2824 fclose (fp); | |
2825 return (NULL); | |
2826 } | |
2827 | |
2828 char * | |
2829 _wnn_get_machine_of_serv_defs (lang) | |
2830 char *lang; | |
2831 { | |
2832 return (get_serv_defs (lang, MACHINE_NAME)); | |
2833 } | |
2834 | |
2835 static char * | |
2836 get_unixdomain_of_serv_defs (lang) | |
2837 char *lang; | |
2838 { | |
2839 return (get_serv_defs (lang, UNIXDOMAIN_NAME)); | |
2840 } | |
2841 | |
2842 static char * | |
2843 get_service_of_serv_defs (lang) | |
2844 char *lang; | |
2845 { | |
2846 return (get_serv_defs (lang, SERVICE_NAME)); | |
2847 } | |
2848 | |
2849 static int | |
2850 get_port_num_of_serv_defs (lang) | |
2851 char *lang; | |
2852 { | |
2853 char *port_char; | |
2854 | |
2855 if ((port_char = get_serv_defs (lang, SERVICE_PORT_NUM)) == NULL) | |
2856 { | |
2857 return (-1); | |
2858 } | |
2859 else | |
2860 { | |
2861 return (atoi (port_char)); | |
2862 } | |
2863 } |