[comp.os.minix] V1.4a #3

ast@cs.vu.nl (Andy Tanenbaum) (01/23/89)

: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
: --------------------------- cut here --------------------------
PATH=/bin:/usr/bin:/usr/ucb
echo Extracting 'memccpy.c'
sed 's/^X//' > 'memccpy.c' << '+ END-OF-FILE ''memccpy.c'
X/*
X * memccpy - copy bytes up to a certain char
X *
X * CHARBITS should be defined only if the compiler lacks "unsigned char".
X * It should be a mask, e.g. 0377 for an 8-bit machine.
X */
X
X#define	NULL	0
X
X#ifndef CHARBITS
X#	define	UNSCHAR(c)	((unsigned char)(c))
X#else
X#	define	UNSCHAR(c)	((c)&CHARBITS)
X#endif
X
XVOIDSTAR
Xmemccpy(dst, src, ucharstop, size)
XVOIDSTAR dst;
XCONST VOIDSTAR src;
XSIZET size;
X{
X	register char *d;
X	register CONST char *s;
X	register SIZET n;
X	register int uc;
X
X	if (size <= 0)
X		return(NULL);
X
X	s = src;
X	d = dst;
X	uc = UNSCHAR(ucharstop);
X	for (n = size; n > 0; n--)
X		if (UNSCHAR(*d++ = *s++) == uc)
X			return(d);
X
X	return(NULL);
X}
+ END-OF-FILE memccpy.c
chmod 'u=rw,g=r,o=r' 'memccpy.c'
set `wc -c 'memccpy.c'`
count=$1
case $count in
656)	:;;
*)	echo 'Bad character count in ''memccpy.c' >&2
		echo 'Count should be 656' >&2
esac
echo Extracting 'memchr.c'
sed 's/^X//' > 'memchr.c' << '+ END-OF-FILE ''memchr.c'
X/*
X * memchr - search for a byte
X *
X * CHARBITS should be defined only if the compiler lacks "unsigned char".
X * It should be a mask, e.g. 0377 for an 8-bit machine.
X */
X
X#define	NULL	0
X
X#ifndef CHARBITS
X#	define	UNSCHAR(c)	((unsigned char)(c))
X#else
X#	define	UNSCHAR(c)	((c)&CHARBITS)
X#endif
X
XVOIDSTAR
Xmemchr(s, ucharwanted, size)
XCONST VOIDSTAR s;
Xint ucharwanted;
XSIZET size;
X{
X	register CONST char *scan;
X	register SIZET n;
X	register int uc;
X
X	scan = s;
X	uc = UNSCHAR(ucharwanted);
X	for (n = size; n > 0; n--)
X		if (UNSCHAR(*scan) == uc)
X			return(scan);
X		else
X			scan++;
X
X	return(NULL);
X}
+ END-OF-FILE memchr.c
chmod 'u=rw,g=r,o=r' 'memchr.c'
set `wc -c 'memchr.c'`
count=$1
case $count in
595)	:;;
*)	echo 'Bad character count in ''memchr.c' >&2
		echo 'Count should be 595' >&2
esac
echo Extracting 'memcmp.c'
sed 's/^X//' > 'memcmp.c' << '+ END-OF-FILE ''memcmp.c'
X/*
X * memcmp - compare bytes
X */
X
Xint				/* <0, == 0, >0 */
Xmemcmp(s1, s2, size)
XCONST VOIDSTAR s1;
XCONST VOIDSTAR s2;
XSIZET size;
X{
X	register CONST char *scan1;
X	register CONST char *scan2;
X	register SIZET n;
X
X	scan1 = s1;
X	scan2 = s2;
X	for (n = size; n > 0; n--)
X		if (*scan1 == *scan2) {
X			scan1++;
X			scan2++;
X		} else
X			return(*scan1 - *scan2);
X
X	return(0);
X}
+ END-OF-FILE memcmp.c
chmod 'u=rw,g=r,o=r' 'memcmp.c'
set `wc -c 'memcmp.c'`
count=$1
case $count in
367)	:;;
*)	echo 'Bad character count in ''memcmp.c' >&2
		echo 'Count should be 367' >&2
esac
echo Extracting 'memcpy.c'
sed 's/^X//' > 'memcpy.c' << '+ END-OF-FILE ''memcpy.c'
X/*
X * memcpy - copy bytes
X */
X
XVOIDSTAR
Xmemcpy(dst, src, size)
XVOIDSTAR dst;
XCONST VOIDSTAR src;
XSIZET size;
X{
X	register char *d;
X	register CONST char *s;
X	register SIZET n;
X
X	if (size <= 0)
X		return(dst);
X
X	s = src;
X	d = dst;
X	if (s <= d && s + (size-1) >= d) {
X		/* Overlap, must copy right-to-left. */
X		s += size-1;
X		d += size-1;
X		for (n = size; n > 0; n--)
X			*d-- = *s--;
X	} else
X		for (n = size; n > 0; n--)
X			*d++ = *s++;
X
X	return(dst);
X}
+ END-OF-FILE memcpy.c
chmod 'u=rw,g=r,o=r' 'memcpy.c'
set `wc -c 'memcpy.c'`
count=$1
case $count in
450)	:;;
*)	echo 'Bad character count in ''memcpy.c' >&2
		echo 'Count should be 450' >&2
esac
echo Extracting 'memset.c'
sed 's/^X//' > 'memset.c' << '+ END-OF-FILE ''memset.c'
X/*
X * memset - set bytes
X *
X * CHARBITS should be defined only if the compiler lacks "unsigned char".
X * It should be a mask, e.g. 0377 for an 8-bit machine.
X */
X
X#ifndef CHARBITS
X#	define	UNSCHAR(c)	((unsigned char)(c))
X#else
X#	define	UNSCHAR(c)	((c)&CHARBITS)
X#endif
X
XVOIDSTAR
Xmemset(s, ucharfill, size)
XCONST VOIDSTAR s;
Xregister int ucharfill;
XSIZET size;
X{
X	register CONST char *scan;
X	register SIZET n;
X	register int uc;
X
X	scan = s;
X	uc = UNSCHAR(ucharfill);
X	for (n = size; n > 0; n--)
X		*scan++ = uc;
X
X	return(s);
X}
+ END-OF-FILE memset.c
chmod 'u=rw,g=r,o=r' 'memset.c'
set `wc -c 'memset.c'`
count=$1
case $count in
524)	:;;
*)	echo 'Bad character count in ''memset.c' >&2
		echo 'Count should be 524' >&2
