1 /*
2  * KAKASI (Kanji Kana Simple inversion program)
3  * $Id: rdic-conv.c,v 1.3 2007-10-23 05:25:56 knok Exp $
4  * Copyright (C) 1992 1994
5  * Hironobu Takahashi (takahasi@tiny.or.jp)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either versions 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with KAKASI, see the file COPYING.  If not, write to the Free
19  * Software Foundation Inc., 59 Temple Place - Suite 330, Boston, MA
20  * 02111-1307, USA.
21  */
22 
23 #include <stdio.h>
24 #include "conv-util.h"
25 
26 static void
jis2ujis(buffer)27 jis2ujis(buffer)
28      unsigned char *buffer;
29 {
30     unsigned char *p, *q;
31     int kanji=0;
32 
33     p = q = buffer;
34     while(*p != '\0') {
35 	if (*p == '\033') {
36 	    if ((p[1] == '$') &&
37 		((p[2] == '@') || (p[2] == 'B'))) {
38 		kanji = 1;
39 		p += 2;
40 	    } else if ((p[1] == '(') &&
41 		       ((p[2] == 'B') || (p[2] == 'J'))) {
42 		kanji = 0;
43 		p += 2;
44 	    } else {
45 		*(q ++) = *p;
46 	    }
47 	} else {
48 	    if (kanji) {
49 		*(q ++) = *(p ++) | 0x80;
50 		*(q ++) = *p | 0x80;
51 	    } else {
52 		*(q ++) = *p;
53 	    }
54 	}
55 	++ p;
56     }
57     *q = '\0';
58 }
59 
60 static void
extract(file_name)61 extract(file_name)
62      char *file_name;
63 {
64     FILE *fp;
65     unsigned char buffer[1024];
66     unsigned char f1[1024], f2[1024], f3[1024];
67 
68     if ((fp = fopen(file_name, "r")) == NULL) {
69 	perror(file_name);
70 	return;
71     }
72 
73     while(fgets((char *)buffer, 1024, fp) != NULL) {
74 	if ((buffer[0] == '\0') || (buffer[0] == '#')) continue;
75 	jis2ujis(buffer);
76 	if (sscanf((const char *)buffer, "%s%s%s", f1, f2, f3) != 3) continue;
77 	if (isallkana(f2) == 0) continue;
78 	if (isallzenkaku(f3) == 0) continue;
79 	if (includekanji(f3) == 0) continue;
80 	printf("%s %s\n", f2, f3);
81     }
82 
83     fclose(fp);
84 }
85 
86 int
main(argc,argv)87 main(argc, argv)
88      int argc;
89      char **argv;
90 {
91     int i;
92     for(i = 1; i < argc; ++ i) {
93 	extract(argv[i]);
94     }
95     return 0;
96 }
97