146178Sbostic /*-
246178Sbostic  * Copyright (c) 1990 The Regents of the University of California.
346178Sbostic  * All rights reserved.
446178Sbostic  *
546178Sbostic  * This code is derived from software contributed to Berkeley by
646178Sbostic  * Margo Seltzer.
746178Sbostic  *
8*50985Sbostic  * Redistribution and use in source and binary forms, with or without
9*50985Sbostic  * modification, are permitted provided that the following conditions
10*50985Sbostic  * are met:
11*50985Sbostic  * 1. Redistributions of source code must retain the above copyright
12*50985Sbostic  *    notice, this list of conditions and the following disclaimer.
13*50985Sbostic  * 2. Redistributions in binary form must reproduce the above copyright
14*50985Sbostic  *    notice, this list of conditions and the following disclaimer in the
15*50985Sbostic  *    documentation and/or other materials provided with the distribution.
16*50985Sbostic  * 3. All advertising materials mentioning features or use of this software
17*50985Sbostic  *    must display the following acknowledgement:
18*50985Sbostic  *	This product includes software developed by the University of
19*50985Sbostic  *	California, Berkeley and its contributors.
20*50985Sbostic  * 4. Neither the name of the University nor the names of its contributors
21*50985Sbostic  *    may be used to endorse or promote products derived from this software
22*50985Sbostic  *    without specific prior written permission.
23*50985Sbostic  *
24*50985Sbostic  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25*50985Sbostic  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26*50985Sbostic  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27*50985Sbostic  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28*50985Sbostic  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29*50985Sbostic  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30*50985Sbostic  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31*50985Sbostic  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32*50985Sbostic  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33*50985Sbostic  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34*50985Sbostic  * SUCH DAMAGE.
3546178Sbostic  */
3646178Sbostic 
3746178Sbostic #ifndef lint
3846178Sbostic char copyright[] =
3946178Sbostic "@(#) Copyright (c) 1990 The Regents of the University of California.\n\
4046178Sbostic  All rights reserved.\n";
4146178Sbostic #endif /* not lint */
4246178Sbostic 
4346178Sbostic #ifndef lint
44*50985Sbostic static char sccsid[] = "@(#)tverify.c	5.2 (Berkeley) 3/12/91";
4546178Sbostic #endif /* not lint */
4646178Sbostic 
4746178Sbostic #include <sys/types.h>
4846178Sbostic #include <stdio.h>
4946178Sbostic #include <sys/file.h>
5046178Sbostic #include <db.h>
5146178Sbostic 
5246178Sbostic #define INITIAL	25000
5346178Sbostic #define MAXWORDS    25000	       /* # of elements in search table */
5446178Sbostic 
5546178Sbostic typedef struct {		       /* info to be stored */
5646178Sbostic 	int num, siz;
5746178Sbostic } info;
5846178Sbostic 
5946178Sbostic char	wp1[8192];
6046178Sbostic char	wp2[8192];
6146178Sbostic main(argc, argv)
6246178Sbostic char **argv;
6346178Sbostic {
6446178Sbostic 	DBT key, res;
6546178Sbostic 	DB	*dbp;
6646178Sbostic 	HASHINFO ctl;
6746178Sbostic 	int	trash;
6846178Sbostic 	int	stat;
6946178Sbostic 
7046178Sbostic 	int i = 0;
7146178Sbostic 
7246178Sbostic 	ctl.nelem = INITIAL;
7346178Sbostic 	ctl.hash = NULL;
7446178Sbostic 	ctl.bsize = 64;
7546178Sbostic 	ctl.ffactor = 1;
7647253Sbostic 	ctl.cachesize = 1024 * 1024;	/* 1 MEG */
7746178Sbostic 	ctl.lorder = 0;
7846178Sbostic 	if (!(dbp = hash_open( "hashtest", O_RDONLY, 0400, &ctl))) {
7946178Sbostic 		/* create table */
8046178Sbostic 		fprintf(stderr, "cannot open: hash table\n" );
8146178Sbostic 		exit(1);
8246178Sbostic 	}
8346178Sbostic 
8446178Sbostic 	key.data = wp1;
8546178Sbostic 	while ( fgets(wp1, 8192, stdin) &&
8646178Sbostic 		fgets(wp2, 8192, stdin) &&
8746178Sbostic 		i++ < MAXWORDS) {
8846178Sbostic /*
8946178Sbostic * put info in structure, and structure in the item
9046178Sbostic */
9146178Sbostic 		key.size = strlen(wp1);
9246178Sbostic 
93*50985Sbostic 		stat = (dbp->get)(dbp, &key, &res,0);
9446178Sbostic 		if (stat < 0) {
9546178Sbostic 		    fprintf ( stderr, "Error retrieving %s\n", key.data );
9646178Sbostic 		    exit(1);
9746178Sbostic 		} else if ( stat > 0 ) {
9846178Sbostic 		    fprintf ( stderr, "%s not found\n", key.data );
9946178Sbostic 		    exit(1);
10046178Sbostic 		}
10146178Sbostic 		if ( memcmp ( res.data, wp2, res.size ) ) {
10246178Sbostic 		    fprintf ( stderr, "data for %s is incorrect.  Data was %s.  Should have been %s\n", key.data, res.data, wp2 );
10346178Sbostic 		}
10446178Sbostic 	}
10546178Sbostic 	(dbp->close)(dbp);
10646178Sbostic 	exit(0);
10746178Sbostic }
108