esac
echo Extracting 'opendir.c'
sed 's/^X//' > 'opendir.c' << '+ END-OF-FILE ''opendir.c'
X/*
X	opendir -- open a directory stream
X
X	last edit:	27-Oct-1988	D A Gwyn
X*/
X
X#include	<sys/errno.h>
X#include	<sys/types.h>
X#include	<sys/stat.h>
X#include	<dirent.h>
X
X#ifdef BSD_SYSV
X#define open	_open			/* avoid emulation overhead */
X#endif
X
Xtypedef char	*pointer;		/* (void *) if you have it */
X
Xextern void	free();
Xextern pointer	malloc();
Xextern int	open(), close(), fstat();
X
Xextern int	errno;
X
X#ifndef NULL
X#define	NULL	0
X#endif
X
X#ifndef O_RDONLY
X#define	O_RDONLY	0
X#endif
X
X#ifndef S_ISDIR				/* macro to test for directory file */
X#define	S_ISDIR( mode )		(((mode) & S_IFMT) == S_IFDIR)
X#endif
X
XDIR *
Xopendir( dirname )
X	char			*dirname;	/* name of directory */
X	{
X	register DIR		*dirp;	/* -> malloc'ed storage */
X	register int		fd;	/* file descriptor for read */
X	/* The following is static just to keep the stack small. */
X	static struct stat	sbuf;	/* result of fstat() */
X
X	if ( (fd = open( dirname, O_RDONLY )) < 0 )
X		return NULL;		/* errno set by open() */
X
X	if ( fstat( fd, &sbuf ) != 0 || !S_ISDIR( sbuf.st_mode ) )
X		{
X		(void)close( fd );
X		errno = ENOTDIR;
X		return NULL;		/* not a directory */
X		}
X
X	if ( (dirp = (DIR *)malloc( sizeof(DIR) )) == NULL
X	  || (dirp->dd_buf = (char *)malloc( (unsigned)DIRBUF )) == NULL
X	   )	{
X		register int	serrno = errno;
X					/* errno set to ENOMEM by sbrk() */
X
X		if ( dirp != NULL )
X			free( (pointer)dirp );
X
X		(void)close( fd );
X		errno = serrno;
X		return NULL;		/* not enough memory */
X		}
X
X	dirp->dd_fd = fd;
X	dirp->dd_loc = dirp->dd_size = 0;	/* refill needed */
X
X	return dirp;
X	}
+ END-OF-FILE opendir.c
chmod 'u=rw,g=r,o=r' 'opendir.c'
set `wc -c 'opendir.c'`
count=$1
case $count in
1541)	:;;
*)	echo 'Bad character count in ''opendir.c' >&2
		echo 'Count should be 1541' >&2
esac
echo Extracting 'popen.c'
sed 's/^X//' > 'popen.c' << '+ END-OF-FILE ''popen.c'
X#include <stdio.h>
X#include <signal.h>
X
Xstatic int pids[20];
X
XFILE *
Xpopen(command, type)
X	char *command, *type;
X{
X	int piped[2];
X	int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2;
X	int pid;
X	extern FILE *fdopen();
X
X	if (Xtype == 2 ||
X	    pipe(piped) < 0 ||
X	    (pid = fork()) < 0) return 0;
X	
X	if (pid == 0) {
X		/* child */
X		register int *p;
X
X		for (p = pids; p < &pids[20]; p++) {
X			if (*p) close(p - pids);
X		}
X		close(piped[Xtype]);
X		dup2(piped[!Xtype], !Xtype);
X		close(piped[!Xtype]);
X		execl("/bin/sh", "sh", "-c", command, (char *) 0);
X		exit(-1);	/* like system() ??? */
X	}
X
X	pids[piped[Xtype]] = pid;
X	close(piped[!Xtype]);
X	return (fdopen(piped[Xtype], type));
X}
X
Xpclose(iop)
X	FILE *iop;
X{
X	int fd = fileno(iop);
X	int status, wret;
X	int (*intsave)() = signal(SIGINT, SIG_IGN);
X	int (*quitsave)() = signal(SIGQUIT, SIG_IGN);
X	int (*hupsave)() = signal(SIGHUP, SIG_IGN);
X
X	fclose(iop);
X	while ((wret = wait(&status)) != -1) {
X		if (wret == pids[fd]) break;
X	}
X	if (wret == -1) status = -1;
X	signal(SIGINT, intsave);
X	signal(SIGQUIT, quitsave);
X	signal(SIGHUP, hupsave);
X	pids[fd] = 0;
X	return (status);
X}
+ END-OF-FILE popen.c
chmod 'u=rw,g=r,o=r' 'popen.c'
set `wc -c 'popen.c'`
count=$1
case $count in
1122)	:;;
*)	echo 'Bad character count in ''popen.c' >&2
		echo 'Count should be 1122' >&2
esac
echo Extracting 'rand.c'
sed 's/^X//' > 'rand.c' << '+ END-OF-FILE ''rand.c'
X/*  rand(3)
X *
X *  Changed to return high order bits. Terrence W. Holm, Nov. 1988
X */
X
Xstatic long _seed = 1L;
X
Xsrand(x)
X  unsigned x;
X  {
X  _seed = (long) x;
X  }
X
Xint rand()
X  {
X  _seed = 1103515245L * _seed + 12345;
X  return( (int) ((_seed >> 16) & 0x7fff) );
X  }
+ END-OF-FILE rand.c
chmod 'u=rw,g=r,o=r' 'rand.c'
set `wc -c 'rand.c'`
count=$1
case $count in
266)	:;;
*)	echo 'Bad character count in ''rand.c' >&2
		echo 'Count should be 266' >&2
esac
echo Extracting 'readdir.c'
sed 's/^X//' > 'readdir.c' << '+ END-OF-FILE ''readdir.c'
X/*
X	readdir -- read next entry from a directory stream
X
X	last edit:	25-Apr-1987	D A Gwyn
X*/
X
X#include	<sys/errno.h>
X#include	<sys/types.h>
X#include	<dirent.h>
X
Xextern int	getdents();		/* SVR3 system call, or emulation */
X
Xextern int	errno;
X
X#ifndef NULL
X#define	NULL	0
X#endif
X
Xstruct dirent *
Xreaddir( dirp )
X	register DIR		*dirp;	/* stream from opendir() */
X	{
X	register struct dirent	*dp;	/* -> directory data */
X
X	if ( dirp == NULL || dirp->dd_buf == NULL )
X		{
X		errno = EFAULT;
X		return NULL;		/* invalid pointer */
X		}
X
X	do	{
X		if ( dirp->dd_loc >= dirp->dd_size )	/* empty or obsolete */
X			dirp->dd_loc = dirp->dd_size = 0;
X
X		if ( dirp->dd_size == 0	/* need to refill buffer */
X		  && (dirp->dd_size =
X			getdents( dirp->dd_fd, dirp->dd_buf, (unsigned)DIRBUF )
X		     ) <= 0
X		   )
X			return NULL;	/* EOF or error */
X
X		dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc];
X		dirp->dd_loc += dp->d_reclen;
X		}
X	while ( dp->d_ino == 0L );	/* don't rely on getdents() */
X
X	return dp;
X	}
+ END-OF-FILE readdir.c
chmod 'u=rw,g=r,o=r' 'readdir.c'
set `wc -c 'readdir.c'`
count=$1
case $count in
991)	:;;
*)	echo 'Bad character count in ''readdir.c' >&2
		echo 'Count should be 991' >&2
