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

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 'bcmp.c'
sed 's/^X//' > 'bcmp.c' << '+ END-OF-FILE ''bcmp.c'
X/*
X - bcmp - Berklix equivalent of memcmp
X */
X
Xint				/* == 0 or != 0 for equality and inequality */
Xbcmp(s1, s2, length)
XCONST char *s1;
XCONST char *s2;	
Xint length;
X{
X	return(memcmp((CONST VOIDSTAR)s1, (CONST VOIDSTAR)s2, (SIZET)length));
X}
+ END-OF-FILE bcmp.c
chmod 'u=rw,g=r,o=r' 'bcmp.c'
set `wc -c 'bcmp.c'`
count=$1
case $count in
243)	:;;
*)	echo 'Bad character count in ''bcmp.c' >&2
		echo 'Count should be 243' >&2
esac
echo Extracting 'bcopy.c'
sed 's/^X//' > 'bcopy.c' << '+ END-OF-FILE ''bcopy.c'
X/*
X - bcopy - Berklix equivalent of memcpy
X */
X
Xbcopy(src, dst, length)
XCONST char *src;
Xchar *dst;
Xint length;
X{
X	extern VOIDSTAR memcpy();
X
X	(void) memcpy((VOIDSTAR)dst, (CONST VOIDSTAR)src, (SIZET)length);
X}
+ END-OF-FILE bcopy.c
chmod 'u=rw,g=r,o=r' 'bcopy.c'
set `wc -c 'bcopy.c'`
count=$1
case $count in
211)	:;;
*)	echo 'Bad character count in ''bcopy.c' >&2
		echo 'Count should be 211' >&2
esac
echo Extracting 'bzero.c'
sed 's/^X//' > 'bzero.c' << '+ END-OF-FILE ''bzero.c'
X/*
X - bzero - Berklix subset of memset
X */
X
Xbzero(dst, length)
Xchar *dst;
Xint length;
X{
X	extern VOIDSTAR memset();
X
X	(void) memset((VOIDSTAR)dst, 0, (SIZET)length);
X}
+ END-OF-FILE bzero.c
chmod 'u=rw,g=r,o=r' 'bzero.c'
set `wc -c 'bzero.c'`
count=$1
case $count in
167)	:;;
*)	echo 'Bad character count in ''bzero.c' >&2
		echo 'Count should be 167' >&2
esac
echo Extracting 'closedir.c'
sed 's/^X//' > 'closedir.c' << '+ END-OF-FILE ''closedir.c'
X/*
X	closedir -- close a directory stream
X
X	last edit:	11-Nov-1988	D A Gwyn
X*/
X
X#include	<sys/errno.h>
X#include	<sys/types.h>
X#include	<dirent.h>
X
Xtypedef char	*pointer;		/* (void *) if you have it */
X
Xextern void	free();
Xextern int	close();
X
Xextern int	errno;
X
X#ifndef NULL
X#define	NULL	0
X#endif
X
Xint
Xclosedir( dirp )
X	register DIR	*dirp;		/* stream from opendir() */
X	{
X	register int	fd;
X
X	if ( dirp == NULL || dirp->dd_buf == NULL )
X		{
X		errno = EFAULT;
X		return -1;		/* invalid pointer */
X		}
X
X	fd = dirp->dd_fd;		/* bug fix thanks to R. Salz */
X	free( (pointer)dirp->dd_buf );
X	free( (pointer)dirp );
X	return close( fd );
X	}
+ END-OF-FILE closedir.c
chmod 'u=rw,g=r,o=r' 'closedir.c'
set `wc -c 'closedir.c'`
count=$1
case $count in
630)	:;;
*)	echo 'Bad character count in ''closedir.c' >&2
		echo 'Count should be 630' >&2
esac
echo Extracting 'ctype.c'
sed 's/^X//' > 'ctype.c' << '+ END-OF-FILE ''ctype.c'
X/*  ctype.c  */
X
X/*  Included ^I..^M in iscntrl(3). Added toupper(3) and  */
X/*  tolower(3)        Terrence W. Holm      Oct. 1988    */
X
X
X#include <ctype.h>
X#include <stdio.h>
X
Xchar _ctype_[] = {
X	0,
X	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
X	_C,	_S|_C,	_S|_C,	_S|_C,	_S|_C,	_S|_C,	_C,	_C,
X	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
X	_C,	_C,	_C,	_C,	_C,	_C,	_C,	_C,
X	_S|_SP,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
X	_P,	_P,	_P,	_P,	_P,	_P,	_P,	_P,
X	_N,	_N,	_N,	_N,	_N,	_N,	_N,	_N,
X	_N,	_N,	_P,	_P,	_P,	_P,	_P,	_P,
X	_P,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U|_X,	_U,
X	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
X	_U,	_U,	_U,	_U,	_U,	_U,	_U,	_U,
X	_U,	_U,	_U,	_P,	_P,	_P,	_P,	_P,
X	_P,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L|_X,	_L,
X	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
X	_L,	_L,	_L,	_L,	_L,	_L,	_L,	_L,
X	_L,	_L,	_L,	_P,	_P,	_P,	_P,	_C
X};
X
X
Xtoupper( c )
X  int c;
X  {
X  return( islower(c) ? _toupper(c) : c );
X  }
X
X
Xtolower( c )
X  int c;
X  {
X  return( isupper(c) ? _tolower(c) : c );
X  }
+ END-OF-FILE ctype.c
chmod 'u=rw,g=r,o=r' 'ctype.c'
set `wc -c 'ctype.c'`
count=$1
case $count in
934)	:;;
*)	echo 'Bad character count in ''ctype.c' >&2
		echo 'Count should be 934' >&2
