[comp.sources.misc] uupc.macl.8.8

Stuart.Lynne@van-bc.UUCP (Stuart Lynne) (08/17/87)

>From uucp Wed Aug 12 02:44 PDT 1987
>From slynne  Wed Aug 12 02:43:38 1987 remote from slmac
Received: by van-bc.uucp (smail2.3)
	id AA17617; 12 Aug 87 02:43:38 PDT (Wed)
Received: by slmac.vnet.van-bc.uucp (pcmail) Wed Aug 12 02:38:20 1987
Date: Wed Aug 12 02:38:20 1987
From: Stuart Lynne - test a mac <slynne@slmac.vnet.van-bc.uucp>
Message-ID: <150@slmac.vnet.van-bc.uucp>
To: sl@van-bc
Subject: shar/uupc.macl.8.8

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	README.MAC
#	Makefile
#	genv.h
#	ndir.h
#	sio.h
#	rename.c
#	splitname.c
#	scandir.c
#	ndir.c
#	chdir.c
#	getcwd.c
#	genv.c
#	sio.c
#	getargs.c
#	mkdir.c
#	hfixnam.c
#	macinit.c
# This archive created: Sun Jun 21 21:59:59 1987
# By:	Stuart Lynne - test a mac ()
export PATH; PATH=/bin:$PATH
if test -f 'README.MAC'
then
       echo shar: will not over-write existing file "'README.MAC'"
else
cat << \SHAR_EOF > 'README.MAC'


mac library		May 21, 1987		Stuart Lynne

These files define various library routines that I have found useful
in porting unix software to the Aztec mac environment.

Have fun!

For more information, bug fixes, more routines:

		Stuart.Lynne@van-bc.uucp
		604-937-7532

SHAR_EOF
chmod +x 'README.MAC'
fi # end of overwriting check
if test -f 'Makefile'
then
       echo shar: will not over-write existing file "'Makefile'"
else
cat << \SHAR_EOF > 'Makefile'
#
#		makefile for rz/sz/ezmail/uuslave/pcmail/mail
#
#
#			Copyright (c) 1986 Stuart Lynne
#

#
#	Rules
#

.c.o:
	cc $(CFLAGS) $*.c

.asm.o:
	as	$(AFLAGS) $*.asm

.a.o:
	as	$(AFLAGS) $*.a


#
#	Macros
#

CFLAGS=  
AFLAGS=
LFLAGS= -lc
LLIB= 

SFiles = rename.c splitname.c scandir.c ndir.c chdir.c getcwd.c \
		genv.c sio.c getargs.c mkdir.c hfixnam.c macinit.c 
		
Files = rename.o splitname.o scandir.o ndir.o chdir.o getcwd.o \
		genv.o sio.o getargs.o mkdir.o hfixnam.o macinit.o 

all:	$(Files) 
	libutil -o "$$CLIB""x.lib" $(Files)

/usr/include/local/genv.h: genv.h
	cp genv.h /usr/include/local/genv.h

genv.o: genv.c genv.h
	cc -dSLAZTECMAC genv.c -o genv.o

splitname: splitname.c
	cc -dTEST -o splitname.o splitname.c
	ln -o splitname splitname.o $(LFLAGS)
	rm splitname.o

rename: rename.c splitname.o hfixnam.o
	cc -dTEST -o rename.o rename.c
	ln -o rename rename.o splitname.o hfixnam.o $(LFLAGS)
	rm rename.o

ndir: ndir.c hfixnam.o
	cc -dTEST -o ndir.o ndir.c
	ln -o ndir ndir.o hfixnam.o $(LFLAGS)
	rm dir.o

hfixnam: hfixnam.c
	cc -dTEST -o hfixnam.o hfixnam.c
	ln -o hfixnam hfixnam.o $(LFLAGS)
	rm hfixnam.o

chdir: chdir.c
	cc -dTEST -o chdir.o chdir.c
	ln -o chdir chdir.o hfixnam.o $(LFLAGS)
	rm chdir.o

mkdir: mkdir.c
	cc -dTEST -o mkdir.o mkdir.c
	ln -o mkdir mkdir.o hfixnam.o $(LFLAGS)
	rm mkdir.o

getcwd: getcwd.c
	cc -dTEST -o getcwd.o getcwd.c
	ln -o getcwd getcwd.o hfixnam.o $(LFLAGS)
	rm getcwd.o

genv: genv.c
	cc -dSLAZTECMAC -dTEST -o genv.o genv.c
	ln -o genv genv.o $(LFLAGS)
	rm genv.o

shar:
	shar  README.MAC Makefile *.h $(SFiles) > shar.maclib
SHAR_EOF
chmod +x 'Makefile'
fi # end of overwriting check
if test -f 'genv.h'
then
       echo shar: will not over-write existing file "'genv.h'"
else
cat << \SHAR_EOF > 'genv.h'
/* 		genv.c
 
 
 
		copyright (C) 1987 Stuart Lynne
 
		Copying and use of this program are controlled by the terms of the
		Free Software Foundations GNU Emacs General Public License.
 
 
		version		0.1		March 31/1987
 
	
 
environment variables
 
	The following evironment variables are defined:
 
		MAILBOX		current user's mailbox, 	"sl"
		NAME		current user's name, 		"Stuart Lynne"
		HOME		current user's home dir		"/usr/sl"
		DOMAIN		domain of this machine, 	"mac.van-bc.can"
		MAILDIR		where mail is kept,			"/usr/mail"
		CONFDIR		where config data is  kept,	"/usr/lib/uucp"
		SPOOLDIR	where spooled files are 	"/usr/spool/uucp"
		PUBDIR		public spool directory		"/usr/spool/uucppublic"
 		MAILSERVICE	who do we send remote mail	"van-bc"
 		NODENAME	what is our local nodename	"slmac"
 		DEVICE		what is the default device	".a"
 		SPEED		what is the default speed	"1200"
 		TEMPDIR		what is temp directory		"/tmp"
 
*/
 

