]> git.lizzy.rs Git - plan9front.git/blob - acme/bin/source/spout.c
audiohda: fix syntax error
[plan9front.git] / acme / bin / source / spout.c
1 #include <u.h>
2 #include <libc.h>
3 #include <ctype.h>
4 #include <bio.h>
5
6 void    spout(int, char*);
7
8 Biobuf bout;
9
10 void
11 main(int argc, char *argv[])
12 {
13         int i, fd;
14
15         Binit(&bout, 1, OWRITE);
16         if(argc == 1)
17                 spout(0, "");
18         else
19                 for(i=1; i<argc; i++){
20                         fd = open(argv[i], OREAD);
21                         if(fd < 0){
22                                 fprint(2, "spell: can't open %s: %r\n", argv[i]);
23                                 continue;
24                         }
25                         spout(fd, argv[i]);
26                         close(fd);
27                 }
28         exits(nil);
29 }
30
31 Biobuf b;
32
33 void
34 spout(int fd, char *name)
35 {
36         char *s, *t, *w;
37         Rune r;
38         int inword, wordchar;
39         int n, wn, wid, c, m;
40         char buf[1024];
41
42         Binit(&b, fd, OREAD);
43         n = 0;
44         wn = 0;
45         while((s = Brdline(&b, '\n')) != nil){
46                 if(s[0] == '.')
47                         for(c=0; c<3 && *s>' '; c++){
48                                 n++;
49                                 s++;
50                         }
51                 inword = 0;
52                 w = s;
53                 t = s;
54                 do{
55                         c = *(uchar*)t;
56                         if(c < Runeself)
57                                 wid = 1;
58                         else{
59                                 wid = chartorune(&r, t);
60                                 c = r;
61                         }
62                         wordchar = 0;
63                         if(isalpha(c))
64                                 wordchar = 1;
65                         if(inword && !wordchar){
66                                 if(c=='\'' && isalpha(t[1]))
67                                         goto Continue;
68                                 m = t-w;
69                                 if(m > 1){
70                                         memmove(buf, w, m);
71                                         buf[m] = 0;
72                                         Bprint(&bout, "%s:#%d,#%d:%s\n", name, wn, n, buf);
73                                 }
74                                 inword = 0;
75                         }else if(!inword && wordchar){
76                                 wn = n;
77                                 w = t;
78                                 inword = 1;
79                         }
80                         if(c=='\\' && (isalpha(t[1]) || t[1]=='(')){
81                                 switch(t[1]){
82                                 case '(':
83                                         m = 4;
84                                         break;
85                                 case 'f':
86                                         if(t[2] == '(')
87                                                 m = 5;
88                                         else
89                                                 m = 3;
90                                         break;
91                                 case 's':
92                                         if(t[2] == '+' || t[2]=='-'){
93                                                 if(t[3] == '(')
94                                                         m = 6;
95                                                 else
96                                                         m = 4;
97                                         }else{
98                                                 if(t[2] == '(')
99                                                         m = 5;
100                                                 else if(t[2]=='1' || t[2]=='2' || t[2]=='3')
101                                                         m = 4;
102                                                 else
103                                                         m = 3;
104                                         }
105                                         break;
106                                 default:
107                                         m = 2;
108                                 }
109                                 while(m-- > 0){
110                                         if(*t == '\n')
111                                                 break;
112                                         n++;
113                                         t++;
114                                 }
115                                 continue;
116                         }
117         Continue:
118                         n++;
119                         t += wid;
120                 }while(c != '\n');
121         }
122         Bterm(&b);
123 }