esac
echo Extracting 'ctype.note'
sed 's/^X//' > 'ctype.note' << '+ END-OF-FILE ''ctype.note'
XEFTH MINIX report #50  - October 1988 -  ctype(3) changes
X
X
XI have changed iscntrl(3), isprint(3), isgraph(3), 
Xtoupper(3) and tolower(3) to be as defined in POSIX.
X"man" pages are included.
X
X
XFiles changed: /usr/include/ctype.h and minix/lib/libc/ctype.c
X
XDetails of changes:
X	1) isprint(3) now includes SPACE.
X	2) isgraph(3) added.
X	3) iscntrl(3) now includes all control characters.
X	4) The old toupper() and tolower() are now
X	   called _toupper() and _tolower().
X	5) Subroutines were added to perform the correct
X	   toupper(3) and tolower(3).
X	6) Toascii(3) added.
+ END-OF-FILE ctype.note
chmod 'u=rw,g=r,o=r' 'ctype.note'
set `wc -c 'ctype.note'`
count=$1
case $count in
571)	:;;
*)	echo 'Bad character count in ''ctype.note' >&2
		echo 'Count should be 571' >&2
esac
echo Extracting 'curses.c'
sed 's/^X//' > 'curses.c' << '+ END-OF-FILE ''curses.c'
X/************************************************************************
X *									*
X *			 Tiny pseudo "curses" package			*
X *									*
X *		v1.0	870117	DBW - D. Wecker, initial hack		*
X *		v1.1    881003  W. Toomey, hacked to get it to use	*
X *				Termcap, and to not foul input.		*
X *				Borrowed a bit of code from Alistair	*
X *				Crooks' `show.c' posted on 870730.	*
X *									*
X ************************************************************************/
X
X/* #include <sys/ioctl.h>	- the ioctl calls seem to stop input */
X#include <sgtty.h>
X#include <signal.h>
X#include <stdio.h>
Xstruct sgttyb old_tty,new_tty;
X
Xextern char	*tgetstr();	/* termcap getstring capability */
Xextern char	*tgoto();	/* termcap goto (x, y) */
Xextern char	*getenv();	/* get an environment variable */
X
X
X#define ROWS	24
X#define COLS	80
X#define NORMAL	0x00
X#define BOLD	0x80
X
Xchar		termcap[1024];	/* termcap buffer */
Xchar		tc[100];	/* area to hold string capabilities */
Xchar		*ttytype;	/* terminal type from env */
Xchar		*arp;		/* pointer for use in tgetstr */
Xchar		*cp;		/* character pointer */
X
Xchar		*cl;		/* clear screen capability */
Xchar		*cm;		/* cursor motion capability */
Xchar		*so;		/* start standout capability */
Xchar		*se;		/* end standout capability */
X
X
Xchar	nscrn[ROWS][COLS],
X	cscrn[ROWS][COLS],
X	row,
X	col,
X	mode;
Xchar	str[256];
X
X
X/*
X *	fatal - report error and die. Never returns
X */
Xvoid
Xfatal(s)
Xchar	*s;
X{
X	(void) fprintf(stderr, "curses: %s\n", s);
X	exit(1);
X}
X
X
X/*
X *	outc - call putchar, necessary because putchar is a macro.
X */
Xint
Xoutc(c)
Xint	c;
X{
X	putchar(c);
X}
X
X
Xmove(y,x)
Xint y,x;
X    {
X    row = y;
X    col = x;
X    }
X
Xclrtoeol() {
X    int i;
X
X    for (i = col; i < COLS; i++) nscrn[row][i] = ' ' | mode;
X    }
X
Xprintw(fmt,a1,a2,a3,a4,a5)
Xchar	*fmt,*a1,*a2,*a3,*a4,*a5;
X    {
X    int i,j,k;
X
X    sprintf(str,fmt,a1,a2,a3,a4,a5);
X    j = 0; k=row;
X    for (i = col; i < COLS && k < ROWS && str[j] != '\000'; i++)
X	if (str[j] != '\n')
X	  nscrn[k][i] = str[j++] | mode;
X        else { i=0; j++; k++; }
X    col = i; row=k;
X    }
X
Xclrtobot() {
X    int i,j;
X
X    clrtoeol();
X    for (i = row+1; i < ROWS; i++)
X	for (j = 0; j < COLS; j++)
X	    nscrn[i][j] = ' ' | mode;
X    }
X
Xstandout() {
X    mode = BOLD;
X    }
X
Xstandend() {
X    mode = NORMAL;
X    }
X
Xaddstr(s)
Xchar	*s;
X    {
X    printw("%s",s);
X    }
X
Xinitscr() {
X    int	    i,j;
X/* 
X    ioctl(0,TIOCGETP,&old_tty);			I don't have a clue
X    ioctl(0,TIOCGETP,&new_tty);			why these are used,
X    new_tty.sg_flags |= RAW;			but I've commented them
X    new_tty.sg_flags &= ~ECHO;			out to get stdin working.
X    ioctl(0,TIOCSETP,&new_tty);
X*/
X   if ((ttytype = getenv("TERM")) == NULL)
X     fatal("No terminal type set in environment");
X
X   if (tgetent(termcap, ttytype) != 1)
X     fatal("No termcap entry for terminal");
X   arp = tc;
X   cl = tgetstr("cl", &arp);
X   so = tgetstr("so", &arp);
X   se = tgetstr("se", &arp);
X   cm = tgetstr("cm", &arp);
X
X    row	    = 0;
X    col	    = 0;
X    mode    = NORMAL;
X    for (i = 0; i < ROWS; i++)
X	for (j = 0; j < COLS; j++)
X	    nscrn[i][j] = cscrn[i][j] = ' ';
X    tputs(cl,1,outc);
X    }
X
Xclear() {
X    row = 0;
X    col = 0;
X    clrtobot();
X    }
X
Xendwin() {
X    move(ROWS-1,0);
X    refresh();
X/* 
X    ioctl(0,TIOCSETP,&old_tty);
X */
X    }
X
Xchar inch() {
X    return(nscrn[row][col] & 0x7F);
X    }
X
Xtouchwin() {
X    int i,j;
X
X    for (i=0; i<ROWS; i++)
X	for (j=0; j<COLS; j++)
X	    cscrn[i][j] = ' ';
X    tputs(cl,1,outc);
X    }
X
Xrefresh() {
X    int	i,j,mode;
X
X    mode = NORMAL;
X    for (i=0; i < ROWS; i++) {
X	for (j = 0; j < COLS; j++) {
X	    if (nscrn[i][j] != cscrn[i][j]) {
X		cp=tgoto(cm,j+1,i+1);
X		tputs(cp,1,outc);
X		while (nscrn[i][j] != cscrn[i][j]) {
X		    if (mode == NORMAL && (nscrn[i][j] & BOLD) == BOLD) {
X			tputs(so,1,outc);
X			mode = BOLD;
X			}
X		    else if (mode == BOLD && (nscrn[i][j] & BOLD) == NORMAL) {
X			tputs(se,1,outc);
X			mode = NORMAL;
X			}
X		    cscrn[i][j] = nscrn[i][j];
X		    fputc(nscrn[i][j] & 0x7F,stdout);
X		    j++;
X		    }
X		}
X	    }
X	}
X    cp=tgoto(cm,col+1,row+1);
X    tputs(cp,1,outc);
X    if (mode) tputs(se,1,outc);
X    fflush(stdout);
X    }
+ END-OF-FILE curses.c
chmod 'u=rw,g=r,o=r' 'curses.c'
set `wc -c 'curses.c'`
count=$1
case $count in
4095)	:;;
*)	echo 'Bad character count in ''curses.c' >&2
		echo 'Count should be 4095' >&2
