[comp.sources.misc] uupc.ami.8.6

allbery@ncoast.UUCP (08/17/87)

>From uucp Wed Aug 12 02:30 PDT 1987
>From slynne  Wed Aug 12 02:30:19 1987 remote from slmac
Received: by van-bc.uucp (smail2.3)
	id AA17514; 12 Aug 87 02:30:19 PDT (Wed)
Received: by slmac.vnet.van-bc.uucp (pcmail) Wed Aug 12 02:35:17 1987
Date: Wed Aug 12 02:35:17 1987
From: Stuart Lynne - test a mac <slynne@slmac.vnet.van-bc.uucp>
Message-ID: <146@slmac.vnet.van-bc.uucp>
To: sl@van-bc
Subject: shar/uupc.ami.8.6

#! /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:
#	amiga/README.Amiga
#	amiga/Makefile.ami
#	amiga/Makefile
#	amiga/chdir.c
#	amiga/genv.c
#	amiga/genv.dyna
#	amiga/genv.h
#	amiga/getcwd.c
#	amiga/host.c
#	amiga/host.h
#	amiga/mkdir.c
#	amiga/mlib.c
#	amiga/ndir.c
#	amiga/ndir.h
#	amiga/SerialIO.c
#	amiga/sio.c
#	amiga/sleep.c
#	amiga/Timer.c
#	amiga/ulib.c
# This archive created: Wed Aug 12 02:03:37 1987
# By:	Stuart Lynne - test a mac ()
export PATH; PATH=/bin:$PATH
if test -f 'amiga/README.Amiga'
then
       echo shar: will not over-write existing file "'amiga/README.Amiga'"
else
cat << \SHAR_EOF > 'amiga/README.Amiga'
README.Amiga 			July 29, 1987		Jeff Lydiatt

This directory contains all the support code for the dcp serial
I/O  routines,  the  directory  manipulation  support,  code to
support  a  portable version of the unix getenv() function, and
the  startup  code  for  both  uupc  and  mail.   Here is a brief
description of the files:

Directory of PCMail:PCMail/AMIGA

  makefile	- compiles support modules for this directory.
  Makefile.ami - makefile for uupc directory
  genv.h	- header file for genv.c
  host.h	- includes for uupc and mail programs.
  ndir.h	- Amiga version of unix directory structures.
  SerialIO.c	- very low level serial I/O device support.
  Timer.c	- provides low level timer device support.
  chdir.c	- chdir( path), makes "path" the current directory. 
  genv.c	- reads the profile, provides getenv() function.
  genv.dyna	- more flexible version of the above, but gurus!
  getcwd.c	- return the path name of the current directory.
  host.c	- prologue and epilogue for both uupc and mail. 
  mkdir.c	- code for mkdir() to make a directory.  
  mlib.c	- not sure: not used by anything I can see.
  ndir.c	- defines opendir(), readdir(), and closedir(). 
  sio.c		- defines SIOInit(), SIOSpeed(), SIOInBuffer(),
		  SIOClose(), SIOWrite(), SIORead()
  sleep.c	- implements sleep( seconds ); 
  ulib.c	- implements dcp routines swrite(), sread(), openline(),
		  closeline(), rnews(), and shell().


You  should first compile all the all the files in this directory
using  the  makefile supplied.  Not all files need to be compiled
here.   Some  of  the  object  modules need to be in the primary,
portable-file  directory  and  will  be  included  as needed from
there.

BUGS:

This  version  has  been  compiled  and tested under Manx Aztec C
v3.40a  with patch 3 installed.  I have been using it extensively
over  the  past couple of weeks with minor problems.  There is an
occasional guru that I can't seem to trace down, so beware.

There  seems to be a problem if the functions contained in genv.c
uses  malloc  to  support  environment  variables.   The genv.bac
version  contains  a  slightly  out of date version that would be
much nicer to use if someone can find the problem.
 
If you have any questions, please contact me:

   jlydiatt@jlami.van-bc.UUCP   (Jeff Lydiatt)
   {ihnp4!albera!ubc-vision,uunet}!van-bc!jlami!jlydiattSHAR_EOF
cat << \SHAR_EOF > amiga/makefile
MakeThemAll:	getcwd.o chdir.o mkdir.o ndir.o sio.o Timer.o SerialIO.o \
		sleep.o genv.o

genv.o:	genv.h


SHAR_EOF
chmod +x 'amiga/README.Amiga'
fi # end of overwriting check
if test -f 'amiga/Makefile.ami'
then
       echo shar: will not over-write existing file "'amiga/Makefile.ami'"
else
cat << \SHAR_EOF > 'amiga/Makefile.ami'
#		Makefile for uu/dcp with Amiga Aztec C
#
#		Jeff Lydiatt
#		June/87
#		Modeled after Stuart Lynne's for the Mac.
#


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

LFLAGS= -lc
CFLAGS=
AMILIB=	local/getcwd.o local/chdir.o local/mkdir.o local/ndir.o\
	local/genv.o

SIOLIB=	local/sio.o local/Timer.o local/SerialIO.o local/sleep.o


OFILES= dcp.o dcpsys.o dcpxfer.o dcpgpkt.o rmail.o lib.o


all:	 uupc mail
	echo uupc & mail done

#
# .o dependicies
#
dcp.o: dcp.c dcp.h local/host.h
dcpsys.o: dcpsys.c dcp.h local/host.h
dcpxfer.o: dcpxfer.c dcp.h local/host.h
dcpgpkt.o: dcpgpkt.c dcp.h local/host.h
lib.o: lib.c local/host.h
lmail.o: pcmail.c lmail.c local/host.h
mailhost.o: local/host.c local/host.h
mail.o: local/host.h
mlib.o: local/mlib.c local/host.h
ulib.o: local/ulib.c local/host.h
uuhost.o: local/host.c local/host.h

#
# mail
#
mail: lmail.o mailhost.o mail.o mlib.o lib.o Makefile
	ln mailhost.o mail.o lmail.o mlib.o lib.o $(AMILIB) $(LFLAGS) -o mail

#
# uupc
#
uupc:	uuhost.o $(OFILES) ulib.o $(AMILIB) $(SIOLIB) Makefile
	ln uuhost.o $(OFILES) ulib.o $(AMILIB) $(SIOLIB) $(LFLAGS) -o uupc

#
# simple shar constructing
#
SDCP 	= README.Install README.DCP \
		dcp.c dcp.h dcpgpkt.c dcpsys.c dcpxfer.c
SUU	= README.UU Makefile.ami Makefile.mac \
	host.h ndir.h lib.c lmail.c mail.c mailhost.c mlib.c \
	pcmail.c rmail.c ulib.c uuhost.c systems profile
SMAC	= mac/README.MAC \
	mac/host.c mac/host.h mac/mlib.c mac/ulib.c mac/profile

AMI	= amiga/README.Amiga amiga/makefile\
	amiga/genv.h amiga/host.h amiga/ndir.h \
	amiga/SerialIO.c amiga/Timer.c amiga/chdir.c amiga/genv.c \
	amiga/genv.dyna amiga/getcwd.c amiga/host.c amiga/mkdir.c \
	amiga/mlib.c amiga/ndir.c amiga/sio.c amiga/sleep.c amiga/ulib.c
 		
#
# Note: Manx's makefile seems to have a bug that forbids indirection
#	such as "shar >lib a.c  b.c c.c"
#	however "make >lib" seems to work fine if you edit out the
#	commands make echos as it proceeds through the makefile.
#
#	Try make >uulib/dcp shardcp for example.
#
shardcp:
	shar  $(SDCP)
