[comp.os.minix] V1.3 posting #11 - shell diffs

ast@cs.vu.nl (Andy Tanenbaum) (06/05/88)

: 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 'LISTING'
sed 's/^X//' > 'LISTING' << '+ END-OF-FILE ''LISTING'
Xtotal 15
X-rw-rw-rw-  1 ast             0 Jun  4 22:33 LISTING
X-rw-rw-rw-  1 ast            78 Jun  4 22:32 makefile.diff
X-rw-rw-rw-  1 ast           668 Jun  4 22:32 sh.h.diff
X-rw-rw-rw-  1 ast           322 Jun  4 22:32 sh1.c.diff
X-rw-rw-rw-  1 ast           338 Jun  4 22:32 sh2.c.diff
X-rw-rw-rw-  1 ast           440 Jun  4 22:32 sh3.c.diff
X-rw-rw-rw-  1 ast           730 Jun  4 22:32 sh4.c.diff
X-rw-rw-rw-  1 ast          8254 Jun  4 22:32 sh5.c.diff
+ END-OF-FILE LISTING
chmod 'u=rw,g=rw,o=rw' 'LISTING'
set `wc -c 'LISTING'`
count=$1
case $count in
456)	:;;
*)	echo 'Bad character count in ''LISTING' >&2
		echo 'Count should be 456' >&2
esac
echo Extracting 'makefile.diff'
sed 's/^X//' > 'makefile.diff' << '+ END-OF-FILE ''makefile.diff'
X2c2
X< l=../../lib
X---
X> l=/lib
X7c7
X< 	@chmem =8000 sh
X---
X> 	@chmem =20000 sh
+ END-OF-FILE makefile.diff
chmod 'u=rw,g=rw,o=rw' 'makefile.diff'
set `wc -c 'makefile.diff'`
count=$1
case $count in
78)	:;;
*)	echo 'Bad character count in ''makefile.diff' >&2
		echo 'Count should be 78' >&2
esac
echo Extracting 'sh.h.diff'
sed 's/^X//' > 'sh.h.diff' << '+ END-OF-FILE ''sh.h.diff'
X113,116c113
X< 	union {
X< 		char	*io_name;	/* file name */
X< 		struct block *io_here;	/* here structure pointer */
X< 	} io_un;
X---
X> 	char	*io_name;	/* file name */
X261,263c258
X< #define	XIO	4	/* file IO */
X< #define XHERE	0x80	/* Any of the above inside a here document */
X< #define XMASK	0x7f	/* Get the actual task */
X---
X> #define	XIO	3	/* file IO */
X266c261
X< #define	INSUB()	((e.iop->task&XMASK)==XGRAVE||(e.iop->task&XMASK)==XDOLL)
X---
X> #define	INSUB()	(e.iop->task == XGRAVE || e.iop->task == XDOLL)
X273a269
X> int	herechar();
X301c297
X< struct	io	*setbase(/* struct io * */);
X---
X> struct io *setbase(/* struct io * */);
X329a326
X> int	getarea(/* char *obj */);
+ END-OF-FILE sh.h.diff
chmod 'u=rw,g=rw,o=rw' 'sh.h.diff'
set `wc -c 'sh.h.diff'`
count=$1
case $count in
668)	:;;
*)	echo 'Bad character count in ''sh.h.diff' >&2
		echo 'Count should be 668' >&2
esac
echo Extracting 'sh1.c.diff'
sed 's/^X//' > 'sh1.c.diff' << '+ END-OF-FILE ''sh1.c.diff'
X145c145
X< 	if (name[0] == '-') {
X---
X> 	if (name && name[0] == '-') {
X213c213,215
X< 	freearea(areanum = 1);
X---
X> 	areanum = 1;
X> 	freehere(areanum);
X> 	freearea(areanum);
X221a224
X> 	setjmp(failpt = m1);	/* Bruce Evans' fix */
X905a909,915
X> }
X> 
X> int
X> getarea(cp)
X> char *cp;
X> {
X> 	return ((struct region*)cp-1)->area;
+ END-OF-FILE sh1.c.diff
chmod 'u=rw,g=rw,o=rw' 'sh1.c.diff'
set `wc -c 'sh1.c.diff'`
count=$1
case $count in
322)	:;;
*)	echo 'Bad character count in ''sh1.c.diff' >&2
		echo 'Count should be 322' >&2
