146176Sbostic /*-
2*61217Sbostic  * Copyright (c) 1991, 1993
3*61217Sbostic  *	The Regents of the University of California.  All rights reserved.
446176Sbostic  *
546176Sbostic  * This code is derived from software contributed to Berkeley by
646176Sbostic  * Margo Seltzer.
746176Sbostic  *
850986Sbostic  * %sccs.include.redist.c%
946176Sbostic  */
1046176Sbostic 
1146176Sbostic #ifndef lint
12*61217Sbostic static char copyright[] =
13*61217Sbostic "@(#) Copyright (c) 1991, 1993\n\
14*61217Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1546176Sbostic #endif /* not lint */
1646176Sbostic 
1746176Sbostic #ifndef lint
18*61217Sbostic static char sccsid[] = "@(#)tread2.c	8.1 (Berkeley) 06/04/93";
1946176Sbostic #endif /* not lint */
2046176Sbostic 
2146176Sbostic #include <sys/types.h>
2250986Sbostic #include <sys/file.h>
2346176Sbostic #include <stdio.h>
2446176Sbostic #include <db.h>
2546176Sbostic 
2646176Sbostic #define INITIAL	25000
2746176Sbostic #define MAXWORDS    25000	       /* # of elements in search table */
2846176Sbostic 
2946176Sbostic typedef struct {		       /* info to be stored */
3046176Sbostic 	int num, siz;
3146176Sbostic } info;
3246176Sbostic 
3350985Sbostic char	wp1[8192];
3450985Sbostic char	wp2[8192];
main(argc,argv)3546176Sbostic main(argc, argv)
3646176Sbostic char **argv;
3746176Sbostic {
3846176Sbostic 	DBT item, key, res;
3946176Sbostic 	DB	*dbp;
4046176Sbostic 	HASHINFO ctl;
4146176Sbostic 	int	stat;
4246176Sbostic 
4346176Sbostic 	int i = 0;
4446176Sbostic 
4546176Sbostic 	ctl.nelem = INITIAL;
4646176Sbostic 	ctl.hash = NULL;
4746176Sbostic 	ctl.bsize = 64;
4846176Sbostic 	ctl.ffactor = 1;
4947253Sbostic 	ctl.cachesize = atoi(*argv++);
5046176Sbostic 	ctl.lorder = 0;
5151079Sbostic 	if (!(dbp = dbopen( "hashtest", O_RDONLY, 0400, DB_HASH, &ctl))) {
5246176Sbostic 		/* create table */
5346176Sbostic 		fprintf(stderr, "cannot open: hash table\n" );
5446176Sbostic 		exit(1);
5546176Sbostic 	}
5646176Sbostic 
5746176Sbostic 	key.data = wp1;
5846176Sbostic 	item.data = wp2;
5950985Sbostic 	while ( fgets(wp1, 8192, stdin) &&
6050985Sbostic 		fgets(wp2, 8192, stdin) &&
6146176Sbostic 		i++ < MAXWORDS) {
6246176Sbostic /*
6346176Sbostic * put info in structure, and structure in the item
6446176Sbostic */
6546176Sbostic 		key.size = strlen(wp1);
6646176Sbostic 		item.size = strlen(wp2);
6746176Sbostic 
6850985Sbostic 		stat = (dbp->get)(dbp, &key, &res,0);
6946176Sbostic 		if (stat < 0) {
7046176Sbostic 		    fprintf ( stderr, "Error retrieving %s\n", key.data );
7146176Sbostic 		    exit(1);
7246176Sbostic 		} else if ( stat > 0 ) {
7346176Sbostic 		    fprintf ( stderr, "%s not found\n", key.data );
7446176Sbostic 		    exit(1);
7546176Sbostic 		}
7646176Sbostic 	}
7746176Sbostic 	(dbp->close)(dbp);
7846176Sbostic 	exit(0);
7946176Sbostic }
80