sharuu:
	shar $(SUU)
sharami:
	shar $(AMI)


SHAR_EOF
chmod +x 'amiga/Makefile.ami'
fi # end of overwriting check
if test -f 'amiga/Makefile'
then
       echo shar: will not over-write existing file "'amiga/Makefile'"
else
cat << \SHAR_EOF > 'amiga/Makefile'
MakeThemAll:	getcwd.o chdir.o mkdir.o ndir.o sio.o Timer.o SerialIO.o \
		sleep.o genv.o

genv.o:	genv.h

SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/chdir.c'
then
       echo shar: will not over-write existing file "'amiga/chdir.c'"
else
cat << \SHAR_EOF > 'amiga/chdir.c'
#include <libraries/dos.h>
#include <exec/memory.h>
#include <functions.h>

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

#ifndef NULL
#define NULL 0L
#endif


/*------------------------------------------------------------------*/
/*	chdir(path): make path the current directory. Return Ok/Not */
/*------------------------------------------------------------------*/

int chdir( path )
char *path;
{
	register struct Lock *lock;
	struct Lock *oldLock;
#ifdef TEST
	fprintf( stderr, "Changing to directory \"%s\"\n\n", path );
#endif	

	lock = Lock( path, ACCESS_READ );
	if ( lock == 0L )
	   return (int)IoErr();
	oldLock = CurrentDir( lock );
	if ( oldLock )
	   UnLock( oldLock );
	return 0;
}


#ifdef TEST
main()
{
	char command[108];
	FILE *f;

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

	if (f = fopen("abc", "r"))
	  {
	   fprintf( stderr, "Opened Ok!\n");
	   fclose( f );
	  }
	else
	   fprintf( stderr, "Can't open abc\n");

	exit(NULL);
}

#endif



SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/genv.c'
then
       echo shar: will not over-write existing file "'amiga/genv.c'"
else
cat << \SHAR_EOF > 'amiga/genv.c'
/* 		genv.c
 
 
 
		copyright (C) 1987 Jeff Lydiatt
 
		Copying and use of this program are controlled by the terms of the
		Free Software Foundations GNU Emacs General Public License.
 
 
		version		0.1		09 July 87
 
 
 
*/
 
#include <stdio.h>
 
#include "genv.h"

     /* Environment variables are in file "PROFILE" */
#define PROFILE ":usr/lib/uucp/profile"

#define SAME	0
#define MAXLINE 255

#define DMAILBOX	"mailbox"
#define	DNAME		"noname"
#define	DDOMAIN		"pc.uucp"
#define	DMAILDIR	":usr/spool/mail"
#define DHOME		":usr/noname"
#define	DCONFDIR	":usr/lib/uucp"
#define	DSPOOLDIR	":usr/spool/uucp"
#define DLOGDIR		":usr/spool/uucp"
#define DPUBDIR		":usr/spool/uucppublic"
#define DNEWSDIR	":usr/spool/rnews"
#define DTEMPDIR	"RAM:T"
#define	DMAILSERVICE	"host"
#define	DNODENAME	"noname"
#define	DDEVICE		"CON:"
#define	DSPEED		"1200"

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

#include <stdio.h>
#include <ctype.h>

struct environment
  {
     char name[16];
     char value[64];

  };
typedef struct environment ENV;

static ENV profile[]=
  {
	MAILBOX, 	"",
	NAME,		"",
	DOMAIN,		"",
	MAILDIR,	"",
	HOME,		"",
	CONFDIR,	"",
	SPOOLDIR,	"",
	LOGDIR,		"",
	PUBDIR,		"",
	NEWSDIR2,	"",
	TEMPDIR,	"",
	MAILSERVICE,	"",
	NODENAME,	"",
	DEVICE,		"",
	SPEED,		"",
	"",		"",
  };	
char	*name = NULL;
char	*mailbox = NULL;
char	*home = NULL;
char	*domain = NULL;
char	*maildir = NULL;
char	*confdir = NULL;
char 	*spooldir = NULL;
char	*logdir = NULL;
char	*pubdir = NULL;
char	*mailserv = NULL;
char	*nodename = NULL;
char	*device = NULL;
char	*speed = NULL;
char	*tempdir = NULL;
char	*newsdir = NULL;

/*--------------------------------------------------------------*/
/*	getone: get next character file f.  f already open	*/
/*--------------------------------------------------------------*/

static int getone( f )
FILE *f;
{
   char c, line[256];
   static int pos = 0;
   static int len = 0;

   if ( ++pos > len || line[pos] == '\0' ) 
     {
	if ( fgets( line, 255, f ) == NULL )
	   return EOF;
	pos = 0;
	len = strlen( line );
     }

   c = line[pos];
   return c;
   
}

/*--------------------------------------------------------------*/
/*	getsym: get next symbol from file f.  f already open	*/
/*--------------------------------------------------------------*/

#define ID	1001
#define DELIM	1002
#define STR	1003
#define EOL	1004
#define OTHER	1005
#define UNKNOWN -1000

static int getsym( f, sym )
FILE *f;
char *sym;
{
   /* Simple non reentrant, non reuseable get next symbol from file f */
   /* Valid symbols are:
        Type	Symbol Returned	Comment

	ID	<identifier>	any valid c identifier.
        DELIM	'='		an equal sign.
	STR	a string	anything between "" or ''.
	EOL	'\n'		a newline.
	EOF			the end of file character.
	OTHER   a character	anything else.
	
	Comments begin with # and are delimited by an end of line
   */

   static int lastchar = UNKNOWN; /* Unknown */
   int c, delim;

   /* strip leading white space */

   if ( lastchar != UNKNOWN )
      c = lastchar;
   else
      c = getone( f );

   while ( c == ' ' || c == '\t' )
      c = getone( f );
   lastchar = UNKNOWN;
 
  /* Comments are '#' delimited by EOL character */

   if ( c == '#' )
      while ( c != '\n' && c != EOF )
	 c = getone( f );

   if ( c == EOF )		/* End of file? */
      return EOF;

   if ( c == '\n' )		/* End of Line? */
     {
	strcpy( sym, "\n" );
	return EOL;
     }

   if ( c == '=' )		/* Delimiter '='? */
     {
	strcpy( sym, "=" );
	return DELIM;
     } 

   if ( c == '\"' || c == '\'' )/* String ? */
     {
	delim = c;
	while ( (c = getone( f )) != delim && c != EOF && c != '\n' )
	   *sym++ = c;
	*sym = '\0';
	c = getone( f );
	return STR;
     }

   if ( isalpha( c ) )		/* Identifier ? */
     {
	*sym++ = c;
	while ( ( c = getone( f )) == '_' || isalnum(c) )
	  *sym++ = c;
	*sym = '\0';
	lastchar = c;
	return ID;
     }

   *sym++ = c;
   *sym = '\0';
   return OTHER;

}
	

/*--------------------------------------------------------------*/
/*	setenv: insert an environment variable into my list	*/
/*--------------------------------------------------------------*/

static void setenv( var, value )
char *var;
char *value;
{
	register ENV *p;

	for ( p = &profile[0];
	      *(p->name) != '\0';
	      ++p ) 
	  {
	     if ( strcmp( p->name, var ) == SAME )
		{

	  	   strcpy( p->name, var );
		   strcpy( p->value, value);
		   break;
		}
	   }
}

/*--------------------------------------------------------------*/
/*	getenv: get pointer to value of environment variable	*/
/*--------------------------------------------------------------*/

