sed1.c revision bdcaf82257ab2deb6b46efaaa4bc93a1a44b3885
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <fcntl.h>
#include "sed.h"
#include <regexp.h>
char *cbp;
char *ebp;
char *lcomend;
int dolflag;
int sflag;
int jflag;
int delflag;
long long lnum;
char *spend;
char *hspend;
int nflag;
int f;
char *ifname;
int numpass;
char *trans[040] = {
"\\01",
"\\02",
"\\03",
"\\04",
"\\05",
"\\06",
"\\07",
"-<",
"->",
"\n",
"\\13",
"\\14",
"\\15",
"\\16",
"\\17",
"\\20",
"\\21",
"\\22",
"\\23",
"\\24",
"\\25",
"\\26",
"\\27",
"\\30",
"\\31",
"\\32",
"\\33",
"\\34",
"\\35",
"\\36",
"\\37"
};
char rub[] = {"\\177"};
extern char TMMES[];
static void arout(void);
void
{
int c;
char *execp;
if (file) {
}
} else {
f = 0;
ifname = "standard input";
}
if(pending) {
pending = 0;
goto yes;
}
for(;;) {
(void) close(f);
return;
}
if(p1) {
p1 = 0;
c = (unsigned char)p2[1];
goto yes;
ipc++;
continue;
}
}
}
if(!dolflag) {
goto yes;
ipc++;
continue;
}
c = (unsigned char)p1[1];
goto yes;
ipc++;
continue;
}
if(p2)
if(p2)
} else {
goto yes;
ipc++;
continue;
}
}
ipc++;
continue;
}
yes:
if(delflag)
break;
if(jflag) {
jflag = 0;
break;
}
} else
ipc++;
}
}
arout();
}
delflag = 0;
}
}
static int
{
char *p1;
if(gf) {
if(*expbuf) return(0);
} else {
locs = 0;
}
}
static int
{
numpass = 0;
sflag = 0; /* Flags if any substitution was made */
while(*loc2) {
}
}
return(sflag);
}
static void
{
int c;
if(n > 0 && n < 999)
{numpass++;
if(n != numpass) return;
}
sflag = 1;
while(c = *rp++) {
if (c == '&')
else if (c == '\\') {
c = *rp++;
else
*sp++ = c;
} else
*sp++ = c;
*--sp = '\0';
goto out;
}
}
*--sp = '\0';
break;
}
out:
}
{
break;
}
return(sp);
}
static void
{
int i;
char *execp;
case ACOM:
lnum);
} else {
*aptr = 0;
}
break;
case CCOM:
delflag = 1;
}
break;
case DCOM:
delflag++;
break;
case CDCOM:
while(*p1 != '\n') {
if(*p1++ == 0) {
delflag++;
return;
}
}
p1++;
jflag++;
break;
case EQCOM:
break;
case GCOM:
break;
case CGCOM:
*spend++ = '\n';
do {
*--p1 = '\0';
}
break;
case HCOM:
break;
case CHCOM:
*hspend++ = '\n';
do {
*--p1 = '\0';
}
break;
case ICOM:
break;
case BCOM:
jflag = 1;
break;
case LCOM:
genbuf[72] = 0;
while(*p1)
if((unsigned char)*p1 >= 040) {
if(*p1 == 0177) {
*p2 = '\\';
}
p2--;
p1++;
continue;
}
*p2++ = '\\';
*p2 = '\\';
}
*p2 = '\\';
}
*p2 = '\\';
}
*p2 = '\\';
}
} else {
*p2 = '\\';
}
}
} else {
*p2 = '\\';
}
p2--;
p1++;
}
*p2 = 0;
break;
case NCOM:
if(!nflag) {
}
arout();
delflag = 1;
break;
}
break;
case CNCOM:
arout();
*spend++ = '\n';
delflag = 1;
break;
}
break;
case PCOM:
break;
case CPCOM:
break;
case QCOM:
if(!nflag) {
}
exit(0);
case RCOM:
lnum);
} else {
*aptr = 0;
}
break;
case SCOM:
i = substitute(ipc);
}
else
goto cpcom;
goto wcom;
break;
case TCOM:
if(sflag == 0) break;
sflag = 0;
jflag = 1;
break;
wcom:
case WCOM:
break;
case XCOM:
break;
case YCOM:
break;
}
}
char *addr;
{
int c;
sflag = 0;
for (;;) {
return(0);
}
if(c < 0) {
exit(2);
}
}
if ((c = *p2++) == '\n') {
if(f >= 0) {
(void) close(f);
f = -1;
}
if(eargc == 0)
dolflag = 1;
}
if(c < 0) {
exit(2);
}
}
break;
}
if(c)
*p1++ = c;
}
lnum++;
*p1 = 0;
return(p1);
}
char x4;
char *ep;
{
char *p;
if(p == ep + 1)
return(ep);
return(p);
}
int
{
switch(err) {
case 11:
comperr("Range endpoint too large: %s");
break;
case 16:
comperr("Bad number: %s");
break;
case 25:
comperr("``\\digit'' out of range: %s");
break;
case 36:
comperr("Illegal or missing delimiter: %s");
break;
case 41:
comperr("No remembered search string: %s");
break;
case 42:
comperr("\\( \\) imbalance: %s");
break;
case 43:
comperr("Too many \\(: %s");
break;
case 44:
comperr("More than 2 numbers given in \\{ \\}: %s");
break;
case 45:
comperr("} expected after \\: %s");
break;
case 46:
comperr("First number exceeds second in \\{ \\}: %s");
break;
case 49:
comperr("[ ] imbalance: %s");
break;
case 50:
break;
default:
exit(2);
break;
}
return (0);
}
static void
arout(void)
{
char *p1;
char c;
int t;
while(*++aptr) {
} else {
continue;
c = t;
}
}
}
*aptr = 0;
}