esac
echo Extracting 'fdopen.c'
sed 's/^X//' > 'fdopen.c' << '+ END-OF-FILE ''fdopen.c'
X#include <stdio.h>
X
XFILE *
Xfdopen(fd ,mode)
X	int fd;
X	char *mode;
X{
X	register int i;
X	FILE *fp;
X	char *malloc();
X	int flags = 0;
X
X	for (i = 0; _io_table[i] != 0 ; i++)
X		if ( i >= NFILES )
X			return(NULL);
X
X	switch(*mode) {
X		case 'w':
X			flags |= WRITEMODE;
X			break;
X		case 'a':
X			flags |= WRITEMODE;
X			break;
X		case 'r':
X			flags |= READMODE;
X			break;
X		default:
X			return(NULL);
X	}
X
X	if ((fp = (FILE *) malloc (sizeof(FILE))) == NULL)
X		return(NULL);
X
X	fp->_count = 0;
X	fp->_fd = fd;
X	fp->_flags = flags;
X	fp->_buf = malloc(BUFSIZ);
X	fp->_flags |= IOMYBUF;
X	fp->_ptr = fp->_buf;
X	_io_table[i] = fp;
X	return(fp);
X}
+ END-OF-FILE fdopen.c
chmod 'u=rw,g=r,o=r' 'fdopen.c'
set `wc -c 'fdopen.c'`
count=$1
case $count in
621)	:;;
*)	echo 'Bad character count in ''fdopen.c' >&2
		echo 'Count should be 621' >&2
