xref: /illumos-gate/usr/src/cmd/refer/mkey1.c (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
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 #include <stdio.h>
16 #include <locale.h>
17 
18 extern char *comname;	/* "/usr/lib/refer/eign" */
19 int wholefile = 0;
20 int keycount = 100;
21 int labels = 1;
22 int minlen = 3;
23 extern int comcount;
24 char *iglist = "XYZ#";
25 
26 extern void dofile();
27 extern void err();
28 extern char *trimnl();
29 
30 int
31 main(int argc, char *argv[])
32 {
33 	/*
34 	 * this program expects as its arguments a list of
35 	 * files and generates a set of lines of the form
36 	 *	filename:byte-add,length (tab) key1 key2 key3
37 	 * where the byte addresses give the position within
38 	 * the file and the keys are the strings off the lines
39 	 * which are alphabetic, first six characters only.
40 	 */
41 
42 	int i;
43 	char *name, qn[200];
44 	char *inlist = 0;
45 
46 	FILE *f, *ff;
47 
48 	(void) setlocale(LC_ALL, "");
49 
50 #if !defined(TEXT_DOMAIN)
51 #define	TEXT_DOMAIN "SYS_TEST"
52 #endif
53 	(void) textdomain(TEXT_DOMAIN);
54 
55 	while (argc > 1 && argv[1][0] == '-') {
56 		switch (argv[1][1]) {
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 		ff = fopen(inlist, "r");
94 		while (fgets(qn, 200, ff)) {
95 			trimnl(qn);
96 			f = fopen(qn, "r");
97 			if (f != NULL)
98 				dofile(f, qn);
99 			else
100 				fprintf(stderr, gettext("Can't read %s\n"), qn);
101 		}
102 	} else
103 		if (argc <= 1)
104 			dofile(stdin, "");
105 		else
106 			for (i = 1; i < argc; i++) {
107 				f = fopen(name = argv[i], "r");
108 				if (f == NULL)
109 					err(gettext("No file %s"), name);
110 				else
111 					dofile(f, name);
112 			}
113 	return (0);
114 }
115