sed2.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1995-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
#include "sed.h"
#include <ctype.h>
#define IBUG "interpreter bug %d"
char *stdouterr = "writing standard output";
void
cputchar(int c)
{
}
void
{
cputchar('\n');
}
/* return 1 if action is to be taken on current line,
-1 if (numeric) address has been passed,
0 otherwise*/
int
{
return 1;
return ateof();
return -1;
return 0;
}
/* return 2 on non-final line of a selected range,
1 on any other selected line,
0 on non-selected lines
(the 1-2 distinction matters only for 'c' commands) */
int
{
int active;
switch(q - ipc) {
case 0: /* 0 address */
return !neg;
case 1: /* 1 address */
case 2:
case 3: /* 2 address */
q--; /* points to activity indicator */
case 0:
break;
case 1:
*q = recno;
if(active)
*q |= INACT;
case -1:
if(active) {
return neg;
}
}
}
default:
return 0; /* dummy */
}
}
void
{
assure(t, 1);
t->w = t->s;
*t->w = 0;
}
void
{
to->w += n;
*to->w = 0;
}
/* EASY COMMANDS */
unsigned char *
{
return 0; /* dummy */
}
unsigned char *
{
}
unsigned char *
{
return 0;
}
unsigned char *
{
word n;
if(end == 0)
end++;
return script->s;
}
unsigned char *
{
}
unsigned char *
{
if(hold.s == 0)
*data->w++ = '\n';
}
unsigned char *
{
if(hold.s == 0)
*data->w++ = '\n';
}
unsigned char *
{
*hold.w++ = '\n';
}
unsigned char *
{
}
unsigned char *
{
}
unsigned char *
{
}
unsigned char *
{
}
unsigned char *
{
*data->w++ = '\n';
*--data->w = 0;
}
unsigned char *
{
if(!nflag)
return 0;
}
unsigned char *
{
word n;
if(end == 0)
else
cputchar('\n');
}
unsigned char *
{
}
unsigned char *
{
qflag++;
return script->w;
}
unsigned char *
{
sflag = 0;
if(tflag)
else
}
unsigned char *
{
*data->w = '\n';
*data->w = 0;
}
unsigned char *
{
}
unsigned char *
{
unsigned char *t;
if(hold.s == 0)
}
unsigned char *
{
unsigned char *s = (unsigned char*)data->s;
unsigned char *w = (unsigned char*)data->w;
unsigned char *b;
unsigned int c, x;
int i, n;
Sfio_t *f;
if(x = (unsigned int)(*m++ - (unsigned char*)0)) {
if(!(f = sfstropen()))
while(s<w) {
b = s;
c = mbchar(s);
if(c < x && m[c]) {
n = m[c][0];
i = 0;
while(++i<=n)
sfputc(f, m[c][i]);
}
else
while(b<s)
sfputc(f, *b++);
}
x = (unsigned int)sfstrtell(f);
}
else
for(b = (unsigned char*)m; s<w; s++)
*s = b[*s];
}
/* MISCELLANY */
unsigned char *
{
if(!sflag)
if(flags & REG_SUB_PRINT)
if(flags & REG_SUB_WRITE)
}
struct { char p, q; } digram[] = {
'\\', '\\',
'\a', 'a',
'\b', 'b',
'\f', 'f',
'\n', 'n',
'\r', 'r',
'\t', 't',
'\v', 'v',
};
#define LEMAX 72
#define CHMAX 4
unsigned char *
{
word n;
int j;
unsigned char *s;
unsigned char *b;
unsigned char *o;
unsigned char *e;
b = buf;
o = b;
if(*s == digram[j].p) {
*b++ = '\\';
*b++ = digram[j].q;
goto hit;
}
if(!isprint(*s))
else
*b++ = *s;
hit:
n = o - buf;
cputchar('\\');
cputchar('\n');
e = b;
b = buf;
while(o < e)
*b++ = *o++;
}
}
*b++ = '$';
*b++ = '\n';
n = b - buf;
}
/* END-OF-CYCLE STUFF */
unsigned char *
{
todo.w += sizeof(unsigned char*);
}
unsigned char *
{
}
void
coda(void)
{
word *q;
unsigned char *p;
Sfio_t *f;
if(todo.s == 0)
return;
q = instr(*(unsigned char**)p);
switch(code(*q)) {
case 'a':
continue;
case 'r':
if(f == 0)
continue;
sfclose(f);
continue;
default:
}
}
}
/* execution functions return pointer to next instruction */
};
void
{
unsigned char *pc;
int sel;
if(sel) {
cmd = 'd';
if(pc == 0)
return;
} else
}
if(!nflag)
}