Blame src/plugins/kdb/db2/libdb2/test/hash1.tests/tcreat3.c

Packit fd8b60
/*-
Packit fd8b60
 * Copyright (c) 1991, 1993
Packit fd8b60
 *	The Regents of the University of California.  All rights reserved.
Packit fd8b60
 *
Packit fd8b60
 * This code is derived from software contributed to Berkeley by
Packit fd8b60
 * Margo Seltzer.
Packit fd8b60
 *
Packit fd8b60
 * Redistribution and use in source and binary forms, with or without
Packit fd8b60
 * modification, are permitted provided that the following conditions
Packit fd8b60
 * are met:
Packit fd8b60
 * 1. Redistributions of source code must retain the above copyright
Packit fd8b60
 *    notice, this list of conditions and the following disclaimer.
Packit fd8b60
 * 2. Redistributions in binary form must reproduce the above copyright
Packit fd8b60
 *    notice, this list of conditions and the following disclaimer in the
Packit fd8b60
 *    documentation and/or other materials provided with the distribution.
Packit fd8b60
 * 3. All advertising materials mentioning features or use of this software
Packit fd8b60
 *    must display the following acknowledgement:
Packit fd8b60
 *	This product includes software developed by the University of
Packit fd8b60
 *	California, Berkeley and its contributors.
Packit fd8b60
 * 4. Neither the name of the University nor the names of its contributors
Packit fd8b60
 *    may be used to endorse or promote products derived from this software
Packit fd8b60
 *    without specific prior written permission.
Packit fd8b60
 *
Packit fd8b60
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit fd8b60
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit fd8b60
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit fd8b60
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit fd8b60
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit fd8b60
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit fd8b60
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit fd8b60
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit fd8b60
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit fd8b60
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit fd8b60
 * SUCH DAMAGE.
Packit fd8b60
 */
Packit fd8b60
Packit fd8b60
#ifndef lint
Packit fd8b60
static char copyright[] =
Packit fd8b60
"@(#) Copyright (c) 1991, 1993\n\
Packit fd8b60
	The Regents of the University of California.  All rights reserved.\n";
Packit fd8b60
#endif /* not lint */
Packit fd8b60
Packit fd8b60
#ifndef lint
Packit fd8b60
static char sccsid[] = "@(#)tcreat3.c	8.1 (Berkeley) 6/4/93";
Packit fd8b60
#endif /* not lint */
Packit fd8b60
Packit fd8b60
#include <sys/types.h>
Packit fd8b60
#include <sys/file.h>
Packit fd8b60
#include <stdio.h>
Packit fd8b60
#include "db-int.h"
Packit fd8b60
Packit fd8b60
#define INITIAL	25000
Packit fd8b60
#define MAXWORDS    25000	       /* # of elements in search table */
Packit fd8b60
Packit fd8b60
char	wp1[8192];
Packit fd8b60
char	wp2[8192];
Packit fd8b60
main(argc, argv)
Packit fd8b60
char **argv;
Packit fd8b60
{
Packit fd8b60
	DBT item, key;
Packit fd8b60
	DB	*dbp;
Packit fd8b60
	HASHINFO ctl;
Packit fd8b60
	FILE *fp;
Packit fd8b60
	int	trash;
Packit fd8b60
Packit fd8b60
	int i = 0;
Packit fd8b60
Packit fd8b60
	argv++;
Packit fd8b60
	ctl.hash = NULL;
Packit fd8b60
	ctl.bsize = atoi(*argv++);
Packit fd8b60
	ctl.ffactor = atoi(*argv++);
Packit fd8b60
	ctl.nelem = atoi(*argv++);
Packit fd8b60
	ctl.lorder = 0;
Packit fd8b60
	if (!(dbp = dbopen( "hashtest",
Packit fd8b60
	    O_CREAT|O_TRUNC|O_RDWR|O_BINARY, 0600, DB_HASH, &ctl))){
Packit fd8b60
		/* create table */
Packit fd8b60
		fprintf(stderr, "cannot create: hash table (size %d)\n",
Packit fd8b60
			INITIAL);
Packit fd8b60
		exit(1);
Packit fd8b60
	}
Packit fd8b60
Packit fd8b60
	key.data = wp1;
Packit fd8b60
	item.data = wp2;
Packit fd8b60
	while ( fgets(wp1, 8192, stdin) &&
Packit fd8b60
		fgets(wp2, 8192, stdin) &&
Packit fd8b60
		i++ < MAXWORDS) {
Packit fd8b60
/*
Packit fd8b60
* put info in structure, and structure in the item
Packit fd8b60
*/
Packit fd8b60
		key.size = strlen(wp1);
Packit fd8b60
		item.size = strlen(wp2);
Packit fd8b60
Packit fd8b60
/*
Packit fd8b60
 * enter key/data pair into the table
Packit fd8b60
 */
Packit fd8b60
		if ((dbp->put)(dbp, &key, &item, R_NOOVERWRITE) != NULL) {
Packit fd8b60
			fprintf(stderr, "cannot enter: key %s\n",
Packit fd8b60
				item.data);
Packit fd8b60
			exit(1);
Packit fd8b60
		}
Packit fd8b60
	}
Packit fd8b60
Packit fd8b60
	(dbp->close)(dbp);
Packit fd8b60
	exit(0);
Packit fd8b60
}