#define	MAILBOX		"MAILBOX"
#define	NAME		"NAME"
#define	HOME		"HOME"
#define	DOMAIN		"DOMAIN"

#define	MAILDIR		"MAILDIR"
#define	CONFDIR		"CONFDIR"
#define SPOOLDIR	"SPOOLDIR"
#define	PUBDIR		"PUBDIR"
#define	MAILSERVICE	"MAILSERVICE"

#define NODENAME	"NODENAME"
#define	DEVICE		"DEVICE"
#define	SPEED		"SPEED"

#define	TEMPDIR		"TEMPDIR"
 

 
extern char	*mailbox;
extern char	*name;
extern char *home;
extern char	*domain;
extern char	*maildir;
extern char	*confdir;
extern char *spooldir;
extern char *pubdir;
extern char	*mailserv;
extern char *nodename;
extern char *device;
extern char *speed;
extern char *tempdir;

 
void loadenv();
void genv();
void mkfilename();

SHAR_EOF
chmod +x 'genv.h'
fi # end of overwriting check
if test -f 'ndir.h'
then
       echo shar: will not over-write existing file "'ndir.h'"
else
cat << \SHAR_EOF > 'ndir.h'
/* @(#)ndir.h	1.4	4/16/85 */
#ifndef DEV_BSIZE
#define	DEV_BSIZE	512
#endif
#define DIRBLKSIZ	DEV_BSIZE
#define	MAXNAMLEN	255

struct	direct {
	long	d_ino;			/* inode number of entry */
	short	d_reclen;		/* length of this record */ 
	short	d_namlen;		/* length of string in d_name */
	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
};

/*
 * The DIRSIZ macro gives the minimum record length which will hold
 * the directory entry.  This requires the amount of space in struct direct
 * without the d_name field, plus enough space for the name with a terminating
 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
 */

#ifdef DIRSIZ
#undef DIRSIZ
#endif /* DIRSIZ */
#define DIRSIZ(dp) \
    ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))

/*
 * Definitions for library routines operating on directories.
 */
/*
typedef struct _dirdesc {
	int	dd_fd;
	long	dd_loc;
	long	dd_size;
	char	dd_buf[DIRBLKSIZ];
} DIR;
*/
typedef struct _dirdesc {
	int 	ioVRefNum;
	long	ioDrDirID;
	int		ioFDirIndex;
} DIR;
#ifndef NULL
#define NULL 0L
#endif
extern	DIR *opendir();
extern	struct direct *readdir();
extern	void closedir();

SHAR_EOF
chmod +x 'ndir.h'
fi # end of overwriting check
if test -f 'sio.h'
then
       echo shar: will not over-write existing file "'sio.h'"
else
cat << \SHAR_EOF > 'sio.h'
/*			sio.h


*/

#include	<serial.h>

#define AIN		"\P.AIN"
#define AOUT	"\P.AOUT"
#define BIN		"\P.BIN"
#define BOUT	"\P.BOUT"

typedef struct SIOPort {
	int refin, refout;
	unsigned short baud, parity, stopbits, databits;
	SerShk	handshake;
	char * out, * in;
	int insize, outsize;
	char * inbuffer, * outbuffer;
} SIOPort;


extern struct SIOPort PortA, PortB, *Port;

extern SIOInit( /*whichport, speed*/ );
extern SIOSpeed( /*speed*/ );
extern SIOHandshake ( /*fInx, fXOn, fCTS, xOn, xOff*/ );
extern SIOSetting( /*speed, parity, stopbits, databits*/ );
extern SIOInBuffer ( /*buf, size*/ );
extern SIOOutBuffer ( /*buf, size*/ );
extern SIOClose ( /*dtr*/ );
extern SIOPurge ();
extern SIOPutchar ( /*ch*/ );
extern SIOWStr ( /*st*/ );

/* timeout is in tenths of a second */
extern int SIORead  ( /*byt, maxcount, tenths*/ );

extern putu( /*c, count, refout*/ );
extern int getn ( /*cp, cmax, cmin, refin*/ );

SHAR_EOF
chmod +x 'sio.h'
fi # end of overwriting check
if test -f 'rename.c'
then
       echo shar: will not over-write existing file "'rename.c'"
else
cat << \SHAR_EOF > 'rename.c'
/* Copyright (C) 1984 by Manx Software Systems, Inc. */

#include	<quickdraw.h>
#include	<pb.h>
#include	<errno.h>

#define		_DEBUG
#include	<max/debug.h>

#ifdef TEST
#include <stdio.h>
#endif

long setdir( path, dir, name )
char * path;
char * dir;
char * name;
{
	CInfoPBRec cpb;
	int err;

	splitname( path, dir, name );
	
#ifdef TEST
	fprintf( stderr, "setdir: \"%s\" \"%s\" \"%s\"\n", name, dir, path );
#endif

	cpb.ioNamePtr = ctop( dir );
	
	cpb.ioVRefNum = 0;
	cpb.ioFDirIndex = 0;
	cpb.u.di.ioDrDirID = 0L;

	if ((err = PBGetCatInfo( &cpb, 0 )) != 0 ) {

#ifdef TEST
	fprintf( stderr, "setdir: err %d\n", err );
#endif
		
	}

	ptoc( dir );

#ifdef TEST
	fprintf( stderr, "setdir: path|%s dir|%s name|%s\n",
				path, dir, name );
#endif

	return( cpb.u.di.ioDrDirID );

}

