1: #include <stdio.h>
2: #include <ctype.h>
3:
4: FILE *dfile;
5: char *filenam = "/usr/dict/words";
6:
7: int fold;
8: int dict;
9: int tab;
10: char entry[250];
11: char word[250];
12: char key[50];
13:
14: main(argc,argv)
15: char **argv;
16: {
17: register c;
18: long top,bot,mid;
19: while(argc>=2 && *argv[1]=='-') {
20: for(;;) {
21: switch(*++argv[1]) {
22: case 'd':
23: dict++;
24: continue;
25: case 'f':
26: fold++;
27: continue;
28: case 't':
29: tab = argv[1][1];
30: if(tab)
31: ++argv[1];
32: continue;
33: case 0:
34: break;
35: default:
36: continue;
37: }
38: break;
39: }
40: argc --;
41: argv++;
42: }
43: if(argc<=1)
44: return;
45: if(argc==2) {
46: fold++;
47: dict++;
48: } else
49: filenam = argv[2];
50: dfile = fopen(filenam,"r");
51: if(dfile==NULL) {
52: fprintf(stderr,"look: can't open %s\n",filenam);
53: exit(2);
54: }
55: canon(argv[1],key);
56: bot = 0;
57: fseek(dfile,0L,2);
58: top = ftell(dfile);
59: for(;;) {
60: mid = (top+bot)/2;
61: fseek(dfile,mid,0);
62: do {
63: c = getc(dfile);
64: mid++;
65: } while(c!=EOF && c!='\n');
66: if(!getword(entry))
67: break;
68: canon(entry,word);
69: switch(compare(key,word)) {
70: case -2:
71: case -1:
72: case 0:
73: if(top<=mid)
74: break;
75: top = mid;
76: continue;
77: case 1:
78: case 2:
79: bot = mid;
80: continue;
81: }
82: break;
83: }
84: fseek(dfile,bot,0);
85: while(ftell(dfile)<top) {
86: if(!getword(entry))
87: return;
88: canon(entry,word);
89: switch(compare(key,word)) {
90: case -2:
91: return;
92: case -1:
93: case 0:
94: puts(entry,stdout);
95: break;
96: case 1:
97: case 2:
98: continue;
99: }
100: break;
101: }
102: while(getword(entry)) {
103: canon(entry,word);
104: switch(compare(key,word)) {
105: case -1:
106: case 0:
107: puts(entry,stdout);
108: continue;
109: }
110: break;
111: }
112: }
113:
114: compare(s,t)
115: register char *s,*t;
116: {
117: for(;*s==*t;s++,t++)
118: if(*s==0)
119: return(0);
120: return(*s==0? -1:
121: *t==0? 1:
122: *s<*t? -2:
123: 2);
124: }
125:
126: getword(w)
127: char *w;
128: {
129: register c;
130: for(;;) {
131: c = getc(dfile);
132: if(c==EOF)
133: return(0);
134: if(c=='\n')
135: break;
136: *w++ = c;
137: }
138: *w = 0;
139: return(1);
140: }
141:
142: canon(old,new)
143: char *old,*new;
144: {
145: register c;
146: for(;;) {
147: *new = c = *old++;
148: if(c==0||c==tab) {
149: *new = 0;
150: break;
151: }
152: if(dict) {
153: if(!isalnum(c))
154: continue;
155: }
156: if(fold) {
157: if(isupper(c))
158: *new += 'a' - 'A';
159: }
160: new++;
161: }
162: }
Defined functions
main
defined in line
14;
never used
Defined variables
dict
defined in line
8; used 3 times
entry
defined in line
10; used 8 times
fold
defined in line
7; used 3 times
key
defined in line
12; used 4 times
tab
defined in line
9; used 3 times
word
defined in line
11; used 6 times