Mercurial > freewnn
annotate Wnn/jutil/wdreg.c @ 28:a7ccf412ba02
more warning suppression
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 06 Mar 2010 23:24:53 +0900 |
parents | c966456648ad |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * $Id: wdreg.c,v 1.8 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 /* | |
33 * UJIS ファイルを読みとって、単語登録を行なう。 | |
34 */ | |
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 #else | |
44 # if HAVE_MALLOC_H | |
45 # include <malloc.h> | |
46 # endif | |
47 #endif /* STDC_HEADERS */ | |
48 #include <sys/types.h> | |
49 #include <sys/file.h> | |
50 #if HAVE_UNISTD_H | |
51 # include <unistd.h> | |
52 #endif | |
53 | |
54 #include "commonhd.h" | |
55 #include "wnn_config.h" | |
56 #include "jllib.h" | |
57 #include "jslib.h" | |
58 #include "jh.h" | |
59 #include "jdata.h" | |
60 #include "wnn_os.h" | |
61 | |
62 extern int init_heap (); | |
63 extern void ujis_header (), read_ujis (); | |
64 extern struct je **jeary; | |
65 | |
66 char *def_server; | |
67 struct JT jt; | |
68 struct wnn_file_head file_head; | |
69 int dic_no = -1; | |
70 char *server_n; | |
71 char *env_n = "wdreg"; | |
72 char *fname = NULL; | |
73 int fid; | |
74 int client = 0; /* server site dict */ | |
75 | |
76 WNN_JSERVER_ID *js; | |
77 struct wnn_env *env, *rev_env; | |
78 static struct wnn_ret_buf rb = { 0, NULL }; | |
79 | |
80 static void | |
81 usage () | |
82 { | |
83 fprintf (stderr, "wdreg [-D server_name] [-n env_name][-d dic_no][-L] [file_name] < text dict\n"); | |
84 fprintf (stderr, "file_name or -d dic_no must be specified\n"); | |
85 fprintf (stderr, "default env_name = wdreg\n"); | |
86 fprintf (stderr, "default server_name = %s\n", def_server); | |
87 fprintf (stderr, "L is to specify that the file at the client site.\n"); | |
88 exit (1); | |
89 } | |
90 | |
91 static void | |
92 err () | |
93 { | |
94 printf ((char *) wnn_perror ()); | |
95 printf ("\n bye.\n"); | |
96 exit (1); | |
97 } | |
98 | |
99 int | |
100 main (argc, argv) | |
101 int argc; | |
102 char **argv; | |
103 { | |
104 extern int optind; | |
105 extern char *optarg; | |
106 struct wnn_dic_info *info; | |
107 int c; | |
108 int k; | |
109 int num; | |
110 char *cswidth_name; | |
111 extern char *get_cswidth_name (); | |
112 extern void set_cswidth (); | |
113 extern char *getenv (); | |
114 | |
115 if (getenv (WNN_DEF_SERVER_ENV)) | |
116 { | |
117 def_server = getenv (WNN_DEF_SERVER_ENV); | |
118 } | |
119 else | |
120 { | |
121 def_server = ""; | |
122 } | |
123 server_n = def_server; | |
124 | |
28
a7ccf412ba02
more warning suppression
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
22
diff
changeset
|
125 if ((cswidth_name = get_cswidth_name (WNN_DEFAULT_LANG))) |
0 | 126 set_cswidth (create_cswidth (cswidth_name)); |
127 while ((c = getopt (argc, argv, "D:n:d:L")) != EOF) | |
128 { | |
129 switch (c) | |
130 { | |
131 case 'D': | |
132 server_n = optarg; | |
133 break; | |
134 case 'n': | |
135 env_n = optarg; | |
136 break; | |
137 case 'd': | |
138 dic_no = atoi (optarg); | |
139 break; | |
140 case 'L': | |
141 client = 1; | |
142 break; | |
143 default: | |
144 usage (); | |
145 break; | |
146 } | |
147 } | |
148 if (optind) | |
149 { | |
150 optind--; | |
151 argc -= optind; | |
152 argv += optind; | |
153 } | |
154 if (argc > 1) | |
155 { | |
156 fname = argv[1]; | |
157 } | |
158 if (fname && dic_no != -1) | |
159 usage (); | |
160 if (!fname && dic_no == -1) | |
161 usage (); | |
162 | |
163 rb.buf = (char *) malloc ((unsigned) (rb.size = 0)); | |
164 | |
165 init_heap (MAX_ENTRIES * HEAP_PER_LINE, MAX_ENTRIES * YOMI_PER_LINE, MAX_ENTRIES, MAX_ENTRIES, stdin); | |
166 | |
167 #ifdef CHINESE | |
168 { | |
169 int which_dict; | |
170 ujis_header (&which_dict); | |
171 } | |
172 #else | |
173 ujis_header (); | |
174 #endif | |
175 read_ujis (NORMAL, 0, 0); | |
176 | |
177 if ((js = js_open (server_n, WNN_TIMEOUT)) == NULL) | |
178 err (); | |
179 if ((env = js_connect (js, env_n)) == NULL) | |
180 err (); | |
181 if (fname) | |
182 { | |
183 if (client) | |
184 { | |
185 if (access (fname, F_OK) == -1) | |
186 { | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
187 if (js_dic_file_create_client (env, fname, WNN_REV_DICT, (w_char *)"", "", "") == -1) |
0 | 188 { |
189 err (); | |
190 } | |
191 } | |
192 if ((fid = js_file_send (env, fname)) == -1) | |
193 { | |
194 err (); | |
195 } | |
196 } | |
197 else | |
198 { | |
199 WNN_FILE_STAT s; | |
200 if (js_file_stat (env, fname, &s) == -1) | |
201 { | |
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
202 if (js_dic_file_create (env, fname, WNN_REV_DICT, (w_char *)"", "", "") == -1) |
0 | 203 { |
204 err (); | |
205 } | |
206 } | |
207 if ((fid = js_file_read (env, fname)) == -1) | |
208 err (); | |
209 } | |
210 if ((dic_no = js_dic_add (env, fid, -1, 0, 0, WNN_DIC_RW, WNN_DIC_RW, "", "")) == -1) | |
211 err (); | |
212 } | |
213 | |
214 if ((num = js_dic_list (env, &rb)) == -1) | |
215 err (); | |
216 | |
217 info = (struct wnn_dic_info *) (rb.buf); | |
218 for (k = 0; k < num; k++) | |
219 { | |
220 if (info[k].dic_no == dic_no) | |
221 break; | |
222 } | |
223 if (k == num) | |
224 { | |
225 /* | |
226 fprintf(stderr, "指定された番号の辞書は、環境に存在しません。\n"); | |
227 */ | |
228 fprintf (stderr, "The specified dictionary isn't exist in current environment\n"); | |
229 exit (1); | |
230 } | |
231 if (info[k].type != WNN_UD_DICT && info[k].type != WNN_REV_DICT) | |
232 { | |
233 /* | |
234 fprintf(stderr, "指定された番号の辞書は、登録可能ではありません。\n"); | |
235 */ | |
236 fprintf (stderr, "The specified dictionary isn't registable\n"); | |
237 exit (1); | |
238 } | |
239 for (k = 0; k < jt.maxserial; k++) | |
240 { | |
241 if (js_word_add (env, dic_no, jeary[k]->yomi, jeary[k]->kan, jeary[k]->comm, jeary[k]->hinsi, jeary[k]->hindo) == -1) | |
242 { | |
243 err (); | |
244 } | |
245 } | |
246 if (fname) | |
247 { | |
248 if (client) | |
249 { | |
250 if (js_file_receive (env, fid, "") == -1) | |
251 err (); | |
252 } | |
253 else | |
254 { | |
255 if (js_file_write (env, fid, "") == -1) | |
256 err (); | |
257 } | |
258 fprintf (stderr, "Wrote the file back.\n"); | |
259 } | |
260 exit (0); | |
261 } |