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