esac
echo Extracting 'sh2.c.diff'
sed 's/^X//' > 'sh2.c.diff' << '+ END-OF-FILE ''sh2.c.diff'
X124a125,126
X> 		if((peeksym = yylex(0)) == '&')
X> 			t = block(TASYNC, t, NOBLOCK, NOWORDS);
X126,127d127
X< 			if (c == '&')
X< 				t = block(TASYNC, t, NOBLOCK, NOWORDS);
X129a130,131
X> 			if((peeksym = yylex(0)) == '&')
X> 				p = block(TASYNC, p, NOBLOCK, NOWORDS);
X136a139
X> 
X559c562
X< 	iop->io_un.io_name = cp;
X---
X> 	iop->io_name = cp;
+ END-OF-FILE sh2.c.diff
chmod 'u=rw,g=rw,o=rw' 'sh2.c.diff'
set `wc -c 'sh2.c.diff'`
count=$1
case $count in
338)	:;;
*)	echo 'Bad character count in ''sh2.c.diff' >&2
		echo 'Count should be 338' >&2
esac
echo Extracting 'sh3.c.diff'
sed 's/^X//' > 'sh3.c.diff' << '+ END-OF-FILE ''sh3.c.diff'
X177a178
X> 	freehere(areanum);
X216c217
X< 		else
X---
X> 		else if (cp != NULL)
X270,271d270
X< 	if (t->type == TPAREN)
X< 		exit(execute(t->left, NOPIPE, NOPIPE, FEXEC));
X275a275,276
X> 	if (t->type == TPAREN)
X> 		exit(execute(t->left, NOPIPE, NOPIPE, FEXEC));
X322c323
X< 		cp = iop->io_un.io_name;
X---
X> 		cp = iop->io_name;
X343c344
X< 		u = herein(iop->io_un.io_here, iop->io_flag&IOXHERE);
X---
X> 		u = herein(iop->io_name, iop->io_flag&IOXHERE);
+ END-OF-FILE sh3.c.diff
chmod 'u=rw,g=rw,o=rw' 'sh3.c.diff'
set `wc -c 'sh3.c.diff'`
count=$1
case $count in
440)	:;;
*)	echo 'Bad character count in ''sh3.c.diff' >&2
		echo 'Count should be 440' >&2
esac
echo Extracting 'sh4.c.diff'
sed 's/^X//' > 'sh4.c.diff' << '+ END-OF-FILE ''sh4.c.diff'
X2,5c2,7
X< #include "signal.h"
X< #include "errno.h"
X< #include "setjmp.h"
X< #include "stat.h"
X---
X> #include <signal.h>
X> #include <errno.h>
X> #include <setjmp.h>
X> #include <sys/types.h>
X> #include <sys/stat.h>
X> #include <sys/dir.h>
X350,354c352,354
X< 	
X< 	/* jrp debug */
X< 	scraphere();
X< 
X< 	freearea(areanum = 1);	/* free old space */
X---
X> 	areanum = 1;
X> 	freehere(areanum);
X> 	freearea(areanum);	/* free old space */
X379,384d378
X< #define	DIRSIZ	14
X< struct	direct
X< {
X< 	unsigned short	d_ino;
X< 	char	d_name[DIRSIZ];
X< };
X725a720,732
X> }
X> 
X> char *
X> memcpy(ato, from, nb)
X> register char *ato, *from;
X> register int nb;
X> {
X> 	register char *to;
X> 
X> 	to = ato;
X> 	while (--nb >= 0)
X> 		*to++ = *from++;
X> 	return(ato);
+ END-OF-FILE sh4.c.diff
chmod 'u=rw,g=rw,o=rw' 'sh4.c.diff'
set `wc -c 'sh4.c.diff'`
count=$1
case $count in
730)	:;;
*)	echo 'Bad character count in ''sh4.c.diff' >&2
		echo 'Count should be 730' >&2
