146173Sbostic /*- 250986Sbostic * Copyright (c) 1991 The Regents of the University of California. 346173Sbostic * All rights reserved. 446173Sbostic * 546173Sbostic * This code is derived from software contributed to Berkeley by 646173Sbostic * Margo Seltzer. 746173Sbostic * 850986Sbostic * %sccs.include.redist.c% 946173Sbostic */ 1046173Sbostic 1146173Sbostic #ifndef lint 1246173Sbostic char copyright[] = 1350986Sbostic "@(#) Copyright (c) 1991 The Regents of the University of California.\n\ 1446173Sbostic All rights reserved.\n"; 1546173Sbostic #endif /* not lint */ 1646173Sbostic 1746173Sbostic #ifndef lint 18*51076Sbostic static char sccsid[] = "@(#)tcreat3.c 5.4 (Berkeley) 09/11/91"; 1946173Sbostic #endif /* not lint */ 2046173Sbostic 2146173Sbostic #include <sys/types.h> 2250986Sbostic #include <sys/file.h> 2346173Sbostic #include <stdio.h> 2446173Sbostic #include <db.h> 2546173Sbostic 2646173Sbostic #define INITIAL 25000 2746173Sbostic #define MAXWORDS 25000 /* # of elements in search table */ 2846173Sbostic 2946173Sbostic char wp1[8192]; 3046173Sbostic char wp2[8192]; 3146173Sbostic main(argc, argv) 3246173Sbostic char **argv; 3346173Sbostic { 3446173Sbostic DBT item, key; 3546173Sbostic DB *dbp; 3646173Sbostic HASHINFO ctl; 3746173Sbostic FILE *fp; 3846173Sbostic int trash; 3946173Sbostic 4046173Sbostic int i = 0; 4146173Sbostic 4246173Sbostic argv++; 4346173Sbostic ctl.hash = NULL; 4446173Sbostic ctl.bsize = atoi(*argv++); 4546173Sbostic ctl.ffactor = atoi(*argv++); 4646173Sbostic ctl.nelem = atoi(*argv++); 4746173Sbostic ctl.lorder = 0; 48*51076Sbostic if (!(dbp = dbopen( "hashtest", 49*51076Sbostic O_CREAT|O_TRUNC|O_RDWR, 0600, DB_HASH, &ctl))){ 5046173Sbostic /* create table */ 5146173Sbostic fprintf(stderr, "cannot create: hash table (size %d)\n", 5246173Sbostic INITIAL); 5346173Sbostic exit(1); 5446173Sbostic } 5546173Sbostic 5646173Sbostic key.data = wp1; 5746173Sbostic item.data = wp2; 5846173Sbostic while ( fgets(wp1, 8192, stdin) && 5946173Sbostic fgets(wp2, 8192, stdin) && 6046173Sbostic i++ < MAXWORDS) { 6146173Sbostic /* 6246173Sbostic * put info in structure, and structure in the item 6346173Sbostic */ 6446173Sbostic key.size = strlen(wp1); 6546173Sbostic item.size = strlen(wp2); 6646173Sbostic 6746173Sbostic /* 6846173Sbostic * enter key/data pair into the table 6946173Sbostic */ 7046173Sbostic if ((dbp->put)(dbp, &key, &item, R_NOOVERWRITE) != NULL) { 7146173Sbostic fprintf(stderr, "cannot enter: key %s\n", 7246173Sbostic item.data); 7346173Sbostic exit(1); 7446173Sbostic } 7546173Sbostic } 7646173Sbostic 7746173Sbostic (dbp->close)(dbp); 7846173Sbostic exit(0); 7946173Sbostic } 80