1 #ifndef lint 2 static char sccsid[] = "@(#)lookup.c 2.2 09/23/83"; 3 #endif not lint 4 # include "stdio.h" 5 # include "streams.h" 6 # include "bib.h" 7 8 char *locate(); 9 10 int max_klen = 6; /* max length of keys */ 11 char *common = /* name of file of common words */ 12 COMFILE; 13 char INDEX[maxstr] = /* name of index file */ 14 INDXFILE; 15 16 int argc; 17 char **argv; 18 19 main(argcount,arglist) 20 int argcount; 21 char **arglist; 22 { char *refs; 23 char keys[maxstr]; 24 char *p,*q; 25 char one_index[maxstr]; 26 27 argc= argcount-1; 28 argv= arglist+1; 29 flags(); 30 31 /* add SYSINDEX to search path. all names are comma terminated */ 32 strcat(INDEX, ","); 33 strcat(INDEX, SYSINDEX); 34 strcat(INDEX, ","); 35 36 while (fgets(keys,maxstr,stdin)!=NULL) 37 { for (p = one_index, q = INDEX; *q != 0 ; q++) 38 if (*q == ',' ) 39 { *p = 0; 40 refs = locate(keys, one_index, max_klen, common); 41 if( refs==NULL ) 42 { fprintf(stderr, 43 "%s removed from index list.\n", one_index); 44 /* delete this file name (shift remainder on top) */ 45 strcpy(q-strlen(one_index),q+1); 46 q = q-strlen(one_index)-1; 47 } 48 if (refs!=NULL && *refs!=NULL) break; 49 p = one_index; 50 } 51 else *p++ = *q; 52 53 if (refs==NULL || *refs==NULL) printf("No references found.\n"); 54 else printf("%s", refs); 55 if (refs!=NULL) free(refs); 56 } 57 exit(0); 58 } 59 60 # define operand (strlen(*argv+2)==0 ? (argv++,argc--,*argv) : *argv+2) 61 62 flags() 63 { for (; argc>0 && *argv[0]=='-'; argc--,argv++) 64 { switch ((*argv)[1]) 65 { case 'l': max_klen= atoi(operand); 66 break; 67 case 'c': common= operand; 68 break; 69 case 'p': strcpy(INDEX,operand); 70 break; 71 default: fprintf(stderr, "unknown flag '%s'\n", *argv); 72 } 73 } 74 } 75