esac
echo Extracting 'fortune.dat'
sed 's/^X//' > 'fortune.dat' << '+ END-OF-FILE ''fortune.dat'
XA bore is a man who, when you ask him how he is, tells you.
X  - B. L. Taylor
X%%
XOh gracious, why wasn't I born old and ugly?
X  - Dickens
X%%
XWeather is a literary specialty, and no untrained hand
Xcan turn out a good article on it.
X  - M. Twain
X%%
XA verbal contract isn't worth the paper it's written on.
X  - S. Goldwyn
X%%
X"Classic." A book which people praise and don't read.
X  - M. Twain
X%%
XThree may keep a secret, if two of them are dead.
X  - Benjamin Franklin
X%%
XEverything is funny as long as it is happening
Xto someone else.
X  - Will Rogers
X%%
XI never forget a face, but in your case I'll make an exception.
X  - Groucho Marx
X%%
XOne of the most striking differences between a cat and a lie
Xis that a cat has only nine lives.
X  - M. Twain
X%%
XWhy is it that we rejoice at a birth and grieve at a funeral?
XIt is because we are not the person involved.
X  - M. Twain
X%%
XWhen angry, count four;
Xwhen very angry, swear.
X  - M. Twain
X%%
XA perfect vacuum exists only in the minds of men.
X  - P. H. Beck
X%%
XThose whose courses are different cannot lay plans for one another.
X  - Confucian Analects Bk. 15:39
X%%
XLearning without thought is labor lost;
Xthought without learning is perilous.
X  - Confucian Analects Bk. 2:15
X%%
XThe falsely dramatic drives out the truly dull.
X  - Gennerat's Law
X%%
XOur universe is simply one of those things that happen from time to time.
X  - Edward Tryon
X%%
XWhen you have eliminated the impossible, whatever remains,
Xhowever improbable, must be the truth.
X  - Sherlock Holmes
X%%
Xadmiration, n.
XOur polite recognition of another's resemblance to ourselves.
X  - Ambrose Bierce, "The Devil's Dictionary"
X%%
Xbore, n.
XA person who talks when you wish him to listen.
X  - Ambrose Bierce, "The Devil's Dictionary"
X%%
Xcoward, n.
XOne who in a perilous emergency thinks with his legs.
X  - Ambrose Bierce, "The Devil's Dictionary"
X%%
XWhat is worth doing is worth the trouble of asking somebody to do it.
X%%
XFamous remarks are very seldom quoted correctly.
X  - Simeon Strunsky
X%%
XTo go beyond is as wrong as to fall short.
X  - Confucian Analects, Bk. 11:15,iii
X%%
XHe who speaks without modesty will find
Xit difficult to make his words good.
X  - Confucian Analects, Bk. 14:21
X%%
XHeaven and earth are not humane.
XThey regard all things as straw dogs.
X  - Lao Tzu
X%%
XHe who knows others is wise.
XHe who knows himself is enlightened.
X  - Lao Tzu
X%%
XHe who knows does not speak.
XHe who speaks does not know.
X  - Lao Tzu
X%%
XTo know that you do not know is the best.
XTo pretend to know when you do not know is a disease.
X  - Lao Tzu
X%%
XTime is the most valuable thing a man can spend.
X  - Theophrastus
X%%
XYou cannot put the same shoe on every foot.
X  - Publilius Syrus
X%%
XIf I have seen further it is by standing on the shoulders of giants.
X  - Sir Isaac Newton
X%%
XThe probability of someone watching you is
Xproportional to the stupidity of your action.
X  - A. Kindsvater
X%%
XThe various forms of worship, which prevailed in the Roman world,
Xwere all considered by the people as equally true; by the philosopher,
Xas equally false; and by the magistrate, as equally useful.
X  - Edward Gibbon, "The Decline and Fall of the Roman Empire"
X%%
XOf course you realize this means war!
X  - Bugs Bunny
X%%
XThe optimist proclaims that we live in the best of all possible worlds;
Xand the pessimist fears this is true.
X  - James Branch Cabell
X%%
XNever underestimate the power of human stupidity.
X  - From the "Notebooks of Lazarus Long" by Robert Heinlein
X%%
XOnly a mediocre person is always at his best.
X  - W. Somerset Maugham
X%%
XLife is a continuing series of multiple-choice questions, with the answers
Xtorn out of the back of the book.
X  - Sydney J. Harris
X%%
XThere is a theory which states that if ever anyone discovers exactly what
Xthe Universe is for and why it is  here. it  will instantly disappear and
Xbe replaced by something even more bizarre and inexplicable.
X
XThere is another theory which states that this has already happened.
X  - Douglas Adams, "The Restaurant at the end of the Universe"
X%%
XThe following sentence is false.
XThe preceding sentence is true.
X%%
XA well-frog cannot imagine the ocean, nor can a
Xsummer insect conceive of ice. How can a scholar
Xunderstand the Tao? He is restricted by his own
Xlearning.
X  - Chung-tse
X%%
Xpanic: can't spare any memory for you today.
X%%
X!XINIM ni deppart m'I !pleH
X%%
Xpanic: page segment violation
X%%
Xpanic: not enough memory (hey, I've got some very cheap 41256's for you)
X%% 
XHeaven wheels above you
XDisplaying to you eternal glories
XAnd still your eyes are on the ground.
X  - Dante
X%%
XWhen the mind is disturbed, the multiplicity of things is
Xproduced, but when the mind is quieted, the multiplicity
Xof things disappears.
X  - Ashvaghosha, "The Awakening of Faith.
X%%
+ END-OF-FILE fortune.dat
chmod 'u=rw,g=r,o=r' 'fortune.dat'
set `wc -c 'fortune.dat'`
count=$1
case $count in
4719)	:;;
*)	echo 'Bad character count in ''fortune.dat' >&2
		echo 'Count should be 4719' >&2
