0
|
1 /*
|
|
2 * $Id: wnnkill.c,v 1.10 2005/01/30 17:14:20 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, 2002, 2004, 2005
|
|
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 #elif HAVE_STRINGS_H
|
|
41 # include <strings.h>
|
|
42 #endif /* STDC_HEADERS */
|
|
43 #if HAVE_UNISTD_H
|
|
44 # include <unistd.h>
|
|
45 #endif
|
|
46 #include <stdarg.h> /* assume ANSI-C */
|
|
47 #include "jllib.h"
|
|
48 #include "jslib.h"
|
|
49 #include "jd_sock.h"
|
|
50 #include "commonhd.h"
|
|
51 #include "wnn_config.h"
|
|
52 #include "wnn_os.h"
|
|
53
|
|
54 WNN_JSERVER_ID *js;
|
|
55 struct wnn_ret_buf rb = { 0, NULL };
|
|
56 #define BUFSTRLEN 1024
|
|
57
|
|
58 #ifdef JAPANESE
|
|
59 int ocode = TTY_KCODE;
|
|
60 #endif
|
|
61 #ifdef CHINESE
|
|
62 #ifdef TAIWANESE
|
|
63 int ocode = (TTY_TCODE + 6);
|
|
64 #else /* TAIWANESE */
|
|
65 int ocode = (TTY_CCODE + 4);
|
|
66 #endif /* TAIWANESE */
|
|
67 #endif /* CHINESE */
|
|
68 #ifdef KOREAN
|
|
69 int ocode = TTY_HCODE;
|
|
70 #endif
|
|
71
|
|
72 static void out (const char* format, ...);
|
|
73 static void usage (char *prog);
|
|
74
|
|
75 int
|
|
76 main (int argc, char** argv)
|
|
77 {
|
|
78 int c;
|
|
79 char *serv;
|
|
80 int x;
|
|
81 static char lang[64] = { 0 };
|
|
82 char *server_env = NULL;
|
|
83 char *prog = argv[0];
|
|
84 extern char *_wnn_get_machine_of_serv_defs (), *get_server_env ();
|
|
85
|
|
86 /*
|
|
87 char* p;
|
|
88
|
|
89 if ((p = getenv("LANG")) != NULL) {
|
|
90 strcpy(lang, p);
|
|
91 lang[5] = '\0';
|
|
92 } else {
|
|
93 lang[0] = '\0';
|
|
94 }
|
|
95
|
|
96 if (*lang == '\0')
|
|
97 */
|
|
98 strcpy (lang, WNN_DEFAULT_LANG);
|
|
99
|
|
100 #ifdef JAPANESE
|
|
101 # define OPTSTRING "USJL:"
|
|
102 #endif
|
|
103 #ifdef CHINESE
|
|
104 # define OPTSTRING "USJBCL:"
|
|
105 #endif /* CHINESE */
|
|
106 #ifdef KOREAN
|
|
107 # define OPTSTRING "UL:"
|
|
108 #endif
|
|
109
|
|
110 while ((c = getopt (argc, argv, OPTSTRING)) != EOF)
|
|
111 {
|
|
112 switch (c)
|
|
113 {
|
|
114 case 'U':
|
|
115 #ifdef JAPANESE
|
|
116 ocode = J_EUJIS;
|
|
117 #endif
|
|
118 #ifdef CHINESE
|
|
119 ocode = C_EUGB;
|
|
120 #endif
|
|
121 #ifdef KOREAN
|
|
122 ocode = K_EUKSC;
|
|
123 #endif
|
|
124 break;
|
|
125 #ifdef JAPANESE
|
|
126 case 'J':
|
|
127 ocode = J_JIS;
|
|
128 break;
|
|
129 case 'S':
|
|
130 ocode = J_SJIS;
|
|
131 break;
|
|
132 #endif
|
|
133 #ifdef CHINESE
|
|
134 case 'B':
|
|
135 ocode = (C_BIG5 + 6);
|
|
136 break;
|
|
137 case 'C':
|
|
138 ocode = (C_ECNS11643 + 6);
|
|
139 break;
|
|
140 #endif /* CHINESE */
|
|
141 case 'L':
|
|
142 strcpy (lang, optarg);
|
|
143 break;
|
|
144 default:
|
|
145 usage (prog);
|
|
146 exit (1);
|
|
147 break;
|
|
148 }
|
|
149 }
|
|
150 if (optind)
|
|
151 {
|
|
152 optind--;
|
|
153 argc -= optind;
|
|
154 argv += optind;
|
|
155 }
|
|
156
|
|
157 if ((server_env = get_server_env (lang)) == NULL)
|
|
158 {
|
|
159 server_env = WNN_DEF_SERVER_ENV;
|
|
160 }
|
|
161 if (argc > 1)
|
|
162 {
|
|
163 serv = argv[1];
|
|
164 }
|
|
165 else if (!(serv = getenv (server_env)))
|
|
166 {
|
|
167 serv = "";
|
|
168 }
|
|
169
|
|
170 if (!*serv)
|
|
171 {
|
28
|
172 if ((serv = _wnn_get_machine_of_serv_defs (lang)))
|
0
|
173 {
|
|
174 if ((js = js_open_lang (serv, lang, WNN_TIMEOUT)) == NULL)
|
|
175 {
|
|
176 serv = "";
|
|
177 }
|
|
178 }
|
|
179 }
|
|
180 if (js == NULL && (js = js_open_lang (serv, lang, WNN_TIMEOUT)) == NULL)
|
|
181 {
|
|
182 out ("%s:", prog);
|
|
183 if (serv && *serv)
|
|
184 out ("%s", serv);
|
|
185 out ("%s\n", wnn_perror_lang (lang));
|
|
186 /* fprintf(stderr, "Can't connect to jserver.\n"); */
|
|
187 exit (255);
|
|
188 }
|
|
189 if ((x = js_kill (js)) > 0)
|
|
190 {
|
|
191 if (x == 1)
|
|
192 out ("%d User Exists.\n", x);
|
|
193 else
|
|
194 out ("%d Users Exist.\n", x);
|
|
195 out ("%s Not Killed.\n", server_env);
|
|
196 exit (1);
|
|
197 }
|
|
198 else if (x == 0)
|
|
199 {
|
|
200 out ("%s Terminated\n", server_env);
|
|
201 exit (0);
|
|
202 }
|
|
203 else
|
|
204 {
|
|
205 out ("%s Terminated\n", server_env);
|
|
206 exit (2);
|
|
207 }
|
|
208 exit (0);
|
|
209 }
|
|
210
|
|
211 #ifdef JAPANESE
|
|
212 extern int eujis_to_jis8 (), eujis_to_sjis ();
|
|
213 #endif
|
|
214 #ifdef CHINESE
|
|
215 extern int ecns_to_big5 ();
|
|
216 #endif
|
|
217
|
|
218 static void
|
|
219 out (const char* format, ...)
|
|
220 {
|
|
221 va_list ap;
|
|
222 char buf[BUFSTRLEN];
|
|
223 char jbuf[BUFSTRLEN];
|
|
224 int len;
|
|
225
|
|
226 va_start (ap, format);
|
|
227 #ifdef HAVE_SNPRINTF /* Should also have vsnprintf */
|
|
228 vsnprintf (buf, BUFSTRLEN, format, ap);
|
|
229 #else
|
|
230 vsprintf (buf, format, ap); /* Dangerous */
|
|
231 #endif /* HAVE_SNPRINTF */
|
|
232 va_end (ap);
|
|
233 len = strlen (buf);
|
|
234
|
|
235 switch (ocode)
|
|
236 {
|
|
237 #ifdef JAPANESE
|
|
238 case J_EUJIS:
|
|
239 #endif
|
|
240 #ifdef CHINESE
|
|
241 case (C_EUGB + 4):
|
|
242 case (C_ECNS11643 + 6):
|
|
243 #endif /* CHINESE */
|
|
244 #ifdef KOREAN
|
|
245 case K_EUKSC:
|
|
246 #endif
|
|
247 strncpy (jbuf, buf, len + 1);
|
|
248 break;
|
|
249 #ifdef JAPANESE
|
|
250 case J_JIS:
|
|
251 eujis_to_jis8 (jbuf, buf, len + 1);
|
|
252 break;
|
|
253 case J_SJIS:
|
|
254 eujis_to_sjis (jbuf, buf, len + 1);
|
|
255 break;
|
|
256 #endif
|
|
257 #ifdef CHINESE
|
|
258 case (C_BIG5 + 6):
|
|
259 ecns_to_big5 (jbuf, buf, len + 1);
|
|
260 break;
|
|
261 #endif /* CHINESE */
|
|
262 }
|
|
263 fprintf (stderr, "%s", jbuf);
|
|
264 }
|
|
265
|
|
266 static void
|
|
267 usage (char *prog)
|
|
268 {
|
|
269 fprintf (stderr, "Usage: %s [-%s] [-L lang] [hostname]\n", prog,
|
|
270 #if defined(JAPANESE)
|
|
271 "USJ"
|
|
272 #elif defined(CHINESE)
|
|
273 "USJBC"
|
|
274 #elif defined(KOREAN)
|
|
275 "U"
|
|
276 #else
|
|
277 "<Unexpected Situation!>"
|
|
278 #endif
|
|
279 );
|
|
280 }
|