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

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