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