rename(old, new)
char *old, *new;
{
	register int i, err;
	long int freeb;
	int vrefnum;
	
	union {
		struct HPrmBlkRec pb;
		struct CMovePBRec cm;
	} pbcm;
		
	char nbuf[64], ndir[64], nname[32];
	char obuf[64], odir[64], oname[32];


	/* get vRefNum */
	if ( (i=hfixnam(old, obuf)) == 0 ||
			 	(pbcm.pb.ioVRefNum = hfixnam(new, nbuf)) == 0
			)
		return(-1);
	if (i != pbcm.pb.ioVRefNum) {
		errno = EINVAL;
		return(-1);
	}

	
#ifdef TEST
	fprintf( stderr, "rename: obuf|%s -> nbuf|%s\n", obuf, nbuf );
#endif

	/* get dir refnums, fix path names, get dir name, and name */
	pbcm.cm.ioNewDirID = setdir( nbuf, ndir, nname );
	pbcm.cm.ioDirID = setdir( obuf, odir, oname );	
	
	/* use name only */
	if ( pbcm.cm.ioDirID != pbcm.cm.ioNewDirID ) {
#ifdef TEST
		fprintf( stderr, "rename: catmove\n" );
		fprintf( stderr, "rename: %ld|%s -> %ld|%s\n", 
				pbcm.cm.ioDirID, obuf, pbcm.cm.ioNewDirID, ndir );
#endif
		/* use full path name including volume name */
		pbcm.pb.ioNamePtr = ctop(obuf);
		pbcm.cm.ioNewName = ctop(ndir);
		err = PBCatMove(&pbcm, 0);
	}
	else
		err = 0;
	if (err) {
		if (err == -48)
			err = EEXIST;
		errno = err;
		return(-1);
	}
	else {
#ifdef TEST
	fprintf( stderr, "rename: rename\n" );
	fprintf( stderr, "rename: %ld|%s -> %ld|%s\n", 
			pbcm.cm.ioDirID, oname, pbcm.cm.ioNewDirID, nname);
#endif
		pbcm.pb.ioNamePtr = ctop(oname);
		pbcm.pb.u.iop.ioVersNum = 0;
		pbcm.pb.u.iop.ioMisc = ctop(nname);
		pbcm.cm.ioDirID =  pbcm.cm.ioNewDirID;
		err = PBHRename(&pbcm, 0);
		if (err) {
			if (err == -48)
				err = EEXIST;
			errno = err;
			return(-1);
		}
		else
			return(0);
	}
}

#ifdef TEST
#include <errno.h>

main()
{
	char command[100];

	char f1[100], f2[100];

	while(gets(command) != NULL) {
		sscanf( command, "%s%s", f1, f2 );

		fprintf( stderr, "test: %s %s\n", f1, f2 );

		if ( rename( f1, f2 ) == 0 )
			fprintf( stderr, "test: OK\n\n" );
		else
			fprintf( stderr, "test: ERROR %d\n\n", errno );
	}
}
#endif
SHAR_EOF
chmod +x 'rename.c'
fi # end of overwriting check
if test -f 'splitname.c'
then
       echo shar: will not over-write existing file "'splitname.c'"
else
cat << \SHAR_EOF > 'splitname.c'


/* splitname

		split and and copy directory and filename from 
		pathname to dir and name
*/
splitname( path, dir, name )
char * path;
char * dir;
char * name;
{
	register char *cp;
	register int i;

	strcpy( dir, path );
	i = strlen( dir);
	cp = dir + i;


	while ((i-- > 0) && (*--cp != '/') && (*cp != ':') );

	if (*cp == '/') cp++;
	else if (*cp == ':') cp++;
	
	strcpy( name, cp );
	*cp = '\0';

}

#ifdef TEST
#include <stdio.h>

main ()

{
	char buf[100];
	char dir[100], name[100];

	while (gets( buf ) != NULL ) {
		splitname( buf, dir, name );
		printf( "%s -> \"%s\"   \"%s\"\n", buf, dir, name );
	}
}

#endif
SHAR_EOF
chmod +x 'splitname.c'
fi # end of overwriting check
if test -f 'scandir.c'
then
       echo shar: will not over-write existing file "'scandir.c'"
else
cat << \SHAR_EOF > 'scandir.c'
/*
 *	scandir - a SysV library routine that simulates the
 *		  BSD 4.3 version.
 *
 *	returns:
 *		-1 for failures
 *		# of files found if successful
 *
 *	Produces a list of files which are contained in the
 *	directory "dirname".
 *
 *	The list is returned through "namelist" which is an
 *	array of pointers to (struct direct).  This list of
 *	pointers are malloc'ed and should be freed when
 *	done with.
 *
 *	The passed function "select" is passed a (struct direct)
 *	pointer for each directory entry.  If "select" returns
 *	non-zero the entry is included in "namelist", otherwise
 *	it is not.  If "select" is NULL, all entries are returned.
 *
 *	The function "compar" is passed a pair of pointers to
 *	(struct direct) and is used to sort "namelist" via qsort.
 *	If "compar" is NULL, the names are unsorted.
 *
 *	This source is public domain and the author claims no
 *	rights to it.  It may be copied, spindled, or mutilated.
 *
 *	R.J. Esposito - Bell of Pennsylvania
 *
 */

#include <stdio.h>
/*#include <sys/types.h>*/
#include <ndir.h>

