Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/refer/mkey1.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


# include "mkey.h"

int	wholefile = 0;
int	keycount = 100;
int	labels = 1;
int	minlen = 3;
char	*iglist = "XYZ#";

#define MAXLENARG 200
#define	ga(x,y) {if (--argc <= 1) err("missing parameter for %s", y); x = (++argv)[1];}

void
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[MAXLENARG];
	char	*inlist = 0;
	FILE *f, *ff;

	progname = mkprogname(argv[0]);
	for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
		switch (argv[1][1]) {
		case 'c':
			ga(comname, "-c");
			break;
		case 'w':
			wholefile = 1;  
			break;
		case 'f':
			ga(inlist, "-f");
			break;
		case 'i':
			ga(iglist, "-i");
			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;
		}
	}
	if (inlist) {
		ff = efopen(inlist, "r");
		while (fgets(qn, MAXLENARG, ff)) {
			trimnl(qn);
			f = efopen (qn, "r");
			dofile(f, qn);
		}
	} else if (argc <= 1) {
		dofile(stdin, "");
	} else
		for (i = 1; i < argc; i++) {
			f = efopen(name = argv[i], "r");
			dofile(f, name);
		}
	exit(0);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.