|
root / base / usr / src / cmd / refer / mkey1.c
mkey1.c C 115 lines 2.3 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
/*	  All Rights Reserved  	*/

/*
 * Copyright (c) 1980 Regents of the University of California.
 * All rights reserved. The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#include <stdio.h>
#include <locale.h>

extern char *comname;	/* "/usr/lib/refer/eign" */
int wholefile = 0;
int keycount = 100;
int labels = 1;
int minlen = 3;
extern int comcount;
char *iglist = "XYZ#";

extern void dofile();
extern void err();
extern char *trimnl();

int
main(int argc, char *argv[])
{
	/*
	 * this program expects as its arguments a list of
	 * files and generates a set of lines of the form
	 *	filename:byte-add,length (tab) key1 key2 key3
	 * where the byte addresses give the position within
	 * the file and the keys are the strings off the lines
	 * which are alphabetic, first six characters only.
	 */

	int i;
	char *name, qn[200];
	char *inlist = 0;

	FILE *f, *ff;

	(void) setlocale(LC_ALL, "");

#if !defined(TEXT_DOMAIN)
#define	TEXT_DOMAIN "SYS_TEST"
#endif
	(void) textdomain(TEXT_DOMAIN);

	while (argc > 1 && argv[1][0] == '-') {
		switch (argv[1][1]) {
		case 'c':
			comname = argv[2];
			argv++;
			argc--;
			break;
		case 'w':
			wholefile = 1;
			break;
		case 'f':
			inlist = argv[2];
			argv++;
			argc--;
			break;
		case 'i':
			iglist = argv[2];
			argv++;
			argc--;
			break;
		case 'l':
			minlen = atoi(argv[1]+2);
			if (minlen <= 0) minlen = 3;
			break;
		case 'n': /* number of common words to use */
			comcount = atoi(argv[1]+2);
			break;
		case 'k': /* number  of keys per file max */
			keycount = atoi(argv[1]+2);
			break;
		case 's': /* suppress labels, search only */
			labels = 0;
			break;
		}
		argc--;
		argv++;
	}
	if (inlist) {
		ff = fopen(inlist, "r");
		while (fgets(qn, 200, ff)) {
			trimnl(qn);
			f = fopen(qn, "r");
			if (f != NULL)
				dofile(f, qn);
			else
				fprintf(stderr, gettext("Can't read %s\n"), qn);
		}
	} else
		if (argc <= 1)
			dofile(stdin, "");
		else
			for (i = 1; i < argc; i++) {
				f = fopen(name = argv[i], "r");
				if (f == NULL)
					err(gettext("No file %s"), name);
				else
					dofile(f, name);
			}
	return (0);
}