esac
echo Extracting 'rename.c'
sed 's/^X//' > 'rename.c' << '+ END-OF-FILE ''rename.c'
X/* rename.c -- file renaming routine */
X
X/* rename(from, to)
X * char *from, *to;
X */
X
Xint rename(from,to)
Xregister char *from, *to;
X{
X    (void) unlink(to);
X    if (link(from, to) < 0)
X	return(-1);
X
X    (void) unlink(from);
X    return(0);
X}
X
+ END-OF-FILE rename.c
chmod 'u=rw,g=r,o=r' 'rename.c'
set `wc -c 'rename.c'`
count=$1
case $count in
242)	:;;
*)	echo 'Bad character count in ''rename.c' >&2
		echo 'Count should be 242' >&2
esac
echo Extracting 'rewinddir.c'
sed 's/^X//' > 'rewinddir.c' << '+ END-OF-FILE ''rewinddir.c'
X/*
X	rewinddir -- rewind a directory stream
X
X	last edit:	25-Apr-1987	D A Gwyn
X
X	This is not simply a call to seekdir(), because seekdir()
X	will use the current buffer whenever possible and we need
X	rewinddir() to forget about buffered data.
X*/
X
X#include	<sys/errno.h>
X#include	<sys/types.h>
X#include	<dirent.h>
X
Xextern off_t	lseek();
X
Xextern int	errno;
X
X#ifndef NULL
X#define	NULL	0
X#endif
X
X#ifndef SEEK_SET
X#define	SEEK_SET	0
X#endif
X
Xvoid
Xrewinddir( dirp )
X	register DIR		*dirp;	/* stream from opendir() */
X	{
X	if ( dirp == NULL || dirp->dd_buf == NULL )
X		{
X		errno = EFAULT;
X		return;			/* invalid pointer */
X		}
X
X	dirp->dd_loc = dirp->dd_size = 0;	/* invalidate buffer */
X	(void)lseek( dirp->dd_fd, (off_t)0, SEEK_SET );	/* may set errno */
X	}
+ END-OF-FILE rewinddir.c
chmod 'u=rw,g=r,o=r' 'rewinddir.c'
set `wc -c 'rewinddir.c'`
count=$1
case $count in
746)	:;;
*)	echo 'Bad character count in ''rewinddir.c' >&2
		echo 'Count should be 746' >&2
esac
echo Extracting 'rindex.c'
sed 's/^X//' > 'rindex.c' << '+ END-OF-FILE ''rindex.c'
X/*
X * rindex - find last occurrence of a character in a string
X */
X
X#define	NULL	0
X
Xchar *				/* found char, or NULL if none */
Xrindex(s, charwanted)
XCONST char *s;
Xchar charwanted;
X{
X	extern char *strrchr();
X
X	return(strrchr(s, charwanted));
X}
+ END-OF-FILE rindex.c
chmod 'u=rw,g=r,o=r' 'rindex.c'
set `wc -c 'rindex.c'`
count=$1
case $count in
245)	:;;
*)	echo 'Bad character count in ''rindex.c' >&2
		echo 'Count should be 245' >&2
esac
echo Extracting 'seekdir.c'
sed 's/^X//' > 'seekdir.c' << '+ END-OF-FILE ''seekdir.c'
X/*
X	seekdir -- reposition a directory stream
X
X	last edit:	24-May-1987	D A Gwyn
X
X	An unsuccessful seekdir() will in general alter the current
X	directory position; beware.
X
X	NOTE:	4.nBSD directory compaction makes seekdir() & telldir()
X		practically impossible to do right.  Avoid using them!
X*/
X
X#include	<sys/errno.h>
X#include	<sys/types.h>
X#include	<dirent.h>
X
Xextern off_t	lseek();
X
Xextern int	errno;
X
X#ifndef NULL
X#define	NULL	0
X#endif
X
X#ifndef SEEK_SET
X#define	SEEK_SET	0
X#endif
X
Xtypedef int	bool;			/* Boolean data type */
X#define	false	0
X#define	true	1
X
Xvoid
Xseekdir( dirp, loc )
X	register DIR	*dirp;		/* stream from opendir() */
X	register off_t	loc;		/* position from telldir() */
X	{
X	register bool	rewind;		/* "start over when stymied" flag */
X
X	if ( dirp == NULL || dirp->dd_buf == NULL )
X		{
X		errno = EFAULT;
X		return;			/* invalid pointer */
X		}
X
X	/* A (struct dirent)'s d_off is an invented quantity on 4.nBSD
X	   NFS-supporting systems, so it is not safe to lseek() to it. */
X
X	/* Monotonicity of d_off is heavily exploited in the following. */
X
X	/* This algorithm is tuned for modest directory sizes.  For
X	   huge directories, it might be more efficient to read blocks
X	   until the first d_off is too large, then back up one block,
X	   or even to use binary search on the directory blocks.  I
X	   doubt that the extra code for that would be worthwhile. */
X
X	if ( dirp->dd_loc >= dirp->dd_size	/* invalid index */
X	  || ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off > loc
X					/* too far along in buffer */
X	   )
X		dirp->dd_loc = 0;	/* reset to beginning of buffer */
X	/* else save time by starting at current dirp->dd_loc */
X
X	for ( rewind = true; ; )
X		{
X		register struct dirent	*dp;
X
X		/* See whether the matching entry is in the current buffer. */
X
X		if ( (dirp->dd_loc < dirp->dd_size	/* valid index */
X		   || readdir( dirp ) != NULL	/* next buffer read */
X		   && (dirp->dd_loc = 0, true)	/* beginning of buffer set */
X		     )
X		  && (dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off
X			<= loc		/* match possible in this buffer */
X		   )	{
X			for ( /* dp initialized above */ ;
X			      (char *)dp < &dirp->dd_buf[dirp->dd_size];
X			      dp = (struct dirent *)((char *)dp + dp->d_reclen)
X			    )
X				if ( dp->d_off == loc )
X					{	/* found it! */
X					dirp->dd_loc =
X						(char *)dp - dirp->dd_buf;
X					return;
X					}
X
X			rewind = false;	/* no point in backing up later */
X			dirp->dd_loc = dirp->dd_size;	/* set end of buffer */
X			}
X		else			/* whole buffer past matching entry */
X			if ( !rewind )
X				{	/* no point in searching further */
X				errno = EINVAL;
X				return;	/* no entry at specified loc */
X				}
X			else	{	/* rewind directory and start over */
X				rewind = false;	/* but only once! */
X
X				dirp->dd_loc = dirp->dd_size = 0;
X
X				if ( lseek( dirp->dd_fd, (off_t)0, SEEK_SET )
X					!= 0
X				   )
X					return;	/* errno already set (EBADF) */
X
X				if ( loc == 0 )
X					return; /* save time */
X				}
X		}
X	}
+ END-OF-FILE seekdir.c
chmod 'u=rw,g=r,o=r' 'seekdir.c'
set `wc -c 'seekdir.c'`
count=$1
case $count in
2965)	:;;
*)	echo 'Bad character count in ''seekdir.c' >&2
		echo 'Count should be 2965' >&2
