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