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