146178Sbostic /*-
2*61217Sbostic  * Copyright (c) 1991, 1993
3*61217Sbostic  *	The Regents of the University of California.  All rights reserved.
446178Sbostic  *
546178Sbostic  * This code is derived from software contributed to Berkeley by
646178Sbostic  * Margo Seltzer.
746178Sbostic  *
850986Sbostic  * %sccs.include.redist.c%
946178Sbostic  */
1046178Sbostic 
1146178Sbostic #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";
1546178Sbostic #endif /* not lint */
1646178Sbostic 
1746178Sbostic #ifndef lint
18*61217Sbostic static char sccsid[] = "@(#)tverify.c	8.1 (Berkeley) 06/04/93";
1946178Sbostic #endif /* not lint */
2046178Sbostic 
2146178Sbostic #include <sys/types.h>
2250986Sbostic #include <sys/file.h>
2346178Sbostic #include <stdio.h>
2446178Sbostic #include <db.h>
2546178Sbostic 
2646178Sbostic #define INITIAL	25000
2746178Sbostic #define MAXWORDS    25000	       /* # of elements in search table */
2846178Sbostic 
2946178Sbostic typedef struct {		       /* info to be stored */
3046178Sbostic 	int num, siz;
3146178Sbostic } info;
3246178Sbostic 
3346178Sbostic char	wp1[8192];
3446178Sbostic char	wp2[8192];
main(argc,argv)3546178Sbostic main(argc, argv)
3646178Sbostic char **argv;
3746178Sbostic {
3846178Sbostic 	DBT key, res;
3946178Sbostic 	DB	*dbp;
4046178Sbostic 	HASHINFO ctl;
4146178Sbostic 	int	trash;
4246178Sbostic 	int	stat;
4346178Sbostic 
4446178Sbostic 	int i = 0;
4546178Sbostic 
4646178Sbostic 	ctl.nelem = INITIAL;
4746178Sbostic 	ctl.hash = NULL;
4846178Sbostic 	ctl.bsize = 64;
4946178Sbostic 	ctl.ffactor = 1;
5047253Sbostic 	ctl.cachesize = 1024 * 1024;	/* 1 MEG */
5146178Sbostic 	ctl.lorder = 0;
5251081Sbostic 	if (!(dbp = dbopen( "hashtest", O_RDONLY, 0400, DB_HASH, &ctl))) {
5346178Sbostic 		/* create table */
5446178Sbostic 		fprintf(stderr, "cannot open: hash table\n" );
5546178Sbostic 		exit(1);
5646178Sbostic 	}
5746178Sbostic 
5846178Sbostic 	key.data = wp1;
5946178Sbostic 	while ( fgets(wp1, 8192, stdin) &&
6046178Sbostic 		fgets(wp2, 8192, stdin) &&
6146178Sbostic 		i++ < MAXWORDS) {
6246178Sbostic /*
6346178Sbostic * put info in structure, and structure in the item
6446178Sbostic */
6546178Sbostic 		key.size = strlen(wp1);
6646178Sbostic 
6750985Sbostic 		stat = (dbp->get)(dbp, &key, &res,0);
6846178Sbostic 		if (stat < 0) {
6946178Sbostic 		    fprintf ( stderr, "Error retrieving %s\n", key.data );
7046178Sbostic 		    exit(1);
7146178Sbostic 		} else if ( stat > 0 ) {
7246178Sbostic 		    fprintf ( stderr, "%s not found\n", key.data );
7346178Sbostic 		    exit(1);
7446178Sbostic 		}
7546178Sbostic 		if ( memcmp ( res.data, wp2, res.size ) ) {
7646178Sbostic 		    fprintf ( stderr, "data for %s is incorrect.  Data was %s.  Should have been %s\n", key.data, res.data, wp2 );
7746178Sbostic 		}
7846178Sbostic 	}
7946178Sbostic 	(dbp->close)(dbp);
8046178Sbostic 	exit(0);
8146178Sbostic }
82