File: scankoku.c

package info (click to toggle)
t-code 1%3A2.0beta9-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,632 kB
  • ctags: 507
  • sloc: lisp: 7,176; sh: 488; ansic: 440; perl: 270; makefile: 116
file content (103 lines) | stat: -rw-r--r-- 1,754 bytes parent folder | download
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
97
98
99
100
101
102
103
#include <stdio.h>
#if	0
#ifndef X68K
#include <lchar.h>
#endif
#endif
#define BEGIN	0
#define HYOOKI	1
#define YOMI	2
#define HINSI	3

int
scankoku(fd,pool,hyooki,midasi,hinsi)
FILE *fd;
unsigned short *pool;
unsigned short **hyooki,**midasi,**hinsi;
{
	int mode=BEGIN;
	int j=0;
	register int lc;
	int x1,x2;

	while((lc=getlc(fd))!=EOF && lc!='\n') {
		switch(mode) {
		case(BEGIN):
			if(lc<256) continue;
			hyooki[j]=pool;
			mode=HYOOKI;
		case(HYOOKI):
			if(lc=='<' || lc==' ') {
				*pool++=0;
				midasi[j]=pool;
				if(lc==' ') {
					hinsi[0]=pool;
					mode=HINSI;
					goto case_hinsi;
				}
				mode=YOMI;
			}
			else if(hiraDA2(lc)) {
				*pool++=lc; *pool++=0;
				midasi[j]=pool;
				*pool++=lc; *pool++=0;
				hyooki[++j]=pool;
			}
			else {
				*pool++=lc;
			}
			break;
		case(YOMI):
			if(lc=='>') {
				*pool++=0;
				hyooki[++j]=pool;
				mode=HYOOKI;
			}
			else {
				*pool++=lc;
			}
			break;
		case(HINSI):
		case_hinsi:
			if(fscanf(fd,"%x %x",&x1,&x2)!=2)
				fputs("HINSI field missing\n",stderr),
				fflush(stderr);
			else {
				*pool++=(x1<<8)|x2;
				*pool=0;
			}
			break;
		}
	}
	if(lc==EOF && j==0) return EOF;
	hyooki[j]=0;
	midasi[j]=0;
	return j;
}

#ifdef STUB
#ifndef putlchar
#define putlchar(c)	putlc((c),stdout)
#endif
unsigned short buf[1000];
unsigned short *hyooki[20];
unsigned short *midasi[20];
unsigned short *hinsi[1];

main(int argc, char *argv[]) {
	register int i;
	FILE *fp = fopen(argv[1], "r");
	while((i=scankoku(fp,buf,hyooki,midasi,hinsi))>=0) {
		register unsigned short *lp;
		for(i=0; i<19 && hyooki[i]!=0; i++) {
			lp=hyooki[i];
			while(*lp) putlchar(*lp++);
			putlchar('<');
			lp=midasi[i];
			while(*lp) putlchar(*lp++);
			putlchar('>');
		}
		putlchar('\n');
	}
}
#endif