0
|
1 /*
|
|
2 * $Id: dtoa.c,v 1.9 2005/06/12 17:14:23 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, 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 /*
|
|
33 辞書を ASCII 形式の辞書に変換するプログラム。
|
|
34 */
|
|
35
|
|
36 #ifndef lint
|
|
37 static char *rcs_id = "$Id: dtoa.c,v 1.9 2005/06/12 17:14:23 aonoto 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 # include <string.h>
|
|
48 #else
|
|
49 # if HAVE_MALLOC_H
|
|
50 # include <malloc.h>
|
|
51 # endif
|
|
52 # if HAVE_STRINGS_H
|
|
53 # include <strings.h>
|
|
54 # endif
|
|
55 #endif /* STDC_HEADERS */
|
|
56 #if HAVE_UNISTD_H
|
|
57 # include <unistd.h>
|
|
58 #endif
|
|
59
|
|
60 #include "commonhd.h"
|
|
61 #include "wnn_config.h"
|
|
62 #include "jslib.h"
|
|
63 #include "jh.h"
|
|
64 #include "jdata.h"
|
|
65 #include "wnn_string.h"
|
|
66 #include "wnn_os.h"
|
|
67
|
|
68 #ifdef CONVERT_with_SiSheng
|
|
69 #include "cplib.h"
|
|
70 extern int pzy_flag; /* Pinyin or Zhuyin */
|
|
71 #endif
|
|
72
|
|
73 extern void parse_options (), usage (), input_dic (), udtoujis (), kset (), sdtoujis (), ghindo (), sort (), output_ujis (), exit1 (), init_jeary (), get_kanji_str ();
|
|
74 extern int input_header (), input_comment (), input_hinsi_list (), little_endian (), revdic (), wnn_loadhinsi (), init_heap (), w_stradd (), input_hindo_header (), motoni2 ();
|
|
75 #ifdef CONVERT_with_SiSheng
|
|
76 extern int cwnn_yincod_pzy_str (), input_sisheng ();
|
|
77 #endif
|
|
78 static int rdtoujis (), set_hinsi (), input_hindo (), add_hindo ();
|
|
79 /* Moved from Wnn/etc/bdic.c */
|
|
80 int get_n_EU_str (FILE* ifpter, int n, w_char* st);
|
|
81 int get_short (short* sp, FILE* ifpter);
|
|
82
|
|
83 int which_dict;
|
|
84
|
|
85 char *com_name;
|
|
86 char infile[LINE_SIZE];
|
|
87 int esc_expand = 1;
|
|
88
|
|
89 int serial_out = 0;
|
|
90 int need_sort = 1;
|
|
91 struct JT jt;
|
|
92 struct wnn_file_head file_head;
|
|
93
|
|
94 char *hinsi_file_name = NULL;
|
|
95
|
|
96 int
|
|
97 main (argc, argv)
|
|
98 int argc;
|
|
99 char **argv;
|
|
100 {
|
|
101 FILE *ifpter;
|
|
102 char *cswidth_name;
|
|
103 extern char *get_cswidth_name ();
|
|
104 extern void set_cswidth ();
|
|
105
|
|
106 com_name = argv[0];
|
|
107
|
|
108 if (cswidth_name = get_cswidth_name (WNN_DEFAULT_LANG))
|
|
109 set_cswidth (create_cswidth (cswidth_name));
|
|
110 parse_options (&argc, &argv);
|
|
111
|
|
112 if ((ifpter = fopen (infile, "r")) == NULL)
|
|
113 {
|
|
114 fprintf (stderr, "Can't open the input file %s.\n", infile);
|
|
115 perror ("");
|
|
116 exit (1);
|
|
117 }
|
|
118 if (input_header (ifpter, &jt, &file_head) == -1)
|
|
119 exit (1);
|
|
120 which_dict = jt.syurui;
|
|
121 input_comment (ifpter);
|
|
122 input_hinsi_list (ifpter);
|
|
123 input_dic (ifpter);
|
|
124 if (little_endian ())
|
|
125 {
|
|
126 revdic (&jt, 0);
|
|
127 }
|
|
128 set_hinsi ();
|
|
129 ghindo (argc - 2, argv + 2); /* Gather Hindo */
|
|
130 if (which_dict == WNN_STATIC_DICT)
|
|
131 {
|
|
132 kset ();
|
|
133 sdtoujis (jt.hontai, 0);
|
|
134 #ifdef CHINESE
|
|
135 }
|
|
136 else if ((which_dict & 0x00ff) == WNN_REV_DICT)
|
|
137 {
|
|
138 #else
|
|
139 }
|
|
140 else if (which_dict == WNN_REV_DICT)
|
|
141 {
|
|
142 #endif
|
|
143 rdtoujis ();
|
|
144 }
|
|
145 else
|
|
146 {
|
|
147 udtoujis ();
|
|
148 }
|
|
149 if (need_sort)
|
|
150 {
|
|
151 sort ();
|
|
152 }
|
|
153 output_ujis (stdout, serial_out, esc_expand);
|
|
154 exit (0);
|
|
155 }
|
|
156
|
|
157
|
|
158 void
|
|
159 parse_options (argc, argv)
|
|
160 int *argc;
|
|
161 char ***argv;
|
|
162 {
|
|
163 int c;
|
|
164 extern int optind;
|
|
165 extern char *optarg;
|
|
166
|
|
167 #ifdef CONVERT_with_SiSheng
|
|
168 # define OPTSTRING "nseEzh:"
|
|
169 #else
|
|
170 # define OPTSTRING "nseEh:"
|
|
171 #endif
|
|
172
|
|
173 while ((c = getopt (*argc, *argv, OPTSTRING)) != EOF)
|
|
174 {
|
|
175 switch (c)
|
|
176 {
|
|
177 case 'n':
|
|
178 need_sort = 0;
|
|
179 break;
|
|
180 case 's':
|
|
181 serial_out = 1;
|
|
182 break;
|
|
183 case 'e':
|
|
184 esc_expand = 1;
|
|
185 break;
|
|
186 case 'E':
|
|
187 esc_expand = 0;
|
|
188 break;
|
|
189 case 'h':
|
|
190 hinsi_file_name = optarg;
|
|
191 break;
|
|
192 #ifdef CONVERT_with_SiSheng
|
|
193 case 'z':
|
|
194 pzy_flag = CWNN_ZHUYIN;
|
|
195 break;
|
|
196 #endif
|
|
197 default:
|
|
198 usage ();
|
|
199 }
|
|
200 }
|
|
201 if (optind)
|
|
202 {
|
|
203 optind--;
|
|
204 *argc -= optind;
|
|
205 *argv += optind;
|
|
206 }
|
|
207 if (*argc < 2)
|
|
208 {
|
|
209 usage ();
|
|
210 }
|
|
211 strcpy (infile, (*argv)[1]);
|
|
212 if (wnn_loadhinsi (hinsi_file_name) != 0)
|
|
213 {
|
|
214 fprintf (stderr, "Can't Open hinsi_file.\n");
|
|
215 exit (1);
|
|
216 }
|
|
217 }
|
|
218
|
|
219
|
|
220 void
|
|
221 usage ()
|
|
222 {
|
|
223 fprintf (stderr, "Usage: %s [-nse -h hinsi_file_name] <dictionary file> <hindo file>*\n", com_name);
|
|
224 fprintf (stderr, "Output the Text dictionary to stdout\n");
|
|
225 #ifdef CONVERT_with_SiSheng
|
|
226 fprintf (stderr, "-z : Output Zhuyin (Default is Pinyin)\n");
|
|
227 #endif
|
|
228 exit1 ();
|
|
229 }
|
|
230
|
|
231 void
|
|
232 input_dic (ifpter)
|
|
233 FILE *ifpter;
|
|
234 {
|
|
235
|
|
236 init_heap (0, /* jt.maxkanji, */
|
|
237 jt.maxserial * YOMI_PER_LINE * 5, /* may be enough */
|
|
238 jt.maxserial, jt.maxserial, stdin);
|
|
239 jt.table = (struct uind1 *) malloc (jt.maxtable * sizeof (struct uind1));
|
|
240 jt.hontai = (UCHAR *) malloc (jt.maxhontai);
|
|
241 jt.ri1[D_YOMI] = (struct rind1 *) malloc (jt.maxri1[D_YOMI] * sizeof (struct rind1));
|
|
242 jt.ri1[D_KANJI] = (struct rind1 *) malloc (jt.maxri1[D_KANJI] * sizeof (struct rind1));
|
|
243 jt.kanji = (UCHAR *) malloc (jt.maxkanji + 1);
|
|
244 jt.ri2 = (struct rind2 *) malloc (jt.maxserial * sizeof (struct rind2));
|
|
245 jt.hinsi = (w_char *) malloc (jt.maxserial * sizeof (w_char));
|
|
246 if (!jt.table || !jt.hontai || !jt.ri1[D_YOMI] || !jt.ri1[D_KANJI] || !jt.kanji || !jt.ri2 || !jt.hinsi)
|
|
247 {
|
|
248 fprintf (stderr, "Malloc Failed.\n");
|
|
249 exit (1);
|
|
250 }
|
|
251 init_jeary ();
|
|
252
|
|
253 input_hindo (ifpter);
|
|
254 fread (jt.hinsi, 2, jt.maxserial, ifpter);
|
|
255 #ifdef CONVERT_with_SiSheng
|
|
256 if (which_dict == CWNN_REV_DICT)
|
|
257 input_sisheng (ifpter);
|
|
258 #endif
|
|
259 fread (jt.kanji, 1, jt.maxkanji, ifpter);
|
|
260 /* input_kanji(ifpter); */
|
|
261 fread (jt.table, sizeof (struct uind1), jt.maxtable, ifpter);
|
|
262 fread (jt.ri1[D_YOMI], sizeof (struct rind1), jt.maxri1[D_YOMI], ifpter);
|
|
263 fread (jt.ri1[D_KANJI], sizeof (struct rind1), jt.maxri1[D_KANJI], ifpter);
|
|
264 fread (jt.hontai, 1, jt.maxhontai, ifpter);
|
|
265 fread (jt.ri2, sizeof (struct rind2), jt.maxserial, ifpter);
|
|
266 }
|
|
267
|
|
268 void
|
|
269 udtoujis ()
|
|
270 {
|
|
271
|
|
272 w_char yomi[LENGTHYOMI]; /* 2 byte yomi */
|
|
273 w_char kan[LENGTHYOMI]; /* 2 byte kanji */
|
|
274 w_char comm[LENGTHYOMI];
|
|
275 w_char ryomi[LENGTHYOMI];
|
|
276 register struct uind2 *hop;
|
|
277 register int i, k;
|
|
278 register int serial;
|
|
279 int len;
|
|
280 UCHAR *c;
|
|
281
|
|
282 for (i = 0; i < jt.maxtable; i++)
|
|
283 {
|
|
284 for (hop = (struct uind2 *) (jt.table[i].pter + (char *) jt.hontai); hop != (struct uind2 *) jt.hontai; hop = (struct uind2 *) (hop->next + (char *) jt.hontai))
|
|
285 {
|
|
286 /* Though each hop has the same yomi, but calculate yomi each time. */
|
|
287 yomi[0] = jt.table[i].yomi1 >> 16;
|
|
288 yomi[1] = jt.table[i].yomi1 & 0xffff;
|
|
289 if (yomi[1])
|
|
290 {
|
|
291 yomi[2] = jt.table[i].yomi2 >> 16;
|
|
292 if (yomi[2])
|
|
293 {
|
|
294 yomi[3] = jt.table[i].yomi2 & 0xffff;
|
|
295 }
|
|
296 }
|
|
297 len = hop->yomi[0];
|
|
298 wnn_Strncpy (yomi + 4, (hop->yomi) + 1, len - 4);
|
|
299 yomi[len] = 0;
|
|
300 serial = hop->serial;
|
|
301 for (k = hop->kosuu, c = hop->kanjipter + jt.kanji; k > 0; k--, serial++)
|
|
302 {
|
|
303 get_kanji_str (c, kan, NULL, comm);
|
|
304 jeary[serial]->kanji = c;
|
|
305 c += *c;
|
|
306 jeary[serial]->serial = serial;
|
|
307 #ifdef CONVERT_with_SiSheng
|
|
308 wnn_Strcpy (ryomi, yomi);
|
|
309 #else
|
|
310 wnn_Sreverse (ryomi, yomi);
|
|
311 #endif
|
|
312 w_stradd (ryomi, &jeary[serial]->yomi);
|
|
313 w_stradd (kan, &jeary[serial]->kan);
|
|
314 w_stradd (comm, &jeary[serial]->comm);
|
|
315 }
|
|
316 }
|
|
317 }
|
|
318 }
|
|
319
|
|
320 /* SD routine */
|
|
321
|
|
322 w_char yomi[LENGTHYOMI];
|
|
323 int je = 0;
|
|
324
|
|
325 void
|
|
326 kset ()
|
|
327 {
|
|
328 int i;
|
|
329 UCHAR *c;
|
|
330 w_char kan[LENGTHYOMI]; /* 2 byte kanji */
|
|
331 w_char comm[LENGTHYOMI]; /* 2 byte kanji */
|
|
332
|
|
333
|
|
334 c = jt.kanji;
|
|
335 for (i = 0; i < jt.maxserial; i++)
|
|
336 {
|
|
337 get_kanji_str (c, kan, NULL, comm);
|
|
338 w_stradd (kan, &jeary[i]->kan);
|
|
339 w_stradd (comm, &jeary[i]->comm);
|
|
340 jeary[i]->kanji = c;
|
|
341 c += *c;
|
|
342 }
|
|
343 }
|
|
344
|
|
345 void
|
|
346 sdtoujis (hopter, level)
|
|
347 char *hopter;
|
|
348 register int level;
|
|
349 {
|
|
350 register int k, j;
|
|
351 register int tsize;
|
|
352 register w_char *charst;
|
|
353 register w_char *sumst;
|
|
354 int *ptrst;
|
|
355 static w_char ry[LENGTHYOMI];
|
|
356
|
|
357 yomi[level + 1] = 0;
|
|
358 switch (*(w_char *) hopter)
|
|
359 {
|
|
360 case ST_NORMAL:
|
|
361 tsize = *(w_char *) (hopter + 2);
|
|
362 charst = (w_char *) (hopter + 12);
|
|
363 sumst = ((w_char *) charst + tsize + 2); /* + 2 keeps two zero words */
|
|
364 ptrst = (int *) ((w_char *) sumst + tsize);
|
|
365 for (k = 0; k < tsize; k++)
|
|
366 {
|
|
367 j = sumst[k] - sumst[k - 1];
|
|
368 if (j)
|
|
369 {
|
|
370 yomi[level] = charst[k];
|
|
371 for (; j > 0; j--)
|
|
372 {
|
|
373 jeary[je]->serial = je;
|
|
374 #ifdef CONVERT_with_SiSheng
|
|
375 wnn_Strcpy (ry, yomi);
|
|
376 #else
|
|
377 wnn_Sreverse (ry, yomi);
|
|
378 #endif
|
|
379 w_stradd (ry, &jeary[je++]->yomi);
|
|
380 }
|
|
381 }
|
|
382 }
|
|
383 for (k = 0; k < tsize; k++)
|
|
384 {
|
|
385 if (ptrst[k] != ENDPTR)
|
|
386 {
|
|
387 yomi[level] = charst[k];
|
|
388 sdtoujis ((char *) jt.hontai + ptrst[k], level + 1);
|
|
389 }
|
|
390 }
|
|
391 break;
|
|
392 case ST_NOENT:
|
|
393 tsize = *(w_char *) (hopter + 2);
|
|
394 charst = (w_char *) (hopter + 4);
|
|
395 ptrst = (int *) AL_INT ((w_char *) charst + tsize);
|
|
396 for (k = 0; k < tsize; k++)
|
|
397 {
|
|
398 if (ptrst[k] != ENDPTR)
|
|
399 {
|
|
400 yomi[level] = charst[k];
|
|
401 sdtoujis ((char *) jt.hontai + ptrst[k], level + 1);
|
|
402 }
|
|
403 }
|
|
404 break;
|
|
405 case ST_NOPTER:
|
|
406 tsize = *(w_char *) (hopter + 2);
|
|
407 charst = (w_char *) (hopter + 12);
|
|
408 sumst = ((w_char *) charst + tsize + 2); /* + 2 keeps two zero words */
|
|
409 for (k = 0; k < tsize; k++)
|
|
410 {
|
|
411 j = sumst[k] - sumst[k - 1];
|
|
412 if (j)
|
|
413 {
|
|
414 yomi[level] = charst[k];
|
|
415 for (; j > 0; j--)
|
|
416 {
|
|
417 jeary[je]->serial = je;
|
|
418 #ifdef CONVERT_with_SiSheng
|
|
419 wnn_Strcpy (ry, yomi);
|
|
420 #else
|
|
421 wnn_Sreverse (ry, yomi);
|
|
422 #endif
|
|
423 w_stradd (ry, &jeary[je++]->yomi);
|
|
424 }
|
|
425 }
|
|
426 }
|
|
427 break;
|
|
428 case ST_SMALL:
|
|
429 yomi[level] = *(w_char *) (hopter + 2);
|
|
430 sdtoujis (hopter + 4, level + 1);
|
|
431 break;
|
|
432 }
|
|
433 }
|
|
434
|
|
435 static int
|
|
436 rdtoujis ()
|
|
437 {
|
|
438 w_char yomi[LENGTHYOMI]; /* 2 byte yomi */
|
|
439 w_char kan[LENGTHYOMI]; /* 2 byte yomi */
|
|
440 w_char comm[LENGTHYOMI]; /* 2 byte yomi */
|
|
441 register struct rind2 *hop;
|
|
442 register int hopi;
|
|
443 register int i;
|
|
444 register int serial;
|
|
445
|
|
446 for (i = 0; i < jt.maxri1[D_YOMI]; i++)
|
|
447 {
|
|
448 for (hopi = jt.ri1[D_YOMI][i].pter; hopi != RD_ENDPTR; hopi = hop->next[D_YOMI])
|
|
449 {
|
|
450 hop = hopi + jt.ri2;
|
|
451 /* Though each hop has the same yomi, but calculate yomi each time. */
|
|
452 get_kanji_str (hop->kanjipter + jt.kanji, kan, yomi, comm);
|
|
453 #ifdef CONVERT_with_SiSheng
|
|
454 cwnn_yincod_pzy_str (yomi, yomi, wnn_Strlen (yomi), pzy_flag);
|
|
455 #endif
|
|
456 serial = hopi;
|
|
457 jeary[serial]->kanji = hop->kanjipter + jt.kanji;
|
|
458 jeary[serial]->serial = serial;
|
|
459
|
|
460 w_stradd (yomi, &jeary[serial]->yomi);
|
|
461 w_stradd (kan, &jeary[serial]->kan);
|
|
462 w_stradd (comm, &jeary[serial++]->comm);
|
|
463 }
|
|
464 }
|
|
465 return (0);
|
|
466 }
|
|
467
|
|
468 void
|
|
469 ghindo (argc, argv)
|
|
470 int argc;
|
|
471 char **argv;
|
|
472 {
|
|
473 FILE *fp;
|
|
474 struct wnn_file_head h_file_head;
|
|
475 struct HJT hjt;
|
|
476
|
|
477
|
|
478 while (argc-- > 0)
|
|
479 {
|
|
480 if ((fp = fopen (*argv++, "r")) == NULL)
|
|
481 {
|
|
482 fprintf (stderr, "can't open %s\n", *(argv - 1));
|
|
483 perror ("error in ghindo");
|
|
484 exit (1);
|
|
485 }
|
|
486 if (input_hindo_header (fp, &hjt, &h_file_head) == -1)
|
|
487 {
|
|
488 perror ("error in ghindo 1");
|
|
489 exit (1);
|
|
490 }
|
|
491 if (bcmp (&file_head.file_uniq_org, &hjt.dic_file_uniq, sizeof (struct wnn_file_uniq)))
|
|
492 {
|
|
493 fprintf (stderr, "%s(%s)Dic File and Hindo File mismatch.\n", infile, *(argv - 1));
|
|
494 exit (1);
|
|
495 }
|
|
496 add_hindo (fp, hjt.maxserial);
|
|
497 }
|
|
498 }
|
|
499
|
|
500 static int
|
|
501 add_hindo (ifpter, num)
|
|
502 register FILE *ifpter;
|
|
503 int num;
|
|
504 {
|
|
505 register int i;
|
|
506 register int k;
|
|
507 for (i = 0; i < num; i++)
|
|
508 {
|
|
509 jeary[i]->hindo += motoni2 ((k = getc (ifpter)) & 0x7f);
|
|
510 if (k == -1)
|
|
511 return (-1);
|
|
512 }
|
|
513 return (0);
|
|
514 }
|
|
515
|
|
516 /* input dict routines */
|
|
517
|
|
518 int
|
|
519 input_comment (fp)
|
|
520 register FILE *fp;
|
|
521 {
|
|
522 return (get_n_EU_str (fp, jt.maxcomment, file_comment));
|
|
523 }
|
|
524
|
|
525 int
|
|
526 input_hinsi_list (fp)
|
|
527 register FILE *fp;
|
|
528 {
|
|
529 return (get_n_EU_str (fp, jt.maxhinsi_list, hinsi_list));
|
|
530 }
|
|
531
|
|
532
|
|
533 static int
|
|
534 input_hindo (ifpter)
|
|
535 register FILE *ifpter;
|
|
536 {
|
|
537 register int i;
|
|
538 register int k;
|
|
539 for (i = 0; i < jt.maxserial; i++)
|
|
540 {
|
|
541 jeary[i]->hindo = motoni2 ((k = getc (ifpter)) & 0x7f);
|
|
542 if (k == -1)
|
|
543 return (-1);
|
|
544 }
|
|
545 return (0);
|
|
546 }
|
|
547
|
|
548 static int
|
|
549 set_hinsi ()
|
|
550 {
|
|
551 register int i;
|
|
552
|
|
553 for (i = 0; i < jt.maxserial; i++)
|
|
554 {
|
|
555 jeary[i]->hinsi = jt.hinsi[i];
|
|
556 }
|
|
557 return (0);
|
|
558 }
|
|
559
|
|
560 #ifdef CONVERT_with_SiSheng
|
|
561 int
|
|
562 input_sisheng (ifpter)
|
|
563 register FILE *ifpter;
|
|
564 {
|
|
565 register int i;
|
|
566 unsigned short s;
|
|
567
|
|
568 for (i = 0; i < jt.maxserial; i++)
|
|
569 {
|
|
570 if (get_short (&s, ifpter) == -1)
|
|
571 return (-1);
|
|
572 jeary[i]->ss = s;
|
|
573 }
|
|
574 return (0);
|
|
575 }
|
|
576
|
|
577 #endif
|
|
578
|
|
579 int
|
|
580 get_n_EU_str (FILE* ifpter, int n, w_char* st)
|
|
581 {
|
|
582 int k;
|
|
583
|
|
584 for (; n; n--)
|
|
585 {
|
|
586 k = get_short ((short *) st++, ifpter);
|
|
587 if (k == -1)
|
|
588 return (-1);
|
|
589 }
|
|
590 return (0);
|
|
591 }
|
|
592
|
|
593 int
|
|
594 get_short (short* sp, FILE* ifpter)
|
|
595 {
|
|
596 int i = 0;
|
|
597 int k;
|
|
598
|
|
599 i |= (k = getc (ifpter)) << 8;
|
|
600 if (k == -1)
|
|
601 return (-1);
|
|
602 i |= (k = getc (ifpter));
|
|
603 if (k == -1)
|
|
604 return (-1);
|
|
605 *sp = i;
|
|
606 return (0);
|
|
607 }
|