/*
 * Copyright 1990 by Baylor College of Medicine ALL RIGHTS RESERVED. 
 *
 * This program is subject to a license agreement between 
 * Baylor College of Medicine and MIT. Any use inconsistent with
 * said license and any use by persons other than the faculty, 
 * students and staff at MIT or any use on a computer not operated 
 * as part of the Athena Computing Environment (ACE) is expressly 
 * prohibited.
 */
#include <stdio.h>
#include <pwd.h>
#include <ndbm.h>
#include <fcntl.h>

main(argc,argv)
	char *argv[] ;
{
	char path[512];
	struct passwd *pwd;
	int uid;
	DBM *db;
	datum key, data;
	char key_buf[256];
	char data_buf[256];

	if (argc < 4)
	{
		fprintf(stderr,"Usage: %s <database directory> <database name> <intial user name>\n",argv[0]) ;
		exit(-1) ;
	}

	/* extract uid for initial author */
	pwd = getpwnam(argv[3]);
	uid = pwd->pw_uid;

	/* construct path to database file */
	sprintf(path,"%s/%s/vns",argv[1],argv[2]);

	/* open database */
	db = dbm_open(path,O_CREAT | O_RDWR,0700);

	sprintf(key_buf,"Author %d",uid);
	key.dptr = key_buf;
	key.dsize = strlen(key_buf) + 1;

	sprintf(data_buf,"%d",uid);
	data.dptr = data_buf;
	data.dsize = strlen(data_buf) + 1;

	/* store the author entry */
	dbm_store(db,key,data,DBM_INSERT);

	/* close the database */
	dbm_close(db);

	printf("Initial author has been added. The database is ready to use\n");
}
