123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
- #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 = *(u8*)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);
- }
|