static char *getenv( var )
char *var;
{
	register ENV *p;

	for ( p = &profile[0];
	      *(p->name) != '\0';
	      ++p )
	  {
	     if ( strcmp( p->name, var ) == SAME )
	        if ( *p->value != '\0' )
		   return p->value;
		else
		   break;
	  }
	return NULL;
}

/*--------------------------------------------------------------*/
/*	readenv: read environment from a file. 			*/
/*--------------------------------------------------------------*/

static void readenv()
{
   FILE *f;
   int symval;
   char name[MAXLINE+1], value[MAXLINE+1];

   fprintf( stderr, "Opening profile\n");
   if ( (f = fopen( PROFILE, "r" )) == NULL )
     {
	fprintf( stderr, "Can't open profile file \"%s\"\n",
	PROFILE );
	exit( NULL );
     }

    /* File is layed out as follows:

    <environment variable> '=' <ID> | <STRING> # comment....

     */
 
    while ( (symval = getsym( f, name )) != EOF )
      {
	/* Skip over any comment lines */

	while ( symval == EOL )
	   symval = getsym( f, name );
	if ( symval == EOF )
	   break;

	if ( symval != ID )
	  {
	     fprintf( stderr, "Bad environment variable name %s\n", name );
	     exit( NULL );
	  }

	if ( (symval = getsym( f, value )) != DELIM )
	  {
	     fprintf( stderr, "Missing '=' in environment file\n" );
	     exit( NULL );
	  }

	if ( (symval = getsym( f, value )) != ID && symval != STR )
	  {
	     fprintf( stderr, "missing value in environment file\n");
	     exit( NULL );
	  }

	setenv( name, value );
      }
    fclose( f );

}

/*--------------------------------------------------------------*/
/*	exitenv: free that memory when done!			*/
/*--------------------------------------------------------------*/

void exitenv()
{
}

static 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 ); /**/
}

void loadenv()
{

	readenv();	/* read the profile from a file */ 

	/* 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( &logdir, LOGDIR, DLOGDIR );
	genv( &pubdir, PUBDIR, DPUBDIR );
	genv( &mailserv, MAILSERVICE, DMAILSERVICE );
	genv( &nodename, NODENAME, DNODENAME );
	genv( &device, DEVICE, DDEVICE );
	genv( &speed, SPEED, DSPEED );
	genv( &tempdir, TEMPDIR, DTEMPDIR );
	genv( &newsdir, NEWSDIR2, DNEWSDIR );
}
 
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()
{
	register ENV *p;

	loadenv();

	for ( p = &profile[0];
	      *(p->name) != '\0';
	      ++p)

	    fprintf( stderr, "name=\"%s\", value=\"%s\"\n",
		     p->name, p->value);
} 

#endif



SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/genv.dyna'
then
       echo shar: will not over-write existing file "'amiga/genv.dyna'"
else
cat << \SHAR_EOF > 'amiga/genv.dyna'
/* 		genv.c
 
 
 
		copyright (C) 1987 Jeff Lydiatt
 
		Copying and use of this program are controlled by the terms of the
		Free Software Foundations GNU Emacs General Public License.
 
 
		version		0.1		10 July 87
 
 
 
*/
 
#include <stdio.h>
 
#include "genv.h"

     /* Environment variables are in file "PROFILE" */
#define PROFILE ":usr/lib/uucp/profile"

#define SAME	0
#define MAXLINE 255

#define DMAILBOX	"mailbox"
#define	DNAME		"noname"
#define	DDOMAIN		"pc.uucp"
#define	DMAILDIR	":usr/spool/mail"
#define DHOME		":usr/noname"
#define	DCONFDIR	":usr/lib/uucp"
#define	DSPOOLDIR	":usr/spool/uucp"
#define DLOGDIR		":usr/spool/uucp"
#define DPUBDIR		":usr/spool/uucppublic"
#define DNEWSSDIR	":usr/spool/rnews"
#define DTEMPDIR	"RAM:T"
#define	DMAILSERVICE	"host"
#define	DNODENAME	"noname"
#define	DDEVICE		"CON:"
#define	DSPEED		"1200"

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

#include <stdio.h>
#include <ctype.h>

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

/*--------------------------------------------------------------*/
/*	getone: get next character file f.  f already open	*/
/*--------------------------------------------------------------*/

static int getone( f )
FILE *f;
{
   char c, line[256];
   static int pos = 0;
   static int len = 0;

   if ( ++pos > len || line[pos] == '\0' ) 
     {
	if ( fgets( line, 255, f ) == NULL )
	   return EOF;
	pos = 0;
	len = strlen( line );
     }

   c = line[pos];
   return c;
   
}

/*--------------------------------------------------------------*/
/*	getsym: get next symbol from file f.  f already open	*/
/*--------------------------------------------------------------*/

#define ID	1001
#define DELIM	1002
#define STR	1003
#define EOL	1004
#define OTHER	1005
#define UNKNOWN -1000

static int getsym( f, sym )
FILE *f;
char *sym;
{
   /* Simple non reentrant, non reuseable get next symbol from file f */
   /* Valid symbols are:
        Type	Symbol Returned	Comment

	ID	<identifier>	any valid c identifier.
        DELIM	'='		an equal sign.
	STR	a string	anything between "" or ''.
	EOL	'\n'		a newline.
	EOF			the end of file character.
	OTHER   a character	anything else.
	
	Comments begin with # and are delimited by an end of line
   */

   static int lastchar = UNKNOWN;
   int c, delim;

   /* strip leading white space */

   if ( lastchar != UNKNOWN )
      c = lastchar;
   else
      c = getone( f );

   while ( c == ' ' || c == '\t' )
      c = getone( f );
   lastchar = UNKNOWN;
 
  /* Comments are '#' delimited by EOL character */

   if ( c == '#' )
      while ( c != '\n' && c != EOF )
	 c = getone( f );

   if ( c == EOF )		/* End of file? */
      return EOF;

   if ( c == '\n' )		/* End of Line? */
     {
	strcpy( sym, "\n" );
	return EOL;
     }

   if ( c == '=' )		/* Delimiter '='? */
     {
	strcpy( sym, "=" );
	return DELIM;
     } 

   if ( c == '\"' || c == '\'' )/* String ? */
     {
	delim = c;
	while ( (c = getone( f )) != delim && c != EOF && c != '\n' )
	   *sym++ = c;
	*sym = '\0';
	c = getone( f );
	return STR;
     }

   if ( isalpha( c ) )		/* Identifier ? */
     {
	*sym++ = c;
	while ( ( c = getone( f )) == '_' || isalnum(c) )
	  *sym++ = c;
	*sym = '\0';
	lastchar = c;
	return ID;
     }

   *sym++ = c;
   *sym = '\0';
   return OTHER;

}
	
/*--------------------------------------------------------------*/
/*	xmalloc: Just alloc with die on allocation failure	*/
/*--------------------------------------------------------------*/
static char *xmalloc( size )
unsigned int size;
{
	char *malloc();
	register char *p;


	if ( (p = malloc( size )) != NULL )
	   return p;

	fprintf( stderr, "Genv.c: Can't allocated %u bytes\n", size );
	exit( NULL );
}

/*--------------------------------------------------------------*/
/*	setenv: insert an environment variable into my list	*/
/*--------------------------------------------------------------*/

struct environment
   {
	struct environment *next;
	char *name;
	char *value;
   };

typedef struct environment ENV;

static ENV *envList = NULL;

static void setenv( var, value )
char *var;
char *value;
{
	register ENV *envframe;

	envframe = (ENV *) xmalloc( sizeof( ENV ));
	envframe->name  = xmalloc( strlen(var)+1 );
	envframe->value = xmalloc( strlen(value)+1 );
	envframe->next  = envList;
	envList		= envframe;
	
	strcpy( envframe->name, var );
	strcpy( envframe->value, value);
}

/*--------------------------------------------------------------*/
/*	getenv: get pointer to value of environment variable	*/
/*--------------------------------------------------------------*/

static char *getenv( var )
char *var;
{
	register ENV *list;

	for ( list = envList;
	      list != (ENV *)NULL;
	      list = list->next )
	   if ( strcmp( var, list->name ) == SAME )
		return list->value;

	return NULL;
}

/*--------------------------------------------------------------*/
/*	readenv: read environment from a file. 			*/
/*--------------------------------------------------------------*/

static void readenv()
{
   FILE *f;
   int symval;
   char name[MAXLINE+1], value[MAXLINE+1];

   if ( (f = fopen( PROFILE, "r" )) == NULL )
     {
	fprintf( stderr, "Can't open profile file \"%s\"\n",
	PROFILE );
	exit( NULL );
     }

    /* File is layed out as follows:

    <environment variable> '=' <ID> | <STRING> # comment....

     */
 
    while ( (symval = getsym( f, name )) != EOF )
      {
	/* Skip over any comment lines */

	while ( symval == EOL )
	   symval = getsym( f, name );
	if ( symval == EOF )
	   break;

	if ( symval != ID )
	  {
	     fprintf( stderr, "Bad environment variable name %s\n", name );
	     exit( NULL );
	  }

	if ( (symval = getsym( f, value )) != DELIM )
	  {
	     fprintf( stderr, "Missing '=' in environment file\n" );
	     exit( NULL );
	  }

	if ( (symval = getsym( f, value )) != ID && symval != STR )
	  {
	     fprintf( stderr, "missing value in environment file\n");
	     exit( NULL );
	  }

	setenv( name, value );
      }
    fclose( f );

}

/*--------------------------------------------------------------*/
/*	exitenv: free that memory when done!			*/
/*--------------------------------------------------------------*/

void exitenv()
{
	register ENV *p, *q;	

	for ( p = envList; p != NULL; p = q )
	  {
		free( p->name );
		free( p->value);
		q = p->next;
		free( p );
	  }
	envList = NULL;
}

static 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 ); /**/
}

