123353Sdfr/*-
223353Sdfr * Copyright (c) 1991, 1993
323353Sdfr *	The Regents of the University of California.  All rights reserved.
423353Sdfr *
523353Sdfr * This code is derived from software contributed to Berkeley by
623353Sdfr * Margo Seltzer.
723353Sdfr *
823353Sdfr * Redistribution and use in source and binary forms, with or without
923353Sdfr * modification, are permitted provided that the following conditions
1023353Sdfr * are met:
1123353Sdfr * 1. Redistributions of source code must retain the above copyright
1223353Sdfr *    notice, this list of conditions and the following disclaimer.
1323353Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1423353Sdfr *    notice, this list of conditions and the following disclaimer in the
1523353Sdfr *    documentation and/or other materials provided with the distribution.
1623353Sdfr * 4. Neither the name of the University nor the names of its contributors
1723353Sdfr *    may be used to endorse or promote products derived from this software
1823353Sdfr *    without specific prior written permission.
1923353Sdfr *
2023353Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2123353Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2223353Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2323353Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2423353Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2523353Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2623353Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2723353Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2823353Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2950476Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3023353Sdfr * SUCH DAMAGE.
31294299Smarkj */
32206622Suqs
3323353Sdfr#ifndef lint
3423353Sdfrstatic char copyright[] =
35294299Smarkj"@(#) Copyright (c) 1991, 1993\n\
3623353Sdfr	The Regents of the University of California.  All rights reserved.\n";
3723353Sdfr#endif /* not lint */
3884306Sru
3984306Sru#if defined(LIBC_SCCS) && !defined(lint)
4024890Sbdestatic char sccsid[] = "@(#)tverify.c	8.1 (Berkeley) 6/4/93";
4123353Sdfr#endif /* LIBC_SCCS and not lint */
42294299Smarkj#include <sys/cdefs.h>
43294299Smarkj__FBSDID("$FreeBSD$");
4423353Sdfr
4523353Sdfr#include <sys/types.h>
46115440Shmp#include <sys/file.h>
4723353Sdfr#include <stdio.h>
4868857Sru#include <db.h>
49115440Shmp
5023353Sdfr#define INITIAL	25000
5123353Sdfr#define MAXWORDS    25000	       /* # of elements in search table */
5223353Sdfr
5323353Sdfrtypedef struct {		       /* info to be stored */
54121384Shmp	int num, siz;
55121384Shmp} info;
5623353Sdfr
5723353Sdfrchar	wp1[8192];
58131530Sruchar	wp2[8192];
5923353Sdfrmain(argc, argv)
6023353Sdfrchar **argv;
61294299Smarkj{
62294299Smarkj	DBT key, res;
63294299Smarkj	DB	*dbp;
64294299Smarkj	HASHINFO ctl;
65294299Smarkj	int	trash;
66294299Smarkj	int	stat;
67294299Smarkj
68294299Smarkj	int i = 0;
6923353Sdfr
7029966Swosch	ctl.nelem = INITIAL;
7123353Sdfr	ctl.hash = NULL;
7223353Sdfr	ctl.bsize = 64;
73176605Sdavidc	ctl.ffactor = 1;
7423353Sdfr	ctl.cachesize = 1024 * 1024;	/* 1 MEG */
7523353Sdfr	ctl.lorder = 0;
76147647Shmp	if (!(dbp = dbopen( "hashtest", O_RDONLY, 0400, DB_HASH, &ctl))) {
7734504Scharnier		/* create table */
78		fprintf(stderr, "cannot open: hash table\n" );
79		exit(1);
80	}
81
82	key.data = wp1;
83	while ( fgets(wp1, 8192, stdin) &&
84		fgets(wp2, 8192, stdin) &&
85		i++ < MAXWORDS) {
86/*
87* put info in structure, and structure in the item
88*/
89		key.size = strlen(wp1);
90
91		stat = (dbp->get)(dbp, &key, &res,0);
92		if (stat < 0) {
93		    fprintf ( stderr, "Error retrieving %s\n", key.data );
94		    exit(1);
95		} else if ( stat > 0 ) {
96		    fprintf ( stderr, "%s not found\n", key.data );
97		    exit(1);
98		}
99		if ( memcmp ( res.data, wp2, res.size ) ) {
100		    fprintf ( stderr, "data for %s is incorrect.  Data was %s.  Should have been %s\n", key.data, res.data, wp2 );
101		}
102	}
103	(dbp->close)(dbp);
104	exit(0);
105}
106