0
|
1 /*
|
|
2 * $Id: wnnstat.c,v 1.10 2002/05/12 22:51:17 hiroo 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, 2002
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp>
|
|
16 *
|
|
17 * This program is free software; you can redistribute it and/or modify
|
|
18 * it under the terms of the GNU General Public License as published by
|
|
19 * the Free Software Foundation; either version 2 of the License, or
|
|
20 * (at your option) any later version.
|
|
21 *
|
|
22 * This program 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
|
|
25 * GNU General Public License for more details.
|
|
26 *
|
|
27 * You should have received a copy of the GNU General Public License
|
|
28 * along with this program; if not, write to the Free Software
|
|
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
30 */
|
|
31
|
|
32 #ifdef HAVE_CONFIG_H
|
|
33 # include <config.h>
|
|
34 #endif
|
|
35
|
|
36 #include <stdio.h>
|
|
37 #if STDC_HEADERS
|
|
38 # include <stdlib.h>
|
|
39 # include <string.h>
|
|
40 #else /* !STDC_HEADERS */
|
|
41 # if HAVE_MALLOC_H
|
|
42 # include <malloc.h>
|
|
43 # endif
|
|
44 # if HAVE_STRINGS_H
|
|
45 # include <strings.h>
|
|
46 # endif
|
|
47 #endif /* !STDC_HEADERS */
|
|
48 #if HAVE_UNISTD_H
|
|
49 # include <unistd.h>
|
|
50 #endif
|
|
51
|
|
52 #include "jslib.h"
|
|
53 #include "jllib.h"
|
|
54 #include "jd_sock.h"
|
|
55 #include "commonhd.h"
|
|
56 #include "wnn_config.h"
|
|
57 #include "wnn_os.h"
|
|
58 #include "msg.h"
|
|
59
|
|
60 WNN_JSERVER_ID *js;
|
|
61 struct wnn_ret_buf rb = { 0, NULL };
|
|
62 #define WNNSTAT_ENV "This_is_wnnstat"
|
|
63
|
|
64 #define W_WHO 0
|
|
65 #define W_ENV 1
|
|
66 #define W_ALL 2
|
|
67 #define W_FILE 3
|
|
68 #define W_DIC 4
|
|
69 #define W_DIC_ALL 5
|
|
70 #define W_VERSION 6
|
|
71
|
|
72 #ifdef JAPANESE
|
|
73 extern int eujis_to_jis8 (), eujis_to_sjis ();
|
|
74 #endif
|
|
75 #ifdef CHINESE
|
|
76 extern int ecns_to_big5 ();
|
|
77 #endif
|
|
78 static void printall (), printpat (), err (), usage (), who (), dic (), dic_all (), file_all (), wsttost (), out ();
|
|
79
|
|
80 #ifdef CHINESE
|
|
81 #ifdef TAIWANESE
|
|
82 int ocode = (TTY_TCODE + 6);
|
|
83 #else /* TAIWANESE */
|
|
84 int ocode = (TTY_CCODE + 4);
|
|
85 #endif /* TAIWANESE */
|
|
86 #else /* CHINESE */
|
|
87 #ifdef KOREAN
|
|
88 int ocode = TTY_HCODE;
|
|
89 #else /* KOREAN */
|
|
90 int ocode = TTY_KCODE;
|
|
91 #endif /* KOREAN */
|
|
92 #endif /* CHINESE */
|
|
93
|
|
94 int com = W_WHO;
|
|
95
|
|
96 struct msg_cat *cd;
|
|
97
|
|
98 int
|
|
99 main (argc, argv)
|
|
100 int argc;
|
|
101 char **argv;
|
|
102 {
|
|
103 char *serv;
|
|
104 int c, i, j;
|
|
105 WNN_ENV_INFO *w;
|
|
106 static char lang[64] = { 0 };
|
|
107 extern int optind;
|
|
108 extern char *optarg;
|
|
109 extern char *getenv ();
|
|
110 char nlspath[64];
|
|
111 /*
|
|
112 char *p;
|
|
113 */
|
|
114 char *server_env = NULL;
|
|
115 char *prog = argv[0];
|
|
116 extern char *_wnn_get_machine_of_serv_defs (), *get_server_env ();
|
|
117
|
|
118 /*
|
|
119 if ((p = getenv("LANG")) != NULL) {
|
|
120 strcpy(lang, p);
|
|
121 lang[5] = '\0';
|
|
122 } else {
|
|
123 lang[0] = '\0';
|
|
124 }
|
|
125
|
|
126 if (*lang == '\0')
|
|
127 */
|
|
128 strcpy (lang, WNN_DEFAULT_LANG);
|
|
129
|
|
130
|
|
131 #ifdef JAPANESE
|
|
132 # define OPTSTRING "weEdDfFUSJVL:"
|
|
133 #endif
|
|
134 #ifdef CHINESE
|
|
135 # define OPTSTRING "weEdDfFUBCVL:"
|
|
136 #endif
|
|
137 # ifdef KOREAN
|
|
138 # define OPTSTRING "weEdDfFUKVL:"
|
|
139 #endif
|
|
140
|
|
141
|
|
142 while ((c = getopt (argc, argv, OPTSTRING)) != EOF)
|
|
143 {
|
|
144 switch (c)
|
|
145 {
|
|
146 case 'w':
|
|
147 com = W_WHO;
|
|
148 break;
|
|
149 case 'E':
|
|
150 com = W_ALL;
|
|
151 break;
|
|
152 case 'e':
|
|
153 com = W_ENV;
|
|
154 break;
|
|
155 case 'd':
|
|
156 com = W_DIC;
|
|
157 break;
|
|
158 case 'D':
|
|
159 com = W_DIC_ALL;
|
|
160 break;
|
|
161 case 'f':
|
|
162 case 'F':
|
|
163 com = W_FILE;
|
|
164 break;
|
|
165 case 'V':
|
|
166 com = W_VERSION;
|
|
167 break;
|
|
168 case 'U':
|
|
169 #ifdef JAPANESE
|
|
170 ocode = J_EUJIS;
|
|
171 #endif
|
|
172 #ifdef CHINESE
|
|
173 ocode = C_EUGB;
|
|
174 #endif
|
|
175 #ifdef KOREAN
|
|
176 ocode = K_EUKSC;
|
|
177 break;
|
|
178 case 'K':
|
|
179 ocode = K_KSC;
|
|
180 #endif
|
|
181 break;
|
|
182 #ifdef JAPANESE
|
|
183 case 'J':
|
|
184 ocode = J_JIS;
|
|
185 break;
|
|
186 case 'S':
|
|
187 ocode = J_SJIS;
|
|
188 break;
|
|
189 #endif
|
|
190 #ifdef CHINESE
|
|
191 case 'B':
|
|
192 ocode = C_BIG5 + 6;
|
|
193 break;
|
|
194 case 'C':
|
|
195 ocode = C_ECNS11643 + 6;
|
|
196 break;
|
|
197 #endif /* CHINESE */
|
|
198 case 'L':
|
|
199 strcpy (lang, optarg);
|
|
200 break;
|
|
201 default:
|
|
202 usage ();
|
|
203 break;
|
|
204 }
|
|
205 }
|
|
206 if (optind)
|
|
207 {
|
|
208 optind--;
|
|
209 argc -= optind;
|
|
210 argv += optind;
|
|
211 }
|
|
212 strcpy (nlspath, LIBDIR);
|
|
213 strcat (nlspath, "/%L/%N");
|
|
214 cd = msg_open ("wnnstat.msg", nlspath, lang);
|
|
215
|
|
216 rb.buf = (char *) malloc ((unsigned) (rb.size = 0));
|
|
217
|
|
218 if ((server_env = get_server_env (lang)) == NULL)
|
|
219 {
|
|
220 server_env = WNN_DEF_SERVER_ENV;
|
|
221 }
|
|
222 if (argc > 1)
|
|
223 {
|
|
224 serv = argv[1];
|
|
225 }
|
|
226 else if (!(serv = getenv (server_env)))
|
|
227 {
|
|
228 serv = "";
|
|
229 }
|
|
230
|
|
231 if (!*serv)
|
|
232 {
|
28
|
233 if ((serv = _wnn_get_machine_of_serv_defs (lang)))
|
0
|
234 {
|
|
235 if ((js = js_open_lang (serv, lang, WNN_TIMEOUT)) == NULL)
|
|
236 {
|
|
237 serv = "";
|
|
238 }
|
|
239 }
|
|
240 }
|
|
241 if (js == NULL && (js = js_open_lang (serv, lang, WNN_TIMEOUT)) == NULL)
|
|
242 {
|
|
243 out ("%s:", prog);
|
|
244 if (serv && *serv)
|
|
245 out (serv);
|
|
246 out (wnn_perror_lang (lang));
|
|
247 putchar ('\n');
|
|
248 /* out(" jserver と接続出来ません。\n"); */
|
|
249 exit (-1);
|
|
250 }
|
|
251 switch (com)
|
|
252 {
|
|
253 case W_WHO:
|
|
254 who (lang);
|
|
255 break;
|
|
256 case W_ALL:
|
|
257 if ((c = js_env_list (js, &rb)) == -1)
|
|
258 err ();
|
|
259 w = (WNN_ENV_INFO *) rb.buf;
|
|
260 printall (w, c);
|
|
261 break;
|
|
262 case W_ENV:
|
|
263 if ((c = js_env_list (js, &rb)) == -1)
|
|
264 err ();
|
|
265 w = (WNN_ENV_INFO *) rb.buf;
|
|
266 printpat (w, c);
|
|
267 break;
|
|
268 case W_DIC:
|
|
269 dic ();
|
|
270 break;
|
|
271 case W_DIC_ALL:
|
|
272 dic_all ();
|
|
273 break;
|
|
274 case W_FILE:
|
|
275 file_all ();
|
|
276 break;
|
|
277 case W_VERSION:
|
|
278 js_version (js, &i, &j);
|
|
279 printf ("Jserver Version %x, Jlib Version %x\n", i, j);
|
|
280 }
|
|
281 js_close (js);
|
|
282 exit (0);
|
|
283 }
|
|
284
|
|
285 static void
|
|
286 printall (w, c)
|
|
287 WNN_ENV_INFO *w;
|
|
288 int c;
|
|
289 {
|
|
290 int i, j;
|
|
291 /*
|
|
292 out("Env No.\t環境名\t参照数\t付属語\t辞書数(辞書No.)\t\tファイル\n");
|
|
293 */
|
|
294 out (msg_get (cd, 1, "Env No.\tEnv Name\tRefs\tGrammer\tDicts(Dict No.)\t\tFile\n", NULL));
|
|
295 for (i = 0; i < c; i++, w++)
|
|
296 {
|
|
297 out ("%d\t%s\t%d\t%d\t%d(", w->env_id, w->env_name, w->ref_count, w->fzk_fid, w->jishomax);
|
|
298 for (j = 0; j < w->jishomax; j++)
|
|
299 {
|
|
300 if (w->jisho[j] != -1)
|
|
301 out ("%d ", w->jisho[j]);
|
|
302 }
|
|
303 out (")\t");
|
|
304 for (j = 0; j < WNN_MAX_FILE_OF_AN_ENV; j++)
|
|
305 {
|
|
306 if (w->file[j] != -1)
|
|
307 out ("%d ", w->file[j]);
|
|
308 }
|
|
309 putchar ('\n');
|
|
310 }
|
|
311 }
|
|
312
|
|
313 static void
|
|
314 printpat (w, c)
|
|
315 WNN_ENV_INFO *w;
|
|
316 int c;
|
|
317 {
|
|
318 int i;
|
|
319 /*
|
|
320 out("Env No.\t環境名\t参照数\n");
|
|
321 */
|
|
322 out (msg_get (cd, 2, "Env No.\tEnv Name\tRefs\n", NULL));
|
|
323 for (i = 0; i < c; i++, w++)
|
|
324 {
|
|
325 out ("%d\t%s\t%d\n", w->env_id, w->env_name, w->ref_count);
|
|
326 }
|
|
327 }
|
|
328
|
|
329 static void
|
|
330 err ()
|
|
331 {
|
|
332 out (wnn_perror ());
|
|
333 putchar ('\n');
|
|
334 exit (-1);
|
|
335 }
|
|
336
|
|
337 static void
|
|
338 usage ()
|
|
339 {
|
|
340 #ifdef JAPANESE
|
|
341 fprintf (stderr, "wnnstat [-weEdDfFUSJV] [-L lang_name] [server_name]\n");
|
|
342 #endif /* JAPANESE */
|
|
343 #ifdef CHINESE
|
|
344 fprintf (stderr, "cwnnstat [-weEdDfFUBCV] [-L lang_name] [server_name]\n");
|
|
345 #endif /* CHINESE */
|
|
346 #ifdef KOREAN
|
|
347 fprintf (stderr, "kwnnstat [-weEdDfFUKV] [-L lang_name] [server_name]\n");
|
|
348 #endif /* KOREAN */
|
|
349 exit (-1);
|
|
350 }
|
|
351
|
|
352 static void
|
|
353 who (lang)
|
|
354 char *lang;
|
|
355 {
|
|
356 WNN_JWHO *w;
|
|
357 int c, k, j;
|
|
358 struct wnn_env *env;
|
|
359
|
|
360 if ((env = js_connect_lang (js, WNNSTAT_ENV, lang)) == NULL)
|
|
361 err ();
|
|
362
|
|
363 if ((c = js_who (js, &rb)) == -1)
|
|
364 err ();
|
|
365 w = (WNN_JWHO *) rb.buf;
|
|
366 /*
|
|
367 out("ユーザ名:ホスト名\t(ソケットNo.)\t環境番号\n");
|
|
368 */
|
|
369 out (msg_get (cd, 3, "User name:Host name\t(socket)\tEnv No.\n", NULL));
|
|
370 for (k = 0; k < c; k++, w++)
|
|
371 {
|
|
372 if (w->env[0] == env->env_id)
|
|
373 continue;
|
|
374 out ("%s:%s\t\t(%d)\t\t", w->user_name, w->host_name, w->sd);
|
|
375 for (j = 0; j < WNN_MAX_ENV_OF_A_CLIENT; j++)
|
|
376 {
|
|
377 if (w->env[j] != -1)
|
|
378 {
|
|
379 out ("%d ", w->env[j]);
|
|
380 }
|
|
381 }
|
|
382 out ("\n");
|
|
383 }
|
|
384 exit (c - 1);
|
|
385 }
|
|
386
|
|
387 static void
|
|
388 dic ()
|
|
389 {
|
|
390 char ch[256];
|
|
391 WNN_DIC_INFO *w;
|
|
392 int c, k;
|
|
393 if ((c = js_dic_list_all (js, &rb)) == -1)
|
|
394 err ();
|
|
395 w = (WNN_DIC_INFO *) rb.buf;
|
|
396 /*
|
|
397 out("No.\t種類\tニックネーム\tファイル\t\n");
|
|
398 */
|
|
399 out (msg_get (cd, 4, "No.\tDict type\tName\tFile\n", NULL));
|
|
400 for (k = 0; k < c; k++, w++)
|
|
401 {
|
|
402 wsttost (ch, w->comment);
|
|
403 out ("%d:%s\t%s\t%d:%s", w->dic_no,
|
|
404 w->type & 0xff00 ? ((w->type & 0xff00) == (BWNN_REV_DICT & 0xff00) ? bwnn_dic_types[0x00ff & w->type] : cwnn_dic_types[0x00ff & w->type]) : wnn_dic_types[w->type], ch, w->body, w->fname);
|
|
405 if (w->hindo != -1)
|
|
406 {
|
|
407 out ("(%d)\n", w->hindo);
|
|
408 }
|
|
409 else
|
|
410 {
|
|
411 out ("\n");
|
|
412 }
|
|
413 }
|
|
414 }
|
|
415
|
|
416 static void
|
|
417 dic_all ()
|
|
418 {
|
|
419 char ch[256];
|
|
420 WNN_DIC_INFO *w;
|
|
421 int c, k;
|
|
422 if ((c = js_dic_list_all (js, &rb)) == -1)
|
|
423 err ();
|
|
424 w = (WNN_DIC_INFO *) rb.buf;
|
|
425 /*
|
|
426 out("No.種類\t正/逆\t語数\t更新(頻)使用 プライオリティ\t[ニックネーム]\tファイル[(頻度)]\t[パスワード(頻度)]\n");
|
|
427 */
|
|
428 out (msg_get (cd, 5, "No.Dict type\tN/R\tWords\tR/W(F)Use Priorty\t[Name]\tFile[(Freq)]\t[Passwd(Freq)]\n", NULL));
|
|
429 for (k = 0; k < c; k++, w++)
|
|
430 {
|
|
431 wsttost (ch, w->comment);
|
|
432 out ("%d:%s\t%s\t%d\t%s(%s)\t%s %d\t",
|
|
433 w->dic_no, w->type & 0xff00 ? ((w->type & 0xff00) == (BWNN_REV_DICT & 0xff00) ? bwnn_dic_types[0x00ff & w->type] : cwnn_dic_types[0x00ff & w->type]) : wnn_dic_types[w->type],
|
|
434 /*
|
|
435 w->rev ? "逆変換":"正変換",
|
|
436 w->gosuu,
|
|
437 (w->rw)? "不":"可",
|
|
438 (w->hindo_rw)? "不":"可",
|
|
439 (w->enablef)? "中":"停止",
|
|
440 */
|
|
441 w->rev ? msg_get (cd, 6, "Rev", NULL) :
|
|
442 msg_get (cd, 7, "Norm", NULL),
|
|
443 w->gosuu,
|
|
444 (w->rw) ? msg_get (cd, 8, "Y", NULL) : msg_get (cd, 9, "N", NULL),
|
|
445 (w->hindo_rw) ? msg_get (cd, 8, "Y", NULL) : msg_get (cd, 9, "N", NULL), (w->enablef) ? msg_get (cd, 10, "Y", NULL) : msg_get (cd, 11, "N", NULL), w->nice);
|
|
446 if (*ch)
|
|
447 out ("%s\t", ch);
|
|
448 out ("%d:%s\t", w->body, w->fname);
|
|
449 if (w->hindo != -1)
|
|
450 {
|
|
451 out ("(%d:%s)\t", w->hindo, w->hfname);
|
|
452 }
|
|
453 if (w->passwd[0])
|
|
454 out ("%s", w->passwd);
|
|
455 if (w->hpasswd[0])
|
|
456 out ("(%s)", w->hpasswd);
|
|
457 out ("\n");
|
|
458 }
|
|
459 }
|
|
460
|
|
461
|
|
462 static void
|
|
463 file_all ()
|
|
464 {
|
|
465 char *d;
|
|
466 WNN_FILE_INFO_STRUCT *w;
|
|
467 int c, k;
|
|
468 if ((c = js_file_list_all (js, &rb)) == -1)
|
|
469 err ();
|
|
470 w = (WNN_FILE_INFO_STRUCT *) rb.buf;
|
|
471 /*
|
|
472 out("Fid\t種類\t場所\t参照数\t\tファイル名\n");
|
|
473 */
|
|
474 out (msg_get (cd, 12, "Fid\tType\tL/R\tRefs\t\tFile\n", NULL));
|
|
475 for (k = 0; k < c; k++, w++)
|
|
476 {
|
|
477 switch (w->type)
|
|
478 {
|
|
479 case WNN_FT_DICT_FILE:
|
|
480 /*
|
|
481 d = "辞書";
|
|
482 */
|
|
483 d = msg_get (cd, 13, "Dict", NULL);
|
|
484 break;
|
|
485 case WNN_FT_HINDO_FILE:
|
|
486 /*
|
|
487 d = "頻度";
|
|
488 */
|
|
489 d = msg_get (cd, 14, "Freq", NULL);
|
|
490 break;
|
|
491 case WNN_FT_FUZOKUGO_FILE:
|
|
492 /*
|
|
493 d = "付属語";
|
|
494 */
|
|
495 d = msg_get (cd, 15, "Gram", NULL);
|
|
496 break;
|
|
497 }
|
|
498 out ("%d\t%s\t%s\t%d\t%s\n", w->fid, d, w->localf ? "LOCAL" : "REMOTE", w->ref_count, w->name);
|
|
499 }
|
|
500 }
|
|
501
|
|
502
|
|
503 static void
|
|
504 wsttost (c, w)
|
|
505 char *c;
|
|
506 w_char *w;
|
|
507 {
|
|
508 while (*w)
|
|
509 {
|
|
510 if (*w & 0xff00)
|
|
511 *c++ = (*w & 0xff00) >> 8;
|
|
512 *c++ = *w++ & 0x00ff;
|
|
513 }
|
|
514 *c = 0;
|
|
515 }
|
|
516
|
|
517 static void
|
|
518 out (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
|
|
519 char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8, *a9, *a10, *a11, *a12, *a13;
|
|
520 {
|
|
521 int len;
|
|
522 char buf[1024];
|
|
523 char jbuf[1024];
|
|
524 sprintf (buf, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13);
|
|
525
|
|
526 len = strlen (buf);
|
|
527 switch (ocode)
|
|
528 {
|
|
529 #ifdef JAPANESE
|
|
530 case J_EUJIS:
|
|
531 #endif
|
|
532 #ifdef CHINESE
|
|
533 case C_EUGB:
|
|
534 case (C_EUGB + 4):
|
|
535 case (C_ECNS11643 + 6):
|
|
536 #endif /* CHINESE */
|
|
537 #ifdef KOREAN
|
|
538 case K_EUKSC:
|
|
539 #endif
|
|
540 strncpy (jbuf, buf, len + 1);
|
|
541 break;
|
|
542 #ifdef JAPANESE
|
|
543 case J_JIS:
|
|
544 eujis_to_jis8 (jbuf, buf, len + 1);
|
|
545 break;
|
|
546 case J_SJIS:
|
|
547 eujis_to_sjis (jbuf, buf, len + 1);
|
|
548 break;
|
|
549 #endif
|
|
550 #ifdef CHINESE
|
|
551 case (C_BIG5 + 6):
|
|
552 ecns_to_big5 (jbuf, buf, len + 1);
|
|
553 break;
|
|
554 #endif /* CHINESE */
|
|
555 #ifdef KOREAN
|
|
556 case K_KSC:
|
|
557 euksc_to_ksc (jbuf, buf, len + 1);
|
|
558 break;
|
|
559 #endif /* KOREAN */
|
|
560 }
|
|
561 printf ("%s", jbuf);
|
|
562 }
|