esac
echo Extracting 'signal.c'
sed 's/^X//' > 'signal.c' << '+ END-OF-FILE ''signal.c'
X#include "lib.h"
X#include <signal.h>
X
Xint (*vectab[NSIG])();	/* array of functions to catch signals */
X
X/* The definition of signal really should be 
X *  PUBLIC int (*signal(signr, func))()
X * but some compilers refuse to accept this, even though it is correct.
X * The only thing to do if you are stuck with such a defective compiler is
X * change it to
X *  PUBLIC int *signal(signr, func)
X * and change ../h/signal.h accordingly.
X */
X
XPUBLIC int (*signal(signr, func))()
Xint signr;			/* which signal is being set */
Xint (*func)();			/* pointer to function that catches signal */
X{
X  int r,(*old)();
X
X  old = vectab[signr - 1];
X  M.m6_i1 = signr;
X  if (func == SIG_IGN || func == SIG_DFL)
X	/* keep old signal catcher until it is completely de-installed */
X	M.m6_f1 = func;
X  else {
X	/* use new signal catcher immediately (old one may not exist) */
X	vectab[signr - 1] = func;
X	M.m6_f1 = begsig;
X  }
X  r = callx(MM, SIGNAL);
X  if (r < 0) {
X	vectab[signr - 1] = old;	/* undo any pre-installation */
X	return( (int (*)()) r );
X  }
X  vectab[signr - 1] = func;		/* redo any pre-installation */
X  if (r == 1)
X	return(SIG_IGN);
X  return(old);
X}
+ END-OF-FILE signal.c
chmod 'u=rw,g=r,o=r' 'signal.c'
set `wc -c 'signal.c'`
count=$1
case $count in
1135)	:;;
*)	echo 'Bad character count in ''signal.c' >&2
		echo 'Count should be 1135' >&2
esac
echo Extracting 'sleep.c'
sed 's/^X//' > 'sleep.c' << '+ END-OF-FILE ''sleep.c'
X/*  sleep(3)
X *
X *  Sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt.
X *
X *  Changed to conform with POSIX      Terrence W. Holm      Oct. 1988
X */
X
X#include <signal.h>
X
X
Xstatic _alfun()	/* Used with sleep() below */
X  {
X  }
X
X
Xunsigned sleep( secs )
X  unsigned secs;
X
X  {
X  unsigned current_secs;
X  unsigned remaining_secs;
X  int     (*old_signal)();
X
X  if ( secs == 0 )
X    return( 0 );
X
X  current_secs = alarm( 0 );   /*  Is there currently an alarm?  */
X
X  if ( current_secs == 0  ||  current_secs > secs )
X    {
X    old_signal = signal( SIGALRM, _alfun );
X
X    alarm( secs );
X    pause();
X    remaining_secs = alarm( 0 );
X
X    signal( SIGALRM, old_signal );
X
X    if ( current_secs > secs )
X	alarm( current_secs - ( secs - remaining_secs ) );
X
X    return( remaining_secs );
X    }
X
X
X  /*  current_secs <= secs,  ie. alarm should occur before secs  */
X
X  alarm( current_secs );
X  pause();
X  remaining_secs = alarm( 0 );
X
X  alarm( remaining_secs );
X
X  return( secs - ( current_secs - remaining_secs ) );
X  }
+ END-OF-FILE sleep.c
chmod 'u=rw,g=r,o=r' 'sleep.c'
set `wc -c 'sleep.c'`
count=$1
case $count in
1024)	:;;
*)	echo 'Bad character count in ''sleep.c' >&2
		echo 'Count should be 1024' >&2
esac
echo Extracting 'strcat.c'
sed 's/^X//' > 'strcat.c' << '+ END-OF-FILE ''strcat.c'
X/*
X * strcat - append string src to dst
X */
Xchar *				/* dst */
Xstrcat(dst, src)
Xchar *dst;
XCONST char *src;
X{
X	register char *dscan;
X	register CONST char *sscan;
X
X	for (dscan = dst; *dscan != '\0'; dscan++)
X		continue;
X	sscan = src;
X	while ((*dscan++ = *sscan++) != '\0')
X		continue;
X	return(dst);
X}
+ END-OF-FILE strcat.c
chmod 'u=rw,g=r,o=r' 'strcat.c'
set `wc -c 'strcat.c'`
count=$1
case $count in
301)	:;;
*)	echo 'Bad character count in ''strcat.c' >&2
		echo 'Count should be 301' >&2
esac
echo Extracting 'strchr.c'
sed 's/^X//' > 'strchr.c' << '+ END-OF-FILE ''strchr.c'
X/*
X * strchr - find first occurrence of a character in a string
X */
X
X#define	NULL	0
X
Xchar *				/* found char, or NULL if none */
Xstrchr(s, charwanted)
XCONST char *s;
Xregister char charwanted;
X{
X	register CONST char *scan;
X
X	/*
X	 * The odd placement of the two tests is so NUL is findable.
X	 */
X	for (scan = s; *scan != charwanted;)	/* ++ moved down for opt. */
X		if (*scan++ == '\0')
X			return(NULL);
X	return(scan);
X}
+ END-OF-FILE strchr.c
chmod 'u=rw,g=r,o=r' 'strchr.c'
set `wc -c 'strchr.c'`
count=$1
case $count in
418)	:;;
*)	echo 'Bad character count in ''strchr.c' >&2
		echo 'Count should be 418' >&2
esac
echo Extracting 'strcmp.c'
sed 's/^X//' > 'strcmp.c' << '+ END-OF-FILE ''strcmp.c'
X/*
X * strcmp - compare string s1 to s2
X */
X
Xint				/* <0 for <, 0 for ==, >0 for > */
Xstrcmp(s1, s2)
XCONST char *s1;
XCONST char *s2;
X{
X	register CONST char *scan1;
X	register CONST char *scan2;
X
X	scan1 = s1;
X	scan2 = s2;
X	while (*scan1 != '\0' && *scan1 == *scan2) {
X		scan1++;
X		scan2++;
X	}
X
X	/*
X	 * The following case analysis is necessary so that characters
X	 * which look negative collate low against normal characters but
X	 * high against the end-of-string NUL.
X	 */
X	if (*scan1 == '\0' && *scan2 == '\0')
X		return(0);
X	else if (*scan1 == '\0')
X		return(-1);
X	else if (*scan2 == '\0')
X		return(1);
X	else
X		return(*scan1 - *scan2);
X}
+ END-OF-FILE strcmp.c
chmod 'u=rw,g=r,o=r' 'strcmp.c'
set `wc -c 'strcmp.c'`
count=$1
case $count in
637)	:;;
*)	echo 'Bad character count in ''strcmp.c' >&2
		echo 'Count should be 637' >&2