esac
echo Extracting 'getdents.c'
sed 's/^X//' > 'getdents.c' << '+ END-OF-FILE ''getdents.c'
X/*
X	getdents -- get directory entries in a file system independent format
X			(SVR3 system call emulation)
X
X	last edit:	27-Oct-1988	D A Gwyn
X
X	This single source file supports several different methods of
X	getting directory entries from the operating system.  Define
X	whichever one of the following describes your system:
X
X	UFS	original UNIX filesystem (14-character name limit)
X	BFS	4.2BSD (also 4.3BSD) native filesystem (long names)
X	NFS	getdirentries() system call
X
X	Also define any of the following flags that are pertinent:
X
X	ATT_SPEC	check user buffer address for longword alignment
X	BSD_SYSV	BRL UNIX System V emulation environment on 4.nBSD
X	INT_SIGS	<signal.h> thinks that signal handlers have
X			return type int (rather than the standard void)
X	NEG_DELS	deleted entries have inode number -1 rather than 0
X	UNK		have _getdents() system call, but kernel may not
X			support it
X
X	If your C library has a getdents() system call interface, but you
X	can't count on all kernels on which your application binaries may
X	run to support it, change the system call interface name to
X	_getdents() and define "UNK" to enable the system-call validity
X	test in this "wrapper" around _getdents().
X
X	If your system has a getdents() system call that is guaranteed 
X	to always work, you shouldn't be using this source file at all.
X*/
X
X#define  UFS
X
X#include	<sys/errno.h>
X#include	<sys/types.h>
X#ifdef BSD_SYSV
X#include	<sys/_dir.h>		/* BSD flavor, not System V */
X#else
X#include	<sys/dir.h>
X#undef	MAXNAMLEN			/* avoid conflict with SVR3 */
X	/* Good thing we don't need to use the DIRSIZ() macro! */
X#ifdef d_ino				/* 4.3BSD/NFS using d_fileno */
X#undef	d_ino				/* (not absolutely necessary) */
X#else
X#define	d_fileno	d_ino		/* (struct direct) member */
X#endif
X#endif
X#include	<sys/dirent.h>
X#include	<sys/stat.h>
X#ifdef UNK
X#ifndef UFS
X#include "***** ERROR ***** UNK applies only to UFS"
X/* One could do something similar for getdirentries(), but I didn't bother. */
X#endif
X#include	<signal.h>
X#endif
X
X#ifdef BSD_SYSV
Xstruct dirent	__dirent;		/* (just for the DIRENTBASESIZ macro) */
X#endif
X
X#ifdef UFS
X#define	RecLen( dp )	(sizeof(struct direct))	/* fixed-length entries */
X#else	/* BFS || NFS */
X#define	RecLen( dp )	((dp)->d_reclen)	/* variable-length entries */
X#endif
X
X#ifdef NFS
X#ifdef BSD_SYSV
X#define	getdirentries	_getdirentries	/* package hides this system call */
X#endif
Xextern int	getdirentries();
Xstatic long	dummy;			/* getdirentries() needs basep */
X#define	GetBlock( fd, buf, n )	getdirentries( fd, buf, (unsigned)n, &dummy )
X#else	/* UFS || BFS */
X#ifdef BSD_SYSV
X#define read	_read			/* avoid emulation overhead */
X#endif
Xextern int	read();
X#define	GetBlock( fd, buf, n )	read( fd, buf, (unsigned)n )
X#endif
X
X#ifdef UNK
Xextern int	_getdents();		/* actual system call */
X#endif
X
Xextern char	*strncpy();
Xextern int	fstat();
Xextern off_t	lseek();
X
Xextern int	errno;
X
X#ifdef NEG_DELS
X#define	DELETED	(-1)
X#else
X#define	DELETED	0
X#endif
X
X#ifndef DIRBLKSIZ
X#define	DIRBLKSIZ	4096		/* directory file read buffer size */
X#endif
X
X#ifndef NULL
X#define	NULL	0
X#endif
X
X#ifndef SEEK_CUR
X#define	SEEK_CUR	1
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
X#ifdef UFS
X
X/*
X	The following routine is necessary to handle DIRSIZ-long entry names.
X	Thanks to Richard Todd for pointing this out.
X*/
X
Xstatic int
XNameLen( name )				/* return # chars in embedded name */
X	char		name[];		/* -> name embedded in struct direct */
X	{
X	register char	*s;		/* -> name[.] */
X	register char	*stop = &name[DIRSIZ];	/* -> past end of name field */
X
X	for ( s = &name[1];		/* (empty names are impossible) */
X	      *s != '\0'		/* not NUL terminator */
X	   && ++s < stop;		/* < DIRSIZ characters scanned */
X	    )
X		;
X
X	return s - name;		/* # valid characters in name */
X	}
X
X#else	/* BFS || NFS */
X
Xextern int	strlen();
X
X#define	NameLen( name )	strlen( name )	/* names are always NUL-terminated */
X
X#endif
X
X#ifdef UNK
Xstatic enum	{ maybe, no, yes }	state = maybe;
X					/* does _getdents() work? */
X
X#ifdef INT_SIGS
X#define	RET_SIG	int
X#else
X#define	RET_SIG	void
X#endif
X
X/*ARGSUSED*/
Xstatic RET_SIG
Xsig_catch( sig )
X	int	sig;			/* must be SIGSYS */
X	{
X	state = no;			/* attempted _getdents() faulted */
X#ifdef INT_SIGS
X	return 0;			/* telling lies */
X#endif
X	}
X#endif	/* UNK */
X
Xint
Xgetdents( fildes, buf, nbyte )		/* returns # bytes read;
X					   0 on EOF, -1 on error */
X	int			fildes;	/* directory file descriptor */
X	char			*buf;	/* where to put the (struct dirent)s */
X	unsigned		nbyte;	/* size of buf[] */
X	{
X	int			serrno;	/* entry errno */
X	off_t			offset;	/* initial directory file offset */
X	/* The following are static just to keep the stack small. */
X	static struct stat	statb;	/* fstat() info */
X	static union
X		{
X		char		dblk[DIRBLKSIZ
X#ifdef UFS
X				     +1	/* for last entry name terminator */
X#endif
X				    ];
X					/* directory file block buffer */
X		struct direct	dummy;	/* just for alignment */
X		}	u;		/* (avoids having to malloc()) */
X	register struct direct	*dp;	/* -> u.dblk[.] */
X	register struct dirent	*bp;	/* -> buf[.] */
X
X#ifdef UNK
X	if ( state == yes )		/* _getdents() is known to work */
X		return _getdents( fildes, buf, nbyte );
X
X	if ( state == maybe )		/* first time only */
X		{
X		RET_SIG		(*shdlr)();	/* entry SIGSYS handler */
X		register int	retval;	/* return from _getdents() if any */
X
X		shdlr = signal( SIGSYS, sig_catch );
X		retval = _getdents( fildes, buf, nbyte );	/* try it */
X		(void)signal( SIGSYS, shdlr );
X
X		if ( state == maybe )	/* SIGSYS did not occur */
X			{
X			state = yes;	/* so _getdents() must have worked */
X			return retval;
X			}
X		}
X
X	/* state == no; perform emulation */
X#endif
X
X	if ( buf == NULL
X#ifdef ATT_SPEC
X	  || (unsigned long)buf % sizeof(long) != 0	/* ugh */
X#endif
X	   )	{
X		errno = EFAULT;		/* invalid pointer */
X		return -1;
X		}
X
X	if ( fstat( fildes, &statb ) != 0 )
X		return -1;		/* errno set by fstat() */
X
X	if ( !S_ISDIR( statb.st_mode ) )
X		{
X		errno = ENOTDIR;	/* not a directory */
X		return -1;
X		}
X
X	if ( (offset = lseek( fildes, (off_t)0, SEEK_CUR )) < 0 )
X		return -1;		/* errno set by lseek() */
X
X#ifdef BFS				/* no telling what remote hosts do */
X	if ( (unsigned long)offset % DIRBLKSIZ != 0 )
X		{
X		errno = ENOENT;		/* file pointer probably misaligned */
X		return -1;
X		}
X#endif
X
X	serrno = errno;			/* save entry errno */
X
X	for ( bp = (struct dirent *)buf; bp == (struct dirent *)buf; )
X		{			/* convert next directory block */
X		int	size;
X
X		do	size = GetBlock( fildes, u.dblk, DIRBLKSIZ );
X		while ( size == -1 && errno == EINTR );
X
X		if ( size <= 0 )
X			return size;	/* EOF or error (EBADF) */
X
X		for ( dp = (struct direct *)u.dblk;
X		      (char *)dp < &u.dblk[size];
X		      dp = (struct direct *)((char *)dp + RecLen( dp ))
X		    )	{
X#ifndef UFS
X			if ( dp->d_reclen <= 0 )
X				{
X				errno = EIO;	/* corrupted directory */
X				return -1;
X				}
X#endif
X
X			if ( dp->d_fileno != DELETED )
X				{	/* non-empty; copy to user buffer */
X				register int	reclen =
X					DIRENTSIZ( NameLen( dp->d_name ) );
X
X				if ( (char *)bp + reclen > &buf[nbyte] )
X					{
X					errno = EINVAL;
X					return -1;	/* buf too small */
X					}
X
X				bp->d_ino = dp->d_fileno;
X				bp->d_off = offset + ((char *)dp - u.dblk);
X				bp->d_reclen = reclen;
X
X				{
X#ifdef UFS
X				/* Is the following kludge ugly?  You bet. */
X
X				register char	save = dp->d_name[DIRSIZ];
X					/* save original data */
X
X				dp->d_name[DIRSIZ] = '\0';
X					/* ensure NUL termination */
X#endif
X				(void)strncpy( bp->d_name, dp->d_name,
X					       reclen - DIRENTBASESIZ
X					     );	/* adds NUL padding */
X#ifdef UFS
X				dp->d_name[DIRSIZ] = save;
X					/* restore original data */
X#endif
X				}
X
X				bp = (struct dirent *)((char *)bp + reclen);
X				}
X			}
X
X		if ( (char *)dp > &u.dblk[size] )
X			{
X			errno = EIO;	/* corrupted directory */
X			return -1;
X			}
X		}
X
X	errno = serrno;			/* restore entry errno */
X	return (char *)bp - buf;	/* return # bytes read */
X	}
+ END-OF-FILE getdents.c
chmod 'u=rw,g=r,o=r' 'getdents.c'
set `wc -c 'getdents.c'`
count=$1
case $count in
7950)	:;;
*)	echo 'Bad character count in ''getdents.c' >&2
		echo 'Count should be 7950' >&2
