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

Defined functions

canon defined in line 146; used 4 times
compare defined in line 118; used 3 times
getword defined in line 130; used 3 times
main defined in line 15; never used

Defined variables

dict defined in line 9; used 3 times
entry defined in line 11; used 8 times
filenam defined in line 6; used 3 times
fold defined in line 8; used 3 times
key defined in line 13; used 4 times
sccsid defined in line 1; never used
tab defined in line 10; used 3 times
word defined in line 12; used 6 times
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2770
Valid CSS Valid XHTML 1.0 Strict