/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include "sed.h"
char *lastre;
char sseof;
int eflag;
extern int nbra;
int gflag;
int nlno;
int nfiles;
char *cp;
int depth;
int eargc;
char **eargv;
extern int sed; /* IMPORTANT flag !!! */
extern char *comple();
extern char *malloc();
static void dechain(void);
static void fcomp(void);
int
{
int flag_found = 0;
sed = 1;
lnum = 0;
pending = 0;
depth = 0;
fname[0] = "";
nfiles = 1;
if(eargc == 1)
exit(0);
switch (eargv[0][1]) {
case 'n':
nflag++;
continue;
case 'f':
flag_found = 1;
exit(2);
}
fcomp();
continue;
case 'e':
flag_found = 1;
eflag++;
fcomp();
eflag = 0;
continue;
case 'g':
gflag++;
continue;
default:
exit(2);
}
eargv--;
eargc++;
eflag++;
fcomp();
eargv++;
eargc--;
eflag = 0;
}
if(depth)
comperr("Too many {'s");
dechain();
if(eargc <= 0)
else while(--eargc >= 0) {
}
return (0);
}
static void
fcomp(void)
{
char *address();
int i, ii;
if(*linebuf == '#') {
nflag = 1;
}
else {
goto comploop;
}
for(;;) {
/* (void) fprintf(stderr, "cp: %s\n", cp); DEBUG */
if(*cp == ';') {
cp++;
goto comploop;
}
if(op)
else
comperr("First RE may not be null: %s");
} else if(p == 0) {
} else {
cp++;
if(p == 0)
comperr("Illegal line number: %s");
else
} else
}
swit:
switch(*cp++) {
default:
comperr("Unrecognized command: %s");
case '!':
goto swit;
case '{':
comperr("Too many commands: %s");
if(*cp == '\0') continue;
goto comploop;
case '}':
if(--depth < 0)
comperr("Too many }'s");
continue;
case '=':
break;
case ':':
while(*cp++ == ' ');
cp--;
*--tp = '\0';
comperr("Duplicate labels: %s");
} else {
comperr("Too many labels: %s");
}
continue;
case 'a':
if(*cp++ != '\n')
break;
case 'c':
if(*cp++ != ('\n'))
break;
case 'i':
if(*cp++ != ('\n'))
break;
case 'g':
break;
case 'G':
break;
case 'h':
break;
case 'H':
break;
case 't':
goto jtcommon;
case 'b':
while(*cp++ == ' ');
cp--;
if(*cp == '\0') {
} else
break;
}
cp--;
*--tp = '\0';
} else {
}
} else {
comperr("Too many labels: %s");
}
break;
case 'n':
break;
case 'N':
break;
case 'p':
break;
case 'P':
break;
case 'r':
if(*cp++ != ' ')
break;
case 'd':
break;
case 'D':
break;
case 'q':
break;
case 'l':
break;
case 's':
if(op)
else
comperr("First RE may not be null: %s");
} else
if(*cp == 'g') {
cp++;
} else if(gflag)
{i = *cp - '0';
cp++;
while(1)
if(i > 512)
cp++;
}
}
if(*cp == 'p') {
cp++;
}
if(*cp == 'P') {
cp++;
}
if(*cp == 'w') {
cp++;
if(*cp++ != ' ')
comperr("File name too long: %s");
for(i = nfiles - 1; i >= 0; i--)
goto done;
}
comperr("Too many files in w commands: %s");
exit(2);
}
exit(2);
}
}
break;
case 'w':
if(*cp++ != ' ')
comperr("File name too long: %s");
for(i = nfiles - 1; i >= 0; i--)
goto done;
}
comperr("Too many files in w commands: %s");
exit(2);
}
exit(2);
}
break;
case 'x':
break;
case 'y':
break;
}
done:
comperr("Too many commands, last: %s");
if(*cp++ != '\0') {
goto comploop;
}
}
}
char *rhsbuf;
{
char *p, *q;
p = rhsbuf;
q = cp;
for(;;) {
if((*p = *q++) == '\\') {
p++;
*p = *q++;
comperr("``\\digit'' out of range: %s");
p++;
continue;
}
if(*p == sseof) {
*p++ = '\0';
cp = q;
return(p);
}
if(*p++ == '\0')
comperr("Ending delimiter missing on substitution: %s");
}
}
int
char *lbuf;
char *lbend;
{
char *p, *q;
int t;
static char *saveq;
p = lbuf;
if(eflag) {
if(eflag > 0) {
eflag = -1;
if(--eargc <= 0)
exit(2);
q = *++eargv;
while((t = *q++) != '\0') {
if(t == '\n') {
saveq = q;
goto out1;
}
if (p < lbend)
*p++ = t;
if(t == '\\') {
if((t = *q++) == '\0') {
saveq = 0;
return(-1);
}
if (p < lbend)
*p++ = t;
}
}
saveq = 0;
out1:
if (p == lbend)
comperr("Command line too long");
*p = '\0';
return(1);
}
if((q = saveq) == 0) return(-1);
while((t = *q++) != '\0') {
if(t == '\n') {
saveq = q;
goto out2;
}
if(p < lbend)
*p++ = t;
if(t == '\\') {
if((t = *q++) == '\0') {
saveq = 0;
return(-1);
}
if (p < lbend)
*p++ = t;
}
}
saveq = 0;
out2:
if (p == lbend)
comperr("Command line too long");
*p = '\0';
return(1);
}
if(t == '\n') {
if (p == lbend)
comperr("Command line too long");
*p = '\0';
return(1);
}
if (p < lbend)
*p++ = t;
if(t == '\\') {
break;
if(p < lbend)
*p++ = t;
}
}
perror("sed: Error reading pattern file");
exit(2);
}
return(-1);
}
char *expbuf;
{
char *rcp;
long long lno;
if(*cp == '$') {
cp++;
return(expbuf);
}
if ( *cp == '\\' )
cp++;
}
lno = 0;
comperr("Too many line numbers: %s");
return(expbuf);
}
return(0);
}
char *textbuf;
char *tbend;
{
char *p, *q;
p = textbuf;
q = cp;
#ifndef S5EMUL
/*
* Strip off indentation from text to be inserted.
*/
while(*q == '\t' || *q == ' ') q++;
#endif
for(;;) {
if(p > tbend)
return(NULL); /* overflowed the buffer */
if((*p = *q++) == '\\')
*p = *q++;
if(*p == '\0') {
cp = --q;
return(++p);
}
#ifndef S5EMUL
/*
* Strip off indentation from text to be inserted.
*/
if(*p == '\n') {
while(*q == '\t' || *q == ' ') q++;
}
#endif
p++;
}
}
{
return(rp);
rp++;
}
return(0);
}
static void
dechain(void)
{
exit(2);
}
}
}
}
}
char *expbuf;
{
char c;
int i;
char *sp;
if(c == '\\')
tsp++;
if(c == '\0' || c == '\n')
comperr("Ending delimiter missing on string: %s");
}
tsp++;
c &= 0377;
sp++;
c = '\n';
}
ep[c] = '\n';
tsp++;
}
comperr("Transform strings not the same size: %s");
}
if(*tsp == '\0')
comperr("Ending delimiter missing on string: %s");
else
comperr("Transform strings not the same size: %s");
}
for(i = 0; i < 0400; i++)
if(ep[i] == 0)
ep[i] = i;
return(ep + 0400);
}
void
{
exit(2);
}