esac
echo Extracting 'strcpy.c'
sed 's/^X//' > 'strcpy.c' << '+ END-OF-FILE ''strcpy.c'
X/*
X * strcpy - copy string src to dst
X */
Xchar *				/* dst */
Xstrcpy(dst, src)
Xchar *dst;
XCONST char *src;
X{
X	register char *dscan;
X	register CONST char *sscan;
X
X	dscan = dst;
X	sscan = src;
X	while ((*dscan++ = *sscan++) != '\0')
X		continue;
X	return(dst);
X}
+ END-OF-FILE strcpy.c
chmod 'u=rw,g=r,o=r' 'strcpy.c'
set `wc -c 'strcpy.c'`
count=$1
case $count in
257)	:;;
*)	echo 'Bad character count in ''strcpy.c' >&2
		echo 'Count should be 257' >&2
esac
echo Extracting 'strcspn.c'
sed 's/^X//' > 'strcspn.c' << '+ END-OF-FILE ''strcspn.c'
X/*
X * strcspn - find length of initial segment of s consisting entirely
X * of characters not from reject
X */
X
XSIZET
Xstrcspn(s, reject)
XCONST char *s;
XCONST char *reject;
X{
X	register CONST char *scan;
X	register CONST char *rscan;
X	register SIZET count;
X
X	count = 0;
X	for (scan = s; *scan != '\0'; scan++) {
X		for (rscan = reject; *rscan != '\0';)	/* ++ moved down. */
X			if (*scan == *rscan++)
X				return(count);
X		count++;
X	}
X	return(count);
X}
+ END-OF-FILE strcspn.c
chmod 'u=rw,g=r,o=r' 'strcspn.c'
set `wc -c 'strcspn.c'`
count=$1
case $count in
444)	:;;
*)	echo 'Bad character count in ''strcspn.c' >&2
		echo 'Count should be 444' >&2
esac
echo Extracting 'strerror.c'
sed 's/^X//' > 'strerror.c' << '+ END-OF-FILE ''strerror.c'
X/*
X * strerror - map error number to descriptive string
X *
X * This version is obviously somewhat Unix-specific.
X */
Xchar *
Xstrerror(errnum)
Xint errnum;
X{
X	extern int errno, sys_nerr;
X	extern char *sys_errlist[];
X
X	if (errnum > 0 && errnum < sys_nerr)
X		return(sys_errlist[errnum]);
X	else
X		return("unknown error");
X}
+ END-OF-FILE strerror.c
chmod 'u=rw,g=r,o=r' 'strerror.c'
set `wc -c 'strerror.c'`
count=$1
case $count in
317)	:;;
*)	echo 'Bad character count in ''strerror.c' >&2
		echo 'Count should be 317' >&2
esac
echo Extracting 'strlen.c'
sed 's/^X//' > 'strlen.c' << '+ END-OF-FILE ''strlen.c'
X/*
X * strlen - length of string (not including NUL)
X */
XSIZET
Xstrlen(s)
XCONST char *s;
X{
X	register CONST char *scan;
X	register SIZET count;
X
X	count = 0;
X	scan = s;
X	while (*scan++ != '\0')
X		count++;
X	return(count);
X}
+ END-OF-FILE strlen.c
chmod 'u=rw,g=r,o=r' 'strlen.c'
set `wc -c 'strlen.c'`
count=$1
case $count in
218)	:;;
*)	echo 'Bad character count in ''strlen.c' >&2
		echo 'Count should be 218' >&2
esac
echo Extracting 'strncat.c'
sed 's/^X//' > 'strncat.c' << '+ END-OF-FILE ''strncat.c'
X/*
X * strncat - append at most n characters of string src to dst
X */
Xchar *				/* dst */
Xstrncat(dst, src, n)
Xchar *dst;
XCONST char *src;
XSIZET n;
X{
X	register char *dscan;
X	register CONST char *sscan;
X	register SIZET count;
X
X	for (dscan = dst; *dscan != '\0'; dscan++)
X		continue;
X	sscan = src;
X	count = n;
X	while (*sscan != '\0' && --count >= 0)
X		*dscan++ = *sscan++;
X	*dscan++ = '\0';
X	return(dst);
X}
+ END-OF-FILE strncat.c
chmod 'u=rw,g=r,o=r' 'strncat.c'
set `wc -c 'strncat.c'`
count=$1
case $count in
404)	:;;
*)	echo 'Bad character count in ''strncat.c' >&2
		echo 'Count should be 404' >&2
esac
echo Extracting 'strncmp.c'
sed 's/^X//' > 'strncmp.c' << '+ END-OF-FILE ''strncmp.c'
X/*
X * strncmp - compare at most n characters of string s1 to s2
X */
X
Xint				/* <0 for <, 0 for ==, >0 for > */
Xstrncmp(s1, s2, n)
XCONST char *s1;
XCONST char *s2;
XSIZET n;
X{
X	register CONST char *scan1;
X	register CONST char *scan2;
X	register SIZET count;
X
X	scan1 = s1;
X	scan2 = s2;
X	count = n;
X	while (--count >= 0 && *scan1 != '\0' && *scan1 == *scan2) {
X		scan1++;
X		scan2++;
X	}
X	if (count < 0)
X		return(0);
X
X	/*
X	 * The following case analysis is necessary so that characters
X	 * which look negative collate low against normal characters but
X	 * high against the end-of-string NUL.
X	 */
X	if (*scan1 == '\0' && *scan2 == '\0')
X		return(0);
X	else if (*scan1 == '\0')
X		return(-1);
X	else if (*scan2 == '\0')
X		return(1);
X	else
X		return(*scan1 - *scan2);
X}
+ END-OF-FILE strncmp.c
chmod 'u=rw,g=r,o=r' 'strncmp.c'
set `wc -c 'strncmp.c'`
count=$1
case $count in
755)	:;;
*)	echo 'Bad character count in ''strncmp.c' >&2
		echo 'Count should be 755' >&2
