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