1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Margo Seltzer. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #ifndef lint 12 char copyright[] = 13 "@(#) Copyright (c) 1990 The Regents of the University of California.\n\ 14 All rights reserved.\n"; 15 #endif /* not lint */ 16 17 #ifndef lint 18 static char sccsid[] = "@(#)tverify.c 5.1 (Berkeley) 01/31/91"; 19 #endif /* not lint */ 20 21 #include <sys/types.h> 22 #include <stdio.h> 23 #include <sys/file.h> 24 #include <db.h> 25 26 #define INITIAL 25000 27 #define MAXWORDS 25000 /* # of elements in search table */ 28 29 typedef struct { /* info to be stored */ 30 int num, siz; 31 } info; 32 33 char wp1[8192]; 34 char wp2[8192]; 35 main(argc, argv) 36 char **argv; 37 { 38 DBT key, res; 39 DB *dbp; 40 HASHINFO ctl; 41 int trash; 42 int stat; 43 44 int i = 0; 45 46 ctl.nelem = INITIAL; 47 ctl.hash = NULL; 48 ctl.bsize = 64; 49 ctl.ffactor = 1; 50 ctl.ncached = 1024 * 1024; /* 1 MEG */ 51 ctl.lorder = 0; 52 if (!(dbp = hash_open( "hashtest", O_RDONLY, 0400, &ctl))) { 53 /* create table */ 54 fprintf(stderr, "cannot open: hash table\n" ); 55 exit(1); 56 } 57 58 key.data = wp1; 59 while ( fgets(wp1, 8192, stdin) && 60 fgets(wp2, 8192, stdin) && 61 i++ < MAXWORDS) { 62 /* 63 * put info in structure, and structure in the item 64 */ 65 key.size = strlen(wp1); 66 67 stat = (dbp->get)(dbp, &key, &res); 68 if (stat < 0) { 69 fprintf ( stderr, "Error retrieving %s\n", key.data ); 70 exit(1); 71 } else if ( stat > 0 ) { 72 fprintf ( stderr, "%s not found\n", key.data ); 73 exit(1); 74 } 75 if ( memcmp ( res.data, wp2, res.size ) ) { 76 fprintf ( stderr, "data for %s is incorrect. Data was %s. Should have been %s\n", key.data, res.data, wp2 ); 77 } 78 } 79 (dbp->close)(dbp); 80 exit(0); 81 } 82