Mercurial > freewnn
annotate Wnn/jutil/wddel.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: wddel.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 #if HAVE_UNISTD_H | |
| 49 # include <unistd.h> | |
| 50 #endif | |
| 51 | |
| 52 #include "commonhd.h" | |
| 53 #include "wnn_config.h" | |
| 54 #include "jllib.h" | |
| 55 #include "jslib.h" | |
| 56 #include "wnn_string.h" | |
| 57 #include "wnn_os.h" | |
| 58 | |
| 59 #define WORD_DELETE 1 | |
| 60 #define COMMENT_SET 2 | |
| 61 #define HINDO_SET 3 | |
| 62 | |
| 63 #define LINE_SIZE 256 | |
| 64 | |
| 65 char *def_server; | |
| 66 | |
| 67 int dic_no = -1; | |
| 68 char *server_n; | |
| 69 char *env_n = "wddel"; | |
| 70 char *fname = NULL; | |
| 71 int fid; | |
| 72 int client = 0; /* server site dict */ | |
| 73 int what = WORD_DELETE; | |
| 74 | |
| 75 WNN_JSERVER_ID *js; | |
| 76 struct wnn_env *env, *rev_env; | |
| 77 static struct wnn_ret_buf rb = { 0, NULL }; | |
| 78 | |
| 79 static void | |
|
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
80 usage (void) |
| 0 | 81 { |
| 82 fprintf (stderr, "wddel [-D server_name] [-n env_name][-d dic_no][-L][-E][-H][-C] [file_name] < text dict\n"); | |
| 83 fprintf (stderr, "file_name or -d dic_no must be specified\n"); | |
| 84 fprintf (stderr, "default env_name = wddel\n"); | |
| 85 fprintf (stderr, "default server_name = %s\n", def_server); | |
| 86 fprintf (stderr, "L is to specify that the file at the client site.\n"); | |
| 87 fprintf (stderr, "-E is word_delete, -C is word_comment_set, -H is hindo_set.\n"); | |
| 88 exit (1); | |
| 89 } | |
| 90 | |
| 91 static void | |
|
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
92 err (void) |
| 0 | 93 { |
| 94 printf ((char *) wnn_perror ()); | |
| 95 printf ("\n bye.\n"); | |
| 96 exit (1); | |
| 97 } | |
| 98 | |
| 99 int | |
|
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
100 main (int argc, char **argv) |
| 0 | 101 { |
| 102 extern char *getenv (); | |
| 103 extern int optind; | |
| 104 extern char *optarg; | |
| 105 struct wnn_dic_info *info; | |
| 106 int c; | |
| 107 int k; | |
| 108 int num; | |
| 109 int sno; | |
| 110 char s[LINE_SIZE]; | |
| 111 char *cswidth_name; | |
| 112 extern char *get_cswidth_name (); | |
| 113 extern void set_cswidth (); | |
| 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:CHEL")) != 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 'C': | |
| 141 what = COMMENT_SET; | |
| 142 break; | |
| 143 case 'H': | |
| 144 what = HINDO_SET; | |
| 145 break; | |
| 146 case 'E': | |
| 147 what = WORD_DELETE; | |
| 148 break; | |
| 149 case 'L': | |
| 150 client = 1; | |
| 151 break; | |
| 152 default: | |
| 153 usage (); | |
| 154 break; | |
| 155 } | |
| 156 } | |
| 157 if (optind) | |
| 158 { | |
| 159 optind--; | |
| 160 argc -= optind; | |
| 161 argv += optind; | |
| 162 } | |
| 163 if (argc > 1) | |
| 164 { | |
| 165 fname = argv[1]; | |
| 166 } | |
| 167 if (fname && dic_no != -1) | |
| 168 usage (); | |
| 169 if (!fname && dic_no == -1) | |
| 170 usage (); | |
| 171 | |
| 172 | |
| 173 rb.buf = (char *) malloc ((unsigned) (rb.size = 0)); | |
| 174 | |
| 175 if ((js = js_open (server_n, WNN_TIMEOUT)) == NULL) | |
| 176 err (); | |
| 177 if ((env = js_connect (js, env_n)) == NULL) | |
| 178 err (); | |
| 179 if (fname) | |
| 180 { | |
| 181 if (client) | |
| 182 { | |
| 183 if ((fid = js_file_send (env, fname)) == -1) | |
| 184 err (); | |
| 185 } | |
| 186 else | |
| 187 { | |
| 188 if ((fid = js_file_read (env, fname)) == -1) | |
| 189 err (); | |
| 190 } | |
| 191 if ((dic_no = js_dic_add (env, fid, -1, 0, 0, WNN_DIC_RW, WNN_DIC_RW, "", "")) == -1) | |
| 192 err (); | |
| 193 } | |
| 194 | |
| 195 if ((num = js_dic_list (env, &rb)) == -1) | |
| 196 err (); | |
| 197 | |
| 198 info = (struct wnn_dic_info *) (rb.buf); | |
| 199 for (k = 0; k < num; k++) | |
| 200 { | |
| 201 if (info[k].dic_no == dic_no) | |
| 202 break; | |
| 203 } | |
| 204 if (k == num) | |
| 205 { | |
| 206 /* | |
| 207 fprintf(stderr, "指定された番号の辞書は、環境に存在しません。\n"); | |
| 208 */ | |
| 209 fprintf (stderr, "The specified dictionary isn't exist in current environment\n"); | |
| 210 exit (1); | |
| 211 } | |
| 212 if (info[k].type != WNN_UD_DICT && info[k].type != WNN_REV_DICT) | |
| 213 { | |
| 214 /* | |
| 215 fprintf(stderr, "指定された番号の辞書は、登録可能ではありません。\n"); | |
| 216 */ | |
| 217 fprintf (stderr, "The specified dictionary isn't registable\n"); | |
| 218 exit (1); | |
| 219 } | |
| 220 while (fgets (s, sizeof (s), stdin)) | |
| 221 { | |
| 222 char com[LENGTHYOMI]; | |
| 223 char Com[LENGTHYOMI]; | |
| 224 int ima, hindo; | |
| 225 if (s[0] == '\\') | |
| 226 continue; | |
| 227 switch (what) | |
| 228 { | |
| 229 case WORD_DELETE: | |
| 230 if (sscanf (s, "%d", &sno) <= 0) | |
| 231 { | |
| 232 fprintf (stderr, "Bad line \"%s\"", s); | |
| 233 continue; | |
| 234 } | |
| 235 if (js_word_delete (env, dic_no, sno) == -1) | |
| 236 { | |
| 237 fprintf (stderr, "serial-no = %d\n", sno); | |
| 238 err (); | |
| 239 } | |
| 240 break; | |
| 241 case COMMENT_SET: | |
| 242 if (sscanf (s, "%d %s", &sno, com) <= 1) | |
| 243 { | |
| 244 fprintf (stderr, "Bad line \"%s\"", s); | |
| 245 continue; | |
| 246 } | |
| 247 wnn_Sstrcpy (Com, com); | |
|
22
c966456648ad
- fixed argument style in function definition
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
248 if (js_word_comment_set (env, dic_no, sno, (w_char *)Com) == -1) // casting may be wrong --yaz |
| 0 | 249 { |
| 250 fprintf (stderr, "serial-no = %d\n", sno); | |
| 251 err (); | |
| 252 } | |
| 253 break; | |
| 254 case HINDO_SET: | |
| 255 if (sscanf (s, "%d %n %n", &sno, &ima, &hindo) <= 2) | |
| 256 { | |
| 257 fprintf (stderr, "Bad line \"%s\"", s); | |
| 258 continue; | |
| 259 } | |
| 260 if (js_hindo_set (env, dic_no, sno, ima, hindo) == -1) | |
| 261 { | |
| 262 fprintf (stderr, "serial-no = %d\n", sno); | |
| 263 err (); | |
| 264 } | |
| 265 break; | |
| 266 } | |
| 267 } | |
| 268 if (fname) | |
| 269 { | |
| 270 if (client) | |
| 271 { | |
| 272 if (js_file_receive (env, fid, "") == -1) | |
| 273 err (); | |
| 274 } | |
| 275 else | |
| 276 { | |
| 277 if (js_file_write (env, fid, "") == -1) | |
| 278 err (); | |
| 279 } | |
| 280 fprintf (stderr, "Wrote the file back.\n"); | |
| 281 } | |
| 282 exit (0); | |
| 283 } |
