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[] = "@(#)tcreat3.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 char wp1[8192]; 30 char wp2[8192]; 31 main(argc, argv) 32 char **argv; 33 { 34 DBT item, key; 35 DB *dbp; 36 HASHINFO ctl; 37 FILE *fp; 38 int trash; 39 40 int i = 0; 41 42 argv++; 43 ctl.hash = NULL; 44 ctl.bsize = atoi(*argv++); 45 ctl.ffactor = atoi(*argv++); 46 ctl.nelem = atoi(*argv++); 47 ctl.lorder = 0; 48 if (!(dbp = hash_open( "hashtest", O_CREAT|O_TRUNC|O_RDWR, 0600, &ctl))){ 49 /* create table */ 50 fprintf(stderr, "cannot create: hash table (size %d)\n", 51 INITIAL); 52 exit(1); 53 } 54 55 key.data = wp1; 56 item.data = wp2; 57 while ( fgets(wp1, 8192, stdin) && 58 fgets(wp2, 8192, stdin) && 59 i++ < MAXWORDS) { 60 /* 61 * put info in structure, and structure in the item 62 */ 63 key.size = strlen(wp1); 64 item.size = strlen(wp2); 65 66 /* 67 * enter key/data pair into the table 68 */ 69 if ((dbp->put)(dbp, &key, &item, R_NOOVERWRITE) != NULL) { 70 fprintf(stderr, "cannot enter: key %s\n", 71 item.data); 72 exit(1); 73 } 74 } 75 76 (dbp->close)(dbp); 77 exit(0); 78 } 79