esac
echo Extracting 'strncpy.c'
sed 's/^X//' > 'strncpy.c' << '+ END-OF-FILE ''strncpy.c'
X/*
X * strncpy - copy at most n characters of string src to dst
X */
Xchar *				/* dst */
Xstrncpy(dst, src, n)
Xchar *dst;
XCONST char *src;
XSIZET n;
X{
X	register char *dscan;
X	register CONST char *sscan;
X	register SIZET count;
X
X	dscan = dst;
X	sscan = src;
X	count = n;
X	while (--count >= 0 && (*dscan++ = *sscan++) != '\0')
X		continue;
X	while (--count >= 0)
X		*dscan++ = '\0';
X	return(dst);
X}
+ END-OF-FILE strncpy.c
chmod 'u=rw,g=r,o=r' 'strncpy.c'
set `wc -c 'strncpy.c'`
count=$1
case $count in
387)	:;;
*)	echo 'Bad character count in ''strncpy.c' >&2
		echo 'Count should be 387' >&2
esac
echo Extracting 'strpbrk.c'
sed 's/^X//' > 'strpbrk.c' << '+ END-OF-FILE ''strpbrk.c'
X/*
X * strpbrk - find first occurrence of any char from breakat in s
X */
X
X#define	NULL	0
X
Xchar *				/* found char, or NULL if none */
Xstrpbrk(s, breakat)
XCONST char *s;
XCONST char *breakat;
X{
X	register CONST char *sscan;
X	register CONST char *bscan;
X
X	for (sscan = s; *sscan != '\0'; sscan++) {
X		for (bscan = breakat; *bscan != '\0';)	/* ++ moved down. */
X			if (*sscan == *bscan++)
X				return(sscan);
X	}
X	return(NULL);
X}
+ END-OF-FILE strpbrk.c
chmod 'u=rw,g=r,o=r' 'strpbrk.c'
set `wc -c 'strpbrk.c'`
count=$1
case $count in
422)	:;;
*)	echo 'Bad character count in ''strpbrk.c' >&2
		echo 'Count should be 422' >&2
esac
echo Extracting 'strrchr.c'
sed 's/^X//' > 'strrchr.c' << '+ END-OF-FILE ''strrchr.c'
X/*
X * strrchr - find last occurrence of a character in a string
X */
X
X#define	NULL	0
X
Xchar *				/* found char, or NULL if none */
Xstrrchr(s, charwanted)
XCONST char *s;
Xregister char charwanted;
X{
X	register CONST char *scan;
X	register CONST char *place;
X
X	place = NULL;
X	for (scan = s; *scan != '\0'; scan++)
X		if (*scan == charwanted)
X			place = scan;
X	if (charwanted == '\0')
X		return(scan);
X	return(place);
X}
+ END-OF-FILE strrchr.c
chmod 'u=rw,g=r,o=r' 'strrchr.c'
set `wc -c 'strrchr.c'`
count=$1
case $count in
410)	:;;
*)	echo 'Bad character count in ''strrchr.c' >&2
		echo 'Count should be 410' >&2
esac
echo Extracting 'strspn.c'
sed 's/^X//' > 'strspn.c' << '+ END-OF-FILE ''strspn.c'
X/*
X * strspn - find length of initial segment of s consisting entirely
X * of characters from accept
X */
X
XSIZET
Xstrspn(s, accept)
XCONST char *s;
XCONST char *accept;
X{
X	register CONST char *sscan;
X	register CONST char *ascan;
X	register SIZET count;
X
X	count = 0;
X	for (sscan = s; *sscan != '\0'; sscan++) {
X		for (ascan = accept; *ascan != '\0'; ascan++)
X			if (*sscan == *ascan)
X				break;
X		if (*ascan == '\0')
X			return(count);
X		count++;
X	}
X	return(count);
X}
+ END-OF-FILE strspn.c
chmod 'u=rw,g=r,o=r' 'strspn.c'
set `wc -c 'strspn.c'`
count=$1
case $count in
460)	:;;
*)	echo 'Bad character count in ''strspn.c' >&2
		echo 'Count should be 460' >&2
esac
echo Extracting 'strstr.c'
sed 's/^X//' > 'strstr.c' << '+ END-OF-FILE ''strstr.c'
X/*
X * strstr - find first occurrence of wanted in s
X */
X
X#define	NULL	0
X
Xchar *				/* found string, or NULL if none */
Xstrstr(s, wanted)
XCONST char *s;
XCONST char *wanted;
X{
X	register CONST char *scan;
X	register SIZET len;
X	register char firstc;
X	extern int strcmp();
X	extern SIZET strlen();
X
X	/*
X	 * The odd placement of the two tests is so "" is findable.
X	 * Also, we inline the first char for speed.
X	 * The ++ on scan has been moved down for optimization.
X	 */
X	firstc = *wanted;
X	len = strlen(wanted);
X	for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
X		if (*scan++ == '\0')
X			return(NULL);
X	return(scan);
X}
+ END-OF-FILE strstr.c
chmod 'u=rw,g=r,o=r' 'strstr.c'
set `wc -c 'strstr.c'`
count=$1
case $count in
635)	:;;
*)	echo 'Bad character count in ''strstr.c' >&2
		echo 'Count should be 635' >&2
esac
echo Extracting 'strtok.c'
sed 's/^X//' > 'strtok.c' << '+ END-OF-FILE ''strtok.c'
X/*
X * Get next token from string s (NULL on 2nd, 3rd, etc. calls),
X * where tokens are nonempty strings separated by runs of
X * chars from delim.  Writes NULs into s to end tokens.  delim need not
X * remain constant from call to call.
X */
X
X#define	NULL	0
X
Xstatic char *scanpoint = NULL;
X
Xchar *				/* NULL if no token left */
Xstrtok(s, delim)
Xchar *s;
Xregister CONST char *delim;
X{
X	register char *scan;
X	char *tok;
X	register CONST char *dscan;
X
X	if (s == NULL && scanpoint == NULL)
X		return(NULL);
X	if (s != NULL)
X		scan = s;
X	else
X		scan = scanpoint;
X
X	/*
X	 * Scan leading delimiters.
X	 */
X	for (; *scan != '\0'; scan++) {
X		for (dscan = delim; *dscan != '\0'; dscan++)
X			if (*scan == *dscan)
X				break;
X		if (*dscan == '\0')
X			break;
X	}
X	if (*scan == '\0') {
X		scanpoint = NULL;
X		return(NULL);
X	}
X
X	tok = scan;
X
X	/*
X	 * Scan token.
X	 */
X	for (; *scan != '\0'; scan++) {
X		for (dscan = delim; *dscan != '\0';)	/* ++ moved down. */
X			if (*scan == *dscan++) {
X				scanpoint = scan+1;
X				*scan = '\0';
X				return(tok);
X			}
X	}
X
X	/*
X	 * Reached end of string.
X	 */
X	scanpoint = NULL;
X	return(tok);
X}
+ END-OF-FILE strtok.c
chmod 'u=rw,g=r,o=r' 'strtok.c'
set `wc -c 'strtok.c'`
count=$1
case $count in
1103)	:;;
*)	echo 'Bad character count in ''strtok.c' >&2
		echo 'Count should be 1103' >&2
