head     1.5;
branch   ;
access   ;
symbols  Version_2_1:1.5 Version_2:1.5 C_Demo_1:1.4;
locks    ; strict;
comment  @ * @;


1.5
date     90.06.07.18.20.52;  author cimarron;  state Version_2;
branches ;
next     1.4;

1.4
date     89.09.05.16.54.08;  author mao;  state C_Demo_1;
branches ;
next     1.3;

1.3
date     89.06.17.01.54.01;  author hirohama;  state Exp;
branches ;
next     1.2;

1.2
date     89.02.02.16.59.20;  author dillon;  state Stab;
branches ;
next     1.1;

1.1
date     89.01.17.05.58.16;  author cimarron;  state Exp;
branches ;
next     ;


desc
@@


1.5
log
@made changes to simplify header include files
@
text
@static	char	testinit_c[] = "$Header: RCS/testadt.c,v 1.4 89/09/05 16:54:08 mao C_Demo_1 $";

#include <sys/file.h>
#include <stdio.h>
#include <setjmp.h>
#ifndef	NODFLT
#include <pwd.h>
#endif
#include <strings.h>
#include "datadir.h"
#include "skey.h"
#include "log.h"

/*
 *	testinit.c	- standard test program shell
 */

struct	context	TopCxt = {
	-1,						/* ct_user */
	-1,						/* ct_xid */
	(char *)NULL,					/* ct_dbappnd */
	(char *)NULL,					/* ct_dbdbappnd */
	DATADIR,					/* ct_datadir */
	DATADIR,					/* ct_dbdbdir */
	0						/* ct_mmgr */
};
struct	context	*Cxt = &TopCxt;

main(argc, argv)
int	argc;
char	*argv[];
{
	int		uid;				/* uid_t */
	int		namelen;
#ifndef	NODFLT
	char		*datname;
	struct	passwd	*pw;
	extern		endpwent();
#endif
	char		s[80], *t, *u;
	char		*path_in();
	char		*path_out();
	extern		pfree();
	extern	int	Err_file;
	extern	int	Debug_file;
	extern	jmp_buf	Warn_restart;
	int		setjmp();
	int		getuid();			/* uid_t */
	int		geteuid();			/* uid_t */
	int		setuid();
	long		time();
	extern		initbuf();
	extern		initmmgr();
	extern		initfmgr();
	extern		resetmmgr();
	extern		bflush();
	extern		elog();

	Debug_file = fileno(stderr);
	Err_file = open("/dev/null", O_WRONLY, 0666);
#ifndef	NODFLT
	if (argc == 1) {
		if ((pw = getpwuid(uid = getuid())) == (struct passwd *)NULL)
			elog(FATAL,
			     "%s: failed getpwuid()",
			     rindex(argv[0], '/') ?
			     rindex(argv[0], '/') + 1 :
			     argv[0]);
		datname = pw->pw_name;
		endpwent();
	} else if (argc == 2)
		datname = argv[1];
	else
		elog(FATAL,
		     "Usage: %s [datname]",
		     rindex(argv[0], '/') ? rindex(argv[0], '/') + 1 : argv[0]);
	namelen = strlen(datname);
#else
	if (argc != 2)
		elog(FATAL,
		     "Usage: %s datname",
		     rindex(argv[0], '/') ? rindex(argv[0], '/') + 1 : argv[0]);
	namelen = strlen(argv[1]);
#endif
	if (!namelen || namelen > 16)
		elog(FATAL, "Database names are limited to 1 to 16 characters");
	/* XXX other checks too */
	TopCxt.ct_user = uid;
	TopCxt.ct_xid = time(0);
	TopCxt.ct_dbappnd = TopCxt.ct_datadir + sizeof (DATADIR) - 1;
	*TopCxt.ct_dbappnd++ = '/';
#ifndef	NODFLT
	bcopy(datname, TopCxt.ct_dbappnd, namelen);
#else
	bcopy(argv[1], TopCxt.ct_dbappnd, namelen);
#endif
	TopCxt.ct_dbappnd += namelen;
	*TopCxt.ct_dbappnd++ = '/';
	TopCxt.ct_dbdbappnd = TopCxt.ct_dbdbdir + sizeof (DATADIR) - 1;
	bcopy("/dbdb/", TopCxt.ct_dbdbappnd, sizeof ("/dbdb/") - 1);
	TopCxt.ct_dbdbappnd += sizeof ("/dbdb/") - 1;
	setuid(geteuid());
	initbuf();
	initmmgr();
	initfmgr();
	if (setjmp(Warn_restart) != NULL) {
		bflush();
		resetmmgr();
	}
	for(;;) {
		puts("Please enter a path (external string representation)");
		scanf("%s", s);
		t = path_in(s);
		printf("Read %s with internal length %d\n", s, PSIZE(t));
		
		printf("The object returned to output form is %s\n", u = path_out(t));
		pfree(t);
		pfree(u);
	}
}
@


1.4
log
@Working version of C-only demo
@
text
@d1 1
a1 1
static	char	testinit_c[] = "$Header: /usr6/postgres/mao/postgres/src/test/RCS/testadt.c,v 1.3 89/06/17 01:54:01 hirohama Exp $";
d11 1
a11 1
#include "access.h"
@


1.3
log
@*** empty log message ***
@
text
@d1 1
a1 1
static	char	testinit_c[] = "$Header: /usr6/postgres/hirohama/postgres/src/test/RCS/testadt.c,v 1.2 89/02/02 16:59:20 dillon Stab $";
@


1.2
log
@Txfer from old tree
@
text
@d1 1
a1 1
static	char	testinit_c[] = "$Header: testadt.c,v 1.1 87/01/18 20:40:16 dillon Locked $";
a10 1
#include "context.h"
@


1.1
log
@Initial revision
@
text
@d1 1
a1 28

/*
 * 
 * POSTGRES Data Base Management System
 * 
 * Copyright (c) 1988 Regents of the University of California
 * 
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for educational, research, and non-profit purposes and
 * without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation, and that
 * the name of the University of California not be used in advertising
 * or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Permission to incorporate this
 * software into commercial products can be obtained from the Campus
 * Software Office, 295 Evans Hall, University of California, Berkeley,
 * Ca., 94720 provided only that the the requestor give the University
 * of California a free licence to any derived software for educational
 * and research purposes.  The University of California makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 * 
 */



static	char	testinit_c[] = "$Header: testadt.c,v 1.1 88/11/11 16:41:45 postgres Exp $";
@
