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 * 846178Sbostic * %sccs.include.redist.c% 946178Sbostic */ 1046178Sbostic 1146178Sbostic #ifndef lint 1246178Sbostic char copyright[] = 1346178Sbostic "@(#) Copyright (c) 1990 The Regents of the University of California.\n\ 1446178Sbostic All rights reserved.\n"; 1546178Sbostic #endif /* not lint */ 1646178Sbostic 1746178Sbostic #ifndef lint 18*47253Sbostic static char sccsid[] = "@(#)tverify.c 5.2 (Berkeley) 03/12/91"; 1946178Sbostic #endif /* not lint */ 2046178Sbostic 2146178Sbostic #include <sys/types.h> 2246178Sbostic #include <stdio.h> 2346178Sbostic #include <sys/file.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]; 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; 50*47253Sbostic ctl.cachesize = 1024 * 1024; /* 1 MEG */ 5146178Sbostic ctl.lorder = 0; 5246178Sbostic if (!(dbp = hash_open( "hashtest", O_RDONLY, 0400, &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 6746178Sbostic stat = (dbp->get)(dbp, &key, &res); 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