int
scandir(dirname, namelist, select, compar)
char		*dirname;
struct direct	*(*namelist[]);
int		(*select)();
int		(*compar)();
{
	DIR		*dfp;
	struct direct	*dp;
	register int	ii, nf;
	char		*malloc();

	if ((dfp = opendir(dirname)) == NULL)	/* can't open directory */
		return(-1);

	nf = 0;
	while ((dp = readdir(dfp)) != NULL)	/* read thru direcetory */
		if (select == NULL || (*select)(dp))
			nf++;

	if (!nf)				/* nothing found */
		return(0);

	/* malloc memory for the namelist array */

	*namelist = (struct direct **)malloc((nf+1)*sizeof(struct direct *));
	if (*namelist == NULL) {
		fprintf(stderr, "scandir: out of memory\n");
		return(-1);
	}

	for (ii = 0; ii < nf; ii++) {
		(*namelist)[ii] = (struct direct *)malloc(sizeof(struct direct));
		if ((*namelist)[ii] == NULL) {
			fprintf(stderr, "scandir: out of memory\n");
			return(-1);
		}
	}

	/* now re-read the directory loading up the namelist array */

	closedir( dfp );
	if ((dfp = opendir(dirname)) == NULL)	/* can't open directory */
		return(-1);

	(*namelist)[ii] = 0;
	/*seekdir(dfp, 0L);*/
	ii = 0;

	while ((dp = readdir(dfp)) != NULL) {
		if (select == NULL || (*select)(dp)) {
			(*namelist)[ii]->d_ino = dp->d_ino;
			(*namelist)[ii]->d_reclen = dp->d_reclen;
			(*namelist)[ii]->d_namlen = dp->d_namlen;
			strcpy((*namelist)[ii]->d_name, dp->d_name);
			ii++;
		}
	}

	closedir(dfp);
#ifdef test
	if (compar != NULL)		/* sort the list if required */
		qsort((char **)*namelist, nf, sizeof(struct direct *), compar);
#endif

	return(nf);
}

SHAR_EOF
chmod +x 'scandir.c'
fi # end of overwriting check
if test -f 'ndir.c'
then
       echo shar: will not over-write existing file "'ndir.c'"
else
cat << \SHAR_EOF > 'ndir.c'

/*#include <ndir.h>*/
#include <local/ndir.h>

#include <pb.h>

#ifdef TEST
#include <stdio.h>
#define _DEBUG
#include <max/debug.h>
#endif

/*
 * support for Berkeley directory reading routine on a V7 file system
 */

extern char *malloc();

/*
 * open a directory.
 */

DIR *
opendir(name)
char *name;
{
	register DIR *dirp;
	register int fd;

	char buf[100];
	CInfoPBRec cpb;
	int err;

	/* fix name, and get volume reference number */


	cpb.ioVRefNum = hfixnam( name, buf );
	cpb.ioNamePtr = ctop( buf );
	cpb.ioFDirIndex = 0;
	cpb.u.di.ioDrDirID = 0L;

#ifdef TEST
	fprintf( stderr, "opendir: %s\n", buf );
#endif

	if ((err = PBGetCatInfo( &cpb, 0 )) != 0 ) {
#ifdef TEST
		fprintf( stderr, "setdir: PBGetCatInfo %d\n", err );
#endif
		return NULL;
	}

	if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
#ifdef TEST
		fprintf( stderr, "opendir: couldn't malloc %d\n",sizeof(DIR));
#endif
		return NULL;
	}
	dirp->ioVRefNum = cpb.ioVRefNum;
	dirp->ioDrDirID = cpb.u.di.ioDrDirID;
	dirp->ioFDirIndex = 1;

#ifdef TEST
	fprintf( stderr, "opendir: # %ld\n", cpb.u.di.ioDrDirID );
#endif

	return dirp;
}


/*
 * get next entry in a directory.
 */
struct direct *
readdir(dirp)
register DIR *dirp;
{
	CInfoPBRec cpb;
	int err;
	static struct direct dir;

#ifdef TEST
	fprintf( stderr, "readdir: v:%d d:%ld i:%d\n", 
			dirp->ioVRefNum, dirp->ioDrDirID, dirp->ioFDirIndex );
#endif
	strcpy( dir.d_name, "" );
	cpb.ioNamePtr = dir.d_name;
	cpb.ioVRefNum = dirp->ioVRefNum;
	cpb.u.di.ioDrDirID = dirp->ioDrDirID;
	cpb.ioFDirIndex = dirp->ioFDirIndex++;

	if ((err = PBGetCatInfo( &cpb, 0 )) != 0 ) {
#ifdef TEST
		fprintf( stderr, "readdir: err %d\n", err );
#endif
		return NULL;
	}

	dir.d_ino = 0;
	ptoc( dir.d_name );

#ifdef TEST
	fprintf( stderr, "readdir: OK \"%s\"\n",  dir.d_name);
#endif

	dir.d_namlen = strlen(dir.d_name);
	dir.d_reclen = DIRSIZ(&dir);
	return (&dir);
	
}

/*
 * close a directory.
 */
void
closedir(dirp)
register DIR *dirp;
{
	free((char *)dirp);
}


#ifdef TEST
#include <errno.h>

main()
{
	char command[100];

	struct DIR *dirp;
	struct direct *dp;
	
	while(gets(command) != NULL) {

		fprintf( stderr, "test: %s\n", command );

		if ((dirp = opendir( command )) == NULL ) {
			fprintf( stderr, "couldn't open dir %s\n", command );
		}
		while ((dp = readdir(dirp)) != NULL) 
			fprintf( stderr, "%s", dp->d_name );

		closedir( dirp );
	}
}
#endif
SHAR_EOF
chmod +x 'ndir.c'
fi # end of overwriting check
if test -f 'chdir.c'
then
       echo shar: will not over-write existing file "'chdir.c'"
else
cat << \SHAR_EOF > 'chdir.c'

#include <errno.h>
#include <memory.h>
#include <pb.h>
#include <aztec/shell.h>

