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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include <u.h>
#include <libc.h>
#include <ctype.h>
#include <bio.h>
void spout(int, char*);
Biobuf bout;
void
main(int argc, char *argv[])
{
int i, fd;
Binit(&bout, 1, OWRITE);
if(argc == 1)
spout(0, "");
else
for(i=1; i<argc; i++){
fd = open(argv[i], OREAD);
if(fd < 0){
fprint(2, "spell: can't open %s: %r\n", argv[i]);
continue;
}
spout(fd, argv[i]);
close(fd);
}
exits(nil);
}
Biobuf b;
void
spout(int fd, char *name)
{
char *s, *t, *w;
Rune r;
int inword, wordchar;
int n, wn, wid, c, m;
char buf[1024];
Binit(&b, fd, OREAD);
n = 0;
wn = 0;
while((s = Brdline(&b, '\n')) != nil){
if(s[0] == '.')
for(c=0; c<3 && *s>' '; c++){
n++;
s++;
}
inword = 0;
w = s;
t = s;
do{
c = *(uchar*)t;
if(c < Runeself)
wid = 1;
else{
wid = chartorune(&r, t);
c = r;
}
wordchar = 0;
if(isalpha(c))
wordchar = 1;
if(inword && !wordchar){
if(c=='\'' && isalpha(t[1]))
goto Continue;
m = t-w;
if(m > 1){
memmove(buf, w, m);
buf[m] = 0;
Bprint(&bout, "%s:#%d,#%d:%s\n", name, wn, n, buf);
}
inword = 0;
}else if(!inword && wordchar){
wn = n;
w = t;
inword = 1;
}
if(c=='\\' && (isalpha(t[1]) || t[1]=='(')){
switch(t[1]){
case '(':
m = 4;
break;
case 'f':
if(t[2] == '(')
m = 5;
else
m = 3;
break;
case 's':
if(t[2] == '+' || t[2]=='-'){
if(t[3] == '(')
m = 6;
else
m = 4;
}else{
if(t[2] == '(')
m = 5;
else if(t[2]=='1' || t[2]=='2' || t[2]=='3')
m = 4;
else
m = 3;
}
break;
default:
m = 2;
}
while(m-- > 0){
if(*t == '\n')
break;
n++;
t++;
}
continue;
}
Continue:
n++;
t += wid;
}while(c != '\n');
}
Bterm(&b);
}
|