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