xref: /original-bsd/old/refer/mkey/mkey1.c (revision e59fb703)
1 /*-
2  * %sccs.include.proprietary.c%
3  */
4 
5 #ifndef lint
6 static char sccsid[] = "@(#)mkey1.c	4.2 (Berkeley) 04/18/91";
7 #endif /* not lint */
8 
9 #include <stdio.h>
10 
11 extern char *comname;	/* "/usr/lib/eign" */
12 int wholefile = 0;
13 int keycount = 100;
14 int labels = 1;
15 int minlen = 3;
16 extern int comcount;
17 char *iglist = "XYZ#";
18 
19 main (argc,argv)
20 char *argv[];
21 {
22 	/* this program expects as its arguments a list of
23 	 * files and generates a set of lines of the form
24 	 *	filename:byte-add,length (tab) key1 key2 key3
25 	 * where the byte addresses give the position within
26 	 * the file and the keys are the strings off the lines
27 	 * which are alphabetic, first six characters only.
28 	 */
29 
30 	int i;
31 	char *name, qn[200];
32 	char *inlist = 0;
33 
34 	FILE *f, *ff;
35 
36 	while (argc>1 && argv[1][0] == '-')
37 	{
38 		switch(argv[1][1])
39 		{
40 		case 'c':
41 			comname = argv[2];
42 			argv++;
43 			argc--;
44 			break;
45 		case 'w':
46 			wholefile = 1;
47 			break;
48 		case 'f':
49 			inlist = argv[2];
50 			argv++;
51 			argc--;
52 			break;
53 		case 'i':
54 			iglist = argv[2];
55 			argv++;
56 			argc--;
57 			break;
58 		case 'l':
59 			minlen = atoi(argv[1]+2);
60 			if (minlen<=0) minlen=3;
61 			break;
62 		case 'n': /* number of common words to use */
63 			comcount = atoi(argv[1]+2);
64 			break;
65 		case 'k': /* number  of keys per file max */
66 			keycount = atoi(argv[1]+2);
67 			break;
68 		case 's': /* suppress labels, search only */
69 			labels = 0;
70 			break;
71 		}
72 		argc--;
73 		argv++;
74 	}
75 	if (inlist)
76 	{
77 		ff = fopen(inlist, "r");
78 		while (fgets(qn, 200, ff))
79 		{
80 			trimnl(qn);
81 			f = fopen (qn, "r");
82 			if (f!=NULL)
83 				dofile(f, qn);
84 			else
85 				fprintf(stderr, "Can't read %s\n",qn);
86 		}
87 	}
88 	else
89 		if (argc<=1)
90 			dofile(stdin, "");
91 		else
92 			for(i=1; i<argc; i++)
93 			{
94 				f = fopen(name=argv[i], "r");
95 				if (f==NULL)
96 					err("No file %s",name);
97 				else
98 					dofile(f, name);
99 			}
100 	exit(0);
101 }
102