void loadenv()
{

	readenv();	/* read the profile from a file */ 

	/* 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( &logdir, LOGDIR, DLOGDIR );
	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()
{
	register ENV *p;	

	loadenv();

	for ( p = envList; p != NULL; p = p->next )
	  fprintf( stderr, "Name=\"%s\" value=\"%s\"\n", 
		   p->name, p->value );
	
}
#endif



SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/genv.h'
then
       echo shar: will not over-write existing file "'amiga/genv.h'"
else
cat << \SHAR_EOF > 'amiga/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"
	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"
	LOGDIR		where log file are placed	"/usr/spool/uucp"
	PUBDIR		public spool directory		"/usr/spool/uucppublic"
	NEWSDIR		news directory			"/usr/spool/news"
	TEMPDIR		where temp files are created	"/tmp"
	HOME		where uses private files are	"/usr/sl"
	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"
 
*/
 

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

#define	CONFDIR		"CONFDIR"
#define SPOOLDIR	"SPOOLDIR"
#define LOGDIR		"LOGDIR"
#define	PUBDIR		"PUBDIR"
#define NEWSDIR2	"NEWSDIR"
#define TEMPDIR		"TEMPDIR"
#define	MAILSERVICE	"MAILSERVICE"

#define NODENAME	"NODENAME"
#define	DEVICE		"DEVICE"
#define	SPEED		"SPEED"
 
extern char	*mailbox;
extern char	*name;
extern char	*domain;
extern char	*maildir;
extern char	*home;

extern char	*confdir;
extern char	*spooldir;
extern char	*logdir;
extern char	*pubdir;
extern char	*tempdir;
extern char	*mailserv;

extern char	*nodename;
extern char	*device;
extern char	*speed;
extern char	*newsdir;

void loadenv();
void mkfilename();



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

#include <libraries/dos.h>
#include <exec/memory.h>
#include <functions.h>

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

#ifndef NULL
#define NULL 0L
#endif

char * malloc();

/*--------------------------------------------------------------*/
/*    GetCurrentPath: get full path of the current directory    */
/*--------------------------------------------------------------*/

static void GetCurrentPath( path )
register char *path;
{

	char s1[ 108 ];
	char *name;
	register struct Lock *locka, *lockb;
        register struct FileInfoBlock *fib;

	fib = (struct FileInfoBlock *)AllocMem(
	      (long)sizeof(struct FileInfoBlock), MEMF_CHIP | MEMF_CLEAR);
	if ( fib == 0L )
	   {
#ifdef TEST
	     fprintf( stderr, "GetCurrentPath: Oops - Memory allocation failed\n");
#endif
	     *path = '\0';
	     return;
	   }
	
	locka = Lock("", ACCESS_READ );
	*path = s1[0] = '\0';

	while ( locka != NULL )
	  {
	    Examine( locka, fib );
	    name = fib->fib_FileName;
	    if ( *name == '\0' )
		strcpy( path, "RAM" ); /* Patch for Ram disk bug */
	    else
		strcpy( path, name );
	    lockb = ParentDir( locka );
	    UnLock( locka );
	    
	    if ( lockb == NULL )
	        strcat( path, ":");
	    else if ( s1[0] != '\0' )
		strcat( path, "/");
	    strcat( path, s1 );
	    strcpy( s1, path );
	    locka = lockb;
	  }

	FreeMem( fib, (long)sizeof(struct FileInfoBlock) );
}

/*--------------------------------------------------------------*/
/*	getcwd: return the path name of the current directory	*/
/*--------------------------------------------------------------*/

char *getcwd( path, size )
char *path;
int size;
{
	if ( path == (char *)NULL )
	   {
	     if ( (path = malloc(108)) == NULL)
		{
#ifdef TEST
		   fprintf( stderr, "getcwd: malloc failed to get 108 bytes\n");
#endif
		   return NULL;
		}
	   }
	GetCurrentPath( path );
	return path;
}

#ifdef TEST
main()
{

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

#endif



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

		Amiga host 

*/

#include <stdio.h>
#include "host.h"

#include <ctype.h>
#include <setjmp.h>
#include <errno.h>

static char *curdir;
char * getcwd();
int chdir();
int	debuglevel;		/* debuglevelging level */

jmp_buf	dcpexit;

main( argc, argv )
int	argc;
char *argv[];
{

	/* Amiga specific prolog */

	loadenv();
	curdir = getcwd( NULL, 0 );

#ifdef CWDSPOOL
	chdir( spooldir );
#endif

	/* setup longjmp for error exit's */
	if ( setjmp( dcpexit ) == 0 ) {

		MAIN( argc, argv );

	}

	/* Amiga specific epilog */

	exitenv();
	chdir( curdir );
	exit( NULL );

}


/* canonical name conversio routines

	inportpath	canonical -> host
	exportpath	host -> canonical

	host		your local pathname format
	canonical	unix style
*/

importpath( host, canon )
char * host;
char * canon;
{
        register char *s;

	strcpy( host, canon );

        if ( *host == '/' )
	  *host = ':';
}

exportpath( canon, host )
char * host;
char * canon;
{
	strcpy( canon, host );
	if ( *canon == ':' )
	   *canon = '/';
}





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

		Amiga version

*/

#include <time.h>
#include <errno.h>
#include <ctype.h>

#define AMIGA   1
#define SAME 	0
#define	FALSE	0
#define	TRUE	1

#define	TFILENAME	"tmpfile.%.7d"
#define	SFILENAME	"SEQF"

#define SEPCHAR		'/'	/* path separater character		*/
#define SIGFILE		".signature"	/* file containing signature	*/
#define COPYFILE	"mail.sent"	/* copy of sent mail	*/

#define HOSTINIT		/* name of function used to initialize	*/

#define FILEMODE(f)

#define	CALLFILE	"C.%s"
#define	XQTFILE		"X.%s"

#include "local/genv.h"

extern	char * fgets();
extern	char * index();

extern 	int	debuglevel;                  /* debuglevelging level */




SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/mkdir.c'
then
       echo shar: will not over-write existing file "'amiga/mkdir.c'"
else
cat << \SHAR_EOF > 'amiga/mkdir.c'
#include <libraries/dos.h>
#include <exec/memory.h>
#include <functions.h>

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

#ifndef NULL
#define NULL 0L
#endif


/*--------------------------------------------------------------*/
/*	mkdir(name): make a directory with the given name.	*/
/*--------------------------------------------------------------*/

int mkdir( name )
char *name;
{
	register struct Lock *lock;

#ifdef TEST
	fprintf( stderr, "mkdir: %s\n", name );
#endif
	lock = CreateDir( name );
	if ( !lock )
	   return (int)IoErr();
	else 
	   UnLock( lock );
	return 0;
}

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

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

#endif



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


		Amiga library
		

	Things to do in uu host

		serial I/O
		
		directory stuff
			opendir, readdir, closedir

		prolog and epilog

		system call

*/

#include <stdio.h>
#include "host.h"
#include <sgtty.h>

int get_one()
{
	char c;
	
	struct sgttyb stty, sttyo;
	ioctl( 0, TIOCGETP, &stty );
	sttyo = stty;
	stty.sg_flags |= RAW;
/*	stty.sg_flags &= ~ ECHO; */
	ioctl( 0, TIOCSETP, &stty );

	c = fgetc( stdin );
	ioctl( 0, TIOCSETP, &sttyo );

	return( c );
}





SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/ndir.c'
then
       echo shar: will not over-write existing file "'amiga/ndir.c'"
else
cat << \SHAR_EOF > 'amiga/ndir.c'
#include "ndir.h"
#include <exec/memory.h>
#include <functions.h>

#ifdef TEST
#include <stdio.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;
	struct Lock  *lock;

#ifdef TEST
	fprintf( stderr, "opendir: Opening \"%s\"\n", name );
#endif
	if ( ( lock = Lock( name, ACCESS_READ )) == NULL )
	  {
#ifdef TEST
		fprintf( stderr, "opendir: Can't open.\n" );
#endif
		return NULL;
	  }

	if ( (dirp = (DIR *)malloc(sizeof(DIR))) == NULL )
	  {
#ifdef TEST
		fprintf( stderr, "opendir: couldn't malloc %d\n",sizeof(DIR));
#endif
		UnLock( lock );
		return NULL;
	  }
	if ( !Examine( lock, &dirp->fib) )
	  {
#ifdef TEST
	     fprintf( stderr, "opendir: Couldn't Examine directory\n" );
#endif
	     free( dirp );
	     UnLock( lock );
	  }

	dirp->lock = lock;
#ifdef TEST
	fprintf( stderr, "opendir: Sucessful\n" );
#endif

	return dirp;
}


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

	while ( ExNext( dirp->lock, &dirp->fib ) )
	   {
		if ( dirp->fib.fib_DirEntryType <= 0 )
		  {
			dir.d_ino = 0;
			strcpy( dir.d_name, dirp->fib.fib_FileName );
#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);
		  }
	    }

#ifdef TEST
	fprintf( stderr, "readdir: No More Entries.\n" );
#endif
	strcpy( dir.d_name, "" );
	return NULL;

}

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

	UnLock( dirp->lock );
	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 );
		}
		else
		   {
			while ((dp = readdir(dirp)) != NULL) 
				fprintf( stderr, "%s", dp->d_name );
		
			closedir( dirp );
		   }    
	}
}
#endif


SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/ndir.h'
then
       echo shar: will not over-write existing file "'amiga/ndir.h'"
else
cat << \SHAR_EOF > 'amiga/ndir.h'
/* @(#)ndir.h	1.4	4/16/85 */
#include <libraries/dos.h>
#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 {
	struct Lock	*lock;
	struct FileInfoBlock fib;
} DIR;
#ifndef NULL
#define NULL 0L
#endif
extern	DIR *opendir();
extern	struct direct *readdir();
extern	void closedir();


SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/SerialIO.c'
then
       echo shar: will not over-write existing file "'amiga/SerialIO.c'"
else
cat << \SHAR_EOF > 'amiga/SerialIO.c'
/*--------------------------------------------------------------*/
/*	SerialIO.c: Amiga Serial I/O Device Routines		*/
/*      Created: June 1986 by J.A. Lydiatt			*/
/*								*/
/*	Note:							*/
/*	  A Task may only open the serial port once.		*/
/*--------------------------------------------------------------*/

#include <exec/types.h>
#include <exec/memory.h>
#include <stdio.h>
#include <devices/serial.h>
#include <functions.h>

/* Allowable Mode Values */
#define MODEHALF    0
#define MODEFULL    1
#define MODEECHO    2

/* Default starting values */
#define STARTBAUD   1200  /* default baud rate */
#define STARTMODE   MODEFULL
#define SERFLAGS    (SERF_SHARED | SERF_XDISABLED)
#define CTLCHAR     0x11130501    

static int Mode = STARTMODE;
static int amClosing = FALSE;

/* declarations for the serial stuff */
static struct IOExtSer *Read_Request = NULL;
static UBYTE rs_in[2];
static struct IOExtSer *Write_Request = NULL;
static UBYTE rs_out[2];

/* stack to save Serial Port flags */
#define MAXSTACK 10
static int stackSize = 0;
static int   modeStack[ MAXSTACK ];
static UBYTE flagStack[ MAXSTACK ];


/*------------------------------------------------------------*/
/*  GetSerialSigBit: return Read_Request's Signal Bit	      */
/*------------------------------------------------------------*/

int GetSerialSigBit()
{
   return Read_Request->IOSer.io_Message.mn_ReplyPort->mp_SigBit;
}

/*------------------------------------------------------------*/
/*  CheckSerIO : return TRUE if serial port has a character   */
/*------------------------------------------------------------*/

BOOL CheckSerIO()
{
   return (BOOL)( CheckIO( Read_Request ) != NULL);
}

/*------------------------------------------------------------*/
/* 	 FlushSerIO: Flush the receive buffer		      */
/*------------------------------------------------------------*/

void FlushSerIO()
{
   register struct IOExtSer *r = Read_Request;

   AbortIO( r );                 /* abort it */
   AbortIO( Write_Request );

   r->IOSer.io_Command = CMD_FLUSH;
   DoIO( r );                       /* flush all IO requests */
   r->IOSer.io_Command = CMD_CLEAR;
   DoIO( r);                       /* flush receive buffer  */

   if ( !amClosing )
     {
        Read_Request->IOSer.io_Command = CMD_READ;
        BeginIO( r );		   /* start receive request */
     }
}


