146173Sbostic /*- 2*50986Sbostic * 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 * 8*50986Sbostic * %sccs.include.redist.c% 946173Sbostic */ 1046173Sbostic 1146173Sbostic #ifndef lint 1246173Sbostic char copyright[] = 13*50986Sbostic "@(#) 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*50986Sbostic static char sccsid[] = "@(#)tcreat3.c 5.3 (Berkeley) 09/04/91"; 1946173Sbostic #endif /* not lint */ 2046173Sbostic 2146173Sbostic #include <sys/types.h> 22*50986Sbostic #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; 4846173Sbostic if (!(dbp = hash_open( "hashtest", O_CREAT|O_TRUNC|O_RDWR, 0600, &ctl))){ 4946173Sbostic /* create table */ 5046173Sbostic fprintf(stderr, "cannot create: hash table (size %d)\n", 5146173Sbostic INITIAL); 5246173Sbostic exit(1); 5346173Sbostic } 5446173Sbostic 5546173Sbostic key.data = wp1; 5646173Sbostic item.data = wp2; 5746173Sbostic while ( fgets(wp1, 8192, stdin) && 5846173Sbostic fgets(wp2, 8192, stdin) && 5946173Sbostic i++ < MAXWORDS) { 6046173Sbostic /* 6146173Sbostic * put info in structure, and structure in the item 6246173Sbostic */ 6346173Sbostic key.size = strlen(wp1); 6446173Sbostic item.size = strlen(wp2); 6546173Sbostic 6646173Sbostic /* 6746173Sbostic * enter key/data pair into the table 6846173Sbostic */ 6946173Sbostic if ((dbp->put)(dbp, &key, &item, R_NOOVERWRITE) != NULL) { 7046173Sbostic fprintf(stderr, "cannot enter: key %s\n", 7146173Sbostic item.data); 7246173Sbostic exit(1); 7346173Sbostic } 7446173Sbostic } 7546173Sbostic 7646173Sbostic (dbp->close)(dbp); 7746173Sbostic exit(0); 7846173Sbostic } 79