Path: tut!enea!mcvax!seismo!ut-sally!husc6!linus!encore!paradis
From: paradis@encore.UUCP (Jim Paradis)
Newsgroups: comp.os.minix
Subject: Patches to minix shell (7 of 7) - sh5.c
Keywords: minix shell shar fix sh5.c
Message-ID: <1688@encore.UUCP>
Date: 23 Jun 87 19:33:55 GMT
Organization: Encore Computer Corp., Marlboro, MA
Lines: 279

Apply this patch to sh5.c
Strip the "|"s out from in front of this one first...
I tried to post it but inews thought I was including too much
text (grrrrrrrr!)

----------------------------cut here------------------------------
|0a1
|> #define Extern extern
|28c29
|< 	if (ec != '\'') {
|---
|> 	if ((ec != '"') && (ec != '\'')) {
|84a86
|> 
|101a104
|> 
|128c131
|< 	if (ap->aword == NULL)
|---
|> 	if (ap->aword == NULL) {
|129a133
|> 	}
|402d405
|< char *memcpy();
|416c419
|< 	char	*b_start;
|---
|> 	char	*b_linebuf;
|418,419c421,422
|< 	char	*b_line;
|< 	int	b_size;
|---
|> 	char	b_tmpfile[50];
|> 	int	b_fd;
|424c427
|< #define	NCPB	100	/* here text block allocation unit */
|---
|> #define	NCPB	2048		/* here text block allocation unit */
|438a442
|> 	h->h_iop->io_un.io_here = NULL;
|461,462c465,469
|< 	for (h = herelist; h != NULL; h = h->h_next)
|< 		h->h_iop->io_un.io_here = readhere(h->h_tag, h->h_dosub? 0: '\'');
|---
|> 	for (h = herelist; h != NULL; h = h->h_next) {
|> 		h->h_iop->io_un.io_here = 
|> 			readhere(h->h_tag, h->h_dosub? 0: '\'',
|> 				h->h_iop->io_flag & IOXHERE);
|> 	}
|467c474
|< readhere(s, ec)
|---
|> readhere(s, ec, nolit)
|476a484,488
|> 	bp->b_linebuf = (char *)space(NCPB);
|> 	if (bp->b_linebuf == 0) {
|> 		/* jrp - should release bp here... */
|> 		return(0);
|> 	}
|482,485c494,499
|< 		bp->b_size = 0;
|< 		bp->b_line = 0;
|< 		bp->b_next = 0;
|< 		bp->b_start = 0;
|---
|> 
|> 		/* jrp changes */
|> 		bp->b_linebuf[0] = 0;
|> 		bp->b_next = bp->b_linebuf;
|> 		bp->b_tmpfile[0] = 0;
|> 		bp->b_fd = -1;
|490c504
|< 				if (savec(c, bp) == 0) {
|---
|> 				if (savec(c, bp, nolit) == 0) {
|495,496c509,510
|< 			savec(0, bp);
|< 			if (strcmp(s, bp->b_line) == 0 || c == 0)
|---
|> 			savec(0, bp, nolit);
|> 			if (strcmp(s, bp->b_linebuf) == 0 || c == 0)
|498,499c512
|< 			bp->b_next[-1] = '\n';
|< 			bp->b_line = bp->b_next;
|---
|> 			savec('\n', bp, nolit);
|501c514
|< 		*bp->b_line = 0;
|---
|> 		*bp->b_linebuf = 0;
|511c524
|< savec(c, bp)
|---
|> savec(c, bp, nolit)
|514c527,535
|< 	register char *np;
|---
|> 	/* jrp - gutted routine completely, modified to use temp file. */
|> 	
|> 	/* If the file is not open, see if a filename needs to be
|> 	 * created.  If so, create one.  Then create the file.
|> 	 */
|> 	char *	lp;
|> 	char *	cp;
|> 	static int inc;
|> 	int	len;
|516,525c537,561
|< 	if (bp->b_start == NULL || bp->b_next+1 >= bp->b_start+bp->b_size) {
|< 		np = space(bp->b_size + NCPB);
|< 		if (np == 0)
|< 			return(0);
|< 		memcpy(np, bp->b_start, bp->b_size);
|< 		bp->b_size += NCPB;
|< 		bp->b_line = np + (bp->b_line-bp->b_start);
|< 		bp->b_next = np + (bp->b_next-bp->b_start);
|< 		xfree(bp->b_start);
|< 		bp->b_start = np;
|---
|> 	if(bp->b_fd < 0) {
|> 	    if(bp->b_tmpfile[0] == 0) {
|> 		/* Key this by the PID plus a tag... */
|> 		for (cp = bp->b_tmpfile, lp = "/tmp/shtm"; 
|> 		     (*cp = *lp++) != '\0'; cp++)
|> 			;
|> 
|> 		inc = (inc + 1) % 100;
|> 		lp = putn(getpid()*100 + inc);
|> 		for (; (*cp = *lp++) != '\0'; cp++)
|> 			;
|> 	    }
|> 
|> 	    /* Create the file, then open it for
|> 	     * read/write access.  After opening the
|> 	     * file, unlink it to it'll go away when
|> 	     * we're through using it.
|> 	     */
|> 	    bp->b_fd = creat(bp->b_tmpfile, 0600);
|> 	    close(bp->b_fd);
|> 	    bp->b_fd = open(bp->b_tmpfile, 2);
|> 	    unlink(bp->b_tmpfile);
|> 	    if(bp->b_fd < 0) {
|> 	        return(0);
|> 	    }
|527,528c563,589
|< 	*bp->b_next++ = c;
|< 	return(1);
|---
|> 
|> 	/* Stuff the character into the line buffer.  If it's a
|> 	 * newline, then insert it before the trailing null, write
|> 	 * out the line, and reset the line buffer.
|> 	 */
|> 	if(c == '\n') {
|> 	    bp->b_next[-1] = '\n';
|> 	    bp->b_next[0] = '\0';
|> 	    len = strlen(bp->b_linebuf);
|> 
|> 	    /* Write this out, unless the line ended
|> 	     * with a backslash...
|> 	     */
|> 	    if((len > 1) && (bp->b_next[-2] != '\\')) {
|> 		write_linebuf(bp, nolit);
|> 	    }
|> 
|> 	    return(1);
|> 	}
|> 	else {
|> 	    if(bp->b_next == &(bp->b_linebuf[NCPB - 1])) {
|> 		prs("here: line buffer full\n");
|> 		return(0);
|> 	    }
|> 	    *(bp->b_next++) = c;
|> 	    return(1);
|> 	}
|530a592,620
|> write_linebuf(bp, nolit)
|> struct block * bp;
|> {
|> 
|> 	char c;
|> 	jmp_buf ev;
|> 
|> 	if(nolit) {
|> 		if (newenv(setjmp(errpt = ev)) == 0) {
|> 			PUSHIO(aword, bp->b_linebuf, strchar);
|> 			setbase(e.iop);
|> 			e.iop->task |= XHERE;
|> 			while ((c = subgetc(0, 0)) != 0) {
|> 				c &= ~ QUOTE;
|> 				write(bp->b_fd, &c, sizeof c);
|> 			}
|> 			quitenv();
|> 		
|> 		}
|> 	}
|> 	else {
|> 		write(bp->b_fd, bp->b_linebuf, strlen(bp->b_linebuf));
|> 	}
|> 
|> 	/* Zap the line buffer for next time... */
|> 	bp->b_next = bp->b_linebuf;
|> 	bp->b_linebuf[0] = 0;
|> }
|> 
|534,537c624
|< 	register tf;
|< 	char tname[50];
|< 	static int inc;
|< 	register char *cp, *lp;
|---
|> 	int	ret_fd;
|541,549d627
|< 	for (cp = tname, lp = "/tmp/shtm"; (*cp = *lp++) != '\0'; cp++)
|< 		;
|< 	lp = putn(getpid()*100 + inc++);
|< 	for (; (*cp = *lp++) != '\0'; cp++)
|< 		;
|< 	if ((tf = creat(tname, 0666)) >= 0) {
|< 		if (xdoll) {
|< 			char c;
|< 			jmp_buf ev;
|551,565c629,631
|< 			if (newenv(setjmp(errpt = ev)) == 0) {
|< 				PUSHIO(aword, bp->b_start, strchar);
|< 				setbase(e.iop);
|< 				while ((c = subgetc(0, 0)) != 0) {
|< 					c &= ~ QUOTE;
|< 					write(tf, &c, sizeof c);
|< 				}
|< 				quitenv();
|< 			} else
|< 				unlink(tname);
|< 		} else
|< 			write(tf, bp->b_start, bp->b_line-bp->b_start);
|< 		close(tf);
|< 		tf = open(tname, 0);
|< 		unlink(tname);
|---
|> 	/* If we have a temp file, then rewind it to the beginning */
|> 	if(bp->b_fd < 0) {
|> 		return(-1);
|567c633,642
|< 	return(tf);
|---
|> 
|> 	lseek(bp->b_fd, 0L, 0);
|> 
|> 	/* Free up this block pointer, as we're
|> 	 * not going to need it anymore.
|> 	 */
|> 	xfree(bp->b_linebuf);
|> 	xfree(bp);
|> 
|> 	return(bp->b_fd);
|571a647,669
|> 	struct here * h;
|> 	struct here * nexth;
|> 	struct block * bp;
|> 
|> 
|> 	/* Close and unlink any files associated with
|> 	 * heres in progress, and free up all the
|> 	 * associated structures. 
|> 	 */
|> 	h = herelist;
|> 	while(h != NULL) {
|> 		nexth = h->h_next;
|> 		bp = (struct block *)h->h_iop->io_un.io_here;
|> 		if(bp != NULL) {
|> 			if(bp->b_fd >= 0) { close(bp->b_fd); }
|> 			if(*bp->b_tmpfile) { unlink(bp->b_tmpfile); }
|> 			xfree(bp->b_linebuf);
|> 			xfree(bp);
|> 		}
|> 		xfree(h);
|> 		h = nexth;
|> 	}
|> 
 