esac
echo Extracting 'system.c'
sed 's/^X//' > 'system.c' << '+ END-OF-FILE ''system.c'
X/*  system.c
X *
X *  Changed to return() on fork failure, added signal()
X *  calls.          Terrence W. Holm      Oct. 1988
X */
X
X#include <stdio.h>
X#include <signal.h>
X
Xsystem(cmd)
Xchar *cmd;
X{
X    int retstat, procid, waitstat;
X    int (*sigint)(), (*sigquit)();
X
X    if ( (procid = fork()) == 0) {
X	/* Child does an exec of the command. */
X        execl( "/bin/sh", "sh", "-c", cmd, 0 );
X        exit( 127 );
X    }
X
X    /* Check to see if fork failed. */
X    if (procid < 0) return( 127 << 8 );
X
X    sigint  = signal( SIGINT,  SIG_IGN );
X    sigquit = signal( SIGQUIT, SIG_IGN );
X
X    while ( (waitstat = wait(&retstat)) != procid && waitstat != -1 ) ;
X    if (waitstat == -1) retstat = -1;
X
X    signal( SIGINT,  sigint );
X    signal( SIGQUIT, sigquit );
X
X    return(retstat);
X}
+ END-OF-FILE system.c
chmod 'u=rw,g=r,o=r' 'system.c'
set `wc -c 'system.c'`
count=$1
case $count in
781)	:;;
*)	echo 'Bad character count in ''system.c' >&2
		echo 'Count should be 781' >&2
esac
echo Extracting 'telldir.c'
sed 's/^X//' > 'telldir.c' << '+ END-OF-FILE ''telldir.c'
X/*
X	telldir -- report directory stream position
X
X	last edit:	25-Apr-1987	D A Gwyn
X
X	NOTE:	4.nBSD directory compaction makes seekdir() & telldir()
X		practically impossible to do right.  Avoid using them!
X*/
X
X#include	<sys/errno.h>
X#include	<sys/types.h>
X#include	<dirent.h>
X
Xextern off_t	lseek();
X
Xextern int	errno;
X
X#ifndef SEEK_CUR
X#define	SEEK_CUR	1
X#endif
X
Xoff_t
Xtelldir( dirp )				/* return offset of next entry */
X	DIR	*dirp;			/* stream from opendir() */
X	{
X	if ( dirp == NULL || dirp->dd_buf == NULL )
X		{
X		errno = EFAULT;
X		return -1;		/* invalid pointer */
X		}
X
X	if ( dirp->dd_loc < dirp->dd_size )	/* valid index */
X		return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
X	else				/* beginning of next directory block */
X		return lseek( dirp->dd_fd, (off_t)0, SEEK_CUR );
X	}
+ END-OF-FILE telldir.c
chmod 'u=rw,g=r,o=r' 'telldir.c'
set `wc -c 'telldir.c'`
count=$1
case $count in
794)	:;;
*)	echo 'Bad character count in ''telldir.c' >&2
		echo 'Count should be 794' >&2
