File: rdic-conv.c

package info (click to toggle)
kakasi 2.3.6-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,560 kB
  • sloc: sh: 11,430; ansic: 6,734; makefile: 125
file content (96 lines) | stat: -rw-r--r-- 2,233 bytes parent folder | download | duplicates (4)
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
91
92
93
94
95
96
/*
 * KAKASI (Kanji Kana Simple inversion program)
 * $Id: rdic-conv.c,v 1.3 2007-10-23 05:25:56 knok Exp $
 * Copyright (C) 1992 1994
 * Hironobu Takahashi (takahasi@tiny.or.jp)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either versions 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it 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 KAKASI, see the file COPYING.  If not, write to the Free
 * Software Foundation Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#include <stdio.h>
#include "conv-util.h"

static void
jis2ujis(buffer)
     unsigned char *buffer;
{
    unsigned char *p, *q;
    int kanji=0;

    p = q = buffer;
    while(*p != '\0') {
	if (*p == '\033') {
	    if ((p[1] == '$') &&
		((p[2] == '@') || (p[2] == 'B'))) {
		kanji = 1;
		p += 2;
	    } else if ((p[1] == '(') &&
		       ((p[2] == 'B') || (p[2] == 'J'))) {
		kanji = 0;
		p += 2;
	    } else {
		*(q ++) = *p;
	    }
	} else {
	    if (kanji) {
		*(q ++) = *(p ++) | 0x80;
		*(q ++) = *p | 0x80;
	    } else {
		*(q ++) = *p;
	    }
	}
	++ p;
    }
    *q = '\0';
}

static void
extract(file_name)
     char *file_name;
{
    FILE *fp;
    unsigned char buffer[1024];
    unsigned char f1[1024], f2[1024], f3[1024];

    if ((fp = fopen(file_name, "r")) == NULL) {
	perror(file_name);
	return;
    }

    while(fgets((char *)buffer, 1024, fp) != NULL) {
	if ((buffer[0] == '\0') || (buffer[0] == '#')) continue;
	jis2ujis(buffer);
	if (sscanf((const char *)buffer, "%s%s%s", f1, f2, f3) != 3) continue;
	if (isallkana(f2) == 0) continue;
	if (isallzenkaku(f3) == 0) continue;
	if (includekanji(f3) == 0) continue;
	printf("%s %s\n", f2, f3);
    }

    fclose(fp);
}

int
main(argc, argv)
     int argc;
     char **argv;
{
    int i;
    for(i = 1; i < argc; ++ i) {
	extract(argv[i]);
    }
    return 0;
}