/*
* Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 1992 Diomidis Spinellis.
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Diomidis Spinellis of Imperial College, University of London.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wchar.h>
#include <wctype.h>
#include <termio.h>
#include <libintl.h>
#include <note.h>
#include "defs.h"
#include "extern.h"
static void flush_appends(void);
static int substitute(struct s_command *);
/* Iov structure for 'w' commands. */
#define OUT() do { \
} while (0)
void
process(void)
{
char *p;
p = NULL;
pd = 0;
top:
continue;
}
case '{':
goto redirect;
case 'a':
sizeof (struct s_appends) *
appendx++;
break;
case 'b':
goto redirect;
case 'c':
pd = 1;
psl = 0;
break;
case 'd':
pd = 1;
goto new;
case 'D':
if (pd)
goto new;
if (psl == 0 ||
pd = 1;
goto new;
} else {
psl -=
goto top;
}
case 'g':
break;
case 'G':
break;
case 'h':
break;
case 'H':
break;
case 'i':
break;
case 'l':
break;
case 'n':
OUT();
exit(0);
pd = 0;
break;
case 'N':
exit(0);
break;
case 'p':
if (pd)
break;
OUT();
break;
case 'P':
if (pd)
break;
}
OUT();
if (p != NULL)
break;
case 'q':
OUT();
exit(0);
/*NOTREACHED*/
case 'r':
sizeof (struct s_appends) *
appendx++;
break;
case 's':
break;
case 't':
if (sdone) {
sdone = 0;
goto redirect;
}
break;
case 'w':
if (pd)
break;
== -1)
break;
case 'x':
/*
* If the hold space is null, make it empty
* but not null. Otherwise the pattern space
* will become null after the swap, which is
* an abnormal condition.
*/
break;
case 'y':
break;
break;
case ':':
case '}':
break;
case '=':
}
} /* for all cp */
OUT();
} /* for all lines */
}
/*
* TRUE if the address passed matches the current program state
* (lastline, linenumber, ps).
*/
#define MATCH(a) \
/*
* Return TRUE if the command applies to the current line. Sets the start
* line for process ranges. Interprets the non-select (``!'') flag.
*/
static int
{
int r;
lastaddr = 0;
r = 1;
lastaddr = 1;
r = 1;
r = 1;
/*
* We missed the 2nd address due to a branch,
* so just close the range and return false.
*/
r = 0;
} else
r = 1;
/*
* If the second address is a number less than or
* equal to the line number first selected, only
* one line shall be selected.
* -- POSIX 1003.2
* Likewise if the relative second line address is zero.
*/
lastaddr = 1;
else {
}
r = 1;
} else
r = 0;
else
}
/*
* Reset the sed processor to its initial state.
*/
void
resetstate(void)
{
/*
* Reset all in-range markers.
*/
/*
* Clear out the hold space.
*/
}
/*
* substitute --
* Do substitutions in the pattern space. Currently, we build a
* copy of the new pattern space in the substitute space structure
* and then swap them.
*/
static int
{
int lastempty, n;
char *s;
s = ps;
fatal(_("\\%u not defined in the RE"),
}
}
return (0);
n = cp->u.s->n;
lastempty = 1;
switch (n) {
case 0: /* Global */
do {
/* Locate start of replaced string. */
/* Copy leading retained string. */
/* Add in regular expression. */
}
/* Move past this match. */
lastempty = 0;
} else {
APPEND);
lastempty = 1;
}
/* Copy trailing retained string. */
if (slen > 0)
break;
default: /* Nth occurrence */
while (--n) {
if (slen < 0)
return (0);
return (0);
}
/* FALLTHROUGH */
case 1: /* 1st occurrence */
/* Locate start of replaced string. */
/* Copy leading retained string. */
/* Add in regular expression. */
/* Copy trailing retained string. */
break;
}
/*
* Swap the substitute space and the pattern space, and make sure
* that any leftover pointers into stdio memory get lost.
*/
/* Handle the 'p' flag. */
if (cp->u.s->p)
OUT();
/* Handle the 'w' flag. */
}
return (1);
}
/*
* do_tr --
* Perform translation ('y' command) in the pattern space.
*/
static void
{
char c, *p;
int i;
if (MB_CUR_MAX == 1) {
/*
* Single-byte encoding: perform in-place translation
* of the pattern space.
*/
} else {
/*
* Multi-byte encoding: perform translation into the
* translation space, then swap the translation and
* pattern spaces.
*/
/* Clean translation space. */
clen = 1;
continue;
}
for (i = 0; i < y->nmultis; i++)
break;
if (i < y->nmultis) {
} else {
clen = 1;
}
}
/* Swap the translation space and the pattern space. */
}
}
/*
* Flush append requests. Always called before reading a line,
* therefore it also resets the substitution done (sdone) flag.
*/
static void
flush_appends(void)
{
FILE *f;
int count, i;
for (i = 0; i < appendx; i++)
case AP_STRING:
break;
case AP_FILE:
/*
* Read files probably shouldn't be cached. Since
* it's not an error to read a non-existent file,
* it's possible that another program is interacting
* with the sed script through the filesystem. It
* would be truly bizarre, but possible. It's probably
* not that big a performance win, anyhow.
*/
break;
while ((count =
outfile);
(void) fclose(f);
break;
}
}
static void
{
const char *p;
termwidth = 60;
if (termwidth == -1) {
else
termwidth = 60;
}
if (termwidth <= 0)
termwidth = 1;
col = 0;
while (len != 0) {
if (clen == 0)
clen = 1;
wc = (unsigned char)*s;
clen = 1;
}
if (wc == '\n') {
col = 0;
col = 0;
}
col = 0;
}
col += 2;
} else {
col = 0;
}
for (i = 0; i < clen; i++)
(int)(unsigned char)s[i]);
}
s += clen;
}
}
static int
{
int eval;
fatal(_("first RE may not be empty"));
} else
/* Set anchors */
switch (eval) {
case 0:
return (1);
case REG_NOMATCH:
return (0);
}
return (0);
}
/*
* regsub - perform substitutions after a regexp match
* Based on a routine by Henry Spencer
*/
static void
{
char c, *dst;
/* XXX What is the +1 for? */ \
}
while ((c = *src++) != '\0') {
if (c == '&')
no = 0;
else
no = -1;
if (no < 0) { /* Ordinary character. */
c = *src++;
NEEDSP(1);
*dst++ = c;
}
}
NEEDSP(1);
*dst = '\0';
}
/*
* cspace --
* Concatenate space: append the source space to the destination space,
* allocating new space as necessary.
*/
void
{
/* Make sure SPACE has enough memory and ramp up quickly. */
NULL)
}
}
/*
* Close all cached opened files and report any errors
*/
void
{
case 's':
break;
case 'w':
break;
case '{':
break;
}
}