xref: /illumos-gate/usr/src/cmd/refer/mkey1.c (revision 2a8bcb4e)
1*11a8fa6cSceastha /*
2*11a8fa6cSceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*11a8fa6cSceastha  * Use is subject to license terms.
4*11a8fa6cSceastha  */
5*11a8fa6cSceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #include <stdio.h>
167c478bd9Sstevel@tonic-gate #include <locale.h>
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate extern char *comname;	/* "/usr/lib/refer/eign" */
197c478bd9Sstevel@tonic-gate int wholefile = 0;
207c478bd9Sstevel@tonic-gate int keycount = 100;
217c478bd9Sstevel@tonic-gate int labels = 1;
227c478bd9Sstevel@tonic-gate int minlen = 3;
237c478bd9Sstevel@tonic-gate extern int comcount;
247c478bd9Sstevel@tonic-gate char *iglist = "XYZ#";
257c478bd9Sstevel@tonic-gate 
26*11a8fa6cSceastha extern void dofile();
27*11a8fa6cSceastha extern void err();
28*11a8fa6cSceastha extern char *trimnl();
29*11a8fa6cSceastha 
30*11a8fa6cSceastha int
main(int argc,char * argv[])31*11a8fa6cSceastha main(int argc, char *argv[])
327c478bd9Sstevel@tonic-gate {
33*11a8fa6cSceastha 	/*
34*11a8fa6cSceastha 	 * this program expects as its arguments a list of
357c478bd9Sstevel@tonic-gate 	 * files and generates a set of lines of the form
367c478bd9Sstevel@tonic-gate 	 *	filename:byte-add,length (tab) key1 key2 key3
377c478bd9Sstevel@tonic-gate 	 * where the byte addresses give the position within
387c478bd9Sstevel@tonic-gate 	 * the file and the keys are the strings off the lines
397c478bd9Sstevel@tonic-gate 	 * which are alphabetic, first six characters only.
407c478bd9Sstevel@tonic-gate 	 */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate 	int i;
437c478bd9Sstevel@tonic-gate 	char *name, qn[200];
447c478bd9Sstevel@tonic-gate 	char *inlist = 0;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate 	FILE *f, *ff;
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
51*11a8fa6cSceastha #define	TEXT_DOMAIN "SYS_TEST"
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
547c478bd9Sstevel@tonic-gate 
55*11a8fa6cSceastha 	while (argc > 1 && argv[1][0] == '-') {
56*11a8fa6cSceastha 		switch (argv[1][1]) {
577c478bd9Sstevel@tonic-gate 		case 'c':
587c478bd9Sstevel@tonic-gate 			comname = argv[2];
59*11a8fa6cSceastha 			argv++;
607c478bd9Sstevel@tonic-gate 			argc--;
617c478bd9Sstevel@tonic-gate 			break;
627c478bd9Sstevel@tonic-gate 		case 'w':
63*11a8fa6cSceastha 			wholefile = 1;
647c478bd9Sstevel@tonic-gate 			break;
657c478bd9Sstevel@tonic-gate 		case 'f':
667c478bd9Sstevel@tonic-gate 			inlist = argv[2];
67*11a8fa6cSceastha 			argv++;
687c478bd9Sstevel@tonic-gate 			argc--;
697c478bd9Sstevel@tonic-gate 			break;
707c478bd9Sstevel@tonic-gate 		case 'i':
717c478bd9Sstevel@tonic-gate 			iglist = argv[2];
72*11a8fa6cSceastha 			argv++;
737c478bd9Sstevel@tonic-gate 			argc--;
747c478bd9Sstevel@tonic-gate 			break;
757c478bd9Sstevel@tonic-gate 		case 'l':
767c478bd9Sstevel@tonic-gate 			minlen = atoi(argv[1]+2);
77*11a8fa6cSceastha 			if (minlen <= 0) minlen = 3;
787c478bd9Sstevel@tonic-gate 			break;
797c478bd9Sstevel@tonic-gate 		case 'n': /* number of common words to use */
807c478bd9Sstevel@tonic-gate 			comcount = atoi(argv[1]+2);
817c478bd9Sstevel@tonic-gate 			break;
827c478bd9Sstevel@tonic-gate 		case 'k': /* number  of keys per file max */
837c478bd9Sstevel@tonic-gate 			keycount = atoi(argv[1]+2);
847c478bd9Sstevel@tonic-gate 			break;
857c478bd9Sstevel@tonic-gate 		case 's': /* suppress labels, search only */
867c478bd9Sstevel@tonic-gate 			labels = 0;
877c478bd9Sstevel@tonic-gate 			break;
887c478bd9Sstevel@tonic-gate 		}
89*11a8fa6cSceastha 		argc--;
907c478bd9Sstevel@tonic-gate 		argv++;
917c478bd9Sstevel@tonic-gate 	}
92*11a8fa6cSceastha 	if (inlist) {
937c478bd9Sstevel@tonic-gate 		ff = fopen(inlist, "r");
94*11a8fa6cSceastha 		while (fgets(qn, 200, ff)) {
957c478bd9Sstevel@tonic-gate 			trimnl(qn);
96*11a8fa6cSceastha 			f = fopen(qn, "r");
97*11a8fa6cSceastha 			if (f != NULL)
987c478bd9Sstevel@tonic-gate 				dofile(f, qn);
997c478bd9Sstevel@tonic-gate 			else
100*11a8fa6cSceastha 				fprintf(stderr, gettext("Can't read %s\n"), qn);
1017c478bd9Sstevel@tonic-gate 		}
102*11a8fa6cSceastha 	} else
103*11a8fa6cSceastha 		if (argc <= 1)
1047c478bd9Sstevel@tonic-gate 			dofile(stdin, "");
1057c478bd9Sstevel@tonic-gate 		else
106*11a8fa6cSceastha 			for (i = 1; i < argc; i++) {
107*11a8fa6cSceastha 				f = fopen(name = argv[i], "r");
108*11a8fa6cSceastha 				if (f == NULL)
109*11a8fa6cSceastha 					err(gettext("No file %s"), name);
1107c478bd9Sstevel@tonic-gate 				else
1117c478bd9Sstevel@tonic-gate 					dofile(f, name);
1127c478bd9Sstevel@tonic-gate 			}
113*11a8fa6cSceastha 	return (0);
1147c478bd9Sstevel@tonic-gate }
115