#define _DEBUG
#include <max/debug.h>
#ifdef TEST
#include <stdio.h>
#endif

#ifndef NULL
#define NULL 0L
#endif

chdir( path )
char * path;
{

	char npath[255];
	CInfoPBRec cpb;
	int err;
	register char * cp;


	/* fix name, and get volume reference number */


	cpb.ioVRefNum =  hfixnam( path, npath );

#ifdef TEST
	fprintf( stderr, "opendir: %s\n", npath );
#endif

	cpb.ioNamePtr = ctop( npath );
	cpb.ioFDirIndex = 0;
	cpb.u.di.ioDrDirID = 0L;
	if ((err = PBGetCatInfo( &cpb, 0 )) != 0 ) {
#ifdef TEST
		fprintf( stderr, "setdir: PBGetCatInfo %d\n", err );
#endif
		return ENOENT;
	}

	/* resize handle */

	ptoc( npath );
	strcpy( npath, index( npath, ':' )+1 );

	while ((cp = index( npath, ':' )) != NULL )
		*cp = '/';

#ifdef TEST
	fprintf( stderr, "chdir: setting curdir to \"%s\"\n", npath );
#endif

	SetHandleSize( Sp->curdir, (long)(strlen( npath )+2));

	if (MemError() != 0)
		return ENOMEM;

	strcpy( *Sp->curdir, npath );

	return 0;

}

#ifdef TEST
main()
{
	char command[100];

	gets( command );
	fprintf( stderr, "%d\n", chdir( command ));
}

#endif

SHAR_EOF
chmod +x 'chdir.c'
fi # end of overwriting check
if test -f 'getcwd.c'
then
       echo shar: will not over-write existing file "'getcwd.c'"
else
cat << \SHAR_EOF > 'getcwd.c'

#include <errno.h>
#include <memory.h>
#include <aztec/shell.h>

#ifdef TEST
#include <stdio.h>
#define _DEBUG
#include <max/debug.h>
#endif

#ifndef NULL
#define NULL 0L
#endif

char * malloc();

char * getcwd( path, size )
char * path;
int size;
{

	register char * cp;

	cp = *Sp->curdir;
	
	if (path == NULL) {
		if (size == 0)
			size = strlen( cp ) + 2;
		path = malloc( size );
	}
	if (size <= strlen( cp )) {
		strcpy( path, "" );
		errno = E2BIG;
		return NULL;
	}

	strcpy( path, "/" );
	strcat( path, cp );
	return( path );
	
}

#ifdef TEST
main()
{

	fprintf( stderr, "%s\n", getcwd( NULL, 0 ));
}

#endif

SHAR_EOF
chmod +x 'getcwd.c'
fi # end of overwriting check
if test -f 'genv.c'
then
       echo shar: will not over-write existing file "'genv.c'"
else
cat << \SHAR_EOF > 'genv.c'
/* 		genv.c
 
 
 
		copyright (C) 1987 Stuart Lynne
 
		Copying and use of this program are controlled by the terms of the
		Free Software Foundations GNU Emacs General Public License.
 
 
		version		0.1		March 31/1987
 
 
 
*/
 
#ifdef UNIX
#include <sys/types.h>
#endif
#ifdef slmacaztec
#include <mac/types.h>
#endif
 
#include <stdio.h>
 
#include "genv.h"

#define DMAILBOX	"mailbox"
#define	DNAME		""
#define DHOME		"/usr/guest"
#define	DDOMAIN		"pc.uucp"
#define	DMAILDIR	"/usr/mail"
#define	DCONFDIR	"/usr/lib/uucp"
#define	DSPOOLDIR	"/usr/spool/uucp"
#define DPUBDIR		"/usr/spool/uucppublic"
#define	DMAILSERVICE	"host"
#define	DNODENAME	""
#define	DDEVICE		".a"
#define	DSPEED		"1200"
#define	DTEMPDIR	"/tmp"

 
#define	TFILENAME	"tmpfile"
#define	FILENAME 	"%s/%s"

char *getenv();
 
void genv();

#ifdef SLAZTECMAC
 
char	rmailbox[64];
char	rname[64];
char	rhome[64];
char	rdomain[64];
char	rmaildir[64];
char	rconfdir[64];
char	rspooldir[64];
char	rpubdir[64];
char	rmailserv[16];
char 	rnodename[16];
char 	rdevice[16];
char 	rspeed[8];
char	rtempdir[64];

char	*mailbox = rmailbox;
char	*name = rname;
char	*home = rhome;
char	*domain = rdomain;
char	*maildir = rmaildir;
char	*confdir = rconfdir;
char	*spooldir = rspooldir;
char	*pubdir = rpubdir;
char	*mailserv = rmailserv;
char 	*nodename = rnodename;
char 	*device = rdevice;
char 	*speed = rspeed;
char	*tempdir = rtempdir;

 
void genv(thename, envname, dflt)
char **thename;
char *envname;
char *dflt;
{
	char * temp;
	
	if ((temp = getenv( envname )) == NULL) {
		/* fprintf( stderr, "genv: %s not found, using %s\n", envname, dflt ); /* */
		temp = dflt;
	}
	strcpy( *thename, temp );
	/*  fprintf( stderr, "genv: %s %s\n", envname, *thename ); /**/
}
#else

char	*mailbox;
char	*name;
char	*domain;
char	*maildir;
char 	*spooldir;
char	*pubdir;
char	*confdir;
char	*mailserv;

void genv(thename, envname, dflt)
char **thename;
char *envname;
char *dflt;
{
	if ((*thename = getenv( envname )) == NULL) {
		fprintf( stderr, "genv: %s not found, using %s\n", envname, dflt );
		*thename = dflt;
	}
	/* fprintf( stderr, "genv: %s %s\n", envname, *thename ); /**/
}
#endif