esac
echo Extracting 'getopt.c'
sed 's/^X//' > 'getopt.c' << '+ END-OF-FILE ''getopt.c'
X/*
X * getopt - get option letter from argv
X *
X *    Getopt(3) is used to ease the process of scanning the
X *    options on a command line. The <argc> and <argv> given
X *    to main() are passed to getopt(3), as well as a string
X *    naming all of the single character option names. If
X *    an option allows an argument, then a ':' is put after
X *    the name in <optstring>.
X *
X *    For example, the <optstring> "af:x" means that the
X *    command accepts the options "-a", "-f" and "-x". The
X *    "-f" option has an argument. When a command line is
X *    entered the options without a following argument may
X *    be grouped together, and there may be space between
X *    the "-f" and its argument in the command line. For
X *    example,
X *
X *	cmd -a -xf arg rest of line
X *
X *    After each call, main() must check the returned option
X *    name and, if appropriate, the argument referenced by
X *    <optarg>. Main() should continue to call getopt(3) until
X *    it returns EOF, at which time main() can use <optind> to
X *    determine how many items still remain on the command line.
X *
X *    The cases for getopt(3) returning EOF are: no more items
X *    in the command line, an item does not start with a "-",
X *    an item is simply "-" or an item is "--". In the latter
X *    case, <optind> is incremented past this item.
X *
X *    Normally getopt(3) will print an error message on stderr
X *    if either an unknown option is encountered or an option
X *    is missing an argument. This output may be suppressed by
X *    setting <opterr> to 0. Errors cause '?' to be returned and
X *    <optopt> to be set to the offending option letter.
X *
X * Output:
X *    o/w : Option character, <optarg> points to possible argument.
X *    EOF : Finished scanning options, <optind> is next <argv>.
X *    '?' : Encountered an illegal option, <optopt> is letter.
X *
X * Copyright (c) Henry Spencer.
X * Written by Henry Spencer.
X *
X * This software is not subject to any license of the American Telephone
X * and Telegraph Company or of the Regents of the University of California.
X *
X * Permission is granted to anyone to use this software for any purpose on
X * any computer system, and to alter it and redistribute it freely, subject
X * to the following restrictions:
X *
X * 1. The author is not responsible for the consequences of use of this
X *    software, no matter how awful, even if they arise from flaws in it.
X *
X * 2. The origin of this software must not be misrepresented, either by
X *    explicit claim or by omission.  Since few users ever read sources,
X *    credits must appear in the documentation.
X *
X * 3. Altered versions must be plainly marked as such, and must not be
X *    misrepresented as being the original software.  Since few users
X *    ever read sources, credits must appear in the documentation.
X *
X * 4. This notice may not be removed or altered.
X */
X
X/*
X * changed index() calls to strchr() - darwin, oct 87.
X *
X * added opterr & optopt     - Terrence W. Holm, Aug. 1988
X */
X
X#include <stdio.h>
X
Xchar	*optarg;	/* Global argument pointer. */
Xint	optind = 0;	/* Global argv index. */
Xint	opterr = 1;	/* Print error flag, default = on */
Xint	optopt;
X
Xstatic char	*scan = NULL;	/* Private scan pointer. */
X
Xextern char	*strchr();
X
Xint
Xgetopt(argc, argv, optstring)
Xint argc;
Xchar *argv[];
Xchar *optstring;
X{
X	register char c;
X	register char *place;
X
X	optarg = NULL;
X
X	if (scan == NULL || *scan == '\0') {
X		if (optind == 0)
X			optind++;
X	
X		if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
X			return(EOF);
X		if (strcmp(argv[optind], "--")==0) {
X			optind++;
X			return(EOF);
X		}
X	
X		scan = argv[optind]+1;
X		optind++;
X	}
X
X	optopt = c = *scan++;
X	place = strchr(optstring, c);
X
X	if (place == NULL || c == ':') {
X		if ( opterr )
X			fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
X		return('?');
X	}
X
X	place++;
X	if (*place == ':') {
X		if (*scan != '\0') {
X			optarg = scan;
X			scan = NULL;
X		} else if (optind < argc) {
X			optarg = argv[optind];
X			optind++;
X		} else {
X			if ( opterr )
X				fprintf(stderr, "%s: -%c argument missing\n", argv[0], c);
X			return('?');
X		}
X	}
X
X	return(c);
X}
+ END-OF-FILE getopt.c
chmod 'u=rw,g=r,o=r' 'getopt.c'
set `wc -c 'getopt.c'`
count=$1
case $count in
4133)	:;;
*)	echo 'Bad character count in ''getopt.c' >&2
		echo 'Count should be 4133' >&2
