1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2 /* All Rights Reserved */
3
4
5 /*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
11 /*
12 * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13 * All Rights Reserved.
14 */
15
16 /* from OpenSolaris "mkey1.c 1.5 05/06/02 SMI" */
17
18 /*
19 * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany
20 *
21 * Sccsid @(#)mkey1.c 1.3 (gritter) 10/22/05
22 */
23
24 #include <stdio.h>
25 #include <locale.h>
26 #include <stdlib.h>
27 #include "refer..c"
28
29 extern char *comname; /* "/usr/lib/refer/eign" */
30 int wholefile = 0;
31 int keycount = 100;
32 int labels = 1;
33 int minlen = 3;
34 extern int comcount;
35 char *iglist = "XYZ#";
36
37 int
main(int argc,char ** argv)38 main (int argc,char **argv)
39 {
40 /* this program expects as its arguments a list of
41 * files and generates a set of lines of the form
42 * filename:byte-add,length (tab) key1 key2 key3
43 * where the byte addresses give the position within
44 * the file and the keys are the strings off the lines
45 * which are alphabetic, first six characters only.
46 */
47
48 int i;
49 char *name, qn[200];
50 char *inlist = 0;
51
52 FILE *f, *ff;
53
54 while (argc>1 && argv[1][0] == '-')
55 {
56 switch(argv[1][1])
57 {
58 case 'c':
59 comname = argv[2];
60 argv++;
61 argc--;
62 break;
63 case 'w':
64 wholefile = 1;
65 break;
66 case 'f':
67 inlist = argv[2];
68 argv++;
69 argc--;
70 break;
71 case 'i':
72 iglist = argv[2];
73 argv++;
74 argc--;
75 break;
76 case 'l':
77 minlen = atoi(argv[1]+2);
78 if (minlen<=0) minlen=3;
79 break;
80 case 'n': /* number of common words to use */
81 comcount = atoi(argv[1]+2);
82 break;
83 case 'k': /* number of keys per file max */
84 keycount = atoi(argv[1]+2);
85 break;
86 case 's': /* suppress labels, search only */
87 labels = 0;
88 break;
89 }
90 argc--;
91 argv++;
92 }
93 if (inlist)
94 {
95 ff = fopen(inlist, "r");
96 while (fgets(qn, 200, ff))
97 {
98 trimnl(qn);
99 f = fopen (qn, "r");
100 if (f!=NULL)
101 dofile(f, qn);
102 else
103 fprintf(stderr, "Can't read %s\n",qn);
104 }
105 }
106 else
107 if (argc<=1)
108 dofile(stdin, "");
109 else
110 for(i=1; i<argc; i++)
111 {
112 f = fopen(name=argv[i], "r");
113 if (f==NULL)
114 err("No file %s",name);
115 else
116 dofile(f, name);
117 }
118 return 0;
119 }
120