void loadenv()
{
	/* get environment var's */
	genv( &name, NAME, DNAME );
	genv( &mailbox, MAILBOX, DMAILBOX );
	genv( &home, HOME, DHOME );
	genv( &domain, DOMAIN, DDOMAIN );
	genv( &maildir, MAILDIR, DMAILDIR );
	genv( &confdir, CONFDIR, DCONFDIR );
	genv( &spooldir, SPOOLDIR, DSPOOLDIR );
	genv( &pubdir, PUBDIR, DPUBDIR );
	genv( &mailserv, MAILSERVICE, DMAILSERVICE );
	genv( &nodename, NODENAME, DNODENAME );
	genv( &device, DEVICE, DDEVICE );
	genv( &speed, SPEED, DSPEED );
	genv( &tempdir, TEMPDIR, DTEMPDIR );
}
 
void mkfilename( filename, dirname, name )
char * filename;
char * dirname;
char * name;
{
	sprintf( filename, FILENAME, dirname, name );	
	/* fprintf( stderr, "New filename %s\n", filename );  /**/	
}


#ifdef TEST
main()
{
	loadenv();
}
#endif

SHAR_EOF
chmod +x 'genv.c'
fi # end of overwriting check
if test -f 'sio.c'
then
       echo shar: will not over-write existing file "'sio.c'"
else
cat << \SHAR_EOF > 'sio.c'
/*			sio.c


				Serial I/O for rz/sz


				Copyright (c) 1986 Stuart Lynne

				June 1986

				

*/
#include <local/sio.h>
#include <stdio.h>

#include <pb.h>

#include <osutil.h>

/* #include <max/macglobals.h> */
#include <max/debug.h>
#include <max/asc.h>

#define FALSE 0
#ifndef TRUE
#define TRUE 1
#endif


struct SIOPort curPort;


struct {
	unsigned baudr;
	int speedcode;
} speeds[] = {
	300,	baud300,
	600,	baud600,
	1200,	baud1200,
	2400,	baud2400,
	4800,	baud4800,
	9600,	baud9600,
	19200,	baud19200,
/*
	38400, 	baud38400,
*/
	57600, 	baud57600,
	9600,	baud9600,
	0,
};

static unsigned
getspeed(code)
{
	register n;

	for (n=0; speeds[n].baudr; ++n)
		if (speeds[n].speedcode == code)
			return speeds[n].baudr;
	return 0;
}


static unsigned
getbaud(code)
char *code;
{
	register n;
	register int Baudrate;
	
	Baudrate = atoi(code);
	
	for (n=0; speeds[n].baudr; ++n)
		if (speeds[n].baudr == Baudrate)
			return speeds[n].speedcode;
	return 0;
}



SIOInit ( whichport, speed )
char * whichport;
char * speed;
{
	char i;
	SerShk	handshake;
	int setting;
	int err;

	/*  fprintf( stderr, "sioinit %s %s\n", whichport, speed ); /* */
	
	if ( 
		strncmp( whichport, ".a", 2 ) == 0 || 
		strncmp( whichport, "a",1 ) == 0 ||
		strcmp( whichport, "modem") == 0
		) 
	{
		curPort.in = AIN;
		curPort.out = AOUT;
	}
	else if (
		strncmp( whichport, ".b", 2 ) == 0 || 
		strncmp( whichport, "b", 1 ) == 0 ||
		strcmp( whichport, "printer") == 0 
		) 
	{
		curPort.in = BIN;
		curPort.out = BOUT;
	}
	else
		return( -1 );

	if ((err = OpenDriver ( curPort.in,  &curPort.refin )) !=0 ) {
		fprintf( stderr, "Err: %d\n", err);
		debugMsg ( ctop( curPort.in ) );
		SysBeep (20); 
		return( -1 );
	}

	
	if ((err=OpenDriver ( curPort.out, &curPort.refout )) !=0 ) {
		fprintf( stderr, "Err: %d\n", err);
		debugMsg ( ctop( curPort.out ) );
		SysBeep (20); 
		return( -1 );
	}
	
	SIOHandshake( FALSE, FALSE, FALSE, XON, XOF );
	SIOSettings( speed, noParity, stop10, data8 );
	return( 0 );
}

SIOSpeed( speed )
char * speed;
{
	SIOSetting( speed, curPort.parity, curPort.stopbits, curPort.databits );
}

SIOHandshake ( fInx, fXOn, fCTS, xOn, xOff )
{	
	int err;
	
	curPort.handshake.fInX = fInx;
	curPort.handshake.fXOn = fXOn;
	curPort.handshake.fCTS = fCTS;

	curPort.handshake.xOn = xOn;
	curPort.handshake.xOff = xOff;
	/* handshake.fXOn = TRUE; */
	
	curPort.handshake.errs = 0;
	curPort.handshake.evts = 0;

	if ((err=SerHShake (curPort.refin, &curPort.handshake ))!=0 ) {
		fprintf( stderr, "Err: %d\n", err);
		debugMsg ("\PSerHShake error");
		SysBeep (20); 
	}
}

SIOSetting( speed, parity, stopbits, databits )
char * speed;
{
	int err;
	int setting;
	
	curPort.baud = getbaud(speed);
	curPort.parity = parity;
	curPort.stopbits = stopbits;
	curPort.databits = databits;
	
	setting = curPort.baud + parity + stopbits + databits;

	if ((err=SerReset(curPort.refin, setting))!=0 )  {
		fprintf( stderr, "Err: %d\n", err);
		debugMsg ("\PSerReset error");
		SysBeep (20);
	}	
}

