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

Defined functions

canon defined in line 144; used 4 times
compare defined in line 116; used 3 times
getword defined in line 128; 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: 1982-06-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1057
Valid CSS Valid XHTML 1.0 Strict