esac
echo Extracting 'help.more'
sed 's/^X//' > 'help.more' << '+ END-OF-FILE ''help.more'
X	<space>	\(en Display next page
X	<return>	\(en Display next line
X	CTRL-B	\(en Go backward half a screenful
X	CTRL-D	\(en Go forward half a screenful
X	CTRL-L	\(en Redisplay the screen
X	#<space>	\(en Go forward # lines
X	=	\(en Print current line number
X	.	\(en Repeat previous command
X	'	\(en (single quote) Go back to start of last search
X	!	\(en Escape to a shell
X	#/<expr>	\(en Go to #-th occurrence of <expr>
X	:f	\(en Display current file name and line number
X	#:n	\(en Skip forward # files
X	#:p	\(en Skip backward # files
X	b	\(en Go backward half a screenful
X	d	\(en Go forward half a screenful
X	#f	\(en Skip # screenfuls
X	h	\(en Display \fI/usr/lib/more.help\fR
X	#n	\(en Go to #-th occurence of last <expr>
X	q	\(en Quit \fImore\fR
X	Q	\(en Quit \fImore\fR
X	#s	\(en Skip # lines
X	v	\(en Try to execute \fI/usr/bin/vi\fR
X	#z	\(en Go forward # lines and set screen size to #
+ END-OF-FILE help.more
chmod 'u=rw,g=r,o=r' 'help.more'
set `wc -c 'help.more'`
count=$1
case $count in
874)	:;;
*)	echo 'Bad character count in ''help.more' >&2
		echo 'Count should be 874' >&2
esac
echo Extracting 'index.c'
sed 's/^X//' > 'index.c' << '+ END-OF-FILE ''index.c'
X/*
X * index - find first occurrence of a character in a string
X */
X
X#define	NULL	0
X
Xchar *				/* found char, or NULL if none */
Xindex(s, charwanted)
XCONST char *s;
Xchar charwanted;
X{
X	extern char *strchr();
X
X	return(strchr(s, charwanted));
X}
+ END-OF-FILE index.c
chmod 'u=rw,g=r,o=r' 'index.c'
set `wc -c 'index.c'`
count=$1
case $count in
242)	:;;
*)	echo 'Bad character count in ''index.c' >&2
		echo 'Count should be 242' >&2
esac
echo Extracting 'lock.c'
sed 's/^X//' > 'lock.c' << '+ END-OF-FILE ''lock.c'
X#include <errno.h>
X
Xtypedef enum { FALSE, TRUE } BOOLEAN;
X
X#define LOCKDIR "/tmp/"     /* or /usr/tmp/ as the case may be */
X#define MAXTRIES 3
X#define NAPTIME 5
X
XBOOLEAN lock(name)          /* acquire lock */
Xchar *name;
X{
X    char *path, *lockpath();
X    int fd, tries;
X    extern int errno;
X
X    path = lockpath(name);
X    tries = 0;
X    while ((fd = creat(path, 0)) == -1 && errno == EACCES)
X    {
X        if (++tries >= MAXTRIES)
X            return(FALSE);
X        sleep(NAPTIME);
X    }
X    if (fd == -1 || close(fd) == -1)
X        syserr("lock");
X    return(TRUE);
X}
X
Xvoid unlock(name)           /* free lock */
Xchar *name;
X{
X    char *lockpath();
X
X    if (unlink(lockpath(name)) == -1)
X        syserr("unlock");
X}
X
Xstatic char *lockpath(name) /* generate lock file path */
Xchar *name;
X{
X    static char path[20];
X    char *strcat();
X
X    strcpy(path, LOCKDIR);
X    return(strcat(path, name));
X}
X
+ END-OF-FILE lock.c
chmod 'u=rw,g=r,o=r' 'lock.c'
set `wc -c 'lock.c'`
count=$1
case $count in
903)	:;;
*)	echo 'Bad character count in ''lock.c' >&2
		echo 'Count should be 903' >&2
esac
echo Extracting 'lrand.c'
sed 's/^X//' > 'lrand.c' << '+ END-OF-FILE ''lrand.c'
X/*  lrand(3)
X *
X *  Author: Terrence W. Holm          Nov. 1988
X *
X *
X *  A prime modulus multiplicative linear congruential
X *  generator (PMMLCG), or "Lehmer generator".
X *  Implementation directly derived from the article:
X *
X *	S. K. Park and K. W. Miller
X *	Random Number Generators: Good Ones are Hard to Find
X *	CACM vol 31, #10. Oct. 1988. pp 1192-1201.
X *
X *
X *  Using the following multiplier and modulus, we obtain a
X *  generator which:
X *
X *	1)  Has a full period: 1 to 2^31 - 2.
X *	2)  Is testably "random" (see the article).
X *	3)  Has a known implementation by E. L. Schrage.
X */
X
X
X#define  A	  16807L	/*  A "good" multiplier	  */
X#define  M   2147483647L	/*  Modulus: 2^31 - 1	  */
X#define  Q       127773L	/*  M / A		  */
X#define  R         2836L	/*  M % A		  */
X
X
Xstatic long _lseed = 1L;
X
X
Xlong seed( lseed )
X  long lseed;
X
X  {
X  long previous_seed = _lseed;
X
X  _lseed = lseed;
X
X  return( previous_seed );
X  }
X
X
Xlong lrand()
X
X  {
X  _lseed = A * (_lseed % Q) - R * (_lseed / Q);
X
X  if ( _lseed < 0 )
X    _lseed += M;
X
X  return( _lseed );
X  }
+ END-OF-FILE lrand.c
chmod 'u=rw,g=r,o=r' 'lrand.c'
set `wc -c 'lrand.c'`
count=$1
case $count in
1061)	:;;
*)	echo 'Bad character count in ''lrand.c' >&2
		echo 'Count should be 1061' >&2
esac
exit 0