SIOInBuffer ( buf, size )
char * buf;
int size;
{
	curPort.inbuffer = buf;
	curPort.insize = size;
	SerSetBuf( curPort.refin, buf, size ); 
}

SIOOutBuffer ( buf, size )
char * buf;
int size;
{
	curPort.outbuffer = buf;
	curPort.outsize = size;
	SerSetBuf( curPort.refout, buf, size ); 
}


SIOClose ( dtr )
{
	struct ParamBlkRec SIOpb;
	
	register Ptr *sp;
	long count;

	if ( dtr != 0) {
		/* drop DTR */
		SIOpb.ioCompletion = NULL;
		SIOpb.u.cp.csRefNum = curPort.refin;
		SIOpb.u.cp.csCode = 18;
		sp = (Ptr) &SIOpb;
		
		/**/ PBControl (&SIOpb, FALSE); /**/
/*
#asm
			move.l	a3,a0
			dc.w	$a004
#endasm
*/
	}
	
	SIOInBuffer( NULL, 0 );
	SIOOutBuffer( NULL, 0 );
	CloseDriver( curPort.refin );
	CloseDriver( curPort.refout );
}


sfflushout ()
{
	}

SIOPurge ()
{
	char		ch;

	while (sread (&ch, 1, 1) == 1);
	
	}

SIOPutchar ( ch )
char ch;
{
	/*fprintf(stderr, "<%02x>", ch);*/
	return( putu ( &ch, 1, curPort.refout ) );	
}

SIOWrite ( buf, count )
char * buf;
int count;
{
	return( putu (buf, count, curPort.refout) );
}

SIOWStr ( st )
char * st;
{
	return( putu (st, strlen(st), curPort.refout) );
}

#define	Ticks			(*(long *)			0x16a)
	
 
/* timeout is in tenths of a second */
int SIORead ( byt, mincount, maxcount, tenths )
char * byt;
int	mincount;
int	 maxcount;
int tenths;
{
	long	timea;
	short	actCount;


	int		i;
	
	timea = Ticks;
	tenths *= 6;
	/* fprintf (stderr, "Read  m= %d T= %ld", maxcount, Ticks  );/**/
	do {
		actCount = getn (byt, mincount, maxcount, curPort.refin );

		if (actCount > 0) {
			/* fprintf (stderr, "  OK: %d\n", actCount);/**/
			return actCount;
			}
		
	} while ((long)(Ticks - timea) < (long) tenths);
	
	/* fprintf (stderr, "  Timed out: t= %d\n  T:%ld", tenths, Ticks );/**/
	return -1;
	}

srdchk ()
{
	struct ParamBlkRec SIOpb;
	
	register Ptr *sp;
	long count;
	
	SIOpb.ioCompletion = NULL;
	SIOpb.u.cp.csRefNum = curPort.refin;
	SIOpb.u.cp.csCode = 2;
	SIOpb.u.cp.csParam.asyncNBytes = 0L;
	
	sp = (Ptr) &SIOpb;
	
	/**/ PBStatus (&SIOpb, FALSE); /**/
/*
#asm
		move.l	a3,a0
		dc.w	$a005
#endasm
*/
	count = SIOpb.u.cp.csParam.asyncNBytes;
	if (count >= 1) 
		return TRUE;
	else 
		return FALSE;
	}


sleep (seconds)
{
	long timea;

	timea = Ticks;
	seconds *= 60;

	while ((long)(Ticks - timea) < (long) seconds);

	}
	
ssendbrk (bnulls)
int bnulls;
{
	int setting;
	
	setting = curPort.baud + noParity + stop10 + data8;

	if (SerReset(curPort.refin, setting) )  {
		debugMsg ("\PSerReset error");
		SysBeep (20);
		}	

  swrite("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", bnulls*2);

	setting = curPort.baud + noParity + stop10 + data8;

	if (SerReset(curPort.refin, setting) )  {
		debugMsg ("\PSerReset error");
		SysBeep (20);
		}	

   return;
	}


/* 	Fill array *cp with characters from serial buffer, starting
	at 0, until cmax. Return actual chars read. Don't read unless
	at least cmin are available.
*/
int getn ( cp, cmin, cmax, refin )
char *cp;
register int cmax, cmin;
register short refin;
{	
	struct ParamBlkRec SIOpb;
register	Ptr	pbp = &SIOpb;

	register int count;

	/* fprintf( stderr, " %d", cmin ); /* */
	
	SIOpb.ioCompletion = NULL;
	SIOpb.u.cp.csRefNum = refin;
	SIOpb.u.cp.csCode = 2;
	SIOpb.u.cp.csParam.asyncNBytes = 0L;
	
	pbp = (Ptr) &SIOpb;

	/**/ PBStatus (&SIOpb, FALSE); /**/
/*
#asm
		move.l	a3,a0
		dc.w	$a005
#endasm
*/
	count = (int) SIOpb.u.cp.csParam.asyncNBytes;
	SIOpb.u.iop.ioReqCount = (long) count;
	if ( count >= cmin) {
		if ( count >  cmax) 
			SIOpb.u.iop.ioReqCount = (long) cmax;
   		SIOpb.u.iop.ioRefNum = refin;
	   	SIOpb.u.iop.ioBuffer = (Ptr) cp;
  	 	SIOpb.u.iop.ioPosMode = 0;
		/* */ PBRead (&SIOpb, FALSE); /* */
/*
#asm
			move.l	a3,a0
			dc.w	$a002
#endasm
*/
		count = (int) SIOpb.u.iop.ioActCount;
		return( count );
		}
	else
		return 0;
}
	

