xref: /titanic_50/usr/src/ucbcmd/sed/sed1.c (revision bdcaf82257ab2deb6b46efaaa4bc93a1a44b3885)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*bdcaf822Sbasabi /*
23*bdcaf822Sbasabi  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*bdcaf822Sbasabi  * Use is subject to license terms.
25*bdcaf822Sbasabi  */
26*bdcaf822Sbasabi 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
31*bdcaf822Sbasabi #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <fcntl.h>
377c478bd9Sstevel@tonic-gate #include "sed.h"
387c478bd9Sstevel@tonic-gate #include <regexp.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate union reptr     *abuf[ABUFSIZE+1];
417c478bd9Sstevel@tonic-gate union reptr **aptr;
427c478bd9Sstevel@tonic-gate char    ibuf[BUFSIZ];
437c478bd9Sstevel@tonic-gate char    *cbp;
447c478bd9Sstevel@tonic-gate char    *ebp;
457c478bd9Sstevel@tonic-gate char    genbuf[LBSIZE+1];
467c478bd9Sstevel@tonic-gate char	*lcomend;
477c478bd9Sstevel@tonic-gate int     dolflag;
487c478bd9Sstevel@tonic-gate int     sflag;
497c478bd9Sstevel@tonic-gate int     jflag;
507c478bd9Sstevel@tonic-gate int     delflag;
517c478bd9Sstevel@tonic-gate long long lnum;
527c478bd9Sstevel@tonic-gate char    holdsp[LBSIZE+1];
537c478bd9Sstevel@tonic-gate char    *spend;
547c478bd9Sstevel@tonic-gate char    *hspend;
557c478bd9Sstevel@tonic-gate int     nflag;
567c478bd9Sstevel@tonic-gate long long tlno[NLINES];
577c478bd9Sstevel@tonic-gate int     f;
587c478bd9Sstevel@tonic-gate char	*ifname;
597c478bd9Sstevel@tonic-gate int	numpass;
607c478bd9Sstevel@tonic-gate union reptr     *pending;
617c478bd9Sstevel@tonic-gate char	*trans[040]  = {
627c478bd9Sstevel@tonic-gate 	"\\01",
637c478bd9Sstevel@tonic-gate 	"\\02",
647c478bd9Sstevel@tonic-gate 	"\\03",
657c478bd9Sstevel@tonic-gate 	"\\04",
667c478bd9Sstevel@tonic-gate 	"\\05",
677c478bd9Sstevel@tonic-gate 	"\\06",
687c478bd9Sstevel@tonic-gate 	"\\07",
697c478bd9Sstevel@tonic-gate 	"-<",
707c478bd9Sstevel@tonic-gate 	"->",
717c478bd9Sstevel@tonic-gate 	"\n",
727c478bd9Sstevel@tonic-gate 	"\\13",
737c478bd9Sstevel@tonic-gate 	"\\14",
747c478bd9Sstevel@tonic-gate 	"\\15",
757c478bd9Sstevel@tonic-gate 	"\\16",
767c478bd9Sstevel@tonic-gate 	"\\17",
777c478bd9Sstevel@tonic-gate 	"\\20",
787c478bd9Sstevel@tonic-gate 	"\\21",
797c478bd9Sstevel@tonic-gate 	"\\22",
807c478bd9Sstevel@tonic-gate 	"\\23",
817c478bd9Sstevel@tonic-gate 	"\\24",
827c478bd9Sstevel@tonic-gate 	"\\25",
837c478bd9Sstevel@tonic-gate 	"\\26",
847c478bd9Sstevel@tonic-gate 	"\\27",
857c478bd9Sstevel@tonic-gate 	"\\30",
867c478bd9Sstevel@tonic-gate 	"\\31",
877c478bd9Sstevel@tonic-gate 	"\\32",
887c478bd9Sstevel@tonic-gate 	"\\33",
897c478bd9Sstevel@tonic-gate 	"\\34",
907c478bd9Sstevel@tonic-gate 	"\\35",
917c478bd9Sstevel@tonic-gate 	"\\36",
927c478bd9Sstevel@tonic-gate 	"\\37"
937c478bd9Sstevel@tonic-gate };
947c478bd9Sstevel@tonic-gate char	rub[] = {"\\177"};
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate extern char TMMES[];
977c478bd9Sstevel@tonic-gate 
98*bdcaf822Sbasabi static int match(char *expbuf, int gf);
99*bdcaf822Sbasabi static int substitute(union reptr *ipc);
100*bdcaf822Sbasabi static void dosub(char *rhsbuf, int n);
101*bdcaf822Sbasabi static void command(union reptr *ipc);
102*bdcaf822Sbasabi static void arout(void);
103*bdcaf822Sbasabi 
104*bdcaf822Sbasabi void
execute(char * file)105*bdcaf822Sbasabi execute(char *file)
1067c478bd9Sstevel@tonic-gate {
107*bdcaf822Sbasabi 	char *p1, *p2;
108*bdcaf822Sbasabi 	union reptr	*ipc;
1097c478bd9Sstevel@tonic-gate 	int	c;
1107c478bd9Sstevel@tonic-gate 	char	*execp;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	if (file) {
1137c478bd9Sstevel@tonic-gate 		if ((f = open(file, 0)) < 0) {
1147c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "sed: ");
1157c478bd9Sstevel@tonic-gate 			perror(file);
1167c478bd9Sstevel@tonic-gate 		}
1177c478bd9Sstevel@tonic-gate 		ifname = file;
1187c478bd9Sstevel@tonic-gate 	} else {
1197c478bd9Sstevel@tonic-gate 		f = 0;
1207c478bd9Sstevel@tonic-gate 		ifname = "standard input";
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	ebp = ibuf;
1247c478bd9Sstevel@tonic-gate 	cbp = ibuf;
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	if(pending) {
1277c478bd9Sstevel@tonic-gate 		ipc = pending;
1287c478bd9Sstevel@tonic-gate 		pending = 0;
1297c478bd9Sstevel@tonic-gate 		goto yes;
1307c478bd9Sstevel@tonic-gate 	}
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	for(;;) {
1337c478bd9Sstevel@tonic-gate 		if((execp = gline(linebuf)) == 0) {
1347c478bd9Sstevel@tonic-gate 			(void) close(f);
1357c478bd9Sstevel@tonic-gate 			return;
1367c478bd9Sstevel@tonic-gate 		}
1377c478bd9Sstevel@tonic-gate 		spend = execp;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 		for(ipc = ptrspace; ipc->r1.command; ) {
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 			p1 = ipc->r1.ad1;
1427c478bd9Sstevel@tonic-gate 			p2 = ipc->r1.ad2;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 			if(p1) {
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 				if(ipc->r1.inar) {
1477c478bd9Sstevel@tonic-gate 					if(*p2 == CEND) {
1487c478bd9Sstevel@tonic-gate 						p1 = 0;
1497c478bd9Sstevel@tonic-gate 					} else if(*p2 == CLNUM) {
1507c478bd9Sstevel@tonic-gate 						c = (unsigned char)p2[1];
1517c478bd9Sstevel@tonic-gate 						if(lnum > tlno[c]) {
1527c478bd9Sstevel@tonic-gate 							ipc->r1.inar = 0;
1537c478bd9Sstevel@tonic-gate 							if(ipc->r1.negfl)
1547c478bd9Sstevel@tonic-gate 								goto yes;
1557c478bd9Sstevel@tonic-gate 							ipc++;
1567c478bd9Sstevel@tonic-gate 							continue;
1577c478bd9Sstevel@tonic-gate 						}
1587c478bd9Sstevel@tonic-gate 						if(lnum == tlno[c]) {
1597c478bd9Sstevel@tonic-gate 							ipc->r1.inar = 0;
1607c478bd9Sstevel@tonic-gate 						}
1617c478bd9Sstevel@tonic-gate 					} else if(match(p2, 0)) {
1627c478bd9Sstevel@tonic-gate 						ipc->r1.inar = 0;
1637c478bd9Sstevel@tonic-gate 					}
1647c478bd9Sstevel@tonic-gate 				} else if(*p1 == CEND) {
1657c478bd9Sstevel@tonic-gate 					if(!dolflag) {
1667c478bd9Sstevel@tonic-gate 						if(ipc->r1.negfl)
1677c478bd9Sstevel@tonic-gate 							goto yes;
1687c478bd9Sstevel@tonic-gate 						ipc++;
1697c478bd9Sstevel@tonic-gate 						continue;
1707c478bd9Sstevel@tonic-gate 					}
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 				} else if(*p1 == CLNUM) {
1737c478bd9Sstevel@tonic-gate 					c = (unsigned char)p1[1];
1747c478bd9Sstevel@tonic-gate 					if(lnum != tlno[c]) {
1757c478bd9Sstevel@tonic-gate 						if(ipc->r1.negfl)
1767c478bd9Sstevel@tonic-gate 							goto yes;
1777c478bd9Sstevel@tonic-gate 						ipc++;
1787c478bd9Sstevel@tonic-gate 						continue;
1797c478bd9Sstevel@tonic-gate 					}
1807c478bd9Sstevel@tonic-gate 					if(p2)
1817c478bd9Sstevel@tonic-gate 						ipc->r1.inar = 1;
1827c478bd9Sstevel@tonic-gate 				} else if(match(p1, 0)) {
1837c478bd9Sstevel@tonic-gate 					if(p2)
1847c478bd9Sstevel@tonic-gate 						ipc->r1.inar = 1;
1857c478bd9Sstevel@tonic-gate 				} else {
1867c478bd9Sstevel@tonic-gate 					if(ipc->r1.negfl)
1877c478bd9Sstevel@tonic-gate 						goto yes;
1887c478bd9Sstevel@tonic-gate 					ipc++;
1897c478bd9Sstevel@tonic-gate 					continue;
1907c478bd9Sstevel@tonic-gate 				}
1917c478bd9Sstevel@tonic-gate 			}
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 			if(ipc->r1.negfl) {
1947c478bd9Sstevel@tonic-gate 				ipc++;
1957c478bd9Sstevel@tonic-gate 				continue;
1967c478bd9Sstevel@tonic-gate 			}
1977c478bd9Sstevel@tonic-gate 	yes:
1987c478bd9Sstevel@tonic-gate 			command(ipc);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 			if(delflag)
2017c478bd9Sstevel@tonic-gate 				break;
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 			if(jflag) {
2047c478bd9Sstevel@tonic-gate 				jflag = 0;
2057c478bd9Sstevel@tonic-gate 				if((ipc = ipc->r2.lb1) == 0) {
2067c478bd9Sstevel@tonic-gate 					ipc = ptrspace;
2077c478bd9Sstevel@tonic-gate 					break;
2087c478bd9Sstevel@tonic-gate 				}
2097c478bd9Sstevel@tonic-gate 			} else
2107c478bd9Sstevel@tonic-gate 				ipc++;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 		}
2137c478bd9Sstevel@tonic-gate 		if(!nflag && !delflag) {
2147c478bd9Sstevel@tonic-gate 			for(p1 = linebuf; p1 < spend; p1++)
2157c478bd9Sstevel@tonic-gate 				(void) putc(*p1, stdout);
2167c478bd9Sstevel@tonic-gate 			(void) putc('\n', stdout);
2177c478bd9Sstevel@tonic-gate 		}
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 		if(aptr > abuf) {
2207c478bd9Sstevel@tonic-gate 			arout();
2217c478bd9Sstevel@tonic-gate 		}
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 		delflag = 0;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	}
2267c478bd9Sstevel@tonic-gate }
227*bdcaf822Sbasabi 
228*bdcaf822Sbasabi static int
match(char * expbuf,int gf)229*bdcaf822Sbasabi match(char *expbuf, int gf)
2307c478bd9Sstevel@tonic-gate {
231*bdcaf822Sbasabi 	char   *p1;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	if(gf) {
2347c478bd9Sstevel@tonic-gate 		if(*expbuf)	return(0);
2357c478bd9Sstevel@tonic-gate 		locs = p1 = loc2;
2367c478bd9Sstevel@tonic-gate 	} else {
2377c478bd9Sstevel@tonic-gate 		p1 = linebuf;
2387c478bd9Sstevel@tonic-gate 		locs = 0;
2397c478bd9Sstevel@tonic-gate 	}
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	circf = *expbuf++;
2427c478bd9Sstevel@tonic-gate 	return(step(p1, expbuf));
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate 
245*bdcaf822Sbasabi static int
substitute(union reptr * ipc)246*bdcaf822Sbasabi substitute(union reptr *ipc)
2477c478bd9Sstevel@tonic-gate {
2487c478bd9Sstevel@tonic-gate 	if(match(ipc->r1.re1, 0) == 0)	return(0);
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	numpass = 0;
2517c478bd9Sstevel@tonic-gate 	sflag = 0;		/* Flags if any substitution was made */
2527c478bd9Sstevel@tonic-gate 	dosub(ipc->r1.rhs, ipc->r1.gfl);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	if(ipc->r1.gfl) {
2557c478bd9Sstevel@tonic-gate 		while(*loc2) {
2567c478bd9Sstevel@tonic-gate 			if(match(ipc->r1.re1, 1) == 0) break;
2577c478bd9Sstevel@tonic-gate 			dosub(ipc->r1.rhs, ipc->r1.gfl);
2587c478bd9Sstevel@tonic-gate 		}
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 	return(sflag);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate 
263*bdcaf822Sbasabi static void
dosub(char * rhsbuf,int n)264*bdcaf822Sbasabi dosub(char *rhsbuf, int n)
2657c478bd9Sstevel@tonic-gate {
266*bdcaf822Sbasabi 	char *lp, *sp, *rp;
2677c478bd9Sstevel@tonic-gate 	int c;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	if(n > 0 && n < 999)
2707c478bd9Sstevel@tonic-gate 		{numpass++;
2717c478bd9Sstevel@tonic-gate 		if(n != numpass) return;
2727c478bd9Sstevel@tonic-gate 		}
2737c478bd9Sstevel@tonic-gate 	sflag = 1;
2747c478bd9Sstevel@tonic-gate 	lp = linebuf;
2757c478bd9Sstevel@tonic-gate 	sp = genbuf;
2767c478bd9Sstevel@tonic-gate 	rp = rhsbuf;
2777c478bd9Sstevel@tonic-gate 	while (lp < loc1)
2787c478bd9Sstevel@tonic-gate 		*sp++ = *lp++;
2797c478bd9Sstevel@tonic-gate 	while(c = *rp++) {
2807c478bd9Sstevel@tonic-gate 		if (c == '&')
2817c478bd9Sstevel@tonic-gate 			sp = place(sp, loc1, loc2);
2827c478bd9Sstevel@tonic-gate 		else if (c == '\\') {
2837c478bd9Sstevel@tonic-gate 			c = *rp++;
2847c478bd9Sstevel@tonic-gate 			if (c >= '1' && c < NBRA+'1')
2857c478bd9Sstevel@tonic-gate 				sp = place(sp, braslist[c-'1'], braelist[c-'1']);
2867c478bd9Sstevel@tonic-gate 			else
2877c478bd9Sstevel@tonic-gate 				*sp++ = c;
2887c478bd9Sstevel@tonic-gate   		} else
2897c478bd9Sstevel@tonic-gate 			*sp++ = c;
2907c478bd9Sstevel@tonic-gate 		if (sp == &genbuf[LBSIZE+1]) {
2917c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "Output line too long.\n");
2927c478bd9Sstevel@tonic-gate 			*--sp = '\0';
2937c478bd9Sstevel@tonic-gate 			goto out;
2947c478bd9Sstevel@tonic-gate 		}
2957c478bd9Sstevel@tonic-gate 	}
2967c478bd9Sstevel@tonic-gate 	lp = loc2;
2977c478bd9Sstevel@tonic-gate 	loc2 = sp - genbuf + linebuf;
2987c478bd9Sstevel@tonic-gate 	while(*sp++ = *lp++)
2997c478bd9Sstevel@tonic-gate 		if (sp == &genbuf[LBSIZE+1]) {
3007c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "Output line too long.\n");
3017c478bd9Sstevel@tonic-gate 			*--sp = '\0';
3027c478bd9Sstevel@tonic-gate 			break;
3037c478bd9Sstevel@tonic-gate 		}
3047c478bd9Sstevel@tonic-gate out:
3057c478bd9Sstevel@tonic-gate 	lp = linebuf;
3067c478bd9Sstevel@tonic-gate 	sp = genbuf;
3077c478bd9Sstevel@tonic-gate 	while (*lp++ = *sp++);
3087c478bd9Sstevel@tonic-gate 	spend = lp-1;
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate 
place(asp,al1,al2)3117c478bd9Sstevel@tonic-gate char	*place(asp, al1, al2)
3127c478bd9Sstevel@tonic-gate char	*asp, *al1, *al2;
3137c478bd9Sstevel@tonic-gate {
314*bdcaf822Sbasabi 	char *sp, *l1, *l2;
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	sp = asp;
3177c478bd9Sstevel@tonic-gate 	l1 = al1;
3187c478bd9Sstevel@tonic-gate 	l2 = al2;
3197c478bd9Sstevel@tonic-gate 	while (l1 < l2) {
3207c478bd9Sstevel@tonic-gate 		*sp++ = *l1++;
3217c478bd9Sstevel@tonic-gate 		if (sp == &genbuf[LBSIZE+1])
3227c478bd9Sstevel@tonic-gate 			break;
3237c478bd9Sstevel@tonic-gate 	}
3247c478bd9Sstevel@tonic-gate 	return(sp);
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate 
327*bdcaf822Sbasabi static void
command(union reptr * ipc)328*bdcaf822Sbasabi command(union reptr *ipc)
3297c478bd9Sstevel@tonic-gate {
330*bdcaf822Sbasabi 	int	i;
331*bdcaf822Sbasabi 	char   *p1, *p2, *p3;
3327c478bd9Sstevel@tonic-gate 	char	*execp;
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	switch(ipc->r1.command) {
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 		case ACOM:
3387c478bd9Sstevel@tonic-gate 			if(aptr >= &abuf[ABUFSIZE]) {
3397c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "Too many appends or reads after line %lld\n",
3407c478bd9Sstevel@tonic-gate 					lnum);
3417c478bd9Sstevel@tonic-gate 			} else {
3427c478bd9Sstevel@tonic-gate 				*aptr++ = ipc;
3437c478bd9Sstevel@tonic-gate 				*aptr = 0;
3447c478bd9Sstevel@tonic-gate 			}
3457c478bd9Sstevel@tonic-gate 			break;
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 		case CCOM:
3487c478bd9Sstevel@tonic-gate 			delflag = 1;
3497c478bd9Sstevel@tonic-gate 			if(!ipc->r1.inar || dolflag) {
3507c478bd9Sstevel@tonic-gate 				for(p1 = ipc->r1.re1; *p1; )
3517c478bd9Sstevel@tonic-gate 					(void) putc(*p1++, stdout);
3527c478bd9Sstevel@tonic-gate 				(void) putc('\n', stdout);
3537c478bd9Sstevel@tonic-gate 			}
3547c478bd9Sstevel@tonic-gate 			break;
3557c478bd9Sstevel@tonic-gate 		case DCOM:
3567c478bd9Sstevel@tonic-gate 			delflag++;
3577c478bd9Sstevel@tonic-gate 			break;
3587c478bd9Sstevel@tonic-gate 		case CDCOM:
3597c478bd9Sstevel@tonic-gate 			p1 = p2 = linebuf;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 			while(*p1 != '\n') {
3627c478bd9Sstevel@tonic-gate 				if(*p1++ == 0) {
3637c478bd9Sstevel@tonic-gate 					delflag++;
3647c478bd9Sstevel@tonic-gate 					return;
3657c478bd9Sstevel@tonic-gate 				}
3667c478bd9Sstevel@tonic-gate 			}
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 			p1++;
3697c478bd9Sstevel@tonic-gate 			while(*p2++ = *p1++);
3707c478bd9Sstevel@tonic-gate 			spend = p2-1;
3717c478bd9Sstevel@tonic-gate 			jflag++;
3727c478bd9Sstevel@tonic-gate 			break;
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 		case EQCOM:
3757c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout, "%lld\n", lnum);
3767c478bd9Sstevel@tonic-gate 			break;
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 		case GCOM:
3797c478bd9Sstevel@tonic-gate 			p1 = linebuf;
3807c478bd9Sstevel@tonic-gate 			p2 = holdsp;
3817c478bd9Sstevel@tonic-gate 			while(*p1++ = *p2++);
3827c478bd9Sstevel@tonic-gate 			spend = p1-1;
3837c478bd9Sstevel@tonic-gate 			break;
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 		case CGCOM:
3867c478bd9Sstevel@tonic-gate 			*spend++ = '\n';
3877c478bd9Sstevel@tonic-gate 			p1 = spend;
3887c478bd9Sstevel@tonic-gate 			p2 = holdsp;
3897c478bd9Sstevel@tonic-gate 			do {
3907c478bd9Sstevel@tonic-gate 				if (p1 == &linebuf[LBSIZE+1]) {
3917c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr, "Output line too long.\n");
3927c478bd9Sstevel@tonic-gate 					*--p1 = '\0';
3937c478bd9Sstevel@tonic-gate 				}
3947c478bd9Sstevel@tonic-gate 			} while(*p1++ = *p2++);
3957c478bd9Sstevel@tonic-gate 			spend = p1-1;
3967c478bd9Sstevel@tonic-gate 			break;
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 		case HCOM:
3997c478bd9Sstevel@tonic-gate 			p1 = holdsp;
4007c478bd9Sstevel@tonic-gate 			p2 = linebuf;
4017c478bd9Sstevel@tonic-gate 			while(*p1++ = *p2++);
4027c478bd9Sstevel@tonic-gate 			hspend = p1-1;
4037c478bd9Sstevel@tonic-gate 			break;
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 		case CHCOM:
4067c478bd9Sstevel@tonic-gate 			*hspend++ = '\n';
4077c478bd9Sstevel@tonic-gate 			p1 = hspend;
4087c478bd9Sstevel@tonic-gate 			p2 = linebuf;
4097c478bd9Sstevel@tonic-gate 			do {
4107c478bd9Sstevel@tonic-gate 				if (p1 == &holdsp[LBSIZE+1]) {
4117c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr, "Hold space overflowed.\n");
4127c478bd9Sstevel@tonic-gate 					*--p1 = '\0';
4137c478bd9Sstevel@tonic-gate 				}
4147c478bd9Sstevel@tonic-gate 			} while(*p1++ = *p2++);
4157c478bd9Sstevel@tonic-gate 			hspend = p1-1;
4167c478bd9Sstevel@tonic-gate 			break;
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 		case ICOM:
4197c478bd9Sstevel@tonic-gate 			for(p1 = ipc->r1.re1; *p1; )
4207c478bd9Sstevel@tonic-gate 				(void) putc(*p1++, stdout);
4217c478bd9Sstevel@tonic-gate 			(void) putc('\n', stdout);
4227c478bd9Sstevel@tonic-gate 			break;
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 		case BCOM:
4257c478bd9Sstevel@tonic-gate 			jflag = 1;
4267c478bd9Sstevel@tonic-gate 			break;
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 		case LCOM:
4307c478bd9Sstevel@tonic-gate 			p1 = linebuf;
4317c478bd9Sstevel@tonic-gate 			p2 = genbuf;
4327c478bd9Sstevel@tonic-gate 			genbuf[72] = 0;
4337c478bd9Sstevel@tonic-gate 			while(*p1)
4347c478bd9Sstevel@tonic-gate 				if((unsigned char)*p1 >= 040) {
4357c478bd9Sstevel@tonic-gate 					if(*p1 == 0177) {
4367c478bd9Sstevel@tonic-gate 						p3 = rub;
4377c478bd9Sstevel@tonic-gate 						while(*p2++ = *p3++)
4387c478bd9Sstevel@tonic-gate 							if(p2 >= lcomend) {
4397c478bd9Sstevel@tonic-gate 								*p2 = '\\';
4407c478bd9Sstevel@tonic-gate 								(void) fprintf(stdout, "%s\n", genbuf);
4417c478bd9Sstevel@tonic-gate 								p2 = genbuf;
4427c478bd9Sstevel@tonic-gate 							}
4437c478bd9Sstevel@tonic-gate 						p2--;
4447c478bd9Sstevel@tonic-gate 						p1++;
4457c478bd9Sstevel@tonic-gate 						continue;
4467c478bd9Sstevel@tonic-gate 					}
4477c478bd9Sstevel@tonic-gate 					if(!isprint(*p1 & 0377)) {
4487c478bd9Sstevel@tonic-gate 						*p2++ = '\\';
4497c478bd9Sstevel@tonic-gate 						if(p2 >= lcomend) {
4507c478bd9Sstevel@tonic-gate 							*p2 = '\\';
4517c478bd9Sstevel@tonic-gate 							(void) fprintf(stdout, "%s\n", genbuf);
4527c478bd9Sstevel@tonic-gate 							p2 = genbuf;
4537c478bd9Sstevel@tonic-gate 						}
4547c478bd9Sstevel@tonic-gate 						*p2++ = (*p1 >> 6) + '0';
4557c478bd9Sstevel@tonic-gate 						if(p2 >= lcomend) {
4567c478bd9Sstevel@tonic-gate 							*p2 = '\\';
4577c478bd9Sstevel@tonic-gate 							(void) fprintf(stdout, "%s\n", genbuf);
4587c478bd9Sstevel@tonic-gate 							p2 = genbuf;
4597c478bd9Sstevel@tonic-gate 						}
4607c478bd9Sstevel@tonic-gate 						*p2++ = ((*p1 >> 3) & 07) + '0';
4617c478bd9Sstevel@tonic-gate 						if(p2 >= lcomend) {
4627c478bd9Sstevel@tonic-gate 							*p2 = '\\';
4637c478bd9Sstevel@tonic-gate 							(void) fprintf(stdout, "%s\n", genbuf);
4647c478bd9Sstevel@tonic-gate 							p2 = genbuf;
4657c478bd9Sstevel@tonic-gate 						}
4667c478bd9Sstevel@tonic-gate 						*p2++ = (*p1++ & 07) + '0';
4677c478bd9Sstevel@tonic-gate 						if(p2 >= lcomend) {
4687c478bd9Sstevel@tonic-gate 							*p2 = '\\';
4697c478bd9Sstevel@tonic-gate 							(void) fprintf(stdout, "%s\n", genbuf);
4707c478bd9Sstevel@tonic-gate 							p2 = genbuf;
4717c478bd9Sstevel@tonic-gate 						}
4727c478bd9Sstevel@tonic-gate 					} else {
4737c478bd9Sstevel@tonic-gate 						*p2++ = *p1++;
4747c478bd9Sstevel@tonic-gate 						if(p2 >= lcomend) {
4757c478bd9Sstevel@tonic-gate 							*p2 = '\\';
4767c478bd9Sstevel@tonic-gate 							(void) fprintf(stdout, "%s\n", genbuf);
4777c478bd9Sstevel@tonic-gate 							p2 = genbuf;
4787c478bd9Sstevel@tonic-gate 						}
4797c478bd9Sstevel@tonic-gate 					}
4807c478bd9Sstevel@tonic-gate 				} else {
4817c478bd9Sstevel@tonic-gate 					p3 = trans[(unsigned char)*p1-1];
4827c478bd9Sstevel@tonic-gate 					while(*p2++ = *p3++)
4837c478bd9Sstevel@tonic-gate 						if(p2 >= lcomend) {
4847c478bd9Sstevel@tonic-gate 							*p2 = '\\';
4857c478bd9Sstevel@tonic-gate 							(void) fprintf(stdout, "%s\n", genbuf);
4867c478bd9Sstevel@tonic-gate 							p2 = genbuf;
4877c478bd9Sstevel@tonic-gate 						}
4887c478bd9Sstevel@tonic-gate 					p2--;
4897c478bd9Sstevel@tonic-gate 					p1++;
4907c478bd9Sstevel@tonic-gate 				}
4917c478bd9Sstevel@tonic-gate 			*p2 = 0;
4927c478bd9Sstevel@tonic-gate 			(void) fprintf(stdout, "%s\n", genbuf);
4937c478bd9Sstevel@tonic-gate 			break;
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate 		case NCOM:
4967c478bd9Sstevel@tonic-gate 			if(!nflag) {
4977c478bd9Sstevel@tonic-gate 				for(p1 = linebuf; p1 < spend; p1++)
4987c478bd9Sstevel@tonic-gate 					(void) putc(*p1, stdout);
4997c478bd9Sstevel@tonic-gate 				(void) putc('\n', stdout);
5007c478bd9Sstevel@tonic-gate 			}
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 			if(aptr > abuf)
5037c478bd9Sstevel@tonic-gate 				arout();
5047c478bd9Sstevel@tonic-gate 			if((execp = gline(linebuf)) == 0) {
5057c478bd9Sstevel@tonic-gate 				pending = ipc;
5067c478bd9Sstevel@tonic-gate 				delflag = 1;
5077c478bd9Sstevel@tonic-gate 				break;
5087c478bd9Sstevel@tonic-gate 			}
5097c478bd9Sstevel@tonic-gate 			spend = execp;
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 			break;
5127c478bd9Sstevel@tonic-gate 		case CNCOM:
5137c478bd9Sstevel@tonic-gate 			if(aptr > abuf)
5147c478bd9Sstevel@tonic-gate 				arout();
5157c478bd9Sstevel@tonic-gate 			*spend++ = '\n';
5167c478bd9Sstevel@tonic-gate 			if((execp = gline(spend)) == 0) {
5177c478bd9Sstevel@tonic-gate 				pending = ipc;
5187c478bd9Sstevel@tonic-gate 				delflag = 1;
5197c478bd9Sstevel@tonic-gate 				break;
5207c478bd9Sstevel@tonic-gate 			}
5217c478bd9Sstevel@tonic-gate 			spend = execp;
5227c478bd9Sstevel@tonic-gate 			break;
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 		case PCOM:
5257c478bd9Sstevel@tonic-gate 			for(p1 = linebuf; p1 < spend; p1++)
5267c478bd9Sstevel@tonic-gate 				(void) putc(*p1, stdout);
5277c478bd9Sstevel@tonic-gate 			(void) putc('\n', stdout);
5287c478bd9Sstevel@tonic-gate 			break;
5297c478bd9Sstevel@tonic-gate 		case CPCOM:
5307c478bd9Sstevel@tonic-gate 	cpcom:
5317c478bd9Sstevel@tonic-gate 			for(p1 = linebuf; *p1 != '\n' && *p1 != '\0'; )
5327c478bd9Sstevel@tonic-gate 				(void) putc(*p1++, stdout);
5337c478bd9Sstevel@tonic-gate 			(void) putc('\n', stdout);
5347c478bd9Sstevel@tonic-gate 			break;
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 		case QCOM:
5377c478bd9Sstevel@tonic-gate 			if(!nflag) {
5387c478bd9Sstevel@tonic-gate 				for(p1 = linebuf; p1 < spend; p1++)
5397c478bd9Sstevel@tonic-gate 					(void) putc(*p1, stdout);
5407c478bd9Sstevel@tonic-gate 				(void) putc('\n', stdout);
5417c478bd9Sstevel@tonic-gate 			}
5427c478bd9Sstevel@tonic-gate 			if(aptr > abuf) arout();
5437c478bd9Sstevel@tonic-gate 			(void) fclose(stdout);
5447c478bd9Sstevel@tonic-gate 			exit(0);
5457c478bd9Sstevel@tonic-gate 		case RCOM:
5467c478bd9Sstevel@tonic-gate 			if(aptr >= &abuf[ABUFSIZE]) {
5477c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "Too many appends or reads after line %lld\n",
5487c478bd9Sstevel@tonic-gate 					lnum);
5497c478bd9Sstevel@tonic-gate 			} else {
5507c478bd9Sstevel@tonic-gate 				*aptr++ = ipc;
5517c478bd9Sstevel@tonic-gate 				*aptr = 0;
5527c478bd9Sstevel@tonic-gate 			}
5537c478bd9Sstevel@tonic-gate 			break;
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 		case SCOM:
5567c478bd9Sstevel@tonic-gate 			i = substitute(ipc);
5577c478bd9Sstevel@tonic-gate 			if(ipc->r1.pfl && nflag && i)
5587c478bd9Sstevel@tonic-gate 				if(ipc->r1.pfl == 1) {
5597c478bd9Sstevel@tonic-gate 					for(p1 = linebuf; p1 < spend; p1++)
5607c478bd9Sstevel@tonic-gate 						(void) putc(*p1, stdout);
5617c478bd9Sstevel@tonic-gate 					(void) putc('\n', stdout);
5627c478bd9Sstevel@tonic-gate 				}
5637c478bd9Sstevel@tonic-gate 				else
5647c478bd9Sstevel@tonic-gate 					goto cpcom;
5657c478bd9Sstevel@tonic-gate 			if(i && ipc->r1.fcode)
5667c478bd9Sstevel@tonic-gate 				goto wcom;
5677c478bd9Sstevel@tonic-gate 			break;
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 		case TCOM:
5707c478bd9Sstevel@tonic-gate 			if(sflag == 0)  break;
5717c478bd9Sstevel@tonic-gate 			sflag = 0;
5727c478bd9Sstevel@tonic-gate 			jflag = 1;
5737c478bd9Sstevel@tonic-gate 			break;
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 		wcom:
5767c478bd9Sstevel@tonic-gate 		case WCOM:
5777c478bd9Sstevel@tonic-gate 			(void) fprintf(ipc->r1.fcode, "%s\n", linebuf);
5787c478bd9Sstevel@tonic-gate 			(void) fflush(ipc->r1.fcode);
5797c478bd9Sstevel@tonic-gate 			break;
5807c478bd9Sstevel@tonic-gate 		case XCOM:
5817c478bd9Sstevel@tonic-gate 			p1 = linebuf;
5827c478bd9Sstevel@tonic-gate 			p2 = genbuf;
5837c478bd9Sstevel@tonic-gate 			while(*p2++ = *p1++);
5847c478bd9Sstevel@tonic-gate 			p1 = holdsp;
5857c478bd9Sstevel@tonic-gate 			p2 = linebuf;
5867c478bd9Sstevel@tonic-gate 			while(*p2++ = *p1++);
5877c478bd9Sstevel@tonic-gate 			spend = p2 - 1;
5887c478bd9Sstevel@tonic-gate 			p1 = genbuf;
5897c478bd9Sstevel@tonic-gate 			p2 = holdsp;
5907c478bd9Sstevel@tonic-gate 			while(*p2++ = *p1++);
5917c478bd9Sstevel@tonic-gate 			hspend = p2 - 1;
5927c478bd9Sstevel@tonic-gate 			break;
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 		case YCOM:
5957c478bd9Sstevel@tonic-gate 			p1 = linebuf;
5967c478bd9Sstevel@tonic-gate 			p2 = ipc->r1.re1;
5977c478bd9Sstevel@tonic-gate 			while(*p1 = p2[(unsigned char)*p1])	p1++;
5987c478bd9Sstevel@tonic-gate 			break;
5997c478bd9Sstevel@tonic-gate 	}
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate 
gline(addr)6037c478bd9Sstevel@tonic-gate char	*gline(addr)
6047c478bd9Sstevel@tonic-gate char	*addr;
6057c478bd9Sstevel@tonic-gate {
606*bdcaf822Sbasabi 	char   *p1, *p2;
607*bdcaf822Sbasabi 	int	c;
6087c478bd9Sstevel@tonic-gate 	sflag = 0;
6097c478bd9Sstevel@tonic-gate 	p1 = addr;
6107c478bd9Sstevel@tonic-gate 	p2 = cbp;
6117c478bd9Sstevel@tonic-gate 	for (;;) {
6127c478bd9Sstevel@tonic-gate 		if (p2 >= ebp) {
6137c478bd9Sstevel@tonic-gate 			if(f < 0 || (c = read(f, ibuf, BUFSIZ)) == 0) {
6147c478bd9Sstevel@tonic-gate 				return(0);
6157c478bd9Sstevel@tonic-gate 			}
6167c478bd9Sstevel@tonic-gate 			if(c < 0) {
6177c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "sed: error reading ");
6187c478bd9Sstevel@tonic-gate 				perror(ifname);
6197c478bd9Sstevel@tonic-gate 				exit(2);
6207c478bd9Sstevel@tonic-gate 			}
6217c478bd9Sstevel@tonic-gate 			p2 = ibuf;
6227c478bd9Sstevel@tonic-gate 			ebp = ibuf+c;
6237c478bd9Sstevel@tonic-gate 		}
6247c478bd9Sstevel@tonic-gate 		if ((c = *p2++) == '\n') {
6257c478bd9Sstevel@tonic-gate 			if(p2 >=  ebp) {
6267c478bd9Sstevel@tonic-gate 				if(f < 0 || (c = read(f, ibuf, BUFSIZ)) == 0) {
6277c478bd9Sstevel@tonic-gate 					if(f >= 0) {
6287c478bd9Sstevel@tonic-gate 						(void) close(f);
6297c478bd9Sstevel@tonic-gate 						f = -1;
6307c478bd9Sstevel@tonic-gate 					}
6317c478bd9Sstevel@tonic-gate 					if(eargc == 0)
6327c478bd9Sstevel@tonic-gate 							dolflag = 1;
6337c478bd9Sstevel@tonic-gate 				}
6347c478bd9Sstevel@tonic-gate 				if(c < 0) {
6357c478bd9Sstevel@tonic-gate 					(void) fprintf(stderr, "sed: error reading ");
6367c478bd9Sstevel@tonic-gate 					perror(ifname);
6377c478bd9Sstevel@tonic-gate 					exit(2);
6387c478bd9Sstevel@tonic-gate 				}
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 				p2 = ibuf;
6417c478bd9Sstevel@tonic-gate 				ebp = ibuf + c;
6427c478bd9Sstevel@tonic-gate 			}
6437c478bd9Sstevel@tonic-gate 			break;
6447c478bd9Sstevel@tonic-gate 		}
6457c478bd9Sstevel@tonic-gate 		if(c)
6467c478bd9Sstevel@tonic-gate 		if(p1 < &linebuf[LBSIZE])
6477c478bd9Sstevel@tonic-gate 			*p1++ = c;
6487c478bd9Sstevel@tonic-gate 	}
6497c478bd9Sstevel@tonic-gate 	lnum++;
6507c478bd9Sstevel@tonic-gate 	*p1 = 0;
6517c478bd9Sstevel@tonic-gate 	cbp = p2;
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 	return(p1);
6547c478bd9Sstevel@tonic-gate }
6557c478bd9Sstevel@tonic-gate 
comple(x1,ep,x3,x4)6567c478bd9Sstevel@tonic-gate char *comple(x1, ep, x3, x4)
6577c478bd9Sstevel@tonic-gate char *x1, *x3;
6587c478bd9Sstevel@tonic-gate char x4;
659*bdcaf822Sbasabi char *ep;
6607c478bd9Sstevel@tonic-gate {
661*bdcaf822Sbasabi 	char *p;
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 	p = compile(x1, ep + 1, x3, x4);
6647c478bd9Sstevel@tonic-gate 	if(p == ep + 1)
6657c478bd9Sstevel@tonic-gate 		return(ep);
6667c478bd9Sstevel@tonic-gate 	*ep = circf;
6677c478bd9Sstevel@tonic-gate 	return(p);
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate 
670*bdcaf822Sbasabi int
regerr(int err)671*bdcaf822Sbasabi regerr(int err)
6727c478bd9Sstevel@tonic-gate {
6737c478bd9Sstevel@tonic-gate 	switch(err) {
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate 	case 11:
6767c478bd9Sstevel@tonic-gate 		comperr("Range endpoint too large: %s");
6777c478bd9Sstevel@tonic-gate 		break;
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	case 16:
6807c478bd9Sstevel@tonic-gate 		comperr("Bad number: %s");
6817c478bd9Sstevel@tonic-gate 		break;
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	case 25:
6847c478bd9Sstevel@tonic-gate 		comperr("``\\digit'' out of range: %s");
6857c478bd9Sstevel@tonic-gate 		break;
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 	case 36:
6887c478bd9Sstevel@tonic-gate 		comperr("Illegal or missing delimiter: %s");
6897c478bd9Sstevel@tonic-gate 		break;
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 	case 41:
6927c478bd9Sstevel@tonic-gate 		comperr("No remembered search string: %s");
6937c478bd9Sstevel@tonic-gate 		break;
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate 	case 42:
6967c478bd9Sstevel@tonic-gate 		comperr("\\( \\) imbalance: %s");
6977c478bd9Sstevel@tonic-gate 		break;
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate 	case 43:
7007c478bd9Sstevel@tonic-gate 		comperr("Too many \\(: %s");
7017c478bd9Sstevel@tonic-gate 		break;
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 	case 44:
7047c478bd9Sstevel@tonic-gate 		comperr("More than 2 numbers given in \\{ \\}: %s");
7057c478bd9Sstevel@tonic-gate 		break;
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate 	case 45:
7087c478bd9Sstevel@tonic-gate 		comperr("} expected after \\: %s");
7097c478bd9Sstevel@tonic-gate 		break;
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 	case 46:
7127c478bd9Sstevel@tonic-gate 		comperr("First number exceeds second in \\{ \\}: %s");
7137c478bd9Sstevel@tonic-gate 		break;
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 	case 49:
7167c478bd9Sstevel@tonic-gate 		comperr("[ ] imbalance: %s");
7177c478bd9Sstevel@tonic-gate 		break;
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 	case 50:
7207c478bd9Sstevel@tonic-gate 		comperr(TMMES);
7217c478bd9Sstevel@tonic-gate 		break;
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	default:
7247c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "Unknown regexp error code %d: %s\n",
7257c478bd9Sstevel@tonic-gate 		    err, linebuf);
7267c478bd9Sstevel@tonic-gate 		exit(2);
7277c478bd9Sstevel@tonic-gate 		break;
7287c478bd9Sstevel@tonic-gate 	}
729*bdcaf822Sbasabi 	return (0);
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate 
732*bdcaf822Sbasabi static void
arout(void)733*bdcaf822Sbasabi arout(void)
7347c478bd9Sstevel@tonic-gate {
735*bdcaf822Sbasabi 	char   *p1;
7367c478bd9Sstevel@tonic-gate 	FILE	*fi;
7377c478bd9Sstevel@tonic-gate 	char	c;
7387c478bd9Sstevel@tonic-gate 	int	t;
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 	aptr = abuf - 1;
7417c478bd9Sstevel@tonic-gate 	while(*++aptr) {
7427c478bd9Sstevel@tonic-gate 		if((*aptr)->r1.command == ACOM) {
7437c478bd9Sstevel@tonic-gate 			for(p1 = (*aptr)->r1.re1; *p1; )
7447c478bd9Sstevel@tonic-gate 				(void) putc(*p1++, stdout);
7457c478bd9Sstevel@tonic-gate 			(void) putc('\n', stdout);
7467c478bd9Sstevel@tonic-gate 		} else {
7477c478bd9Sstevel@tonic-gate 			if((fi = fopen((*aptr)->r1.re1, "r")) == NULL)
7487c478bd9Sstevel@tonic-gate 				continue;
7497c478bd9Sstevel@tonic-gate 			while((t = getc(fi)) != EOF) {
7507c478bd9Sstevel@tonic-gate 				c = t;
7517c478bd9Sstevel@tonic-gate 				(void) putc(c, stdout);
7527c478bd9Sstevel@tonic-gate 			}
7537c478bd9Sstevel@tonic-gate 			(void) fclose(fi);
7547c478bd9Sstevel@tonic-gate 		}
7557c478bd9Sstevel@tonic-gate 	}
7567c478bd9Sstevel@tonic-gate 	aptr = abuf;
7577c478bd9Sstevel@tonic-gate 	*aptr = 0;
7587c478bd9Sstevel@tonic-gate }
759