[comp.sources.atari.st] v01i066: uupc -- UUCP clone

koreth@ssyx.ucsc.edu (Steven Grimm) (07/30/88)

Submitted-by: koreth@ssyx.ucsc.edu (Steven Grimm)
Posting-number: Volume 1, Issue 66
Archive-name: uupc/part02

#!/bin/sh
# this is part 2 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file dcpsys.c continued
#
CurArch=2
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
sed 's/^X//' << 'SHAR_EOF' >> dcpsys.c
X	}
X	sprintf(cname, XQTFILE, rmtname); /* sprintf(cname,"c%.4s",rmtname); */
X	len = strlen(cname);
X	while ((dp = readdir(dirp)) != (struct direct *)NULL) {
X		printmsg( 4, "dscandir: file = %s cname = %s", dp->d_name, cname );
X		if ( strncmp( cname, dp->d_name, len ) == SAME ) {
X			printmsg( 4, "dscandir: match!!" );
X			strcpy(cfile, dp->d_name);
X			closedir( dirp );
X			return( -1 );
X		}
X	}
X	closedir( dirp );
X	return( 0 );
X
X}
X
X
X
X
SHAR_EOF
chmod 0600 dcpsys.c || echo "restore of dcpsys.c fails"
sed 's/^X//' << 'SHAR_EOF' > dcpxfer.c &&
X/*			dcpxfer.c
X
X			Revised edition of dcp
X
X			Stuart Lynne May/87
X
X			Copyright (c) Richard H. Lamb 1985, 1986, 1987
X			Changes Copyright (c) Stuart Lynne 1987
X
X*/
X/* "DCP" a uucp clone. Copyright Richard H. Lamb 1985,1986,1987 */
X/* file send routines */
X#include "dcp.h"
X#include <ctype.h>
X
Xstatic unsigned char	rpacket[MAXPACK];
Xstatic unsigned char	spacket[MAXPACK];
X/**/
X/***************SEND PROTOCOL***************************/
X/*
X *  s d a t a
X *
X *  Send File Data
X */
Xsdata()
X{
X
X	while( TRUE ) {
X
X		if (( *sendpkt) ( spacket, size, 0 ))
X			return (0 );     /* send data */
X		if (( size = bufill( spacket )) == 0 )  /* Get data from file */
X			return( 'Z' ); 						/* If EOF set state to that */
X	}
X
X	return('D');/* Got data, stay in state D */
X
X}
X
X
X/*
X *  b u f i l l
X *
X *  Get a bufferful of data from the file that's being sent.
X *  Only control-quoting is done; 8-bit & repeat count prefixes are
X *  not handled.
X */
Xbufill(buffer)
Xchar	*buffer;/* Buffer */
X{
X	return( read(fp, buffer, pktsize) );/* Handle partial buffer */
X}
X
X
X/*
X *  s b r e a k
X *
X *  Send Break (EOT)
X */
Xsbreak()
X{
X	int	len, i;
X	sprintf(spacket, "H");
X	if ((*sendpkt)(spacket, 0, 1))
X		return(0);
X	if ((*getpkt)(spacket, &len))
X		return(0);
X	printmsg( 2, "Switch modes" );
X	if (spacket[1] == 'N')
X		return('G');
X	return('Y');
X}
X
X
X/**/
X/*
X *  s e o f
X *
X *  Send End-Of-File.
X */
Xseof()
X{
X	int	len, i;
X	if ((*sendpkt)(spacket, 0, 0))
X		return(0);
X	if ((*getpkt)(spacket, &len))
X		return(0); /* rec CY or CN */
X	if (strncmp(spacket, "CY", 2))
X		return(0); /* cant send file */
X	close(fp);
X	fp = (-1);
X 	importpath( hostfile, fromfile );
X	unlink(hostfile);
X	printmsg( 0, "Transfer of %s (%s) completed.  fp=%d", fromfile, hostfile, fp );
X
X	/*
X	fprintf( syslog, "%s!%s (%d/%d-%d:%d:%d) -> %ld / %ld secs", host, id, size, secs );
X	*/
X
X	return('F');                    /* go get the next file to send */
X}
X
X
X/**/
X/*
X *  s f i l e
X *
X *  Send File Header.
X */
Xsfile()
X{
X	int	i, len;
X	char * cp;
X	if (fp == -1) {/* If not already open, */
X		printmsg( 3, "looking for next file..." );
X		if (getfile()) { /* get next file from current work*/
X			fclose( fw );
X			unlink( cfile );/* close and delete completed workfile */
X			fw = (char *)NULL;
X			return('B'); /* end sending session */
X		}
X
X 		importpath( hostfile, fromfile );
X
X		printmsg( 3, "Opening %s (%s) for sending.", fromfile, hostfile );
X		fp = open(hostfile, 0);/* open the file to be sent */
X		if (fp == -1) {/* If bad file pointer, give up */
X			printmsg( 0, "Cannot open file %s (%s).", fromfile, hostfile );
X			return('A');
X		}
X	} else
X		return('A'); /* If somethings already open. were in trouble*/
X	printmsg( 0, "Sending %s (%s) as %s", fromfile, hostfile, tofile );
X	strcpy(spacket, tofile);
X	if ((*sendpkt)(spacket, 0, 1))
X		return(0);       /* send S fromfile tofile */
X	if ((*getpkt)(spacket, &len))
X		return(0);       /* user - tofile 0666. */
X	if (spacket[1] != 'Y')
X		return('A'); 			/* If otherside says no-quit*/
X	size = bufill(spacket);
X	return('D');
X}
X
X
X/**/
X/*
X *  s i n i t
X *
X *  Send Initiate: send this host's parameters and get other side's back.
X */
Xsinit()
X{
X	if ((*openpk)())
X		return('A');
X	return('B');
X}
X
X
X/**/
X/*
X *
X *
X *  getfile
X *
X *  getfile reads the next line from the presently open workfile
X *  (cfile) and determines from this the next file to be sent
X *  (file). If there are no more TRUE is returned.
X *  --A fix for "R from to 0666" should be done here to recieve files
X *  --in addition to sending them. The appropriate "state letter"
X *  --i.e. "R" should be returned to the send "master" or "slave"
X *  --state switching table in "dcp.c"
X *  --I did not implement this since the majority of uucp transactions
X *  --appear to be "S from to 0666" type. RHLamb 1/87
X *
X */
Xgetfile()
X{
X	int	i;
X	char	line[132];
X	register char * cp;
X
X	if ( ! fgets( line, BUFSIZ, fw ) )
X		return(TRUE);
X
X	sscanf(&line[2], "%s ", fromfile);
X	for ( i = 0, cp = line; *cp!='\0'; i++, cp++ ) {
X		if ( strncmp( cp, "0666", 4 ) == 0)
X			break;
X	}
X	cp+=4;
X	*cp = '\0';
X	strcpy(tofile, line);
X 	printmsg(3, "   getfile: fromfile=%s, tofile=%s.", fromfile, tofile);
X	return(FALSE);
X}
X
X
X/**/
X/*********************** MISC SUB SUB PROTOCOL *************************/
X/*
X**
X**schkdir
X** scan the dir
X*/
Xschkdir()
X{
X	char	c;
X	c = scandir();
X	if (c == 'Q') {
X		return('Y');
X	}
X	if (c == 'S') {
X		sprintf(rpacket, "HN");
X		if ((*sendpkt)(rpacket, 0, 1))
X			return(0);
X	}
X	return('B');
X}
X
X
X/**/
X/*
X *
X *      endp() end protocol
X *
X*/
Xendp()
X{
X	sprintf(rpacket, "HY");
X	(*sendpkt)(rpacket, 0, 2); /* dont wait for ACK */
X	(*closepk)();
X	return('P');
X}
X
X
X/**/
X/***********************RECIEVE PROTOCOL**********************/
X/*
X *  r d a t a
X *
X *  Receive Data
X */
Xrdata()
X{
X	int	len;
X	if ((*getpkt)(rpacket, &len))
X		return(0);
X	if (len == 0) {
X		close(fp);
X		sprintf(rpacket, "CY");
X		if ((*sendpkt)(rpacket, 0, 1))
X			return(0);
X		printmsg( 0, "transfer complete" );
X		return('F');
X	}
X	write(fp, rpacket, len);/* Write the data to the file */
X	return('D');/* Remain in data state */
X}
X
X
X/**/
X/*
X *  r f i l e
X *
X *  Receive File Header
X */
Xrfile()
X{
X
X	char 	buf[256];
X	char *	flds[10];
X	int		numflds;
X
X	int		len, i;
X	char	tmpfilename[256]; /*Holds the converted file name */
X	char	*cp;
X
X	printmsg( 3, "rfile entered" );
X
X	cp = buf;
X
X	while ( TRUE ) {
X		if ((*getpkt)( rpacket, &len ))
X			return( 0 );
X		strncpy( cp, rpacket, len );
X		cp += len;
X		if ( *(cp - 1) == '\0' ) break;
X	}
X	if (( buf[0] & 0x7f ) == 'H' )
X		return( 'C' );
X
X	printmsg( 3, "rfile: buf %d \"%s\"", len, buf );
X
X	/* Convert upper case to lower */
X	for (cp = buf; *cp != '\0';cp++)
X		if (isupper(*cp)) tolower(*cp);
X
X	numflds = getargs( buf, flds );
X
X	cp = flds[2];
X	printmsg( 3, "rfile: receive file \"%s\"", cp );
X
X	/* check for ~/ destination -> /usr/spool/uucppublic */
X	if ( strncmp( cp, "~/", 2 ) == SAME )
X		sprintf( tmpfilename, "%s%s", pubdir, cp+1);
X	else
X		strcpy( tmpfilename, cp );
X	printmsg( 3, "rfile: receive file \"%s\"", tmpfilename );
X
X	/* check for dirname only */
X	cp = tmpfilename + strlen( tmpfilename ) - 1;
X	if ( *cp == '\n' )
X		*cp-- = '\0';
X
X	if ( *cp == '/' ) {
X
X		fprintf( stderr, "rfile: fromfile %s\n", flds[1] );
X		cp = rindex( flds[1], '/' );
X		if ( cp == (char *) NULL )
X			cp = flds[1];
X		else
X			cp++;
X
X		fprintf( stderr, "rfile: dironly add   %s\n", cp );
X
X		strcat( tmpfilename, cp );
X	}
X	printmsg( 3, "rfile: receive file \"%s\"", tmpfilename );
X
X
X	/* let host munge filename as appropriate */
X	importpath( tofile, tmpfilename );
X	printmsg( 3, "rfile: receive file \"%s\"", tofile );
X
X	if ((fp = CREAT( tofile, 0775, 'b' )) == -1) { /* Try to open a new file */
X		printmsg( 0, "cannot create %s", tofile ); /* Give up if can't */
X		return('A');
X	}
X
X	printmsg( 0, "Receiving %s as %s", flds[1], tofile );
X	sprintf(rpacket, "SY");
X	if ((*sendpkt)(rpacket, 0, 1))
X		return(0);
X	return('D'); /* Switch to data state */
X}
X
X
X/**/
X/*
X *  r i n i t
X *
X *  Receive Initialization
X */
Xrinit()
X{
X	if ((*openpk)())
X		return(0);
X	return('F');
X}
X
X
X
X
SHAR_EOF
chmod 0600 dcpxfer.c || echo "restore of dcpxfer.c fails"
sed 's/^X//' << 'SHAR_EOF' > dirsubs.c &&
X/*
X * getcwd(), chdir()
X */
X#include <osbind.h>
X#define NULL 0
X
Xextern char *malloc();
Xextern char errno;
X
Xchar *getcwd( pnbuf, maxlen )
Xchar *pnbuf;
Xint  maxlen;
X{
X	int drive;
X
X	if ( pnbuf == (char *)NULL )
X	{
X	   if ( (pnbuf = malloc( 64 )) == (char *)NULL )
X	   {
X	      printf( "getcwd: malloc failure\n" );
X	      exit(-1);
X	   }
X	}
X
X	drive = Dgetdrv();	/* get the current drive */
X	pnbuf[0] = (char)('A'+drive);
X	pnbuf[1] = ':';
X
X	Dgetpath( &pnbuf[2], 0 ); /* get current directory for current drive */
X
X	return( pnbuf );
X}
X
Xint chdir( path )
Xchar *path;
X{
X	int status;
X	/*
X	 * Change current drive if the path has a drive specified
X	 */
X	if ( path[1] == ':' )
X	   Dsetdrv( (int)(path[0]-'A') );
X
X	status = Dsetpath( path );	/* set current path */
X	if ( status == 0 ) return(0);
X	printf("chdir: failed with error %d on %s\n", status, path);
X	errno = status;
X	return(-1);
X}
X
X
SHAR_EOF
chmod 0600 dirsubs.c || echo "restore of dirsubs.c fails"
sed 's/^X//' << 'SHAR_EOF' > dmymath.c &&
X/*
X * ftoa, etoa, atof - Dummy routines so linker does not complain.
X * Will report error and exit should they actually be called.
X */
X
Xdouble atof( nptr )
Xchar *nptr;
X{
X	printf(" atof: Not implemented\n" );
X	exit(-1);
X}
X
Xchar *etoa( fval, buf, prec )
Xdouble fval;
Xchar *buf;
Xint prec;
X{
X	printf(" etoa: Not implemented\n" );
X	exit(-1);
X}
X
Xchar *ftoa( fval, buf, prec )
Xdouble fval;
Xchar *buf;
Xint prec;
X{
X	printf(" ftoa: Not implemented\n" );
X	exit(-1);
X}
X
X
SHAR_EOF
chmod 0600 dmymath.c || echo "restore of dmymath.c fails"
sed 's/^X//' << 'SHAR_EOF' > fgets.c &&
X#include <stdio.h>
X#include <osbind.h>
X#include <ctype.h>
X
X#define TRUE 1
X#define FALSE 0
X
X#define CR '\015'
X#define LF '\012'
X#define BS '\010'
X#define CD '\004'
X#define CU '\025'
X#define CX '\030'
X#define CZ '\032'
X
Xstatic char backsp[] = "\010 \010";
Xstatic char newline[]= "\015\012";
X
X/*
X * Fgets() - A replacement for fgets() that does its own console I/O
X * 	     since the library version seems not to work.
X *	     If the I/O is not to the console then we just call the
X *	     real fgets().
X *
X *	To use you must define fgets as Fgets either at the top of your
X *	source file or in a common header file.
X */
X
Xchar *Fgets( buf, n, stream )
Xchar *buf;
Xint n;
XFILE *stream;
X{
X	static int eof = FALSE;
X	int fd,eol;
X	char *s = buf;
X	char c;
X
X	eol = FALSE;
X	n  -= 1;	/* Leave room for the null character */
X
X	fd = fileno( stream );
X	if ( isatty( fd ) )
X	{
X	   /*
X	    * If the user typed ^Z last time then report EOF on this call.
X	    * Clear EOF as well so that future calls to the console will
X	    * work.
X	    */
X	   if ( eof )
X	   {
X	      eof = FALSE;
X	      return( (char *)NULL );
X	   }
X	   /*
X	    * Not EOF so read up to n character and return the line.
X	    */
X	   while ( ( s - buf ) < n )
X	   {
X	       c = ( Crawcin() & 0xFF );
X	       /*
X	        * If its a printing character then just echo it
X	        */
X	       if (isprint( c ))
X	       {
X	          Cconout( c );
X	          *s++ = c;
X	          continue;
X	       }
X	       /*
X	        * It must be a control character, either process it or
X	        * ignore it.
X	        */
X	       switch (c)
X	       {
X	          case CD:
X	          case CZ:
X	             eof = eol = TRUE;
X	             if ( s == buf ) break;
X	          case CR:
X	          case LF:
X	             eol = TRUE;
X	             *s++ = LF;
X	             if ( ( s - buf ) < n ) *s++ = '\0';
X	             Cconws( newline );
X	             break;
X	          case BS:
X	             if ( s != buf )
X	             {
X	                s--;
X	                Cconws( backsp );
X	             }
X	             break;
X	          case CU:
X	          case CX:
X	             while ( s != buf )
X	             {
X	                s--;
X	                Cconws( backsp );
X	             }
X	          default:
X	             break;
X	      }
X	      if ( eol ) break;
X	   }
X	   if ( eof && s == buf )
X	   {
X	      eof = FALSE;
X	      return( (char *)NULL );
X	   }
X	   return( buf );
X	}
X	/*
X	 * Was not console so call regular fgets() since it seems to
X	 * work for everything else.
X	 */
X	return( fgets( buf, n, stream ) );
X}
X
X#ifdef DEB_Fgets
X
Xextern int errno;
Xchar buf[200];
X
X#define fgets Fgets /* Use our own fgets routine */
X
Xmain ( argc, argv )
Xint argc;
Xchar **argv;
X{
X
X	char *s;
X
X	while ( ( s = fgets( buf, 20, stdin ) ) != (char *)NULL )
X	{
X	   puts(">>");
X	   puts( s );
X	   puts("<<");
X	}
X	return( errno );
X}
X#endif
X
X
SHAR_EOF
chmod 0600 fgets.c || echo "restore of fgets.c fails"
sed 's/^X//' << 'SHAR_EOF' > genv.c &&
X/*	genv.c
X 
X 
X 
X	copyright (C) 1987 Stuart Lynne
X 
X	Copying and use of this program are controlled by the terms of the
X	Free Software Foundations GNU Emacs General Public License.
X 
X 
X	version		0.1		March 31/1987
X 
X 
X 
X*/
X 
X#include <stdio.h>
X
X#ifndef NULL
X#define NULL 0
X#endif
X 
X#include "genv.h"
X/*
X#define DMAILBOX	"mailbox"
X#define	DNAME		"noname"
X#define	DDOMAIN		"pc.uucp"
X#define	DMAILDIR	"\\usr\\spool\\mail"
X#define DHOME		"\\usr\\noname"
X#define	DCONFDIR	"\\usr\\lib\\uucp"
X#define	DSPOOLDIR	"\\usr\\spool\\uucp"
X#define DLOGDIR		"\\usr\\spool\\uucp"
X#define DPUBDIR		"\\usr\\spool\\uucppublic"
X#define DNEWSSDIR	"\\usr\\spool\\rnews"
X#define DTEMPDIR	"\\tmp"
X#define	DMAILSERVICE	"host"
X#define	DNODENAME	"noname"
X#define	DDEVICE		"AUX:"
X#define	DSPEED		"1200"
X*/
X 
X#define	TFILENAME	"tmpfile"
X#define	FILENAME 	"%s\\%s"
X
Xchar *getenv();
Xchar *malloc();
Xvoid genv();
X
Xextern int debuglevel;
X
X#ifdef NOMALLOC
Xchar	rmailbox[64];
Xchar	rname[64];
Xchar	rdomain[64];
Xchar	rmaildir[64];
Xchar	rhome[64];
Xchar	rconfdir[64];
Xchar	rlogdir[64];
Xchar	rspooldir[64];
Xchar	rpubdir[64];
Xchar	rnewssdir[64];
Xchar	rtempdir[64];
Xchar	rmailserv[16];
Xchar 	rnodename[16];
Xchar 	rdevice[16];
Xchar 	rspeed[64];
X
Xchar	*mailbox = rmailbox;
Xchar	*name = rname;
Xchar	*domain = rdomain;
Xchar	*maildir = rmaildir;
Xchar	*home = rhome;
Xchar	*confdir = rconfdir;
Xchar	*spooldir = rspooldir;
Xchar	*pubdir = rpubdir;
Xchar	*logdir = rlogdir;
Xchar	*newssdir = rnewssdir;
Xchar	*tempdir = rtempdir;
Xchar	*mailserv = rmailserv;
Xchar 	*nodename = rnodename;
Xchar 	*device = rdevice;
Xchar 	*speed = rspeed;
X#else
Xchar	*mailbox;
Xchar	*name;
Xchar	*domain;
Xchar	*maildir;
Xchar	*home;
Xchar	*confdir;
Xchar	*spooldir;
Xchar	*logdir;
Xchar	*pubdir;
Xchar	*newssdir;
Xchar	*tempdir;
Xchar	*mailserv;
Xchar 	*nodename;
Xchar 	*device;
Xchar 	*speed;
X#endif
X 
Xvoid genv(thename, envname, dflt)
Xchar **thename;
Xchar *envname;
Xchar *dflt;
X{
X	char *temp;
X	
X	if ((temp = getenv( envname )) == (char *)NULL) {
X	   if ( debuglevel > 0 )
X	      fprintf( stderr, "genv: %s not found, using %s\n",
X	                       envname, dflt );
X	   temp = dflt;
X	}
X	*thename = malloc( strlen( temp ) + 1 );
X	strcpy( *thename, temp );
X	if ( debuglevel > 0 )
X	   fprintf( stderr, "genv: %s = %s\n", envname, *thename );
X}
X
Xvoid loadenv()
X{
X	/* get environment var's */
X	genv( &name, "NAME", DNAME );
X	genv( &mailbox, "MAILBOX", DMAILBOX );
X	genv( &domain, "DOMAIN", DDOMAIN );
X	genv( &maildir, "MAILDIR", DMAILDIR );
X	genv( &confdir, "CONFDIR", DCONFDIR );
X	genv( &spooldir, "SPOOLDIR", DSPOOLDIR );
X	genv( &logdir, "LOGDIR", DLOGDIR );
X	genv( &home, "HOME", DHOME );
X	genv( &pubdir, "PUBDIR", DPUBDIR );
X	genv( &newssdir, "NEWSSDIR", DNEWSSDIR );
X	genv( &tempdir, "TEMPDIR", DTEMPDIR );
X	genv( &mailserv, "MAILSERVICE", DMAILSERVICE );
X	genv( &nodename, "NODENAME", DNODENAME );
X	genv( &device, "DEVICE", DDEVICE );
X	genv( &speed, "SPEED", DSPEED );
X}
X 
Xvoid mkfilename( filename, dirname, name )
Xchar *filename;
Xchar *dirname;
Xchar *name;
X{
X	sprintf( filename, FILENAME, dirname, name );	
X	if ( debuglevel > 5 )
X	   fprintf( stderr, "genv: New filename %s\n", filename );
X}
X
X
X#ifdef TEST
Xmain()
X{
X	loadenv();
X}
X#endif
X
X
SHAR_EOF
chmod 0600 genv.c || echo "restore of genv.c fails"
sed 's/^X//' << 'SHAR_EOF' > genv.h &&
X/*	genv.c
X 
X 
X 
X	copyright (C) 1987 Stuart Lynne
X 
X	Copying and use of this program are controlled by the terms of the
X	Free Software Foundations GNU Emacs General Public License.
X 
X 
X	version		0.1		March 31/1987
X 
X	
X 
Xenvironment variables
X 
X	The following evironment variables are defined:
X 
X	MAILBOX		current user's mailbox, 	"sl"
X	NAME		current user's name, 		"Stuart Lynne"
X	DOMAIN		domain of this machine, 	"mac.van-bc.can"
X	MAILDIR		where mail is kept,		"/usr/mail"
X	CONFDIR		where config data is  kept,	"/usr/lib/uucp"
X	SPOOLDIR	where spooled files are 	"/usr/spool/uucp"
X	LOGDIR		where log file are placed	"/usr/spool/uucp"
X	PUBDIR		public spool directory		"/usr/spool/uucppublic"
X	NEWSSDIR	news spool directory		"/usr/spool/rnews"
X	TEMPDIR		where temp files are created	"/tmp"
X	HOME		where uses private files are	"/usr/sl"
X	MAILSERVICE	who do we send remote mail	"van-bc"
X	NODENAME	what is our local nodename	"slmac"
X	DEVICE		what is the default device	".a"
X	SPEED		what is the default speed	"1200"
X 
X*/
X 
X
X#define	MAILBOX		"koreth"
X#define	NAME		"Steven Grimm"
X#define	DOMAIN		"holodek.uucp"
X#define	MAILDIR		"D:\\USR\\SPOOL\\MAIL"
X#define HOME		"D:\\USR\\KORETH"
X
X#define	CONFDIR		"D:\\UUPC"
X#define SPOOLDIR	"D:\\USR\\SPOOL\\UUPC"
X#define LOGDIR		"D:\\USR\\SPOOL\\UUPC"
X#define	PUBDIR		"D:\\USR\\SPOOL\\UUPC"
X#define	NEWSSDIR	"D:\\USR\\SPOOL\\NEWS"
X#define TEMPDIR		"D:\\TMP"
X#define	MAILSERVICE	"ssyx"
X
X#define	DMAILBOX	"koreth"
X#define	DNAME		"Steven Grimm"
X#define	DDOMAIN		"holodek.uucp"
X#define	DMAILDIR	"D:\\USR\\SPOOL\\MAIL"
X#define DHOME		"D:\\USR\\KORETH"
X
X#define	DCONFDIR	"D:\\UUPC"
X#define DSPOOLDIR	"D:\\USR\\SPOOL\\UUPC"
X#define DLOGDIR		"D:\\USR\\SPOOL\\UUPC"
X#define	DPUBDIR		"D:\\USR\\SPOOL\\UUPC"
X#define	DNEWSSDIR	"D:\\USR\\SPOOL\\NEWS"
X#define DTEMPDIR	"D:\\TMP"
X#define	DMAILSERVICE	"ssyx"
X
X#define NODENAME	"holodek"
X#define	DEVICE		"AUX:"
X#define	SPEED		"2400"
X
X#define DNODENAME	"holodek"
X#define	DDEVICE		"AUX:"
X#define	DSPEED		"2400"
X 
Xextern char	*mailbox;
Xextern char	*name;
Xextern char	*domain;
Xextern char	*maildir;
Xextern char	*home;
X
Xextern char	*confdir;
Xextern char	*spooldir;
Xextern char	*newssdir;
Xextern char	*pubdir;
Xextern char	*tempdir;
Xextern char	*mailserv;
X
Xextern char	*nodename;
Xextern char	*device;
Xextern char	*speed;
X
Xvoid loadenv();
Xvoid genv();
Xvoid mkfilename();
X
X
SHAR_EOF
chmod 0600 genv.h || echo "restore of genv.h fails"
sed 's/^X//' << 'SHAR_EOF' > getargs.c &&
X#include <ctype.h>
X
Xint getargs( line, flds )
Xchar *line;
Xchar **flds;
X{
X	int i = 0;
X	char *s;
X
X	while ( (*line != '\0') && (*line != '\n') )
X	{
X	   if ( isspace(*line) )
X	   {
X	      line++;
X	      continue;
X	   }
X	   *flds++ = line;
X	   i++;
X	   while( (isspace(*line) == 0) && (*line != '\0') ) line++;
X	   if (isspace(*line)) *line++ = '\0';
X	}
X	return(i);
X}
X
X#ifdef TEST
X
Xchar comline[64] = "this is a test\n";
X
Xmain(argc, argv)
Xint argc;
Xchar *argv;
X{
X	char *flds[60];
X	int  i,j;
X
X	i = getargs( comline, flds );
X
X	printf( "Num args = %d\n", i );
X
X	for (j=0; j<i; j++)
X	  printf( "Arg[%d] = %d %s\n", j, strlen(flds[j]), flds[j] );
X}
X#endif
X
X
X
SHAR_EOF
chmod 0600 getargs.c || echo "restore of getargs.c fails"
sed 's/^X//' << 'SHAR_EOF' > getenv.c &&
X/*
X * char *getenv( s )
X *
X */
X#include <string.h>
X#define strchr index
X#define strrchr rindex
X
Xextern char *_base;		/* pointer to base page */
X
X#ifndef NULL
X#define NULL 0
X#endif
X
Xchar *getenv( s )
Xchar *s;
X{
X   char *envp;
X   int  n;
X
X   envp = *(char **)(_base + 44);	/* pointer to enviroment strings */
X
X/*printf( "Base address = %lx, Enviroment = %lx\n", _base, envp ); /* */
X
X   if ( *envp == '\0' ) return (char *)NULL;
X
X   while ( *envp != '\0' )
X   {
X
X/*printf( "Checking %s\n", envp ); /* */
X
X      n = strlen(s);
X
X      if ( strncmp( envp, s, n ) != 0 )
X      {
X         while ( *envp++ != '\0' );
X/*printf( "Failed match, next string at %lx\n", envp ); /* */
X         continue;
X      }
X/*printf( "Matched %s\n", envp ); /* */
X      envp += n;			  /* skip over variable name */
X      if ( *envp != '=' )
X      {
X         envp = strchr( envp, '\0' ) + 1; /* skip this string */
X         continue;
X      }
X      break;
X   }
X   return ( ( *envp != '=' ) ? (char *)NULL : ++envp );
X}
X
X#ifdef TEST
X
Xmain( argc, argv )
Xint argc;
Xchar **argv;
X{
X	char *s;
X
X	argc--;			/* skip program name */
X	argv++;
X
X	while ( argc-- )
X	{
X	  s = *argv;
X	  while ( *s != '\0' )
X	  {
X	    if ( *s >= 'a' && *s <= 'z' ) *s = *s - 32;
X	    *s++;
X	  }
X	  s = getenv( *argv );
X	  if (s == (char *)NULL)
X	    printf( "%s is not defined\n", *argv );
X	  else
X	    printf( "%s = %s\n", *argv, s );
X	  argv++;
X	}
X}
X#endif
X
X
SHAR_EOF
chmod 0600 getenv.c || echo "restore of getenv.c fails"
sed 's/^X//' << 'SHAR_EOF' > getone.c &&
X#include <osbind.h>
X
Xint get_one()
X{
X	int c;
X
X	c = Crawcin() & 0xFF;
X	if ( c == '\r' ) c = '\n';
X	return( c );
X}
X
X
SHAR_EOF
chmod 0600 getone.c || echo "restore of getone.c fails"
sed 's/^X//' << 'SHAR_EOF' > host.c &&
X#include <stdio.h>
X#include "genv.h"
X
Xint  chdir();
Xvoid loadenv();
Xvoid printmsg();
X
Xextern int errno;
X
Xchar *curdir;
Xchar *getcwd();
Xchar c_curdir[256];
X
Xjmp_buf	dcpexit;
X
X
Xmain( argc, argv )
Xint argc;
Xchar **argv;
X{
X	/* host specific prolog */
X	loadenv();
X	curdir = getcwd( c_curdir, 0 );
X	if (chdir( spooldir ) != 0)
X	{
X	   return(errno);
X	}
X
X	/* setup longjmp for error exit's */
X	if ( setjmp( dcpexit ) == 0 ) {
X
X		MAIN(argc, argv );
X
X	}
X	
X
X	/* host specific epilog */
X	if (chdir( curdir ) != 0)
X	{
X	   return(errno);
X	}
X	return(0);
X}
X
X
SHAR_EOF
chmod 0600 host.c || echo "restore of host.c fails"
sed 's/^X//' << 'SHAR_EOF' > host.h &&
X/* Atari ST, Alcyon C Version 4.14a					*/
X/* Host specific defines for uu and mail				*/
X
X#include <ctype.h>
X#include <strings.h>
X#include <osbind.h>
X#include "time.h"
X#include "genv.h"
X
X#define XENIX		/* don't send debugging info in startup message	*/
X#define fgets Fgets	/* use our own fgets to fix problem in runtime	*/
X#define mkdir(x) Dcreate(x)	/* create directory				*/
X
X#define ATARIST
X
X#define strchr  index
X#define strrchr rindex
X#define FILEMODE(f)
X
X#define SEPCHAR		'\\'	/* path separater character		*/
X#define XQTFILE 	"X_%.6s"	/* prefix for execute files		*/
X#define CALLFILE	"C_%.6s"	/* prefix for call files		*/
X#define TFILENAME	"TM.%03ld"	/* template for temporary files	*/
X#define SFILENAME	"SEQF"		/* name of the sequence file		*/
X#define SIGFILE		"SIGNATUR"	/* file containing signature	*/
X#define COPYFILE	"MAIL\\MAILSENT"	/* copy of sent mail	*/
X#define NEWSDIR		"\\usr\\spool\\rnews\\%02d%02d%02d%02d.%03d"	/* format for news name	*/
X#define HOSTINIT		/* name of function used to initialize	*/
X
X/* Rsconf() defines */
X
X#define RSR		(-1)		/* leave as is			*/
X#define TSR		(-1)		/* " "     " "			*/
X#define SCR		(-1)		/* " "     " "			*/
X#define UCR		(0x88)		/* 8-bits, no parity, 2 stops	*/
X#define NOFLOW		(0)		/* no flow control		*/
X
X#define B19200		(0)		/* 19200 baud			*/
X#define B9600		(1)		/* 9600 baud			*/
X#define B4800		(2)		/* 4800 baud			*/
X#define B2400		(4)		/* 2400 baud			*/
X#define B1200		(7)		/* 1200 baud			*/
X#define B300		(9)		/*  300 baud			*/
X
X/* misc. defines */
X
X#ifndef TRUE
X#define FALSE		(0)
X#define TRUE		(-1)
X#endif
X
X#ifndef SAME
X#define SAME		(0)
X#endif
X
X#define AUX		(1)		/* rs232 port			*/
X#define CON		(2)		/* console			*/
X
X#define CTRL(X)		(X & 037)	/* get a control character	*/
X
X#define	IBUFSIZ		(0x1000)
X#define	OBUFSIZ		(0x1000)
X
X/* typedef for Iorec() stuff (modified & improved by Martin Minow) */
X	
Xstruct iorec
X  {
X    char	*ibuf;		/* Pointer to input buffer */
X    int		ibufsize;	/* Size of input buffer    */
X    int		ibufhd;		/* Head index              */
X    int		ibuftl;		/* Tail index		   */
X    int		ibuflow;	/* Low water mark	   */
X    int		ibufhi;		/* Hi water mark	   */
X  };
X    
Xtypedef struct {
X    struct iorec in;			/*  0 Input buffer		*/
X    struct iorec out;			/* 14 Output buffer		*/
X} IOREC;
X
X
X/*
X * Rsconf() returns the "old" parameters in a longword encoded as follows:
X * bits		value
X * 31-24	UCR
X * 23-16	RSR
X * 15- 8	TSR
X *  8- 0	SCR
X *
X * Note that we must redefine the Rsconf() macro.
X */
X
X
X#define	RS_UCR_SHIFT	24
X#define RS_RSR_SHIFT	16
X#define RS_TSR_SHIFT	 8
X#define RS_SCR_SHIFT	 0
X
Xextern int errno;
X
X
SHAR_EOF
chmod 0600 host.h || echo "restore of host.h fails"
sed 's/^X//' << 'SHAR_EOF' > inoutpth.c &&
X#include <strings.h>
X#include <ctype.h>
X
X#define NULL 0
X#define strchr index
X#define strrchr rindex
X
X#define min(x,y) (((x) < (y)) ? (x) : (y))
X/*
X *                  Canonical name conversion routines
X *
X * These routines convert file name between canonical form which is defined
X * as a 'unix' style pathname and whatever format the host system can
X * handle.
X */
X
X/*
X * importpath( host, canon )
X *
X * Convert a canonical name to a format the host can handle
X *
X * Mung the canonical file name as follows:
X *   1 - strip any path from the canonical name
X *   2 - copy up to 8 character from the canonical name converting . to _
X *   3 - if the name was longer than 8 character copy a . to the host name
X *       and then copy the up to three characters from the tail of the
X *	 canonical name to the host name.
X */
Xchar *importpath( host, canon )
Xchar *host, *canon;
X{
X	char *s,*out,c;
X	int  i,j,l;
X
X	out  = host;
X
X	/*
X	 * get a pointer to the last component of the path
X	 */
X
X	if ( (s = strrchr( canon, '/' )) == (char *)NULL ) s = canon;
X	else s++;
X
X	j = min(l = strlen(s),8);
X
X	for (i=0; i<j; i++)
X	{
X	   c = *s++;
X	   *out++ = (c == '.') ? '_' : c;
X	}
X	*out = '\0';
X
X	while (*s != '\0') s++;
X
X	if (l>8)
X	   for (i=0; i<3; i++)
X	      if (*--s == '.') { s++; break; }
X
X	if (*s != '\0')
X	{
X
X	   strcat( out, "." );
X	   strcat( out, s );
X	}
X
X	return( host );
X}
X
X/*
X * exportpath( canon, host )
X *
X * Convert a host name into canonical name
X *
X * Copy file name from host to canon converting an underscore in the second
X * character to a dot and any other dots into the letter B.
X *
X */
Xexportpath( canon, host )
Xchar *host, *canon;
X{
X	register char c;
X	register char *s = canon;
X	do
X	{
X	   c = *s = tolower( *host );
X	   if ( c == '.' ) *s = 'B';
X	   s++;
X	} while ( *host++ != '\0' );
X
X	*canon = toupper( *canon );
X	if ( canon[1] == '_' )
X	   canon[1] = '.';
X}
X
X
SHAR_EOF
chmod 0600 inoutpth.c || echo "restore of inoutpth.c fails"
sed 's/^X//' << 'SHAR_EOF' > lib.c &&
X/* 		lib.c
X
X*/
X
X#include <stdio.h>
X#include <ctype.h>
X#include "host.h"
X
X#ifndef NULL
X#define NULL 0L
X#endif
X
Xchar *index();
Xchar *rindex();
X
XMKDIR( path )
Xchar * path;
X{
X	char * cp = path;
X
X	if ( *cp == '\0' )
X		return( 0 );
X
X	/* see if we need to make any intermediate directories */
X	while ( ( cp = index( cp, '\\' ) ) != (char *) NULL ) {
X		*cp = '\0';
X		mkdir( path );
X		*cp = '\\';
X		cp++;
X	}
X
X	/* make last dir */
X	return( mkdir( path ) );
X
X}
X
XCHDIR( path )
Xchar * path;
X{
X	char * cp = path;
X
X	if ( *cp == '\0' )
X		return( 0 );
X
X	MKDIR( path );
X
X	/* change to last directory */
X	return( chdir( path ) );
X
X}
X
XFILE * FOPEN( name, mode, ftype )
Xchar * name;
Xchar * mode;
Xchar ftype;
X{
X
X	char * last;
X	FILE * results;
X
X	/* are we opening for write or append */
X
X	FILEMODE( ftype );
X	results = fopen( name, mode );
X
X	if ( results != (FILE *) NULL || *mode == 'r' )
X		return( results );
X
X	/* are we opening in sub-directory */
X	last = rindex( name, '/' );
X
X	/* lets just verify that all sub-dir's exist */
X	if ( last != (char *) NULL ) {
X		*last = '\0';
X		MKDIR( name );
X		*last = '/';
X	}
X
X	/* now try open again */
X	return( fopen( name, mode ));
X
X}
X
Xint CREAT( name, mode, ftyp )
Xchar * name;
Xint mode;
Xchar ftyp;
X{
X
X	char * last;
X	int results;
X
X	/* are we opening for write or append */
X	FILEMODE( ftyp );
X	results = creat( name, mode );
X
X	if ( results != -1 )
X		return( results );
X
X	/* are we opening in sub-directory */
X	last = rindex( name, '/' );
X
X	/* lets just verify that all sub-dir's exist */
X	if ( last != (char *) NULL ) {
X		*last = '\0';
X		MKDIR( name );
X		*last = '/';
X	}
X
X	/* now try open again */
X	return( creat( name, mode ) );
X
X}
X
Xextern FILE *logfile;
Xextern int debuglevel;
Xextern int remote;
X
X#define MASTER 1
X
X
Xint getargs( line, flds )
Xchar *line;
Xchar **flds;
X{
X	int i = 0;
X	char *s;
X
X	while ( (*line != '\0') && (*line != '\n') )
X	{
X	   if ( isspace(*line) )
X	   {
X	      line++;
X	      continue;
X	   }
X	   *flds++ = line;
X	   i++;
X	   while( (isspace(*line) == 0) && (*line != '\0') ) line++;
X	   if (isspace(*line)) *line++ = '\0';
X	}
X	return(i);
X}
X
X
X
SHAR_EOF
chmod 0600 lib.c || echo "restore of lib.c fails"
sed 's/^X//' << 'SHAR_EOF' > lmail.c &&
X/*			lmail.c
X
X*/
X
X#define NOMAIN
X/* #define RMAIL /* if defined we get rmail() else we get lmail() */
X
X#include	"pcmail.c"
SHAR_EOF
chmod 0600 lmail.c || echo "restore of lmail.c fails"
sed 's/^X//' << 'SHAR_EOF' > mail.c &&
X/*
X *	mail.c
X */
X
X#define	exit	return
X
X#include <stdio.h>
X#include "host.h"
X
XFILE *FOPEN();
XFILE *freopen();
X
Xchar *index(), *rindex();
X
Xint	debuglevel = 0;
X
X#define LSIZE   	256
X
Xchar	line[LSIZE];
Xchar	resp[LSIZE];
X
Xchar	mfilename[132];
X
Xstruct ldesc {
X   int   	delete;		/* status of this message */
X   long		adr;		/* address of From line */
X   long		date;		/* address of Date: line */
X   long		subject;	/* address of Subject: line */
X   long		from;		/* address of From: line */
X   long		size;		/* number of lines */
X};
X
Xstruct	ldesc letters[300];
X
Xint   	letternum   = 0;
Xchar   	thefilename[50];
X
Xchar   	tmailbox[64];
Xchar 	tmailbag[64];
X
X
XFILE   	*fmailbox;
XFILE 	*rmailbox;
XFILE	*fmailbag;
X
Xint	error = 0;
Xint	modified;
X
Xint	printonly;
X
Xint	PageCount = 0;
X
Xmailmain(argc, argv)
Xchar **argv;
X{
X
X	/* HOSTINIT;
X	loadenv(); */
X
X	mkfilename( tmailbox, tempdir, "mailbox");
X	mkfilename( tmailbag, tempdir, "mailbag");
X
X	unlink( tmailbox );
X
X	if ( mailbox == (char *)NULL )
X		mailbox = "???";
X
X	if ( argc == 1 ||
X		( argv[1][0] == '-' ) && ( argv[1][1] != 's' ))
X		showmail (argc, argv );
X	else
X		lmail (argc, argv );
X
X	finis();
X
X}
X
Xfinis()
X{
X	if ( fmailbag != (FILE *)NULL) fclose( fmailbag );
X	unlink( tmailbox );
X	unlink( tmailbag );
X	exit( error );
X}
X
X/*	sendmail
X	send message n to "line"
X*/
Xsendmail( n, line )
Xchar *line;
X{
X	char 	*argv[50];
X	int 	argc;
X	char	buf[BUFSIZ];
X	long 	bytes;
X
X	/* open a temporary file */
X	fmailbag = FOPEN( tmailbag, "w", 'b' );
X
X	/* copy nth message to mailbag file */
X	fseek( fmailbox, letters[ n ].adr, 0 );
X	bytes = letters[ n+1 ].adr - letters[ n ].adr;
X
X	while( bytes > 0 && fgets( buf, BUFSIZ, fmailbox) ) {
X		fputs( buf, fmailbag  );
X		bytes -= strlen( buf );
X	}
X
X	fclose( fmailbag );
X
X	/* use mailbag as stdin to mail delivery */
X	fclose( stdin );
X	FILEMODE( 'b' );
X	if ( freopen( tmailbag, "r", stdin ) != (FILE *)NULL ) {
X		argc = getargs( line, argv );
X
X		lmail( argc, argv );
X
X		fclose( stdin );
X	}
X	
X#ifdef MSDOS
X	FILEMODE( 't' );
X	freopen( CONSOLE, "r", stdin );
X#else
X	freopen( device, "r", stdin );
X#endif
X
X	/* get rid of mailbag */
X	unlink( tmailbag );
X}
X
X
Xinvert( i )
X{
X	return( letternum - i - 1 );
X}
X
X/*
X * Generate the return address for a letter by looking at the "From "
X * line.
X */
Xchar *returnaddress(let)
Xint let;
X{
X	struct ldesc *lp;
X	static char from[256];
X	char line[256], *i, *k;
X
X	lp = &letters[let];
X
X	readaline( lp->adr, line );
X
X	i = index(line+5, ' ');
X	if (i == NULL)
X		i = &line[strlen(line)];
X	strncpy( from, line+4, i-line-4 );
X	from[i-line-4] = '\0';
X
X	return from;
X}
X
X/*
X * Turn a subject into a reply (if it isn't already).  If there was no
X * subject line, return NULL.
X */
Xchar *re(let)
Xint let;
X{
X	static char newsub[256];
X	char subline[256];
X
X	subline[0] = '\0';
X
X	readaline(letters[let].subject, subline);
X	if (! subline[0])
X		return NULL;
X
X	if (subline[9] == 'R' && subline[10] == 'e' && subline[11] == ':')
X		strcpy(newsub, subline+9);
X	else
X	{
X		strcpy(newsub, "Re:  ");
X		strcat(newsub, subline+9);
X	}
X
X	return newsub;
X}
X
Xshowmail(argc, argv)
Xchar **argv;
X{
X	int flg, i, j, k, print;
X	char *p, *cp, *getnext();
X	long nextadr;
X	struct ldesc *letter;
X
X	/* get mailbox file name */
X	mkfilename( mfilename, maildir, mailbox );
X
X	/* parse arg's */
X	for (; argc > 1; argv++, argc--) {
X	   if ( argv[1][0] == '-' ) {
X	      if ( argv[1][1] == 'f' ) {
X	         if ( argc >= 3) {
X	            if ( argv[2][0] == '=' )
X	               mkfilename( mfilename, maildir, &argv[2][1] );
X	            else
X	               strcpy( mfilename, argv[2] );
X	         argv++;
X	         argc--;
X	         }
X
X	      } else if ( argv[1][1 ]== 'p' ) printonly++;
X	   else {
X	      fprintf(stderr, "mail: unknown option %c\n", argv[1][1]);
X	      finis();
X	   }
X	   } else break;
X	}
X
X
X
X	/* open real mailbox file */
X	if (( rmailbox = FOPEN( mfilename, "r", 'b' ))  == (FILE *)NULL) {
X		fprintf( stdout, "No mail in %s.\n", mfilename );
X		return;
X	}
X
X	/* open up tmp mailbox file */
X  	if (( fmailbox = FOPEN( tmailbox, "w", 'b' )) == (FILE *)NULL ) {
X		fprintf( stderr, "mail: cannot open %s for writing\n", tmailbox );
X		finis();
X	}
X
X
X	/* copy real mailbox file to tmp mailbox file */
X	letternum = 0 ;
X	nextadr = 0;
X	while ( fgets(line, LSIZE, rmailbox ) ) {
X		fputs( line, fmailbox );
X
X		if ( strncmp( line, "From ", 5 ) == SAME ) {
X			letter = &letters[letternum++];
X			letter->from =
X			letter->subject =
X			letter->date = -1L;
X			letter->adr = nextadr;
X			letter->delete = FALSE;
X			letter->size = 0L;
X		}else if ( strncmp( line, "Date: ", 6 ) == SAME )
X			letter->date = nextadr;
X		else if ( strncmp( line, "From: ", 6 ) == SAME )
X			letter->from = nextadr;
X		else if ( strncmp( line, "Subject: ", 9 ) == SAME )
X			letter->subject = nextadr;
X
X		letter->size += 1L;
X		nextadr += strlen( line )+1;	/* +1 for \r\n */
X	}
X
X	letters[letternum].adr = nextadr;   /* last plus 1 */
X
X	/* close mailbox files */
X	fclose( rmailbox );
X	fclose( fmailbox );
X
X	fmailbox = FOPEN( tmailbox, "r", 'b' );
X
X	modified = 0;
X
X	if ( printonly ) {
X		j = letternum;
X		while ( j > 0 ) {
X			pager( j );
X			j--;
X		}
X
X		return;
X     }
X
X
X	printsub( -1 );
X
X	i = letternum - 1;
X	while ( TRUE ) {
X
X		if ( i < 0 )
X			i = 0;
X		if ( i >= letternum)
X			i = letternum - 1;
X		j = invert( i );
X
X		fprintf( stdout, "%d ? ", invert( i ) );
X		fflush(stdout);
X
X		if ( ! fgets( resp, LSIZE, stdin) )
X			break;
X
X		switch ( resp[0] ) {
X		default:
X			fprintf(stderr, "usage\n");
X		case '?':
X			print = 0;
X			fprintf( stderr, "q\tquit\n" );
X			fprintf( stderr, "x\texit\tmailbox restored\n" );
X			fprintf( stderr, "p\tprint message\n" );
X			fprintf( stderr, "s[file]\tsave message to a file (default =mbox)\n" );
X			fprintf( stderr, "w[file]\ttsave message to a file (default =mbox) without header\n" );
X			fprintf( stderr, "-\tprint last message\n" );
X			fprintf( stderr, "d\tdelete current message\n" );
X			fprintf( stderr, "+\tnext message (no delete)\n" );
X			fprintf( stderr, "f user\tforward current message to user\n" );
X			fprintf( stderr, "m user\tmail a message to user\n" );
X			fprintf( stderr, "r\treply to current message\n" );
X			fprintf( stderr, "g num\t set current message\n" );
X			break;
X		case '+':
X		case 'n':
X			i-- ;
X			break;
X		case 'g':
X			i = invert( atoi( resp+2 ) );
X			break;
X		case '0':
X		case '1':
X		case '2':
X		case '3':
X		case '4':
X		case '5':
X		case '6':
X		case '7':
X		case '8':
X		case '9':
X			i = invert( atoi( resp ) );
X			break;
X
X		case 'x':
X			modified = 0;
X		case 'q':
X			goto donep;
X		case '\n':
X		case 'p':
X			pager( j );
X			break;
X		case '^':
X		case '-':
X			i++;
X			break;
X		case 'y':
X		case 'w':
X		case 's':
X			flg = 0;
X			if (resp[1] != '\n' && resp[1] != ' ') {
X				printf("illegal\n");
X				flg++;
X				print = 0;
X				continue;
X			}
X			if (strlen( resp ) == 1)
X				strcat( resp, " =mbox" );
X			for (p = resp+1; (p = getnext( &cp, p )) != (char *)NULL; ) {
X			   if ( *cp == '=' )
X	                      mkfilename( thefilename, maildir, ++cp );
X			   else
X			      strcpy( thefilename, cp );
X			   fprintf( stderr, "%s to %s\n",
X			   		(resp[0] == 's') ? "Appending":"Writing", thefilename );
X			   if (( fmailbag=FOPEN( thefilename, "a", 't' )) == (FILE *)NULL ) {
X			      fprintf( stdout, "mail: cannot append to %s\n",
X			               thefilename );
X			   flg++;
X			   continue;
X			   }
X			   copymsg( j, fmailbag, resp[0]=='w' );
X			   fclose( fmailbag );
X			}
X			if (flg)
X				print = 0;
X			else {
X				letters[j].delete = TRUE;
X				modified++;
X				i--;
X			}
X			break;
X		case 'm':
X			mailto(resp+1, NULL);
X			break;
X		case 'r':
X			fprintf( stdout, "To: %s\n", returnaddress(j) );
X			mailto(returnaddress(j), re(j));
X			break;
X		case 'f':
X			flg = 0;
X			if (resp[1] == '\n' || resp[1] == '\0') {
X				i++;
X				continue;
X			}
X			if (resp[1] != ' ') {
X				printf( "invalid command\n" );
X				flg++;
X				print = 0;
X				continue;
X			}
X
X			sendmail( j, p );
X
X			if (flg)
X				print = 0;
X			else {
X				letters[j].delete = TRUE;
X				modified++;
X				i++;
X			}
X			break;
X
X		case 'd':
X			letters[j].delete = TRUE;
X			modified++;
X			i--;
X			if (resp[1] == 'q')
X				goto donep;
X			break;
X
X		case 'h':
X			printsub( -1 );
X			break;
X
X		case 'H':
X			printsub( i );
X			break;
X
X		}
X
X	}
X	donep:
X	if ( modified )
X		copyback();
X}
X
X/*
X * Invoke lmail with a particular destination and, possibly, subject.
X */
Xmailto(who, what)
Xchar *who, *what;
X{
X	char sub[256];
X	char *argv[5];
X	int  argc = 1;
X
X	argv[0] = "lmail";
X	printf("Subject: ");
X	fflush(stdout);
X
X	if (what != NULL)
X		puts(what);
X	else
X		gets(what = sub);
X
X	putchar('\n');
X
X	argv[argc++] = "-s";
X	argv[argc++] = what;
X
X	while (*who == ' ')
X		who++;
X
X	argv[argc++] = who;
X
X	lmail(argc, argv);
X}
X
Xreadaline( adr, line )
Xlong adr;
Xchar *line;
X{
X	char 	buf[132];
X	char	*cp;
X
X	*line = '\0';
X	if ( adr != -1L )
X		if ( fseek( fmailbox, adr, 0 ) == 0 )
X			if ( fgets( buf, 132, fmailbox ) )
X				strcpy( line, buf );
X
X	if ( (cp = index( line, '\n' ) ) != (char *) NULL)
X		*cp = '\0';
X}
X
X
Xprintsub( K )
X{
X	struct ldesc	*ld;
X	int		j;
X	char	from[132], subject[132], date[132], line[132];
X	char	*sp, *dp, *lp, *tp;
X	int k, mink, maxk;
X
X	pagereset();
X
X	if ( K == -1 ) {
X		maxk = letternum -1;
X		mink = 0;
X	}
X	else
X		maxk = mink = K;
X
X	for ( k = maxk ; k >= mink ; k-- ) {
X
X		j = invert( k );
X		ld = & letters[ j /*k*/];
X
X 		(void)strcpy(from, "unknown");	/* default to "unknown" */
X		readaline( ld->from, line );
X		if ( strlen( line ) > 0 ) {
X			/* Assume From: mailbox@site.domain */
X			/* get first usable stuff after From: */
X			sp = index( line, ':' ) + 1;
X
X			/* do we have From: mailbox@site.domain ( Proper Name ) */
X			if ( ( ( tp = index( line, '(' )) != (char *) NULL &&
X					( lp = index( line, ')')) != (char *) NULL  ) )
X				sp = ++tp;
X			/* or we may have From: Proper Name < mailbox@site.domain > */
X			else
X				lp = index( line, '<');
X
X			if (lp != NULL)
X				if ( *lp == '<' || *lp == ')' )
X					--lp;
X
X			/* if we didn't get either of the last two, just grab line */
X			if ( lp < sp || lp == (char *) NULL )
X				lp = line + strlen( line ) - 1;
X
X			/*debugMsg("\PCheck isspace *sp");*/
X			while ( isspace( *sp ) ) sp++;
X
X			/*debugMsg("\PCheck isspace *lp");*/
X			while ( isspace( *lp ) ) lp--;
X
X			dp = from;
X			while ( sp <= lp ) *dp++ = *sp++;
X			*dp = '\0';
X		}
X
X		/* Date: Wed May 13 23:59:53 1987 */
X 		*date = '\0';	/* default date to null */
X		readaline( ld->date, date );
X		if ( strlen( date ) > 0 ) {
X			sscanf( date, "%*s %*s %s %s", line, subject );
X			sprintf( date, "%s %s", line, subject );
X		}
X
X		strcpy( subject, "--- no subject ---" );
X		readaline( ld->subject, line );
X		if ( strlen( line ) > 0 ) {
X			sp = line;
X			while ( !isspace( *sp ) ) sp++;
X			while ( isspace( *sp ) ) sp++;
X			strcpy( subject, sp );
X			}
X
X		from[20] = '\0';
X		date[6] = '\0';
X		subject[35] = '\0';
X
X		sprintf( line, "%3d  %6s  %20s %35s (%6d)\n",
X						j, date, from, subject, ld->size );
X		if ( pageline( line ) == TRUE )
X			break;
X	}
X}
X
X
Xcopyback()
X{
X	register i, n, c;
X	int new = 0;
X
X	if (( fmailbag = FOPEN( mfilename, "w", 'b' )) == (FILE *)NULL ) {
X		fprintf (stderr, "mail: can't rewrite %s\n", mfilename );
SHAR_EOF
echo "End of part 2, continue with part 3"
echo "3" > s2_seq_.tmp
exit 0