/*------------------------------------------------------------*/
/*  PushSerState: save current io flags                       */
/*------------------------------------------------------------*/
void PushSerState()
{
   register struct IOExtSer *r = Read_Request; 

   if ( stackSize < MAXSTACK )
     {
        /* Save the current Mode */
        modeStack[ stackSize ] = Mode;
        
	/* Get the current flags */
	AbortIO( r );
	flagStack[ stackSize++ ] = r->io_SerFlags;
	BeginIO( r );
     }
}

/*------------------------------------------------------------*/
/*  PullSerState: restore last saved flag state		      */
/*------------------------------------------------------------*/
void PullSerState()
{
   register struct IOExtSer *r = Read_Request; 

   if ( stackSize > 0 )
     {
	/* Reset the Mode */
	Mode = modeStack[ --stackSize ];

	/* Set the old flags */
	AbortIO( r );
	r->io_SerFlags = flagStack[ stackSize ];
	r->IOSer.io_Command = SDCMD_SETPARAMS;
	DoIO( r );
	r->IOSer.io_Command = CMD_READ;
	BeginIO( r );
     }
}
/*-------------------------------------------------------------*/
/*           CloseSerialIO: Close the serial port              */
/*-------------------------------------------------------------*/
void CloseSerialIO()
{
   register struct IOExtSer *r = Read_Request;
   register struct IOExtSer *w = Write_Request;

   if ( r != NULL )
     {
	amClosing = TRUE;
	CloseDevice( r );
	DeletePort( r->IOSer.io_Message.mn_ReplyPort );
	FreeMem( r, (long)sizeof( struct IOExtSer ) );
	Read_Request = NULL;
      }

    if ( w != NULL )
      {
	CloseDevice( w );
	DeletePort( w->IOSer.io_Message.mn_ReplyPort );
	FreeMem( w, (long)sizeof( struct IOExtSer ) );
	Write_Request = NULL;
      }
}
/*-------------------------------------------------------------*/
/* InitSerialIO: Open serial IO - return read Port	       */
/*-------------------------------------------------------------*/	
struct IOExtSer *InitSerialIO()
{
   register struct IOExtSer *r, *w;

   if ( Read_Request != NULL )
      {
	fprintf( stderr, "Error: Serial Port already open for read.\n");
	return NULL;
      }
   r = (struct IOExtSer *) AllocMem( (long)sizeof(struct IOExtSer),
     (long)(MEMF_PUBLIC|MEMF_CLEAR));
   if (r == NULL)
	return NULL;

   Read_Request = r;
   r->io_SerFlags = SERFLAGS;
   r->io_CtlChar  = CTLCHAR;
   r->IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",NULL);
   if(OpenDevice(SERIALNAME,NULL,r,NULL))
      {
	 fprintf( stderr, "Can't open Read device\n");
	goto q4;
      }

   r->io_Baud = STARTBAUD;
   r->io_ReadLen = 8;
   r->io_WriteLen = 8;
   r->IOSer.io_Command = SDCMD_SETPARAMS;
   DoIO(r);
   r->IOSer.io_Command = CMD_READ;
   r->IOSer.io_Length = 1;
   r->IOSer.io_Data = (APTR)&rs_in[0];


   if ( Write_Request != NULL )
      {
	fprintf( stderr, "Error: Serial Port already open for writing.\n");
	goto q3;
      }
   w = (struct IOExtSer *)AllocMem( (long)sizeof( struct IOExtSer ),
      (long)MEMF_PUBLIC|MEMF_CLEAR);
   if (w == NULL) goto q3;

   Write_Request = w;
   w->io_SerFlags = SERFLAGS;
   w->io_CtlChar  = CTLCHAR;
   w->IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS",NULL);
   if(OpenDevice(SERIALNAME,NULL,w,NULL))
      {
	fprintf( stderr, "Can't open Write device\n");
	goto q1;
      }
   w->io_Baud = STARTBAUD;
   w->io_ReadLen = 8;
   w->io_WriteLen = 8;
   w->IOSer.io_Command = SDCMD_SETPARAMS;
   DoIO(w);

   w->IOSer.io_Command = CMD_WRITE;
   w->IOSer.io_Length = 1;
   w->IOSer.io_Data = (APTR)&rs_out[0];

   BeginIO( r );
   stackSize = 0;

   return r;

q1:   DeletePort( w->IOSer.io_Message.mn_ReplyPort );
q2:   FreeMem( w, (long)sizeof( *w) );
q3:   CloseDevice( r );
q4:   DeletePort( r->IOSer.io_Message.mn_ReplyPort );
q5:   FreeMem( r, (long)sizeof( *r) );

   return NULL;
}

/*----------------------------------------------------------*/
/*         SetXonMode: set Xon On or Off                    */
/*----------------------------------------------------------*/

void SetXonMode( status )
BOOL status;
{

   register UBYTE flags;
   register struct IOExtSer *r = Read_Request; 

   /* Get the current flags */
   AbortIO( r );
   flags = r->io_SerFlags;

   if ( status )
      flags &= ~(SERF_XDISABLED);
   else
      flags |= SERF_XDISABLED; 
   r->io_SerFlags = flags;
   r->IOSer.io_Command = SDCMD_SETPARAMS;
   DoIO( r );
   r->IOSer.io_Command = CMD_READ;
   BeginIO( r );
}

/*----------------------------------------------------------*/
/*         SetSerBaud: set Serial Baud Rate                 */
/*----------------------------------------------------------*/

void SetSerBaud( baud )
int baud;
{
   register struct IOExtSer *r = Read_Request; 

   /* Get the current flags */
   AbortIO( r );
   r->io_Baud = baud;
   r->IOSer.io_Command = SDCMD_SETPARAMS;
   DoIO( r );
   r->IOSer.io_Command = CMD_READ;
   BeginIO( r );
}

/*----------------------------------------------------------*/
/*         SetSerMode: set the Serial Mode		    */
/*----------------------------------------------------------*/

void SetSerMode( mode )
int mode;
{
   Mode = mode;
}

/*----------------------------------------------------------*/
/*   SerIOWrite: Write a byte out the serial port (no echo) */
/*----------------------------------------------------------*/

void SerIOWrite( c )
register UBYTE c;
{
  *rs_out = c;
  DoIO( Write_Request );
}

/*----------------------------------------------------------*/
/* SerIORead: read a byte from the serial port (no echo)    */
/*----------------------------------------------------------*/

UBYTE SerIORead()
{
   register struct IOExtSer *r = Read_Request;
   register UBYTE c;

   WaitIO( r );
   c = *rs_in;
   BeginIO( r );
   return c;
}


SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/sio.c'
then
       echo shar: will not over-write existing file "'amiga/sio.c'"
else
cat << \SHAR_EOF > 'amiga/sio.c'
/*------------------------------------------------------------------*/
/*	Sio.c:  Serial I/O for Amiga Version of PCMail		    */
/*	Created: 27Jun87 by J.A. Lydiatt			    */
/*								    */
/* Exports the following routines required by PCMail:		    */
/*  SIOInit():		Initialize Serial Port			    */
/*  SIOClose():		Close and free Serial Port resources	    */
/*  SIOSpeed():		Set bps					    */
/*  SIORead():		read characters from serial port	    */
/*  SIOWrite():		write characters to serial port		    */
/*  SIOInBuffer():	Set Buffer size for read & writes.	    */
/*  SIOOutBuffer():	(Has no effect in Amiga Version)	    */
/*------------------------------------------------------------------*/

#include <stdio.h>
#ifndef TRUE
#define TRUE -1
#define FALSE 0
#endif

/*--- Timer Function Declarations --- */

