146174Sbostic /*- 246174Sbostic * Copyright (c) 1990 The Regents of the University of California. 346174Sbostic * All rights reserved. 446174Sbostic * 546174Sbostic * This code is derived from software contributed to Berkeley by 646174Sbostic * Margo Seltzer. 746174Sbostic * 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. 3546174Sbostic */ 3646174Sbostic 3746174Sbostic #ifndef lint 3846174Sbostic char copyright[] = 3946174Sbostic "@(#) Copyright (c) 1990 The Regents of the University of California.\n\ 4046174Sbostic All rights reserved.\n"; 4146174Sbostic #endif /* not lint */ 4246174Sbostic 4346174Sbostic #ifndef lint 44*50985Sbostic static char sccsid[] = "@(#)tdel.c 5.2 (Berkeley) 3/12/91"; 4546174Sbostic #endif /* not lint */ 4646174Sbostic 4746174Sbostic #include <sys/types.h> 4846174Sbostic #include <sys/file.h> 4946174Sbostic #include <db.h> 5046174Sbostic #include <stdio.h> 5146174Sbostic 5246174Sbostic #define INITIAL 25000 5346174Sbostic #define MAXWORDS 25000 /* # of elements in search table */ 5446174Sbostic 5546174Sbostic /* Usage: thash pagesize fillfactor file */ 5646174Sbostic char wp1[8192]; 5746174Sbostic char wp2[8192]; 5846174Sbostic main(argc, argv) 5946174Sbostic char **argv; 6046174Sbostic { 6146174Sbostic DBT item, key; 6246174Sbostic DB *dbp; 6346174Sbostic HASHINFO ctl; 6446174Sbostic FILE *fp; 6546174Sbostic int stat; 6646174Sbostic 6746174Sbostic int i = 0; 6846174Sbostic 6946174Sbostic argv++; 7046174Sbostic ctl.nelem = INITIAL; 7146174Sbostic ctl.hash = NULL; 7246174Sbostic ctl.bsize = atoi(*argv++); 7346174Sbostic ctl.ffactor = atoi(*argv++); 7447252Sbostic ctl.cachesize = 1024 * 1024; /* 1 MEG */ 7546174Sbostic ctl.lorder = 0; 7646174Sbostic argc -= 2; 7746174Sbostic if (!(dbp = hash_open( NULL, O_CREAT|O_RDWR, 0400, &ctl))) { 7846174Sbostic /* create table */ 7946174Sbostic fprintf(stderr, "cannot create: hash table size %d)\n", 8046174Sbostic INITIAL); 8146174Sbostic exit(1); 8246174Sbostic } 8346174Sbostic 8446174Sbostic key.data = wp1; 8546174Sbostic item.data = wp2; 8646174Sbostic while ( fgets(wp1, 8192, stdin) && 8746174Sbostic fgets(wp2, 8192, stdin) && 8846174Sbostic i++ < MAXWORDS) { 8946174Sbostic /* 9046174Sbostic * put info in structure, and structure in the item 9146174Sbostic */ 9246174Sbostic key.size = strlen(wp1); 9346174Sbostic item.size = strlen(wp2); 9446174Sbostic 9546174Sbostic /* 9646174Sbostic * enter key/data pair into the table 9746174Sbostic */ 9846174Sbostic if ((dbp->put)(dbp, &key, &item, R_NOOVERWRITE) != NULL) { 9946174Sbostic fprintf(stderr, "cannot enter: key %s\n", 10046174Sbostic item.data); 10146174Sbostic exit(1); 10246174Sbostic } 10346174Sbostic } 10446174Sbostic 10546174Sbostic if ( --argc ) { 10646174Sbostic fp = fopen ( argv[0], "r"); 10746174Sbostic i = 0; 10846174Sbostic while ( fgets(wp1, 8192, fp) && 10946174Sbostic fgets(wp2, 8192, fp) && 11046174Sbostic i++ < MAXWORDS) { 11146174Sbostic key.size = strlen(wp1); 112*50985Sbostic stat = (dbp->del)(dbp, &key, 0); 11346174Sbostic if (stat) { 11446174Sbostic fprintf ( stderr, "Error retrieving %s\n", key.data ); 11546174Sbostic exit(1); 11646174Sbostic } 11746174Sbostic } 11846174Sbostic fclose(fp); 11946174Sbostic } 12046174Sbostic (dbp->close)(dbp); 12146174Sbostic exit(0); 12246174Sbostic } 123