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