extern void CloseTimer();	/* Return Timer's resources to the System */
extern int  OpenTimer(); 	/* Returns True if Timer Device Opened OK */ 
extern void StartTimer();	/* (long)seconds, (long)microseconds      */
extern int  TimerExpired();     /* Returns True if Timer interval expired */

/*--- SerialIO Function Declarations --- */

extern struct EOExtSer *InitSerialIO(); /* problems? return NULL	  */
extern void CloseSerialIO();		/* Return SerialIO resources	  */
extern int  CheckSerIO();		/* TRUE if character available    */
extern char SerIORead();		/* Returns a Char from serial port*/
extern void SerIOWrite(); 		/* Writes one byte to serial port */ 
extern void SetSerBaud();		/* (int)baud - set baud rate	  */

/*--------------------------------------------------------------*/
/*	 getspeed/getbaud: check for valid baud parameters	*/
/*--------------------------------------------------------------*/

static struct {
	unsigned baudr;
	int speedcode;

} speeds[] = {
	300,	300,
	1200,	1200,
	2400,	2400,
	4800,	4800,
	9600,	9600,
	19200, 19200,
	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: initialize serial I/O				*/
/*--------------------------------------------------------------*/


SIOInit ( whichport, speed )
char * whichport;
char * speed;
{
	unsigned int baud;
	extern void SetXonMode();

	/*  fprintf( stderr, "sioinit %s %s\n", whichport, speed ); /* */

	if ( InitSerialIO() == NULL ) {
		fprintf( stderr, "Can't open Serial Port\n" );
		return( -1 );
	}

     if ( baud = getbaud( speed ) )
	SetSerBaud( baud );

     if ( !OpenTimer() )
	{
	   CloseSerialIO();
	   fprintf( stderr, "Can't open the Timer Device\n" );
	   return -1;
        }

     SetXonMode( (int)FALSE );
     return( 0 );
}

/*--------------------------------------------------------------*/
/*	SIOSpeed:  set the serial Baud rate 			*/
/*--------------------------------------------------------------*/

SIOSpeed( speed )
char *speed;
{
    unsigned int baud;

    if ( baud = getbaud( speed ) )
	SetSerBaud( baud );
}

/*--------------------------------------------------------------*/
/*	SIOInBuffer/ SIOOutBuffer:	Set Buffer Size.	*/
/*--------------------------------------------------------------*/

SIOInBuffer ( buf, size )
char * buf;
int size;
{
}

SIOOutBuffer ( buf, size )
char * buf;
int size;
{
}

/*--------------------------------------------------------------*/
/*	SIOClose:	Close Serial port.			*/
/*--------------------------------------------------------------*/

SIOClose ( dtr )
{
   CloseSerialIO();
   CloseTimer();
}

/*--------------------------------------------------------------*/
/*	SIOWrite: send count characters to serial port		*/
/*--------------------------------------------------------------*/

SIOWrite ( buf, count )
register char * buf;
int count;
{
	register int nsent;

	nsent = count;
	while ( nsent-- )
	   SerIOWrite( *buf++ );

	return count;
}

/*--------------------------------------------------------------*/
/*	SIORead: read mincount <= #characters <= maxcount	*/
/*	return  # of characters read, or -1 if timed out after	*/
/*	after tenths / 10 seconds.				*/
/*--------------------------------------------------------------*/


int SIORead ( buf, mincount, maxcount, tenths )
register char *buf;
int	mincount;
int	maxcount;
int	tenths; /* timeout is in tenth's of seconds */
{
        /* A bit of a Kludge to get the project started */

	long seconds, microSeconds;
	unsigned long waitMask;
	int  timerON ;
	register int received;

	/* fprintf (stderr, "Read  m= %d T= %ld", maxcount, Ticks  );/**/



	if ( tenths == 0 )
	   {
		if ( !CheckSerIO() )
		   return -1;
		tenths = 10;
	   }
        seconds = tenths / 10;
	microSeconds = ((long)(tenths) - seconds * 10L) * 100000L;
        
	received = 0;
	waitMask = (1L << GetSerialSigBit()) | (1L << GetTimerSigBit() ); 
	timerON = FALSE;
	do
	  {
	     if ( CheckSerIO() )
	        {
	     	   *buf = SerIORead();
		   ++buf;
		   ++received;
		   if ( mincount <= received && received <= maxcount )
		      return received;
		}
	     if ( !timerON )
		{
		   StartTimer( seconds, microSeconds );
		   timerON = TRUE;
		}
	     Wait( waitMask );

	  }	while ( !TimerExpired() );

	return -1;
}


SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/sleep.c'
then
       echo shar: will not over-write existing file "'amiga/sleep.c'"
else
cat << \SHAR_EOF > 'amiga/sleep.c'
/*--------------------------------------------------------------*/
/* sleep.c:	Implement sleep( seconds ) on the Amiga.	*/
/*--------------------------------------------------------------*/

void sleep( seconds )
unsigned int seconds;
{
     if ( seconds > 0 )
	Delay( (long)( seconds * 50L ));
}

SHAR_EOF
fi # end of overwriting check
if test -f 'amiga/Timer.c'
then
       echo shar: will not over-write existing file "'amiga/Timer.c'"
else
cat << \SHAR_EOF > 'amiga/Timer.c'
/*  
 *  Timer.c: Functions to invoke the Amiga timer:
 *  
 *  External Functions:
 *
 *  OpenTimer, CloseTimer, StartTimer, TimerExpired, GetTimerSigBit
 * 
 *  Maintenance Notes:
 *   05Jul86  - Created by Jeff Lydiatt, Vancouver, Canada.
 */

#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/ports.h>
#include <exec/tasks.h>
#include <exec/io.h>
#include <devices/timer.h>
#include <functions.h>

static struct timerequest TimerIO;
static struct MsgPort    *TimerPort = NULL;
static BOOL timerON;
static BOOL timerExpired;

/*-------------------------------------------------------------*/
/*	OpenTimer: return TRUE if timer opened OK	       */
/*-------------------------------------------------------------*/

BOOL OpenTimer()
{
   register struct timerequest *t = &TimerIO;
   register struct MsgPort *port;

   timerON = FALSE;
   timerExpired = TRUE;
   if ( TimerPort != NULL )
      return TRUE;

   if ( (port = CreatePort("Timer Port", 0L)) == NULL )
      return FALSE;
   else
      TimerPort = port;

   if (OpenDevice(TIMERNAME, UNIT_VBLANK, t, 0L) != 0)
     {
	DeletePort( port );
	TimerPort = NULL;
	return FALSE;
     }

   return TRUE;
}

/*-------------------------------------------------------------*/
/*	CloseTimer: All Done with the timer.		       */
/*-------------------------------------------------------------*/

void CloseTimer()
{
   register struct timerequest *t = &TimerIO;

   if ( timerON )
      AbortIO( t );

   CloseDevice( t );
   DeletePort( TimerPort );
   TimerPort = NULL;
}

/*-------------------------------------------------------------*/
/*	GetTimerSigBit: return Timer signal bit		       */
/*-------------------------------------------------------------*/

int GetTimerSigBit()
{
   return TimerPort->mp_SigBit;
}

/*-------------------------------------------------------------*/
/*	StartTimer: launch the timer.			       */
/*-------------------------------------------------------------*/

void StartTimer(seconds, micros)
ULONG seconds, micros;
{
   register struct timerequest *t = &TimerIO;

   if ( timerON )
     {
	AbortIO( t );
	(void) GetMsg( TimerPort );
	timerON = FALSE;
        timerExpired = TRUE;
     }

   t->tr_time.tv_secs = seconds;
   t->tr_time.tv_micro = micros;
   t->tr_node.io_Command = TR_ADDREQUEST;
   t->tr_node.io_Flags = IOF_QUICK;
   t->tr_node.io_Error = 0;
   t->tr_node.io_Message.mn_ReplyPort = TimerPort;
   SendIO( t );
   timerExpired = FALSE;
   timerON = TRUE;
}

/*-------------------------------------------------------------*/
/*	TimerExpired: returns TRUE if timer expired.	       */
/*-------------------------------------------------------------*/

BOOL TimerExpired()
{
   if ( timerON && ( CheckIO( &TimerIO.tr_node ) == NULL) )
      return FALSE;

   (void)GetMsg( TimerPort );
   timerExpired = TRUE;
   timerON = FALSE;

   return timerExpired;
}


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


		Amiga library
		

	Things to do in uu host

		serial I/O
		
		directory stuff
			opendir, readdir, closedir

		prolog and epilog

		system call

*/

#include <stdio.h>
#include "host.h"
#include <sgtty.h>

/**/
/*
 *
 *      login (for slave in PC mode)
 * Real dumb login handshake
*/
login()
{
	char	logmsg[132];
#ifdef PC
lretry:
	msgtime = 9999;
	rmsg(logmsg, 0); /* wait for a <CR> or <NL> */
	msgtime = 2 * MSGTIME;
	wmsg("Username:", 0);
	rmsg(logmsg, 0);
	printmsg( 0, "Username = %s", logmsg );
	wmsg("Password:", 0);
	rmsg(logmsg, 0);
	printmsg( 14, "Password = %s", logmsg );
	if (strcmp(logmsg, "uucp") != 0) 
		goto lretry;
#endif
	return('I');
}


char inbuf[BUFSIZ];
char outbuf[BUFSIZ];

swrite(data, num)
int	num;
char	*data;
{

	int test;
	unsigned char * cp;

	if (debuglevel > 14)
		fputc( '{', stderr );
	if (debuglevel > 14) {
		test = num;
		cp = data;
		while (test--)
			fprintf( stderr, isprint(*cp)? "{%c}":"{%02x}", *cp++ );
	}
	test = SIOWrite( data, num );
	if (debuglevel > 14)
		fputc( '}', stderr );
	return( test );

}

/* non-blocking read essential to "g" protocol */
/* see "dcpgpkt.c" for description */
/* This all changes in a mtask systems. Requests for */
/* I/O should get qued and an event flag given. Then the */
/* requesting process (e.g.gmachine()) waits for the event */
/* flag to fire processing either a read or a write. */
/* Could be implemented on VAX/VMS or DG but not MS-DOS */
sread(buf, num, timeout)
char	*buf;
int	num, timeout;
{
/*
	return( SIORead( buf, num, num, timeout*10 ) );
*/
	int count;
	int test;
	unsigned char * cp;

	if (debuglevel > 13)
		fputc( '[', stderr );
	printmsg( 15, "sread: num: %d  timeout: %d", num, timeout );
		
	count = SIORead( buf, num, num, timeout*10 );
	printmsg( 15, "sread: read: %d ", count );

	if (debuglevel > 13 && count > 0) {
		test = count;
		cp = buf;
		while (test--)
			fprintf( stderr, isprint(*cp)? "[%c]":"[%02x]", *cp++ );
	}
		
	if (debuglevel > 13)
		fputc( ']', stderr );
	return( count );	
	
}



openline(name, baud)
char	*name, *baud;
{

	printmsg( 3, "openline: name: \"%s\"  baud: \"%s\"", name, baud );
	if ( SIOInit( name, baud ) )
	   return -1;
	SIOInBuffer( inbuf, BUFSIZ );
	SIOOutBuffer( outbuf, BUFSIZ );
	return( 0 );
}


closeline()
{
	SIOClose( 1 );
}


nodot(string)
{
}



notimp( argc, argv )
char *argv[];
{
	/*debuglevelMsg("\Pcheck argc (08) and argv (0a) ");*/
	fprintf( stderr, "shell: %s not implemented\n", *argv );
}

/*------------------------------------------------------------------*/
/*	RNews:	my private rnews!				    */
/*------------------------------------------------------------------*/
static void RNews( inname )
char *inname;
{
	extern	char *newsdir;
	register struct tm	*thetm;
	long	tloc;
	char	filename[132];
	char	format[128];
	FILE 	*f, *fin;
	FILE	*FOPEN();
	char	buf[BUFSIZ];
	
	static int count = 0;
	int	len;
	
	/* inname is of form "D.jlamiBCnnnn".  Pick off the nnnn. */
	len = strlen( inname ) - 1;
	while ( len >= 0 )
	  {
		if ( '0' <= inname[len] && inname[len] <= '9' )
		   --len;
		else
		   break;
	   }

	sprintf( filename, "%s/%s", newsdir, &inname[len+1] );
	if ( (f = FOPEN( filename, "r" )) != NULL )
	   {
		/* Already exists, so make a timestamped one. */
		fclose( f );	
		tloc = time( (long *)NULL );
		thetm = localtime( &tloc );

		sprintf( filename, "%s/%02d%02d%02d%02d%02d%02d.%03d",
			newsdir,
			thetm->tm_year % 100, thetm->tm_mon,
			thetm->tm_mday, thetm->tm_hour,
			thetm->tm_min,  thetm->tm_sec,  count
			);
		++count;
	   }
	
	if ( TRUE /*debuglevel > 5*/ )
		fprintf( stderr, "rnews: %s\n", filename );
	
	if ( (f = FOPEN( filename, "w" )) == (FILE *)NULL ) {
		fprintf( stderr, "rnews: can't open %s\n", filename );
		return;
	}

	if ( (fin = FOPEN( inname, "r" )) == NULL )
	  {
		fprintf( stderr, "rnews: Couldn't open %s\n", inname );
		fclose( f );
		return;
	  }
	
	while ( fgets( buf, BUFSIZ, fin ) != (char *)NULL ) 
		fputs( buf, f );

	fclose( f );
	fclose( fin );
}



/* 		shell


*/

char * getcwd();

shell( command, inname, outname, errname )
char * command;
char * inname;
char * outname;
{

	char	* argvec[50];

	int rmail();
	int rnews();
	
	int 	argcp;

	char **argvp;
	char args;
	

	int	(*proto)();
	
	argcp = 0;

	argcp = getargs( command, argvec );

	argvp = argvec;
	args = argcp;

	if ( debuglevel > 5 ) {
		while ( args ) 
			fprintf( stderr, "arg: %d  %s\n", args--, *argvp++ );
		argvp = argvec;
		args = argcp;
	}
	/* */
	
	proto = notimp;

	if ( strcmp( *argvp, "rmail" ) == SAME )
		proto = rmail;

	else if ( strcmp( *argvp, "rnews" ) == SAME ) {
		/* proto = rnews; */
		RNews( inname );
		return; 
	}
		
	if ( *inname != '\0' ) {
		fprintf( stderr, "reopening stdin as %s\n", inname );
		fprintf( stderr, "curdir: %s\n", getcwd(NULL, 0)); /* */
		if ( freopen( inname, "r", stdin ) == NULL ) 
			fprintf( stderr, "Couldn't open %s, %d\n", inname, errno );
	}
	(proto)( argcp, argvp );

	freopen( "con:", "r", stdin );

}






SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0

--
{ubc-vision,uunet}!van-bc!sl				Stuart.Lynne@van-bc.uucp