esac
echo Extracting 'sh5.c.diff'
sed 's/^X//' > 'sh5.c.diff' << '+ END-OF-FILE ''sh5.c.diff'
X29c29
X< 	if ((ec != '"') && (ec != '\'')) {
X---
X> 	if (ec != '\'') {
X237a238,255
X>  * Return the characters from a here temp file.
X>  */
X> int
X> herechar(ap)
X> register struct ioarg *ap;
X> {
X> 	char c;
X> 
X> 
X> 	if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
X> 		close(ap->afile);
X> 		c = 0;
X> 	}
X> 	return (c);
X> 
X> }
X> 
X> /*
X413,419d430
X< } *herelist;
X< 
X< struct	block {
X< 	char	*b_linebuf;
X< 	char	*b_next;
X< 	char	b_tmpfile[50];
X< 	int	b_fd;
X422c433,434
X< static	struct block *readhere();
X---
X> static	struct here *inhere;		/* list of hear docs while parsing */
X> static	struct here *acthere;		/* list of active here documents */
X424c436
X< #define	NCPB	2048		/* here text block allocation unit */
X---
X> static	char *readhere();
X425a438,439
X> #define	NCPB	100	/* here text block allocation unit */
X> 
X439d452
X< 	h->h_iop->io_un.io_here = NULL;
X441,442c454,455
X< 	if (herelist == 0)
X< 		herelist = h;
X---
X> 	if (inhere == 0)
X> 		inhere = h;
X444c457
X< 		for (lh = herelist; lh!=NULL; lh = lh->h_next)
X---
X> 		for (lh = inhere; lh!=NULL; lh = lh->h_next)
X462,465c475,480
X< 	for (h = herelist; h != NULL; h = h->h_next) {
X< 		h->h_iop->io_un.io_here = 
X< 			readhere(h->h_tag, h->h_dosub? 0: '\'',
X< 				h->h_iop->io_flag & IOXHERE);
X---
X> 	for (h = inhere; h != NULL; h = inhere) {
X> 		h->h_iop->io_name = readhere(h->h_tag, h->h_dosub? 0: '\'');
X> 		/* relink from inhere to acthere list */
X> 		inhere = h->h_next;
X> 		h->h_next = acthere;
X> 		acthere = h;
X467c482
X< 	herelist = NULL;
X---
X> 	inhere = h;
X470,471c485,486
X< static struct block *
X< readhere(s, ec, nolit)
X---
X> static char *
X> readhere(s, ec)
X474c489,490
X< 	register struct block *bp;
X---
X> 	int tf;
X> 	char tname[30];
X476a493,494
X> 	char line [LINELIM+1];
X> 	char *next;
X478,484c496,504
X< 	bp = (struct block *) space(sizeof(*bp));
X< 	if (bp == 0)
X< 		return(0);
X< 	bp->b_linebuf = (char *)space(NCPB);
X< 	if (bp->b_linebuf == 0) {
X< 		/* jrp - should release bp here... */
X< 		return(0);
X---
X> 	tempname(tname);
X> 	tf = creat(tname, 0600);
X> 	if (tf < 0)
X> 		return (0);
X> 	if (newenv(setjmp(errpt = ev)) != 0)
X> 		return (0);
X> 	if (e.iop == iostack && e.iop->iofn == filechar) {
X> 		pushio(e.iop->arg, filechar);
X> 		e.iobase = e.iop;
X486,507c506,514
X< 	if (newenv(setjmp(errpt = ev)) == 0) {
X< 		if (e.iop == iostack && e.iop->iofn == filechar) {
X< 			pushio(e.iop->arg, filechar);
X< 			e.iobase = e.iop;
X< 		}
X< 
X< 		/* jrp changes */
X< 		bp->b_linebuf[0] = 0;
X< 		bp->b_next = bp->b_linebuf;
X< 		bp->b_tmpfile[0] = 0;
X< 		bp->b_fd = -1;
X< 		for (;;) {
X< 			while ((c = getc(ec)) != '\n' && c) {
X< 				if (ec == '\'')
X< 					c &= ~ QUOTE;
X< 				if (savec(c, bp, nolit) == 0) {
X< 					c = 0;
X< 					break;
X< 				}
X< 			}
X< 			savec(0, bp, nolit);
X< 			if (strcmp(s, bp->b_linebuf) == 0 || c == 0)
X---
X> 	for (;;) {
X> 		if (talking && e.iop <= iostack)
X> 			prs(cprompt->value);
X> 		next = line;
X> 		while ((c = getc(ec)) != '\n' && c) {
X> 			if (ec == '\'')
X> 				c &= ~ QUOTE;
X> 			if (next >= &line[LINELIM]) {
X> 				c = 0;
X509c516,517
X< 			savec('\n', bp, nolit);
X---
X> 			}
X> 			*next++ = c;
X511,515c519,523
X< 		*bp->b_linebuf = 0;
X< 		if (c == 0) {
X< 			prs("here document `"); prs(s); err("' unclosed");
X< 		}
X< 		quitenv();
X---
X> 		*next = 0;
X> 		if (strcmp(s, line) == 0 || c == 0)
X> 			break;
X> 		*next++ = '\n';
X> 		write (tf, line, (int)(next-line));
X517,558c525,526
X< 	return(bp);
X< }
X< 
X< static
X< savec(c, bp, nolit)
X< register struct block *bp;
X< {
X< 	/* jrp - gutted routine completely, modified to use temp file. */
X< 	
X< 	/* If the file is not open, see if a filename needs to be
X< 	 * created.  If so, create one.  Then create the file.
X< 	 */
X< 	char *	lp;
X< 	char *	cp;
X< 	static int inc;
X< 	int	len;
X< 
X< 	if(bp->b_fd < 0) {
X< 	    if(bp->b_tmpfile[0] == 0) {
X< 		/* Key this by the PID plus a tag... */
X< 		for (cp = bp->b_tmpfile, lp = "/tmp/shtm"; 
X< 		     (*cp = *lp++) != '\0'; cp++)
X< 			;
X< 
X< 		inc = (inc + 1) % 100;
X< 		lp = putn(getpid()*100 + inc);
X< 		for (; (*cp = *lp++) != '\0'; cp++)
X< 			;
X< 	    }
X< 
X< 	    /* Create the file, then open it for
X< 	     * read/write access.  After opening the
X< 	     * file, unlink it to it'll go away when
X< 	     * we're through using it.
X< 	     */
X< 	    bp->b_fd = creat(bp->b_tmpfile, 0600);
X< 	    close(bp->b_fd);
X< 	    bp->b_fd = open(bp->b_tmpfile, 2);
X< 	    unlink(bp->b_tmpfile);
X< 	    if(bp->b_fd < 0) {
X< 	        return(0);
X< 	    }
X---
X> 	if (c == 0) {
X> 		prs("here document `"); prs(s); err("' unclosed");
X560,586c528,531
X< 
X< 	/* Stuff the character into the line buffer.  If it's a
X< 	 * newline, then insert it before the trailing null, write
X< 	 * out the line, and reset the line buffer.
X< 	 */
X< 	if(c == '\n') {
X< 	    bp->b_next[-1] = '\n';
X< 	    bp->b_next[0] = '\0';
X< 	    len = strlen(bp->b_linebuf);
X< 
X< 	    /* Write this out, unless the line ended
X< 	     * with a backslash...
X< 	     */
X< 	    if((len > 1) && (bp->b_next[-2] != '\\')) {
X< 		write_linebuf(bp, nolit);
X< 	    }
X< 
X< 	    return(1);
X< 	}
X< 	else {
X< 	    if(bp->b_next == &(bp->b_linebuf[NCPB - 1])) {
X< 		prs("here: line buffer full\n");
X< 		return(0);
X< 	    }
X< 	    *(bp->b_next++) = c;
X< 	    return(1);
X< 	}
X---
X> 	close(tf);
X> 	quitenv();
X> 	/* correct area? */
X> 	return (strsave(tname, areanum));
X589,590c534,539
X< write_linebuf(bp, nolit)
X< struct block * bp;
X---
X> /*
X>  * open here temp file.
X>  * if unquoted here, expand here temp file into second temp file.
X>  */
X> herein(hname, xdoll)
X> char *hname;
X591a541
X> 	register hf, tf;
X593,594c543,551
X< 	char c;
X< 	jmp_buf ev;
X---
X> 	if (hname == 0)
X> 		return(-1);
X> 	hf = open(hname, 0);
X> 	if (hf < 0)
X> 		return (-1);
X> 	if (xdoll) {
X> 		char c;
X> 		char tname[30];
X> 		jmp_buf ev;
X596c553,555
X< 	if(nolit) {
X---
X> 		tempname(tname);
X> 		if ((tf = creat(tname, 0600)) < 0)
X> 			return (-1);
X598c557
X< 			PUSHIO(aword, bp->b_linebuf, strchar);
X---
X> 			PUSHIO(afile, hf, herechar);
X600d558
X< 			e.iop->task |= XHERE;
X603c561
X< 				write(bp->b_fd, &c, sizeof c);
X---
X> 				write(tf, &c, sizeof c);
X606,615c564,571
X< 		
X< 		}
X< 	}
X< 	else {
X< 		write(bp->b_fd, bp->b_linebuf, strlen(bp->b_linebuf));
X< 	}
X< 
X< 	/* Zap the line buffer for next time... */
X< 	bp->b_next = bp->b_linebuf;
X< 	bp->b_linebuf[0] = 0;
X---
X> 		} else
X> 			unlink(tname);
X> 		close(tf);
X> 		tf = open(tname, 0);
X> 		unlink(tname);
X> 		return (tf);
X> 	} else
X> 		return (hf);
X618,619c574
X< herein(bp, xdoll)
X< struct block *bp;
X---
X> scraphere()
X621,639c576
X< 	int	ret_fd;
X< 
X< 	if (bp == 0)
X< 		return(-1);
X< 
X< 	/* If we have a temp file, then rewind it to the beginning */
X< 	if(bp->b_fd < 0) {
X< 		return(-1);
X< 	}
X< 
X< 	lseek(bp->b_fd, 0L, 0);
X< 
X< 	/* Free up this block pointer, as we're
X< 	 * not going to need it anymore.
X< 	 */
X< 	xfree(bp->b_linebuf);
X< 	xfree(bp);
X< 
X< 	return(bp->b_fd);
X---
X> 	inhere = NULL;
X642c579,581
X< scraphere()
X---
X> /* unlink here temp files before a freearea(area) */
X> freehere(area)
X> int area;
X644,646c583
X< 	struct here * h;
X< 	struct here * nexth;
X< 	struct block * bp;
X---
X> 	register struct here *h, *hl;
X648,661c585,593
X< 
X< 	/* Close and unlink any files associated with
X< 	 * heres in progress, and free up all the
X< 	 * associated structures. 
X< 	 */
X< 	h = herelist;
X< 	while(h != NULL) {
X< 		nexth = h->h_next;
X< 		bp = (struct block *)h->h_iop->io_un.io_here;
X< 		if(bp != NULL) {
X< 			if(bp->b_fd >= 0) { close(bp->b_fd); }
X< 			if(*bp->b_tmpfile) { unlink(bp->b_tmpfile); }
X< 			xfree(bp->b_linebuf);
X< 			xfree(bp);
X---
X> 	hl = NULL;
X> 	for (h = acthere; h != NULL; hl = h, h = h->h_next)
X> 		if (getarea(h) >= area) {
X> 			if (h->h_iop->io_name != NULL)
X> 				unlink(h->h_iop->io_name);
X> 			if (hl == NULL)
X> 				acthere = h->h_next;
X> 			else
X> 				hl->h_next = h->h_next;
X663,667d594
X< 		xfree(h);
X< 		h = nexth;
X< 	}
X< 
X< 	herelist = NULL;
X670,673c597,598
X< char *
X< memcpy(ato, from, nb)
X< register char *ato, *from;
X< register int nb;
X---
X> tempname(tname)
X> char *tname;
X675c600,601
X< 	register char *to;
X---
X> 	static int inc;
X> 	register char *cp, *lp;
X677,680c603,607
X< 	to = ato;
X< 	while (--nb >= 0)
X< 		*to++ = *from++;
X< 	return(ato);
X---
X> 	for (cp = tname, lp = "/tmp/shtm"; (*cp = *lp++) != '\0'; cp++)
X> 		;
X> 	lp = putn(getpid()*1000 + inc++);
X> 	for (; (*cp = *lp++) != '\0'; cp++)
X> 		;
+ END-OF-FILE sh5.c.diff
chmod 'u=rw,g=rw,o=rw' 'sh5.c.diff'
set `wc -c 'sh5.c.diff'`
count=$1
case $count in
8254)	:;;
*)	echo 'Bad character count in ''sh5.c.diff' >&2
		echo 'Count should be 8254' >&2
esac
exit 0