esac
echo Extracting 'termcap.c'
sed 's/^X//' > 'termcap.c' << '+ END-OF-FILE ''termcap.c'
X/*
X *	termcap.c	1.1	20/7/87		agc	Joypace Ltd
X *
X *	Copyright Joypace Ltd, London, UK, 1987. All rights reserved.
X *	This file may be freely distributed provided that this notice
X *	remains attached.
X *
X *	A public domain implementation of the termcap(3) routines.
X *
X *	improvements and optimalisation by Klamer Schutte 21/11/88
X */
X#include <stdio.h>
X
X#define CAPABLEN	2
X
X#define ISSPACE(c)	((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
X#define ISDIGIT(x)	((x) >= '0' && (x) <= '9')
X
Xextern short	ospeed;		/* output speed */
Xextern char	PC;		/* padding character */
Xextern char	*BC;		/* back cursor movement */
Xextern char	*UP;		/* up cursor movement */
X
Xchar		*capab = NULL;	/* the capability itself */
Xint		incr;		/* set by %i flag */
X
Xextern char	*getenv();	/* new, improved getenv */
Xextern FILE	*fopen();	/* old fopen */
X
X/*
X *	tgetent - get the termcap entry for terminal name, and put it
X *	in bp (which must be an array of 1024 chars). Returns 1 if
X *	termcap entry found, 0 if not found, and -1 if file not found.
X */
Xint
Xtgetent(bp, name)
Xchar	*bp;
Xchar	*name;
X{
X	FILE	*fp;
X	char	*file;
X	char	*cp;
X	short	len = strlen(name);
X	int	get_entry();
X	int	cnt;
X
X	capab = bp;
X	if ((file = getenv("TERMCAP")) != (char *) NULL) {
X		if (*file != '/' &&
X		    (cp = getenv("TERM")) != NULL && strcmp(name, cp) == 0) {
X			(void) strcpy(bp, file);
X			return(1);
X		}
X	} else
X		file = "/etc/termcap";
X	if ((fp = fopen(file, "r")) == (FILE *) NULL)
X	{	capab = NULL;			/* no valid termcap	*/
X		return(-1); 
X	}
X
X	while( get_entry( bp, fp ) )
X	{ 	cp = bp;
X		do
X		{	for(cnt=0; name[cnt] != 0; cnt++, cp++)
X				if (name[cnt] != *cp)
X					break;
X			if ((name[cnt] != 0) || ((*cp != '|') && (*cp != ':')))
X				goto next_name;
X			fclose(fp);
X			return 1;
Xnext_name: 		while( (*cp) && (*cp != '|') && (*cp != ':'))
X				cp++;
X		} while( *cp++ == '|');
X	}	
X	fclose(fp);
X	capab = NULL;				/* no valid termcap	*/
X	return(0);
X	
X}
X
X/* copy entry in termcap file to buf */
Xstatic get_entry( buf, file )
Xregister char	*buf;
Xregister FILE	*file;
X{
X	register int	c, last = 0;
X	
X	while( (c = fgetc( file )) != EOF)
X		if ((*buf++ = c) == '\n')
X			if (last == '\\')
X				buf -= 2;
X			else
X			{	*buf = 0;
X				return 1;
X			}
X		else
X			last = c;
X	return 0;
X}
X	
X/*
X *	tgetnum - get the numeric terminal capability corresponding
X *	to id. Returns the value, -1 if invalid.
X */
Xint
Xtgetnum(id)
Xchar	*id;	
X{
X	register char	*cp;
X
X	if ((cp = capab) == NULL || id == NULL)
X		return(-1);
X	while (*cp++ != ':')			/* skip terminal name	*/
X		;
X	for (; *cp ; cp++) {
X		if ((*id == *cp++) && (id[1] == *cp)){
X			if (cp[1] != '#')
X				return(-1);
X			return atoi( cp + 2 );
X		}
X		while (*cp && *cp != ':')
X			cp++;
X	}
X	return(-1);
X}
X
X/*
X *	tgetflag - get the boolean flag corresponding to id. Returns -1
X *	if invalid, 0 if the flag is not in termcap entry, or 1 if it is
X *	present.
X */
Xint
Xtgetflag(id)
Xchar	*id;
X{
X	register char	*cp;
X
X	if ((cp = capab) == NULL || id == NULL)
X		return(-1);
X	while (*cp++ != ':')			/* skip terminal name	*/
X		;
X	for ( ; *cp ; cp++) {
X		if ((*id == *cp++) && (id[1] == *cp))
X			return(1);
X		while (*cp && *cp != ':')
X			cp++;
X	}
X	return(0);
X}
X
X/*
X *	tgetstr - get the string capability corresponding to id and place
X *	it in area (advancing area at same time). Expand escape sequences
X *	etc. Returns the string, or NULL if it can't do it.
X */
Xchar *
Xtgetstr(id, area)
Xchar	*id;
Xchar	**area;
X{
X	register char	*cp, *wsp;		/* workspace == *area	*/
X	char	*ret;
X	int	i;
X
X	if ((cp = capab) == NULL || id == NULL)
X		return(NULL);
X	while (*cp++ != ':')			/* skip terminal name	*/
X		;
X	for ( ; *cp ; cp++) {
X		if ((*id == *cp++) && (id[1] == *cp)){
X			if (cp[1] != '=')
X				return(NULL);
X			cp += 2;
X			for (ret = wsp = *area; *cp && *cp != ':' ; wsp++, cp++)
X				switch(*cp) {
X				case '^' :
X					*wsp = *++cp - 'A';
X					break;
X				case '\\' :
X					switch(*++cp) {
X					case 'E' :
X						*wsp = '\033';
X						break;
X					case 'n' :
X						*wsp = '\n';
X						break;
X					case 'r' :
X						*wsp = '\r';
X						break;
X					case 't' :
X						*wsp = '\t';
X						break;
X					case 'b' :
X						*wsp = '\b';
X						break;
X					case 'f' :
X						*wsp = '\f';
X						break;
X					case '0' :
X					case '1' :
X					case '2' :
X					case '3' :
X						for (i=0 ; *cp && ISDIGIT(*cp) ; cp++)
X							i = i * 8 + *cp - '0';
X						*wsp = i;
X						cp--;
X						break;
X					case '^' :
X					case '\\' :
X						*wsp = *cp;
X						break;
X					}
X					break;
X				default :
X					*wsp = *cp;
X				}
X			*area = wsp;
X			*(*area)++ = '\0';
X			return(ret);
X		}
X		while (*cp && *cp != ':')
X			cp++;
X	}
X	return(NULL);
X}
X
X/*
X *	tgoto - given the cursor motion string cm, make up the string
X *	for the cursor to go to (destcol, destline), and return the string.
X *	Returns "OOPS" if something's gone wrong, or the string otherwise.
X */
Xchar *
Xtgoto(cm, destcol, destline)
Xchar	*cm;
Xint	destcol;
Xint	destline;
X{
X	register char	*rp;
X	static char	ret[24];
X	int		*dp = &destcol;
X	int 		argno = 0, numval;
X
X	for (rp = ret ; *cm ; cm++) {
X		switch(*cm) {
X		case '%' :
X			switch(*++cm) {
X			case '+' :
X				if (dp == NULL)
X					return("OOPS");
X				*rp++ = *dp + *++cm;
X				dp = (dp == &destcol) ? &destline : NULL;
X				break;
X
X			case '%' :
X				*rp++ = '%';
X				break;
X
X			case 'i' :
X
X				incr = 1;
X				break;
X
X			case 'd' :
X				numval = (argno == 0 ? destline : destcol);
X				numval += incr;
X				argno++;
X				*rp++ = '0' + (numval/10);
X				*rp++ = '0' + (numval%10);
X				break;
X			}
X
X			break;
X		default :
X			*rp++ = *cm;
X		}
X	}
X	*rp = '\0';
X	return(ret);
X}
X
X/*
X *	tputs - put the string cp out onto the terminal, using the function
X *	outc. This should do padding for the terminal, but I can't find a
X *	terminal that needs padding at the moment...
X */
Xint
Xtputs(cp, affcnt, outc)
Xregister char	*cp;
Xint		affcnt;
Xint		(*outc)();
X{
X	if (cp == NULL)
X		return(1);
X	/* do any padding interpretation - left null for MINIX just now */
X	while (*cp)
X		(*outc)(*cp++);
X	return(1);
X}
+ END-OF-FILE termcap.c
chmod 'u=rw,g=r,o=r' 'termcap.c'
set `wc -c 'termcap.c'`
count=$1
case $count in
5908)	:;;
*)	echo 'Bad character count in ''termcap.c' >&2
		echo 'Count should be 5908' >&2
esac
echo Extracting 'utime.c'
sed 's/^X//' > 'utime.c' << '+ END-OF-FILE ''utime.c'
X/* utime(2) for POSIX		Authors: Terrence W. Holm & Edwin L. Froese */
X
X#include "lib.h"
X
X#define NULL  (long *) 0
X
Xextern long time();
X
X
XPUBLIC int utime(name, timp)
Xchar *name;
Xlong current_time, timp[2];
X{
X  if (timp == NULL) {
X      current_time = time(NULL);
X      M.m2_l1 = current_time;
X      M.m2_l2 = current_time;
X  } else {
X      M.m2_l1 = timp[0];
X      M.m2_l2 = timp[1];
X  }
X
X  M.m2_i1 = len(name);
X  M.m2_p1 = name;
X  return callx(FS, UTIME);
X}
+ END-OF-FILE utime.c
chmod 'u=rw,g=r,o=r' 'utime.c'
set `wc -c 'utime.c'`
count=$1
case $count in
459)	:;;
*)	echo 'Bad character count in ''utime.c' >&2
		echo 'Count should be 459' >&2
esac
echo Extracting 'vsprintf.c'
sed 's/^X//' > 'vsprintf.c' << '+ END-OF-FILE ''vsprintf.c'
X#include <stdio.h>
X#include <varargs.h>
X
Xchar *vsprintf(buf,format,argp)
Xchar *buf, *format;
Xva_list argp;
X{
X	FILE _tempfile;
X
X	_tempfile._fd    = -1;
X	_tempfile._flags = WRITEMODE + STRINGS;
X	_tempfile._buf   = buf;
X	_tempfile._ptr   = buf;
X
X	vfprintf(&_tempfile,format,argp);
X	putc('\0',&_tempfile);
X
X	return buf;
X}
+ END-OF-FILE vsprintf.c
chmod 'u=rw,g=r,o=r' 'vsprintf.c'
set `wc -c 'vsprintf.c'`
count=$1
case $count in
318)	:;;
*)	echo 'Bad character count in ''vsprintf.c' >&2
		echo 'Count should be 318' >&2
esac
exit 0