-
Notifications
You must be signed in to change notification settings - Fork 11
/
skkdic-count.c
90 lines (75 loc) · 2.35 KB
/
skkdic-count.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* SKK JISYO TOOLS (SKK dictionary handling tools)
Copyright (C) 1994, 1996, 1999, 2000
Hironobu Takahashi, Masahiko Sato, Kiyotaka Sakai
Author: Hironobu Takahashi, Masahiko Sato, Kiyotaka Sakai, Kenji Yabuuchi
Maintainer: Mikio Nakajima <minakaji@osaka.email.ne.jp>
Keywords: japanese
This file is part of Daredevil SKK.
SKK JISYO TOOLS are free software; you can redistribute them and/or modify
them under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
SKK JISYO TOOLS are distributed in the hope that they will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SKK; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* skkdic-count.c
このプログラムは SKK の辞書に含まれる候補数を数えます。
*/
#include <config.h>
#include <stdio.h>
/* 2005 年版の SKK 辞書では最長の行(「こう」)は 2286 bytes ですが
* 安全のために以下の値としています。*/
#define BUFSIZE 65536
/* 各ファイルの候補を数えます。 */
static void
count_entry(filename, fp)
char *filename;
FILE *fp;
{
unsigned char buffer[BUFSIZE], *p, *q;
int count;
count = 0;
while(fgets(buffer, BUFSIZE, fp) != NULL) {
if ((buffer[0] == ';') || (buffer[0] == '\0')) continue;
for(p = buffer; *p != '\0'; ++ p) {
if ((p[0] == ' ') && (p[1] == '/')) {
/* '/['から先は skk-henkan-okuri-strictly 用のデータなので無視 */
for (q = p+2; (*q != '\0') && (*(q-1) != '/' || *q != '[') ; ++ q) {
if (*q == '/') count++;
}
break;
}
}
}
if (count == 1)
printf("%s: %d candidate\n", filename, count);
else
printf("%s: %d candidates\n", filename, count);
}
/* メインプログラムでは引数を判別します。もしもなければ標準入力
からのデータが得られるものとします。 */
int main(argc, argv)
int argc;
char **argv;
{
int i;
FILE *fp;
if (argc <= 1) {
count_entry("", stdin);
} else {
for (i = 1; i < argc; ++ i) {
if ((fp = fopen(argv[i], "r")) != NULL) {
count_entry(argv[i], fp);
fclose(fp);
} else {
perror(argv[i]);
}
}
}
return 0;
}
/* end of skkdic-count.c */