1 #ifndef lint
2 static char sccsid[] = "@(#)lookup.c 2.6 05/27/93";
3 #endif not lint
4 # include "stdio.h"
5 # include "streams.h"
6 # include "bib.h"
7
8 char *locate();
9
10 int fflag = 0; /* print out file names */
11 int Aflag = 0; /* print hits from All indexes */
12 int max_klen = 6; /* max length of keys */
13 char INDEX[maxstr] = /* name of index file */
14 INDXFILE;
15
16 int argc;
17 char **argv;
18
main(argcount,arglist)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 int found;
27
28 InitDirectory(BMACLIB,N_BMACLIB);
29 InitDirectory(COMFILE,N_COMFILE);
30
31 argc= argcount-1;
32 argv= arglist+1;
33 flags();
34
35 /* add SYSINDEX to search path. all names are comma terminated */
36 strcat(INDEX, ",");
37 strcat(INDEX, SYSINDEX);
38 strcat(INDEX, ",");
39
40 while (fgets(keys,maxstr,stdin)!=NULL)
41 { found = 0;
42 for (p = one_index, q = INDEX; *q != 0 ; q++)
43 if (*q == ',' )
44 { *p = 0;
45 refs = locate(keys, one_index, max_klen, COMFILE);
46 if( refs==NULL )
47 { fprintf(stderr,"%s removed from index list.\n", one_index);
48 /* delete this file name (shift remainder on top) */
49 strcpy(q-strlen(one_index),q+1);
50 q = q-strlen(one_index)-1;
51 }
52 if (refs!=NULL && *refs!=NULL)
53 {
54 printf("%s", refs);
55 free(refs);
56 found = 1;
57 if (!Aflag) break;
58 }
59 p = one_index;
60 }
61 else *p++ = *q;
62
63 if (!found) printf("No references found.\n");
64 }
65 exit(0);
66 }
67
68 # define operand (strlen(*argv+2)==0 ? (argv++,argc--,*argv) : *argv+2)
69
flags()70 flags()
71 {
72 char *p;
73 for (; argc>0 && *argv[0]=='-'; argc--,argv++)
74 { switch ((*argv)[1])
75 { case 'l': max_klen= atoi(operand);
76 break;
77 case 'f': fflag++;
78 break;
79 case 'c': strcpy(COMFILE, operand);
80 break;
81 case 'A': Aflag++;
82 break;
83 case 'p': strcpy(INDEX,operand);
84 break;
85 case 'd':
86 p = &argv[0][2];
87 if (!p) {
88 argv++;
89 p = &argv[0][0];
90 }
91 strreplace(COMFILE, BMACLIB, p);
92 strcpy(BMACLIB, p);
93 break;
94 default: fprintf(stderr, "unknown flag '%s'\n", *argv);
95 }
96 }
97 }
98