1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996, by Sun Microsystems, Inc. 28*7c478bd9Sstevel@tonic-gate * All rights reserved. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" /* from S5R3.1 1.7 */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include <stdio.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 36*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 37*7c478bd9Sstevel@tonic-gate #include "sed.h" 38*7c478bd9Sstevel@tonic-gate #include <regexp.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate union reptr *abuf[ABUFSIZE+1]; 41*7c478bd9Sstevel@tonic-gate union reptr **aptr; 42*7c478bd9Sstevel@tonic-gate char ibuf[BUFSIZ]; 43*7c478bd9Sstevel@tonic-gate char *cbp; 44*7c478bd9Sstevel@tonic-gate char *ebp; 45*7c478bd9Sstevel@tonic-gate char genbuf[LBSIZE+1]; 46*7c478bd9Sstevel@tonic-gate char *lcomend; 47*7c478bd9Sstevel@tonic-gate int dolflag; 48*7c478bd9Sstevel@tonic-gate int sflag; 49*7c478bd9Sstevel@tonic-gate int jflag; 50*7c478bd9Sstevel@tonic-gate int delflag; 51*7c478bd9Sstevel@tonic-gate long long lnum; 52*7c478bd9Sstevel@tonic-gate char holdsp[LBSIZE+1]; 53*7c478bd9Sstevel@tonic-gate char *spend; 54*7c478bd9Sstevel@tonic-gate char *hspend; 55*7c478bd9Sstevel@tonic-gate int nflag; 56*7c478bd9Sstevel@tonic-gate long long tlno[NLINES]; 57*7c478bd9Sstevel@tonic-gate int f; 58*7c478bd9Sstevel@tonic-gate char *ifname; 59*7c478bd9Sstevel@tonic-gate int numpass; 60*7c478bd9Sstevel@tonic-gate union reptr *pending; 61*7c478bd9Sstevel@tonic-gate char *trans[040] = { 62*7c478bd9Sstevel@tonic-gate "\\01", 63*7c478bd9Sstevel@tonic-gate "\\02", 64*7c478bd9Sstevel@tonic-gate "\\03", 65*7c478bd9Sstevel@tonic-gate "\\04", 66*7c478bd9Sstevel@tonic-gate "\\05", 67*7c478bd9Sstevel@tonic-gate "\\06", 68*7c478bd9Sstevel@tonic-gate "\\07", 69*7c478bd9Sstevel@tonic-gate "-<", 70*7c478bd9Sstevel@tonic-gate "->", 71*7c478bd9Sstevel@tonic-gate "\n", 72*7c478bd9Sstevel@tonic-gate "\\13", 73*7c478bd9Sstevel@tonic-gate "\\14", 74*7c478bd9Sstevel@tonic-gate "\\15", 75*7c478bd9Sstevel@tonic-gate "\\16", 76*7c478bd9Sstevel@tonic-gate "\\17", 77*7c478bd9Sstevel@tonic-gate "\\20", 78*7c478bd9Sstevel@tonic-gate "\\21", 79*7c478bd9Sstevel@tonic-gate "\\22", 80*7c478bd9Sstevel@tonic-gate "\\23", 81*7c478bd9Sstevel@tonic-gate "\\24", 82*7c478bd9Sstevel@tonic-gate "\\25", 83*7c478bd9Sstevel@tonic-gate "\\26", 84*7c478bd9Sstevel@tonic-gate "\\27", 85*7c478bd9Sstevel@tonic-gate "\\30", 86*7c478bd9Sstevel@tonic-gate "\\31", 87*7c478bd9Sstevel@tonic-gate "\\32", 88*7c478bd9Sstevel@tonic-gate "\\33", 89*7c478bd9Sstevel@tonic-gate "\\34", 90*7c478bd9Sstevel@tonic-gate "\\35", 91*7c478bd9Sstevel@tonic-gate "\\36", 92*7c478bd9Sstevel@tonic-gate "\\37" 93*7c478bd9Sstevel@tonic-gate }; 94*7c478bd9Sstevel@tonic-gate char rub[] = {"\\177"}; 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate extern char TMMES[]; 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate execute(file) 99*7c478bd9Sstevel@tonic-gate char *file; 100*7c478bd9Sstevel@tonic-gate { 101*7c478bd9Sstevel@tonic-gate register char *p1, *p2; 102*7c478bd9Sstevel@tonic-gate register union reptr *ipc; 103*7c478bd9Sstevel@tonic-gate int c; 104*7c478bd9Sstevel@tonic-gate char *execp; 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate if (file) { 107*7c478bd9Sstevel@tonic-gate if ((f = open(file, 0)) < 0) { 108*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "sed: "); 109*7c478bd9Sstevel@tonic-gate perror(file); 110*7c478bd9Sstevel@tonic-gate } 111*7c478bd9Sstevel@tonic-gate ifname = file; 112*7c478bd9Sstevel@tonic-gate } else { 113*7c478bd9Sstevel@tonic-gate f = 0; 114*7c478bd9Sstevel@tonic-gate ifname = "standard input"; 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate ebp = ibuf; 118*7c478bd9Sstevel@tonic-gate cbp = ibuf; 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate if(pending) { 121*7c478bd9Sstevel@tonic-gate ipc = pending; 122*7c478bd9Sstevel@tonic-gate pending = 0; 123*7c478bd9Sstevel@tonic-gate goto yes; 124*7c478bd9Sstevel@tonic-gate } 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate for(;;) { 127*7c478bd9Sstevel@tonic-gate if((execp = gline(linebuf)) == 0) { 128*7c478bd9Sstevel@tonic-gate (void) close(f); 129*7c478bd9Sstevel@tonic-gate return; 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate spend = execp; 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate for(ipc = ptrspace; ipc->r1.command; ) { 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate p1 = ipc->r1.ad1; 136*7c478bd9Sstevel@tonic-gate p2 = ipc->r1.ad2; 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate if(p1) { 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate if(ipc->r1.inar) { 141*7c478bd9Sstevel@tonic-gate if(*p2 == CEND) { 142*7c478bd9Sstevel@tonic-gate p1 = 0; 143*7c478bd9Sstevel@tonic-gate } else if(*p2 == CLNUM) { 144*7c478bd9Sstevel@tonic-gate c = (unsigned char)p2[1]; 145*7c478bd9Sstevel@tonic-gate if(lnum > tlno[c]) { 146*7c478bd9Sstevel@tonic-gate ipc->r1.inar = 0; 147*7c478bd9Sstevel@tonic-gate if(ipc->r1.negfl) 148*7c478bd9Sstevel@tonic-gate goto yes; 149*7c478bd9Sstevel@tonic-gate ipc++; 150*7c478bd9Sstevel@tonic-gate continue; 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate if(lnum == tlno[c]) { 153*7c478bd9Sstevel@tonic-gate ipc->r1.inar = 0; 154*7c478bd9Sstevel@tonic-gate } 155*7c478bd9Sstevel@tonic-gate } else if(match(p2, 0)) { 156*7c478bd9Sstevel@tonic-gate ipc->r1.inar = 0; 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate } else if(*p1 == CEND) { 159*7c478bd9Sstevel@tonic-gate if(!dolflag) { 160*7c478bd9Sstevel@tonic-gate if(ipc->r1.negfl) 161*7c478bd9Sstevel@tonic-gate goto yes; 162*7c478bd9Sstevel@tonic-gate ipc++; 163*7c478bd9Sstevel@tonic-gate continue; 164*7c478bd9Sstevel@tonic-gate } 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate } else if(*p1 == CLNUM) { 167*7c478bd9Sstevel@tonic-gate c = (unsigned char)p1[1]; 168*7c478bd9Sstevel@tonic-gate if(lnum != tlno[c]) { 169*7c478bd9Sstevel@tonic-gate if(ipc->r1.negfl) 170*7c478bd9Sstevel@tonic-gate goto yes; 171*7c478bd9Sstevel@tonic-gate ipc++; 172*7c478bd9Sstevel@tonic-gate continue; 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate if(p2) 175*7c478bd9Sstevel@tonic-gate ipc->r1.inar = 1; 176*7c478bd9Sstevel@tonic-gate } else if(match(p1, 0)) { 177*7c478bd9Sstevel@tonic-gate if(p2) 178*7c478bd9Sstevel@tonic-gate ipc->r1.inar = 1; 179*7c478bd9Sstevel@tonic-gate } else { 180*7c478bd9Sstevel@tonic-gate if(ipc->r1.negfl) 181*7c478bd9Sstevel@tonic-gate goto yes; 182*7c478bd9Sstevel@tonic-gate ipc++; 183*7c478bd9Sstevel@tonic-gate continue; 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate } 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate if(ipc->r1.negfl) { 188*7c478bd9Sstevel@tonic-gate ipc++; 189*7c478bd9Sstevel@tonic-gate continue; 190*7c478bd9Sstevel@tonic-gate } 191*7c478bd9Sstevel@tonic-gate yes: 192*7c478bd9Sstevel@tonic-gate command(ipc); 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate if(delflag) 195*7c478bd9Sstevel@tonic-gate break; 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate if(jflag) { 198*7c478bd9Sstevel@tonic-gate jflag = 0; 199*7c478bd9Sstevel@tonic-gate if((ipc = ipc->r2.lb1) == 0) { 200*7c478bd9Sstevel@tonic-gate ipc = ptrspace; 201*7c478bd9Sstevel@tonic-gate break; 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate } else 204*7c478bd9Sstevel@tonic-gate ipc++; 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate if(!nflag && !delflag) { 208*7c478bd9Sstevel@tonic-gate for(p1 = linebuf; p1 < spend; p1++) 209*7c478bd9Sstevel@tonic-gate (void) putc(*p1, stdout); 210*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 211*7c478bd9Sstevel@tonic-gate } 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate if(aptr > abuf) { 214*7c478bd9Sstevel@tonic-gate arout(); 215*7c478bd9Sstevel@tonic-gate } 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate delflag = 0; 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate } 220*7c478bd9Sstevel@tonic-gate } 221*7c478bd9Sstevel@tonic-gate match(expbuf, gf) 222*7c478bd9Sstevel@tonic-gate char *expbuf; 223*7c478bd9Sstevel@tonic-gate { 224*7c478bd9Sstevel@tonic-gate register char *p1; 225*7c478bd9Sstevel@tonic-gate 226*7c478bd9Sstevel@tonic-gate if(gf) { 227*7c478bd9Sstevel@tonic-gate if(*expbuf) return(0); 228*7c478bd9Sstevel@tonic-gate locs = p1 = loc2; 229*7c478bd9Sstevel@tonic-gate } else { 230*7c478bd9Sstevel@tonic-gate p1 = linebuf; 231*7c478bd9Sstevel@tonic-gate locs = 0; 232*7c478bd9Sstevel@tonic-gate } 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate circf = *expbuf++; 235*7c478bd9Sstevel@tonic-gate return(step(p1, expbuf)); 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate substitute(ipc) 239*7c478bd9Sstevel@tonic-gate union reptr *ipc; 240*7c478bd9Sstevel@tonic-gate { 241*7c478bd9Sstevel@tonic-gate if(match(ipc->r1.re1, 0) == 0) return(0); 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate numpass = 0; 244*7c478bd9Sstevel@tonic-gate sflag = 0; /* Flags if any substitution was made */ 245*7c478bd9Sstevel@tonic-gate dosub(ipc->r1.rhs, ipc->r1.gfl); 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate if(ipc->r1.gfl) { 248*7c478bd9Sstevel@tonic-gate while(*loc2) { 249*7c478bd9Sstevel@tonic-gate if(match(ipc->r1.re1, 1) == 0) break; 250*7c478bd9Sstevel@tonic-gate dosub(ipc->r1.rhs, ipc->r1.gfl); 251*7c478bd9Sstevel@tonic-gate } 252*7c478bd9Sstevel@tonic-gate } 253*7c478bd9Sstevel@tonic-gate return(sflag); 254*7c478bd9Sstevel@tonic-gate } 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate dosub(rhsbuf,n) 257*7c478bd9Sstevel@tonic-gate char *rhsbuf; 258*7c478bd9Sstevel@tonic-gate int n; 259*7c478bd9Sstevel@tonic-gate { 260*7c478bd9Sstevel@tonic-gate register char *lp, *sp, *rp; 261*7c478bd9Sstevel@tonic-gate int c; 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate if(n > 0 && n < 999) 264*7c478bd9Sstevel@tonic-gate {numpass++; 265*7c478bd9Sstevel@tonic-gate if(n != numpass) return; 266*7c478bd9Sstevel@tonic-gate } 267*7c478bd9Sstevel@tonic-gate sflag = 1; 268*7c478bd9Sstevel@tonic-gate lp = linebuf; 269*7c478bd9Sstevel@tonic-gate sp = genbuf; 270*7c478bd9Sstevel@tonic-gate rp = rhsbuf; 271*7c478bd9Sstevel@tonic-gate while (lp < loc1) 272*7c478bd9Sstevel@tonic-gate *sp++ = *lp++; 273*7c478bd9Sstevel@tonic-gate while(c = *rp++) { 274*7c478bd9Sstevel@tonic-gate if (c == '&') 275*7c478bd9Sstevel@tonic-gate sp = place(sp, loc1, loc2); 276*7c478bd9Sstevel@tonic-gate else if (c == '\\') { 277*7c478bd9Sstevel@tonic-gate c = *rp++; 278*7c478bd9Sstevel@tonic-gate if (c >= '1' && c < NBRA+'1') 279*7c478bd9Sstevel@tonic-gate sp = place(sp, braslist[c-'1'], braelist[c-'1']); 280*7c478bd9Sstevel@tonic-gate else 281*7c478bd9Sstevel@tonic-gate *sp++ = c; 282*7c478bd9Sstevel@tonic-gate } else 283*7c478bd9Sstevel@tonic-gate *sp++ = c; 284*7c478bd9Sstevel@tonic-gate if (sp == &genbuf[LBSIZE+1]) { 285*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "Output line too long.\n"); 286*7c478bd9Sstevel@tonic-gate *--sp = '\0'; 287*7c478bd9Sstevel@tonic-gate goto out; 288*7c478bd9Sstevel@tonic-gate } 289*7c478bd9Sstevel@tonic-gate } 290*7c478bd9Sstevel@tonic-gate lp = loc2; 291*7c478bd9Sstevel@tonic-gate loc2 = sp - genbuf + linebuf; 292*7c478bd9Sstevel@tonic-gate while(*sp++ = *lp++) 293*7c478bd9Sstevel@tonic-gate if (sp == &genbuf[LBSIZE+1]) { 294*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "Output line too long.\n"); 295*7c478bd9Sstevel@tonic-gate *--sp = '\0'; 296*7c478bd9Sstevel@tonic-gate break; 297*7c478bd9Sstevel@tonic-gate } 298*7c478bd9Sstevel@tonic-gate out: 299*7c478bd9Sstevel@tonic-gate lp = linebuf; 300*7c478bd9Sstevel@tonic-gate sp = genbuf; 301*7c478bd9Sstevel@tonic-gate while (*lp++ = *sp++); 302*7c478bd9Sstevel@tonic-gate spend = lp-1; 303*7c478bd9Sstevel@tonic-gate } 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate char *place(asp, al1, al2) 306*7c478bd9Sstevel@tonic-gate char *asp, *al1, *al2; 307*7c478bd9Sstevel@tonic-gate { 308*7c478bd9Sstevel@tonic-gate register char *sp, *l1, *l2; 309*7c478bd9Sstevel@tonic-gate 310*7c478bd9Sstevel@tonic-gate sp = asp; 311*7c478bd9Sstevel@tonic-gate l1 = al1; 312*7c478bd9Sstevel@tonic-gate l2 = al2; 313*7c478bd9Sstevel@tonic-gate while (l1 < l2) { 314*7c478bd9Sstevel@tonic-gate *sp++ = *l1++; 315*7c478bd9Sstevel@tonic-gate if (sp == &genbuf[LBSIZE+1]) 316*7c478bd9Sstevel@tonic-gate break; 317*7c478bd9Sstevel@tonic-gate } 318*7c478bd9Sstevel@tonic-gate return(sp); 319*7c478bd9Sstevel@tonic-gate } 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate command(ipc) 322*7c478bd9Sstevel@tonic-gate union reptr *ipc; 323*7c478bd9Sstevel@tonic-gate { 324*7c478bd9Sstevel@tonic-gate register int i; 325*7c478bd9Sstevel@tonic-gate register char *p1, *p2, *p3; 326*7c478bd9Sstevel@tonic-gate char *execp; 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate 329*7c478bd9Sstevel@tonic-gate switch(ipc->r1.command) { 330*7c478bd9Sstevel@tonic-gate 331*7c478bd9Sstevel@tonic-gate case ACOM: 332*7c478bd9Sstevel@tonic-gate if(aptr >= &abuf[ABUFSIZE]) { 333*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "Too many appends or reads after line %lld\n", 334*7c478bd9Sstevel@tonic-gate lnum); 335*7c478bd9Sstevel@tonic-gate } else { 336*7c478bd9Sstevel@tonic-gate *aptr++ = ipc; 337*7c478bd9Sstevel@tonic-gate *aptr = 0; 338*7c478bd9Sstevel@tonic-gate } 339*7c478bd9Sstevel@tonic-gate break; 340*7c478bd9Sstevel@tonic-gate 341*7c478bd9Sstevel@tonic-gate case CCOM: 342*7c478bd9Sstevel@tonic-gate delflag = 1; 343*7c478bd9Sstevel@tonic-gate if(!ipc->r1.inar || dolflag) { 344*7c478bd9Sstevel@tonic-gate for(p1 = ipc->r1.re1; *p1; ) 345*7c478bd9Sstevel@tonic-gate (void) putc(*p1++, stdout); 346*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 347*7c478bd9Sstevel@tonic-gate } 348*7c478bd9Sstevel@tonic-gate break; 349*7c478bd9Sstevel@tonic-gate case DCOM: 350*7c478bd9Sstevel@tonic-gate delflag++; 351*7c478bd9Sstevel@tonic-gate break; 352*7c478bd9Sstevel@tonic-gate case CDCOM: 353*7c478bd9Sstevel@tonic-gate p1 = p2 = linebuf; 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate while(*p1 != '\n') { 356*7c478bd9Sstevel@tonic-gate if(*p1++ == 0) { 357*7c478bd9Sstevel@tonic-gate delflag++; 358*7c478bd9Sstevel@tonic-gate return; 359*7c478bd9Sstevel@tonic-gate } 360*7c478bd9Sstevel@tonic-gate } 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate p1++; 363*7c478bd9Sstevel@tonic-gate while(*p2++ = *p1++); 364*7c478bd9Sstevel@tonic-gate spend = p2-1; 365*7c478bd9Sstevel@tonic-gate jflag++; 366*7c478bd9Sstevel@tonic-gate break; 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate case EQCOM: 369*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%lld\n", lnum); 370*7c478bd9Sstevel@tonic-gate break; 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate case GCOM: 373*7c478bd9Sstevel@tonic-gate p1 = linebuf; 374*7c478bd9Sstevel@tonic-gate p2 = holdsp; 375*7c478bd9Sstevel@tonic-gate while(*p1++ = *p2++); 376*7c478bd9Sstevel@tonic-gate spend = p1-1; 377*7c478bd9Sstevel@tonic-gate break; 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate case CGCOM: 380*7c478bd9Sstevel@tonic-gate *spend++ = '\n'; 381*7c478bd9Sstevel@tonic-gate p1 = spend; 382*7c478bd9Sstevel@tonic-gate p2 = holdsp; 383*7c478bd9Sstevel@tonic-gate do { 384*7c478bd9Sstevel@tonic-gate if (p1 == &linebuf[LBSIZE+1]) { 385*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "Output line too long.\n"); 386*7c478bd9Sstevel@tonic-gate *--p1 = '\0'; 387*7c478bd9Sstevel@tonic-gate } 388*7c478bd9Sstevel@tonic-gate } while(*p1++ = *p2++); 389*7c478bd9Sstevel@tonic-gate spend = p1-1; 390*7c478bd9Sstevel@tonic-gate break; 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate case HCOM: 393*7c478bd9Sstevel@tonic-gate p1 = holdsp; 394*7c478bd9Sstevel@tonic-gate p2 = linebuf; 395*7c478bd9Sstevel@tonic-gate while(*p1++ = *p2++); 396*7c478bd9Sstevel@tonic-gate hspend = p1-1; 397*7c478bd9Sstevel@tonic-gate break; 398*7c478bd9Sstevel@tonic-gate 399*7c478bd9Sstevel@tonic-gate case CHCOM: 400*7c478bd9Sstevel@tonic-gate *hspend++ = '\n'; 401*7c478bd9Sstevel@tonic-gate p1 = hspend; 402*7c478bd9Sstevel@tonic-gate p2 = linebuf; 403*7c478bd9Sstevel@tonic-gate do { 404*7c478bd9Sstevel@tonic-gate if (p1 == &holdsp[LBSIZE+1]) { 405*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "Hold space overflowed.\n"); 406*7c478bd9Sstevel@tonic-gate *--p1 = '\0'; 407*7c478bd9Sstevel@tonic-gate } 408*7c478bd9Sstevel@tonic-gate } while(*p1++ = *p2++); 409*7c478bd9Sstevel@tonic-gate hspend = p1-1; 410*7c478bd9Sstevel@tonic-gate break; 411*7c478bd9Sstevel@tonic-gate 412*7c478bd9Sstevel@tonic-gate case ICOM: 413*7c478bd9Sstevel@tonic-gate for(p1 = ipc->r1.re1; *p1; ) 414*7c478bd9Sstevel@tonic-gate (void) putc(*p1++, stdout); 415*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 416*7c478bd9Sstevel@tonic-gate break; 417*7c478bd9Sstevel@tonic-gate 418*7c478bd9Sstevel@tonic-gate case BCOM: 419*7c478bd9Sstevel@tonic-gate jflag = 1; 420*7c478bd9Sstevel@tonic-gate break; 421*7c478bd9Sstevel@tonic-gate 422*7c478bd9Sstevel@tonic-gate 423*7c478bd9Sstevel@tonic-gate case LCOM: 424*7c478bd9Sstevel@tonic-gate p1 = linebuf; 425*7c478bd9Sstevel@tonic-gate p2 = genbuf; 426*7c478bd9Sstevel@tonic-gate genbuf[72] = 0; 427*7c478bd9Sstevel@tonic-gate while(*p1) 428*7c478bd9Sstevel@tonic-gate if((unsigned char)*p1 >= 040) { 429*7c478bd9Sstevel@tonic-gate if(*p1 == 0177) { 430*7c478bd9Sstevel@tonic-gate p3 = rub; 431*7c478bd9Sstevel@tonic-gate while(*p2++ = *p3++) 432*7c478bd9Sstevel@tonic-gate if(p2 >= lcomend) { 433*7c478bd9Sstevel@tonic-gate *p2 = '\\'; 434*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", genbuf); 435*7c478bd9Sstevel@tonic-gate p2 = genbuf; 436*7c478bd9Sstevel@tonic-gate } 437*7c478bd9Sstevel@tonic-gate p2--; 438*7c478bd9Sstevel@tonic-gate p1++; 439*7c478bd9Sstevel@tonic-gate continue; 440*7c478bd9Sstevel@tonic-gate } 441*7c478bd9Sstevel@tonic-gate if(!isprint(*p1 & 0377)) { 442*7c478bd9Sstevel@tonic-gate *p2++ = '\\'; 443*7c478bd9Sstevel@tonic-gate if(p2 >= lcomend) { 444*7c478bd9Sstevel@tonic-gate *p2 = '\\'; 445*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", genbuf); 446*7c478bd9Sstevel@tonic-gate p2 = genbuf; 447*7c478bd9Sstevel@tonic-gate } 448*7c478bd9Sstevel@tonic-gate *p2++ = (*p1 >> 6) + '0'; 449*7c478bd9Sstevel@tonic-gate if(p2 >= lcomend) { 450*7c478bd9Sstevel@tonic-gate *p2 = '\\'; 451*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", genbuf); 452*7c478bd9Sstevel@tonic-gate p2 = genbuf; 453*7c478bd9Sstevel@tonic-gate } 454*7c478bd9Sstevel@tonic-gate *p2++ = ((*p1 >> 3) & 07) + '0'; 455*7c478bd9Sstevel@tonic-gate if(p2 >= lcomend) { 456*7c478bd9Sstevel@tonic-gate *p2 = '\\'; 457*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", genbuf); 458*7c478bd9Sstevel@tonic-gate p2 = genbuf; 459*7c478bd9Sstevel@tonic-gate } 460*7c478bd9Sstevel@tonic-gate *p2++ = (*p1++ & 07) + '0'; 461*7c478bd9Sstevel@tonic-gate if(p2 >= lcomend) { 462*7c478bd9Sstevel@tonic-gate *p2 = '\\'; 463*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", genbuf); 464*7c478bd9Sstevel@tonic-gate p2 = genbuf; 465*7c478bd9Sstevel@tonic-gate } 466*7c478bd9Sstevel@tonic-gate } else { 467*7c478bd9Sstevel@tonic-gate *p2++ = *p1++; 468*7c478bd9Sstevel@tonic-gate if(p2 >= lcomend) { 469*7c478bd9Sstevel@tonic-gate *p2 = '\\'; 470*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", genbuf); 471*7c478bd9Sstevel@tonic-gate p2 = genbuf; 472*7c478bd9Sstevel@tonic-gate } 473*7c478bd9Sstevel@tonic-gate } 474*7c478bd9Sstevel@tonic-gate } else { 475*7c478bd9Sstevel@tonic-gate p3 = trans[(unsigned char)*p1-1]; 476*7c478bd9Sstevel@tonic-gate while(*p2++ = *p3++) 477*7c478bd9Sstevel@tonic-gate if(p2 >= lcomend) { 478*7c478bd9Sstevel@tonic-gate *p2 = '\\'; 479*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", genbuf); 480*7c478bd9Sstevel@tonic-gate p2 = genbuf; 481*7c478bd9Sstevel@tonic-gate } 482*7c478bd9Sstevel@tonic-gate p2--; 483*7c478bd9Sstevel@tonic-gate p1++; 484*7c478bd9Sstevel@tonic-gate } 485*7c478bd9Sstevel@tonic-gate *p2 = 0; 486*7c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "%s\n", genbuf); 487*7c478bd9Sstevel@tonic-gate break; 488*7c478bd9Sstevel@tonic-gate 489*7c478bd9Sstevel@tonic-gate case NCOM: 490*7c478bd9Sstevel@tonic-gate if(!nflag) { 491*7c478bd9Sstevel@tonic-gate for(p1 = linebuf; p1 < spend; p1++) 492*7c478bd9Sstevel@tonic-gate (void) putc(*p1, stdout); 493*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 494*7c478bd9Sstevel@tonic-gate } 495*7c478bd9Sstevel@tonic-gate 496*7c478bd9Sstevel@tonic-gate if(aptr > abuf) 497*7c478bd9Sstevel@tonic-gate arout(); 498*7c478bd9Sstevel@tonic-gate if((execp = gline(linebuf)) == 0) { 499*7c478bd9Sstevel@tonic-gate pending = ipc; 500*7c478bd9Sstevel@tonic-gate delflag = 1; 501*7c478bd9Sstevel@tonic-gate break; 502*7c478bd9Sstevel@tonic-gate } 503*7c478bd9Sstevel@tonic-gate spend = execp; 504*7c478bd9Sstevel@tonic-gate 505*7c478bd9Sstevel@tonic-gate break; 506*7c478bd9Sstevel@tonic-gate case CNCOM: 507*7c478bd9Sstevel@tonic-gate if(aptr > abuf) 508*7c478bd9Sstevel@tonic-gate arout(); 509*7c478bd9Sstevel@tonic-gate *spend++ = '\n'; 510*7c478bd9Sstevel@tonic-gate if((execp = gline(spend)) == 0) { 511*7c478bd9Sstevel@tonic-gate pending = ipc; 512*7c478bd9Sstevel@tonic-gate delflag = 1; 513*7c478bd9Sstevel@tonic-gate break; 514*7c478bd9Sstevel@tonic-gate } 515*7c478bd9Sstevel@tonic-gate spend = execp; 516*7c478bd9Sstevel@tonic-gate break; 517*7c478bd9Sstevel@tonic-gate 518*7c478bd9Sstevel@tonic-gate case PCOM: 519*7c478bd9Sstevel@tonic-gate for(p1 = linebuf; p1 < spend; p1++) 520*7c478bd9Sstevel@tonic-gate (void) putc(*p1, stdout); 521*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 522*7c478bd9Sstevel@tonic-gate break; 523*7c478bd9Sstevel@tonic-gate case CPCOM: 524*7c478bd9Sstevel@tonic-gate cpcom: 525*7c478bd9Sstevel@tonic-gate for(p1 = linebuf; *p1 != '\n' && *p1 != '\0'; ) 526*7c478bd9Sstevel@tonic-gate (void) putc(*p1++, stdout); 527*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 528*7c478bd9Sstevel@tonic-gate break; 529*7c478bd9Sstevel@tonic-gate 530*7c478bd9Sstevel@tonic-gate case QCOM: 531*7c478bd9Sstevel@tonic-gate if(!nflag) { 532*7c478bd9Sstevel@tonic-gate for(p1 = linebuf; p1 < spend; p1++) 533*7c478bd9Sstevel@tonic-gate (void) putc(*p1, stdout); 534*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 535*7c478bd9Sstevel@tonic-gate } 536*7c478bd9Sstevel@tonic-gate if(aptr > abuf) arout(); 537*7c478bd9Sstevel@tonic-gate (void) fclose(stdout); 538*7c478bd9Sstevel@tonic-gate exit(0); 539*7c478bd9Sstevel@tonic-gate case RCOM: 540*7c478bd9Sstevel@tonic-gate if(aptr >= &abuf[ABUFSIZE]) { 541*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "Too many appends or reads after line %lld\n", 542*7c478bd9Sstevel@tonic-gate lnum); 543*7c478bd9Sstevel@tonic-gate } else { 544*7c478bd9Sstevel@tonic-gate *aptr++ = ipc; 545*7c478bd9Sstevel@tonic-gate *aptr = 0; 546*7c478bd9Sstevel@tonic-gate } 547*7c478bd9Sstevel@tonic-gate break; 548*7c478bd9Sstevel@tonic-gate 549*7c478bd9Sstevel@tonic-gate case SCOM: 550*7c478bd9Sstevel@tonic-gate i = substitute(ipc); 551*7c478bd9Sstevel@tonic-gate if(ipc->r1.pfl && nflag && i) 552*7c478bd9Sstevel@tonic-gate if(ipc->r1.pfl == 1) { 553*7c478bd9Sstevel@tonic-gate for(p1 = linebuf; p1 < spend; p1++) 554*7c478bd9Sstevel@tonic-gate (void) putc(*p1, stdout); 555*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 556*7c478bd9Sstevel@tonic-gate } 557*7c478bd9Sstevel@tonic-gate else 558*7c478bd9Sstevel@tonic-gate goto cpcom; 559*7c478bd9Sstevel@tonic-gate if(i && ipc->r1.fcode) 560*7c478bd9Sstevel@tonic-gate goto wcom; 561*7c478bd9Sstevel@tonic-gate break; 562*7c478bd9Sstevel@tonic-gate 563*7c478bd9Sstevel@tonic-gate case TCOM: 564*7c478bd9Sstevel@tonic-gate if(sflag == 0) break; 565*7c478bd9Sstevel@tonic-gate sflag = 0; 566*7c478bd9Sstevel@tonic-gate jflag = 1; 567*7c478bd9Sstevel@tonic-gate break; 568*7c478bd9Sstevel@tonic-gate 569*7c478bd9Sstevel@tonic-gate wcom: 570*7c478bd9Sstevel@tonic-gate case WCOM: 571*7c478bd9Sstevel@tonic-gate (void) fprintf(ipc->r1.fcode, "%s\n", linebuf); 572*7c478bd9Sstevel@tonic-gate (void) fflush(ipc->r1.fcode); 573*7c478bd9Sstevel@tonic-gate break; 574*7c478bd9Sstevel@tonic-gate case XCOM: 575*7c478bd9Sstevel@tonic-gate p1 = linebuf; 576*7c478bd9Sstevel@tonic-gate p2 = genbuf; 577*7c478bd9Sstevel@tonic-gate while(*p2++ = *p1++); 578*7c478bd9Sstevel@tonic-gate p1 = holdsp; 579*7c478bd9Sstevel@tonic-gate p2 = linebuf; 580*7c478bd9Sstevel@tonic-gate while(*p2++ = *p1++); 581*7c478bd9Sstevel@tonic-gate spend = p2 - 1; 582*7c478bd9Sstevel@tonic-gate p1 = genbuf; 583*7c478bd9Sstevel@tonic-gate p2 = holdsp; 584*7c478bd9Sstevel@tonic-gate while(*p2++ = *p1++); 585*7c478bd9Sstevel@tonic-gate hspend = p2 - 1; 586*7c478bd9Sstevel@tonic-gate break; 587*7c478bd9Sstevel@tonic-gate 588*7c478bd9Sstevel@tonic-gate case YCOM: 589*7c478bd9Sstevel@tonic-gate p1 = linebuf; 590*7c478bd9Sstevel@tonic-gate p2 = ipc->r1.re1; 591*7c478bd9Sstevel@tonic-gate while(*p1 = p2[(unsigned char)*p1]) p1++; 592*7c478bd9Sstevel@tonic-gate break; 593*7c478bd9Sstevel@tonic-gate } 594*7c478bd9Sstevel@tonic-gate 595*7c478bd9Sstevel@tonic-gate } 596*7c478bd9Sstevel@tonic-gate 597*7c478bd9Sstevel@tonic-gate char *gline(addr) 598*7c478bd9Sstevel@tonic-gate char *addr; 599*7c478bd9Sstevel@tonic-gate { 600*7c478bd9Sstevel@tonic-gate register char *p1, *p2; 601*7c478bd9Sstevel@tonic-gate register c; 602*7c478bd9Sstevel@tonic-gate sflag = 0; 603*7c478bd9Sstevel@tonic-gate p1 = addr; 604*7c478bd9Sstevel@tonic-gate p2 = cbp; 605*7c478bd9Sstevel@tonic-gate for (;;) { 606*7c478bd9Sstevel@tonic-gate if (p2 >= ebp) { 607*7c478bd9Sstevel@tonic-gate if(f < 0 || (c = read(f, ibuf, BUFSIZ)) == 0) { 608*7c478bd9Sstevel@tonic-gate return(0); 609*7c478bd9Sstevel@tonic-gate } 610*7c478bd9Sstevel@tonic-gate if(c < 0) { 611*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "sed: error reading "); 612*7c478bd9Sstevel@tonic-gate perror(ifname); 613*7c478bd9Sstevel@tonic-gate exit(2); 614*7c478bd9Sstevel@tonic-gate } 615*7c478bd9Sstevel@tonic-gate p2 = ibuf; 616*7c478bd9Sstevel@tonic-gate ebp = ibuf+c; 617*7c478bd9Sstevel@tonic-gate } 618*7c478bd9Sstevel@tonic-gate if ((c = *p2++) == '\n') { 619*7c478bd9Sstevel@tonic-gate if(p2 >= ebp) { 620*7c478bd9Sstevel@tonic-gate if(f < 0 || (c = read(f, ibuf, BUFSIZ)) == 0) { 621*7c478bd9Sstevel@tonic-gate if(f >= 0) { 622*7c478bd9Sstevel@tonic-gate (void) close(f); 623*7c478bd9Sstevel@tonic-gate f = -1; 624*7c478bd9Sstevel@tonic-gate } 625*7c478bd9Sstevel@tonic-gate if(eargc == 0) 626*7c478bd9Sstevel@tonic-gate dolflag = 1; 627*7c478bd9Sstevel@tonic-gate } 628*7c478bd9Sstevel@tonic-gate if(c < 0) { 629*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "sed: error reading "); 630*7c478bd9Sstevel@tonic-gate perror(ifname); 631*7c478bd9Sstevel@tonic-gate exit(2); 632*7c478bd9Sstevel@tonic-gate } 633*7c478bd9Sstevel@tonic-gate 634*7c478bd9Sstevel@tonic-gate p2 = ibuf; 635*7c478bd9Sstevel@tonic-gate ebp = ibuf + c; 636*7c478bd9Sstevel@tonic-gate } 637*7c478bd9Sstevel@tonic-gate break; 638*7c478bd9Sstevel@tonic-gate } 639*7c478bd9Sstevel@tonic-gate if(c) 640*7c478bd9Sstevel@tonic-gate if(p1 < &linebuf[LBSIZE]) 641*7c478bd9Sstevel@tonic-gate *p1++ = c; 642*7c478bd9Sstevel@tonic-gate } 643*7c478bd9Sstevel@tonic-gate lnum++; 644*7c478bd9Sstevel@tonic-gate *p1 = 0; 645*7c478bd9Sstevel@tonic-gate cbp = p2; 646*7c478bd9Sstevel@tonic-gate 647*7c478bd9Sstevel@tonic-gate return(p1); 648*7c478bd9Sstevel@tonic-gate } 649*7c478bd9Sstevel@tonic-gate 650*7c478bd9Sstevel@tonic-gate char *comple(x1, ep, x3, x4) 651*7c478bd9Sstevel@tonic-gate char *x1, *x3; 652*7c478bd9Sstevel@tonic-gate char x4; 653*7c478bd9Sstevel@tonic-gate register char *ep; 654*7c478bd9Sstevel@tonic-gate { 655*7c478bd9Sstevel@tonic-gate register char *p; 656*7c478bd9Sstevel@tonic-gate 657*7c478bd9Sstevel@tonic-gate p = compile(x1, ep + 1, x3, x4); 658*7c478bd9Sstevel@tonic-gate if(p == ep + 1) 659*7c478bd9Sstevel@tonic-gate return(ep); 660*7c478bd9Sstevel@tonic-gate *ep = circf; 661*7c478bd9Sstevel@tonic-gate return(p); 662*7c478bd9Sstevel@tonic-gate } 663*7c478bd9Sstevel@tonic-gate 664*7c478bd9Sstevel@tonic-gate regerr(err) 665*7c478bd9Sstevel@tonic-gate register err; 666*7c478bd9Sstevel@tonic-gate { 667*7c478bd9Sstevel@tonic-gate switch(err) { 668*7c478bd9Sstevel@tonic-gate 669*7c478bd9Sstevel@tonic-gate case 11: 670*7c478bd9Sstevel@tonic-gate comperr("Range endpoint too large: %s"); 671*7c478bd9Sstevel@tonic-gate break; 672*7c478bd9Sstevel@tonic-gate 673*7c478bd9Sstevel@tonic-gate case 16: 674*7c478bd9Sstevel@tonic-gate comperr("Bad number: %s"); 675*7c478bd9Sstevel@tonic-gate break; 676*7c478bd9Sstevel@tonic-gate 677*7c478bd9Sstevel@tonic-gate case 25: 678*7c478bd9Sstevel@tonic-gate comperr("``\\digit'' out of range: %s"); 679*7c478bd9Sstevel@tonic-gate break; 680*7c478bd9Sstevel@tonic-gate 681*7c478bd9Sstevel@tonic-gate case 36: 682*7c478bd9Sstevel@tonic-gate comperr("Illegal or missing delimiter: %s"); 683*7c478bd9Sstevel@tonic-gate break; 684*7c478bd9Sstevel@tonic-gate 685*7c478bd9Sstevel@tonic-gate case 41: 686*7c478bd9Sstevel@tonic-gate comperr("No remembered search string: %s"); 687*7c478bd9Sstevel@tonic-gate break; 688*7c478bd9Sstevel@tonic-gate 689*7c478bd9Sstevel@tonic-gate case 42: 690*7c478bd9Sstevel@tonic-gate comperr("\\( \\) imbalance: %s"); 691*7c478bd9Sstevel@tonic-gate break; 692*7c478bd9Sstevel@tonic-gate 693*7c478bd9Sstevel@tonic-gate case 43: 694*7c478bd9Sstevel@tonic-gate comperr("Too many \\(: %s"); 695*7c478bd9Sstevel@tonic-gate break; 696*7c478bd9Sstevel@tonic-gate 697*7c478bd9Sstevel@tonic-gate case 44: 698*7c478bd9Sstevel@tonic-gate comperr("More than 2 numbers given in \\{ \\}: %s"); 699*7c478bd9Sstevel@tonic-gate break; 700*7c478bd9Sstevel@tonic-gate 701*7c478bd9Sstevel@tonic-gate case 45: 702*7c478bd9Sstevel@tonic-gate comperr("} expected after \\: %s"); 703*7c478bd9Sstevel@tonic-gate break; 704*7c478bd9Sstevel@tonic-gate 705*7c478bd9Sstevel@tonic-gate case 46: 706*7c478bd9Sstevel@tonic-gate comperr("First number exceeds second in \\{ \\}: %s"); 707*7c478bd9Sstevel@tonic-gate break; 708*7c478bd9Sstevel@tonic-gate 709*7c478bd9Sstevel@tonic-gate case 49: 710*7c478bd9Sstevel@tonic-gate comperr("[ ] imbalance: %s"); 711*7c478bd9Sstevel@tonic-gate break; 712*7c478bd9Sstevel@tonic-gate 713*7c478bd9Sstevel@tonic-gate case 50: 714*7c478bd9Sstevel@tonic-gate comperr(TMMES); 715*7c478bd9Sstevel@tonic-gate break; 716*7c478bd9Sstevel@tonic-gate 717*7c478bd9Sstevel@tonic-gate default: 718*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "Unknown regexp error code %d: %s\n", 719*7c478bd9Sstevel@tonic-gate err, linebuf); 720*7c478bd9Sstevel@tonic-gate exit(2); 721*7c478bd9Sstevel@tonic-gate break; 722*7c478bd9Sstevel@tonic-gate } 723*7c478bd9Sstevel@tonic-gate } 724*7c478bd9Sstevel@tonic-gate 725*7c478bd9Sstevel@tonic-gate arout() 726*7c478bd9Sstevel@tonic-gate { 727*7c478bd9Sstevel@tonic-gate register char *p1; 728*7c478bd9Sstevel@tonic-gate FILE *fi; 729*7c478bd9Sstevel@tonic-gate char c; 730*7c478bd9Sstevel@tonic-gate int t; 731*7c478bd9Sstevel@tonic-gate 732*7c478bd9Sstevel@tonic-gate aptr = abuf - 1; 733*7c478bd9Sstevel@tonic-gate while(*++aptr) { 734*7c478bd9Sstevel@tonic-gate if((*aptr)->r1.command == ACOM) { 735*7c478bd9Sstevel@tonic-gate for(p1 = (*aptr)->r1.re1; *p1; ) 736*7c478bd9Sstevel@tonic-gate (void) putc(*p1++, stdout); 737*7c478bd9Sstevel@tonic-gate (void) putc('\n', stdout); 738*7c478bd9Sstevel@tonic-gate } else { 739*7c478bd9Sstevel@tonic-gate if((fi = fopen((*aptr)->r1.re1, "r")) == NULL) 740*7c478bd9Sstevel@tonic-gate continue; 741*7c478bd9Sstevel@tonic-gate while((t = getc(fi)) != EOF) { 742*7c478bd9Sstevel@tonic-gate c = t; 743*7c478bd9Sstevel@tonic-gate (void) putc(c, stdout); 744*7c478bd9Sstevel@tonic-gate } 745*7c478bd9Sstevel@tonic-gate (void) fclose(fi); 746*7c478bd9Sstevel@tonic-gate } 747*7c478bd9Sstevel@tonic-gate } 748*7c478bd9Sstevel@tonic-gate aptr = abuf; 749*7c478bd9Sstevel@tonic-gate *aptr = 0; 750*7c478bd9Sstevel@tonic-gate } 751*7c478bd9Sstevel@tonic-gate 752