1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  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 static char copyright[] =
13 "@(#) Copyright (c) 1991, 1993\n\
14 	The Regents of the University of California.  All rights reserved.\n";
15 #endif /* not lint */
16 
17 #ifndef lint
18 static char sccsid[] = "@(#)tcreat3.c	8.1 (Berkeley) 06/04/93";
19 #endif /* not lint */
20 
21 #include <sys/types.h>
22 #include <sys/file.h>
23 #include <stdio.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 = dbopen( "hashtest",
49 	    O_CREAT|O_TRUNC|O_RDWR, 0600, DB_HASH, &ctl))){
50 		/* create table */
51 		fprintf(stderr, "cannot create: hash table (size %d)\n",
52 			INITIAL);
53 		exit(1);
54 	}
55 
56 	key.data = wp1;
57 	item.data = wp2;
58 	while ( fgets(wp1, 8192, stdin) &&
59 		fgets(wp2, 8192, stdin) &&
60 		i++ < MAXWORDS) {
61 /*
62 * put info in structure, and structure in the item
63 */
64 		key.size = strlen(wp1);
65 		item.size = strlen(wp2);
66 
67 /*
68  * enter key/data pair into the table
69  */
70 		if ((dbp->put)(dbp, &key, &item, R_NOOVERWRITE) != NULL) {
71 			fprintf(stderr, "cannot enter: key %s\n",
72 				item.data);
73 			exit(1);
74 		}
75 	}
76 
77 	(dbp->close)(dbp);
78 	exit(0);
79 }
80