int putu( c, count, refout )
char 	*c;
short	count;
short	refout;
{
	struct ParamBlkRec  pb;
register	Ptr	pbp = &pb;
	
	pb.u.iop.ioRefNum = refout;
	pb.u.iop.ioBuffer = c;
	pb.u.iop.ioReqCount = count;
	pb.u.iop.ioPosMode = 0;
  
	/* */ PBWrite(&pb, FALSE ); /* */
/*
#asm
	move.l	a3,a0
	dc.w		$a003
#endasm
*/
	return( (short) pb.u.iop.ioActCount );
}




SHAR_EOF
chmod +x 'sio.c'
fi # end of overwriting check
if test -f 'getargs.c'
then
       echo shar: will not over-write existing file "'getargs.c'"
else
cat << \SHAR_EOF > 'getargs.c'

#include <stdio.h>

getargs(cp, flds)
register char *cp;
char *flds[];
{
	register int count = 0;

	while ( *cp != '\0' ) {
		while ( *cp == ' ' || *cp == '\t')
			*cp++ = '\0';
		if (*cp == '\n')
			*cp = '\0';
		if (*cp != '\0' ) {
			flds[count++] = cp;
			while (*cp != ' ' && *cp != '\t' &&
					 *cp != '\n' && *cp != '\0' )
				cp++;
		}
	}
	flds[count] = NULL;
	return(count);
}

#ifdef testtoken
	/* tokenize command line */
	while ( *cp != '\0' ) {
		/*debuglevelMsg("\PCheck isspace(*cp++)");*/
		if ( isspace(*cp) ) {
			/* terminate previous token */
			*cp++ = '\0';
			/* eat white space */
			while ( isspace(*cp) ) cp++;
		}
		else {
			/* put address of token into argv, inc argc */
			*argvp++ = cp;
			argcp++;
			fprintf( stderr, "shell: token %s\n", cp );
			/*debuglevelMsg("\PCheck !isspace(*cp++)");*/
			while ( !isspace(*cp) ) cp++;
			
		}
	}
#endif

SHAR_EOF
chmod +x 'getargs.c'
fi # end of overwriting check
if test -f 'mkdir.c'
then
       echo shar: will not over-write existing file "'mkdir.c'"
else
cat << \SHAR_EOF > 'mkdir.c'

#include <errno.h>
#include <memory.h>
#include <pb.h>
#include <aztec/shell.h>

#define _DEBUG
#include <max/debug.h>
#ifdef TEST
#include <stdio.h>
#endif

#ifndef NULL
#define NULL 0L
#endif

mkdir( path )
char * path;
{

	char npath[255];
	CInfoPBRec cpb;
	int err;
	register char * cp;


	/* fix name, and get volume reference number */


	cpb.ioVRefNum =  hfixnam( path, npath );

#ifdef TEST
	fprintf( stderr, "opendir: %s\n", npath );
#endif

	cpb.ioNamePtr = ctop( npath );
	cpb.ioFDirIndex = 0;
	cpb.u.di.ioDrDirID = 0L;
	if ((err = PBDirCreate( &cpb, 0 )) != 0 ) {
#ifdef TEST
		fprintf( stderr, "setdir: PBDirCreateGetCatInfo %d\n", err );
#endif
		return ENOENT;
	}



	return 0;

}

#ifdef TEST
main()
{
	char command[100];

	gets( command );
	fprintf( stderr, "%d\n", mkdir( command ));
}

#endif

SHAR_EOF
chmod +x 'mkdir.c'
fi # end of overwriting check
if test -f 'hfixnam.c'
then
       echo shar: will not over-write existing file "'hfixnam.c'"
else
cat << \SHAR_EOF > 'hfixnam.c'

#ifdef TEST
#include <stdio.h>
#endif
#include <pb.h>


hfixnam( path, npath )
char * path;
char * npath;
{

	HPrmBlkRec pb;
	char vname[256];

	strcpy( vname, "" );
	strcpy( npath, "" );
	
	pb.ioNamePtr = vname;

#ifdef TEST
	fprintf( stderr, "hfixnam: before \"%s\"\n", path );
#endif

	pb.ioVRefNum = fixnam( path, npath );

#ifdef TEST
	fprintf( stderr, "hfixnam: vrefnum %d\n", pb.ioVRefNum );
	fprintf( stderr, "hfixnam: after \"%s\"\n", npath );
#endif

	pb.u.hvp.ioVolIndex = 0;

	if (PBGetVInfo(&pb, 0) == 0) {
		ptoc( vname );

#ifdef TEST
		fprintf( stderr, "hfixnam: \"%s\"\n", vname );
#endif

		strcat( vname, npath );
		strcpy( npath, vname );
	}
	
	return pb.ioVRefNum;

}


#ifdef TEST
#include <errno.h>

main()
{
	char command[100];
	char ncommand[100];
	int vrefnum;

	while ( gets( command ) != NULL) {
		fprintf( stderr, "test: %s \n", command );
		vrefnum = hfixnam( command, ncommand );
		fprintf( stderr, "test: %d %s\n", vrefnum, ncommand );
	}
}
#endif
SHAR_EOF
chmod +x 'hfixnam.c'
fi # end of overwriting check
if test -f 'macinit.c'
then
       echo shar: will not over-write existing file "'macinit.c'"
else
cat << \SHAR_EOF > 'macinit.c'
/*			macinit.c




*/

#include <quickdraw.h>
#include <font.h>


macinit()
{

	TextFont( monaco );
	TextSize( 10 );

}

SHAR_EOF
chmod +x 'macinit.c'
fi # end of overwriting check
#	End of shell archive
exit 0

--
{ubc-vision,uunet}!van-bc!sl				Stuart.Lynne@ve:DOS 1.%