f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * Copyright (c) 2005, 2008 Sun Microsystems, Inc. All Rights Reserved.
f82568a780e35e8786958c49a1259434e2088b9cniq * Use is subject to license terms.
f82568a780e35e8786958c49a1259434e2088b9cniq *
11e076839c8d5a82d55e710194d0daac51390dbdsf * Copyright (c) 1984 AT&T
11e076839c8d5a82d55e710194d0daac51390dbdsf * All Rights Reserved
f82568a780e35e8786958c49a1259434e2088b9cniq *
f82568a780e35e8786958c49a1259434e2088b9cniq * Licensed under the Apache License, Version 2.0 (the "License");
f82568a780e35e8786958c49a1259434e2088b9cniq * you may not use this file except in compliance with the License.
f82568a780e35e8786958c49a1259434e2088b9cniq * You may obtain a copy of the License at
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * http://www.apache.org/licenses/LICENSE-2.0.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim *
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * Unless required by applicable law or agreed to in writing, software
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * distributed under the License is distributed on an "AS IS" BASIS,
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * or implied.
f82568a780e35e8786958c49a1259434e2088b9cniq * See the License for the specific language governing permissions and
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * limitations under the License.
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq#include "apr.h"
f82568a780e35e8786958c49a1259434e2088b9cniq#include "apr_strings.h"
f82568a780e35e8786958c49a1259434e2088b9cniq#include "libsed.h"
f82568a780e35e8786958c49a1259434e2088b9cniq#include "sed.h"
f82568a780e35e8786958c49a1259434e2088b9cniq#include "regexp.h"
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq#define CCEOF 22
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int fcomp(sed_commands_t *commands, apr_file_t *fin);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *compsub(sed_commands_t *commands,
f82568a780e35e8786958c49a1259434e2088b9cniq sed_comp_args *compargs, char *rhsbuf);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int rline(sed_commands_t *commands, apr_file_t *fin,
f82568a780e35e8786958c49a1259434e2088b9cniq char *lbuf, char *lbend);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *address(sed_commands_t *commands, char *expbuf,
f82568a780e35e8786958c49a1259434e2088b9cniq apr_status_t* status);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *text(sed_commands_t *commands, char *textbuf, char *endbuf);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic sed_label_t *search(sed_commands_t *commands);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *ycomp(sed_commands_t *commands, char *expbuf);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *comple(sed_commands_t *commands, sed_comp_args *compargs,
f82568a780e35e8786958c49a1259434e2088b9cniq char *x1, char *ep, char *x3, char x4);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic sed_reptr_t *alloc_reptr(sed_commands_t *commands);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int check_finalized(const sed_commands_t *commands);
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniqvoid command_errf(sed_commands_t *commands, const char *fmt, ...)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->errfn && commands->pool) {
f82568a780e35e8786958c49a1259434e2088b9cniq va_list args;
f82568a780e35e8786958c49a1259434e2088b9cniq const char* error;
f82568a780e35e8786958c49a1259434e2088b9cniq va_start(args, fmt);
f82568a780e35e8786958c49a1259434e2088b9cniq error = apr_pvsprintf(commands->pool, fmt, args);
f82568a780e35e8786958c49a1259434e2088b9cniq commands->errfn(commands->data, error);
f82568a780e35e8786958c49a1259434e2088b9cniq va_end(args);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_init_commands
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqapr_status_t sed_init_commands(sed_commands_t *commands, sed_err_fn_t *errfn, void *data,
f82568a780e35e8786958c49a1259434e2088b9cniq apr_pool_t *p)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq memset(commands, 0, sizeof(*commands));
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->errfn = errfn;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->data = data;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->labtab = commands->ltab;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->lab = commands->labtab + 1;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->pool = p;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->respace = apr_pcalloc(p, RESIZE);
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->respace == NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_OOMMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return APR_EGENERAL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep = alloc_reptr(commands);
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->rep == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return APR_EGENERAL;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad1 = commands->respace;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->reend = &commands->respace[RESIZE - 1];
f82568a780e35e8786958c49a1259434e2088b9cniq commands->labend = &commands->labtab[SED_LABSIZE];
f82568a780e35e8786958c49a1259434e2088b9cniq commands->canbefinal = 1;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq return APR_SUCCESS;
f82568a780e35e8786958c49a1259434e2088b9cniq}
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_destroy_commands
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqvoid sed_destroy_commands(sed_commands_t *commands)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_compile_string
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqapr_status_t sed_compile_string(sed_commands_t *commands, const char *s)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq apr_status_t rv;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->earg = s;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->eflag = 1;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq rv = fcomp(commands, NULL);
f82568a780e35e8786958c49a1259434e2088b9cniq if (rv == APR_SUCCESS)
f82568a780e35e8786958c49a1259434e2088b9cniq commands->canbefinal = check_finalized(commands);
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->eflag = 0;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq return (rv != 0 ? APR_EGENERAL : APR_SUCCESS);
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_compile_file
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqapr_status_t sed_compile_file(sed_commands_t *commands, apr_file_t *fin)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq apr_status_t rv = fcomp(commands, fin);
f82568a780e35e8786958c49a1259434e2088b9cniq return (rv != 0 ? APR_EGENERAL : APR_SUCCESS);
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_get_finalize_error
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqchar* sed_get_finalize_error(const sed_commands_t *commands, apr_pool_t* pool)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq const sed_label_t *lab;
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->depth) {
f82568a780e35e8786958c49a1259434e2088b9cniq return SEDERR_TMOMES;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq /* Empty branch chain is not a issue */
f82568a780e35e8786958c49a1259434e2088b9cniq for (lab = commands->labtab + 1; lab < commands->lab; lab++) {
f82568a780e35e8786958c49a1259434e2088b9cniq char *error;
f82568a780e35e8786958c49a1259434e2088b9cniq if (lab->address == 0) {
f82568a780e35e8786958c49a1259434e2088b9cniq error = apr_psprintf(pool, SEDERR_ULMES, lab->asc);
f82568a780e35e8786958c49a1259434e2088b9cniq return error;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (lab->chain) {
f82568a780e35e8786958c49a1259434e2088b9cniq return SEDERR_INTERNAL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_canbe_finalized
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqint sed_canbe_finalized(const sed_commands_t *commands)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq return commands->canbefinal;
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * check_finalized
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int check_finalized(const sed_commands_t *commands)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq const sed_label_t *lab;
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->depth) {
f82568a780e35e8786958c49a1259434e2088b9cniq return 0;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq /* Empty branch chain is not a issue */
f82568a780e35e8786958c49a1259434e2088b9cniq for (lab = commands->labtab + 1; lab < commands->lab; lab++) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (lab->address == 0 || (lab->chain)) {
f82568a780e35e8786958c49a1259434e2088b9cniq return 0;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq return 1;
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * dechain
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic void dechain(sed_label_t *lpt, sed_reptr_t *address)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq sed_reptr_t *rep;
f82568a780e35e8786958c49a1259434e2088b9cniq if ((lpt == NULL) || (lpt->chain == NULL) || (address == NULL))
f82568a780e35e8786958c49a1259434e2088b9cniq return;
f82568a780e35e8786958c49a1259434e2088b9cniq rep = lpt->chain;
f82568a780e35e8786958c49a1259434e2088b9cniq while (rep->lb1) {
f82568a780e35e8786958c49a1259434e2088b9cniq sed_reptr_t *next;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq next = rep->lb1;
f82568a780e35e8786958c49a1259434e2088b9cniq rep->lb1 = address;
f82568a780e35e8786958c49a1259434e2088b9cniq rep = next;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq rep->lb1 = address;
f82568a780e35e8786958c49a1259434e2088b9cniq lpt->chain = NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * fcomp
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int fcomp(sed_commands_t *commands, apr_file_t *fin)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq char *p, *op, *tp;
f82568a780e35e8786958c49a1259434e2088b9cniq sed_reptr_t *pt, *pt1;
f82568a780e35e8786958c49a1259434e2088b9cniq int i, ii;
f82568a780e35e8786958c49a1259434e2088b9cniq sed_label_t *lpt;
f82568a780e35e8786958c49a1259434e2088b9cniq char fnamebuf[APR_PATH_MAX];
f82568a780e35e8786958c49a1259434e2088b9cniq apr_status_t status;
f82568a780e35e8786958c49a1259434e2088b9cniq sed_comp_args compargs;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq op = commands->lastre;
f82568a780e35e8786958c49a1259434e2088b9cniq if (!commands->linebuf) {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->linebuf = apr_pcalloc(commands->pool, LBSIZE + 1);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (rline(commands, fin, commands->linebuf,
f82568a780e35e8786958c49a1259434e2088b9cniq (commands->linebuf + LBSIZE + 1)) < 0)
f82568a780e35e8786958c49a1259434e2088b9cniq return 0;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->linebuf == '#') {
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->linebuf[1] == 'n')
f82568a780e35e8786958c49a1259434e2088b9cniq commands->nflag = 1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq else {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp = commands->linebuf;
f82568a780e35e8786958c49a1259434e2088b9cniq goto comploop;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq for (;;) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (rline(commands, fin, commands->linebuf,
f82568a780e35e8786958c49a1259434e2088b9cniq (commands->linebuf + LBSIZE + 1)) < 0)
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp = commands->linebuf;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniqcomploop:
f82568a780e35e8786958c49a1259434e2088b9cniq while (*commands->cp == ' ' || *commands->cp == '\t')
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == '\0' || *commands->cp == '#')
f82568a780e35e8786958c49a1259434e2088b9cniq continue;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == ';') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq goto comploop;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq p = address(commands, commands->rep->ad1, &status);
f82568a780e35e8786958c49a1259434e2088b9cniq if (status != APR_SUCCESS) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == commands->rep->ad1) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (op)
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad1 = op;
f82568a780e35e8786958c49a1259434e2088b9cniq else {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_NRMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq } else if (p == 0) {
f82568a780e35e8786958c49a1259434e2088b9cniq p = commands->rep->ad1;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad1 = 0;
f82568a780e35e8786958c49a1259434e2088b9cniq } else {
f82568a780e35e8786958c49a1259434e2088b9cniq op = commands->rep->ad1;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == ',' || *commands->cp == ';') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad2 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq p = address(commands, commands->rep->ad2, &status);
f82568a780e35e8786958c49a1259434e2088b9cniq if ((status != APR_SUCCESS) || (p == 0)) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == commands->rep->ad2)
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad2 = op;
f82568a780e35e8786958c49a1259434e2088b9cniq else
f82568a780e35e8786958c49a1259434e2088b9cniq op = commands->rep->ad2;
f82568a780e35e8786958c49a1259434e2088b9cniq } else
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad2 = 0;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if(p > &commands->respace[RESIZE-1]) {
4c6374798c9e6c0fc3b42dbc5a7225f67d27cb9fjailletc command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq while (*commands->cp == ' ' || *commands->cp == '\t')
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniqswit:
f82568a780e35e8786958c49a1259434e2088b9cniq switch(*commands->cp++) {
f82568a780e35e8786958c49a1259434e2088b9cniq default:
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_UCMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case '!':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->negfl = 1;
f82568a780e35e8786958c49a1259434e2088b9cniq goto swit;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case '{':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = BCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->negfl = !(commands->rep->negfl);
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cmpend[commands->depth++] = &commands->rep->lb1;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep = alloc_reptr(commands);
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == '\0')
f82568a780e35e8786958c49a1259434e2088b9cniq continue;
f82568a780e35e8786958c49a1259434e2088b9cniq goto comploop;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case '}':
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->rep->ad1) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD0MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (--commands->depth < 0) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMCMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq *commands->cmpend[commands->depth] = commands->rep;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq continue;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case '=':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = EQCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->rep->ad2) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case ':':
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->rep->ad1) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD0MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq while (*commands->cp++ == ' ');
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp--;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq tp = commands->lab->asc;
f82568a780e35e8786958c49a1259434e2088b9cniq while ((*tp++ = *commands->cp++)) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (tp >= &(commands->lab->asc[8])) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_LTLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq *--tp = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if ((lpt = search(commands)) != NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (lpt->address) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_DLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq dechain(lpt, commands->rep);
f82568a780e35e8786958c49a1259434e2088b9cniq } else {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->lab->chain = 0;
f82568a780e35e8786958c49a1259434e2088b9cniq lpt = commands->lab;
f82568a780e35e8786958c49a1259434e2088b9cniq if (++commands->lab >= commands->labend) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq lpt->address = commands->rep;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq continue;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'a':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = ACOM;
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->rep->ad2) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == '\\')
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp++ != '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->re1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq p = text(commands, commands->rep->re1, commands->reend);
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'c':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = CCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == '\\') commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp++ != ('\n')) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->re1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq p = text(commands, commands->rep->re1, commands->reend);
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'i':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = ICOM;
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->rep->ad2) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == '\\') commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp++ != ('\n')) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->re1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq p = text(commands, commands->rep->re1, commands->reend);
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'g':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = GCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'G':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = CGCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'h':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = HCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'H':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = CHCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 't':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = TCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq goto jtcommon;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'b':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = BCOM;
f82568a780e35e8786958c49a1259434e2088b9cniqjtcommon:
f82568a780e35e8786958c49a1259434e2088b9cniq while (*commands->cp++ == ' ');
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp--;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq if ((pt = commands->labtab->chain) != NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq while ((pt1 = pt->lb1) != NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq pt = pt1;
f82568a780e35e8786958c49a1259434e2088b9cniq pt->lb1 = commands->rep;
f82568a780e35e8786958c49a1259434e2088b9cniq } else
f82568a780e35e8786958c49a1259434e2088b9cniq commands->labtab->chain = commands->rep;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq tp = commands->lab->asc;
f82568a780e35e8786958c49a1259434e2088b9cniq while ((*tp++ = *commands->cp++))
f82568a780e35e8786958c49a1259434e2088b9cniq if (tp >= &(commands->lab->asc[8])) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_LTLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp--;
f82568a780e35e8786958c49a1259434e2088b9cniq *--tp = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if ((lpt = search(commands)) != NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (lpt->address) {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->lb1 = lpt->address;
f82568a780e35e8786958c49a1259434e2088b9cniq } else {
f82568a780e35e8786958c49a1259434e2088b9cniq pt = lpt->chain;
f82568a780e35e8786958c49a1259434e2088b9cniq while ((pt1 = pt->lb1) != NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq pt = pt1;
f82568a780e35e8786958c49a1259434e2088b9cniq pt->lb1 = commands->rep;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq } else {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->lab->chain = commands->rep;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->lab->address = 0;
f82568a780e35e8786958c49a1259434e2088b9cniq if (++commands->lab >= commands->labend) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'n':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = NCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'N':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = CNCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'p':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = PCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'P':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = CPCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'r':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = RCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->rep->ad2) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp++ != ' ') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->re1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq p = text(commands, commands->rep->re1, commands->reend);
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'd':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = DCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'D':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = CDCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->lb1 = commands->ptrspace;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'q':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = QCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->rep->ad2) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'l':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = LCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 's':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = SCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->sseof = *commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->re1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq p = comple(commands, &compargs, (char *) 0, commands->rep->re1,
f82568a780e35e8786958c49a1259434e2088b9cniq commands->reend, commands->sseof);
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == commands->rep->re1) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (op)
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->re1 = op;
f82568a780e35e8786958c49a1259434e2088b9cniq else {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_NRMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim } else
f82568a780e35e8786958c49a1259434e2088b9cniq op = commands->rep->re1;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->rhs = p;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq p = compsub(commands, &compargs, commands->rep->rhs);
f82568a780e35e8786958c49a1259434e2088b9cniq if ((p) == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == 'g') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->gfl = 999;
f82568a780e35e8786958c49a1259434e2088b9cniq } else if (commands->gflag)
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->gfl = 999;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp >= '1' && *commands->cp <= '9') {
f82568a780e35e8786958c49a1259434e2088b9cniq i = *commands->cp - '0';
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq while (1) {
f82568a780e35e8786958c49a1259434e2088b9cniq ii = *commands->cp;
f82568a780e35e8786958c49a1259434e2088b9cniq if (ii < '0' || ii > '9')
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq i = i*10 + ii - '0';
f82568a780e35e8786958c49a1259434e2088b9cniq if (i > 512) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TOOBIG, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->gfl = i;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == 'p') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->pfl = 1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == 'P') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->pfl = 2;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == 'w') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp++ != ' ') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_SMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (text(commands, fnamebuf, &fnamebuf[APR_PATH_MAX]) == NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_FNTL, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq for (i = commands->nfiles - 1; i >= 0; i--)
f82568a780e35e8786958c49a1259434e2088b9cniq if (strcmp(fnamebuf,commands->fname[i]) == 0) {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->findex = i;
f82568a780e35e8786958c49a1259434e2088b9cniq goto done;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->nfiles >= NWFILES) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMWFMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->fname[commands->nfiles] =
f82568a780e35e8786958c49a1259434e2088b9cniq apr_pstrdup(commands->pool, fnamebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->fname[commands->nfiles] == NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_OOMMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->findex = commands->nfiles++;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'w':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = WCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp++ != ' ') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_SMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (text(commands, fnamebuf, &fnamebuf[APR_PATH_MAX]) == NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_FNTL, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq for (i = commands->nfiles - 1; i >= 0; i--)
f82568a780e35e8786958c49a1259434e2088b9cniq if (strcmp(fnamebuf, commands->fname[i]) == 0) {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->findex = i;
f82568a780e35e8786958c49a1259434e2088b9cniq goto done;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->nfiles >= NWFILES) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMWFMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if ((commands->fname[commands->nfiles] =
f82568a780e35e8786958c49a1259434e2088b9cniq apr_pstrdup(commands->pool, fnamebuf)) == NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_OOMMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->findex = commands->nfiles++;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'x':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = XCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq case 'y':
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = YCOM;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->sseof = *commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->re1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq p = ycomp(commands, commands->rep->re1);
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq break;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniqdone:
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep = alloc_reptr(commands);
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->ad1 = p;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp++ != '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->cp[-1] == ';')
f82568a780e35e8786958c49a1259434e2088b9cniq goto comploop;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->rep->command = 0;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->lastre = op;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq return 0;
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *compsub(sed_commands_t *commands,
f82568a780e35e8786958c49a1259434e2088b9cniq sed_comp_args *compargs, char *rhsbuf)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq char *p, *q;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq p = rhsbuf;
f82568a780e35e8786958c49a1259434e2088b9cniq q = commands->cp;
f82568a780e35e8786958c49a1259434e2088b9cniq for(;;) {
f82568a780e35e8786958c49a1259434e2088b9cniq if(p > &commands->respace[RESIZE-1]) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if((*p = *q++) == '\\') {
f82568a780e35e8786958c49a1259434e2088b9cniq p++;
f82568a780e35e8786958c49a1259434e2088b9cniq if(p > &commands->respace[RESIZE-1]) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq *p = *q++;
f82568a780e35e8786958c49a1259434e2088b9cniq if(*p > compargs->nbra + '0' && *p <= '9') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_DOORNG, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq p++;
f82568a780e35e8786958c49a1259434e2088b9cniq continue;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if(*p == commands->sseof) {
f82568a780e35e8786958c49a1259434e2088b9cniq *p++ = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp = q;
f82568a780e35e8786958c49a1259434e2088b9cniq return(p);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if(*p++ == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_EDMOSUB, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * rline
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int rline(sed_commands_t *commands, apr_file_t *fin,
f82568a780e35e8786958c49a1259434e2088b9cniq char *lbuf, char *lbend)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq char *p;
f82568a780e35e8786958c49a1259434e2088b9cniq const char *q;
f82568a780e35e8786958c49a1259434e2088b9cniq int t;
f82568a780e35e8786958c49a1259434e2088b9cniq apr_size_t bytes_read;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq p = lbuf;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if(commands->eflag) {
f82568a780e35e8786958c49a1259434e2088b9cniq if(commands->eflag > 0) {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->eflag = -1;
f82568a780e35e8786958c49a1259434e2088b9cniq q = commands->earg;
f82568a780e35e8786958c49a1259434e2088b9cniq while((t = *q++) != '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->saveq = q;
f82568a780e35e8786958c49a1259434e2088b9cniq goto out1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (p < lbend)
f82568a780e35e8786958c49a1259434e2088b9cniq *p++ = t;
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\\') {
f82568a780e35e8786958c49a1259434e2088b9cniq if((t = *q++) == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->saveq = NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq return(-1);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (p < lbend)
f82568a780e35e8786958c49a1259434e2088b9cniq *p++ = t;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->saveq = NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq out1:
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == lbend) {
42e7c88b40321bece73775998d819c1fe5ddf112sf command_errf(commands, SEDERR_CLTL);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq *p = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq return(1);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if((q = commands->saveq) == 0) return(-1);
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq while((t = *q++) != '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->saveq = q;
f82568a780e35e8786958c49a1259434e2088b9cniq goto out2;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if(p < lbend)
f82568a780e35e8786958c49a1259434e2088b9cniq *p++ = t;
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\\') {
f82568a780e35e8786958c49a1259434e2088b9cniq if((t = *q++) == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->saveq = NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq return(-1);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (p < lbend)
f82568a780e35e8786958c49a1259434e2088b9cniq *p++ = t;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->saveq = NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq out2:
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == lbend) {
42e7c88b40321bece73775998d819c1fe5ddf112sf command_errf(commands, SEDERR_CLTL);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq *p = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq return(1);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq bytes_read = 1;
f82568a780e35e8786958c49a1259434e2088b9cniq /* XXX extremely inefficient 1 byte reads */
f82568a780e35e8786958c49a1259434e2088b9cniq while (apr_file_read(fin, &t, &bytes_read) != APR_SUCCESS) {
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == lbend) {
42e7c88b40321bece73775998d819c1fe5ddf112sf command_errf(commands, SEDERR_CLTL);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq *p = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq return(1);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (p < lbend)
f82568a780e35e8786958c49a1259434e2088b9cniq *p++ = t;
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\\') {
f82568a780e35e8786958c49a1259434e2088b9cniq bytes_read = 1;
f82568a780e35e8786958c49a1259434e2088b9cniq if (apr_file_read(fin, &t, &bytes_read) != APR_SUCCESS) {
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if(p < lbend)
f82568a780e35e8786958c49a1259434e2088b9cniq *p++ = t;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq bytes_read = 1;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq return(-1);
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * address
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *address(sed_commands_t *commands, char *expbuf,
f82568a780e35e8786958c49a1259434e2088b9cniq apr_status_t* status)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq char *rcp;
f82568a780e35e8786958c49a1259434e2088b9cniq apr_int64_t lno;
f82568a780e35e8786958c49a1259434e2088b9cniq sed_comp_args compargs;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq *status = APR_SUCCESS;
f82568a780e35e8786958c49a1259434e2088b9cniq if(*commands->cp == '$') {
f82568a780e35e8786958c49a1259434e2088b9cniq if (expbuf > &commands->respace[RESIZE-2]) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq *status = APR_EGENERAL;
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq *expbuf++ = CEND;
f82568a780e35e8786958c49a1259434e2088b9cniq *expbuf++ = CCEOF;
f82568a780e35e8786958c49a1259434e2088b9cniq return(expbuf);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if (*commands->cp == '/' || *commands->cp == '\\' ) {
f82568a780e35e8786958c49a1259434e2088b9cniq if ( *commands->cp == '\\' )
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->sseof = *commands->cp++;
f82568a780e35e8786958c49a1259434e2088b9cniq return(comple(commands, &compargs, (char *) 0, expbuf, commands->reend,
f82568a780e35e8786958c49a1259434e2088b9cniq commands->sseof));
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq rcp = commands->cp;
f82568a780e35e8786958c49a1259434e2088b9cniq lno = 0;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq while(*rcp >= '0' && *rcp <= '9')
f82568a780e35e8786958c49a1259434e2088b9cniq lno = lno*10 + *rcp++ - '0';
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if(rcp > commands->cp) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (expbuf > &commands->respace[RESIZE-3]) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq *status = APR_EGENERAL;
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq *expbuf++ = CLNUM;
f82568a780e35e8786958c49a1259434e2088b9cniq *expbuf++ = commands->nlno;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->tlno[commands->nlno++] = lno;
f82568a780e35e8786958c49a1259434e2088b9cniq if(commands->nlno >= SED_NLINES) {
42e7c88b40321bece73775998d819c1fe5ddf112sf command_errf(commands, SEDERR_TMLNMES);
f82568a780e35e8786958c49a1259434e2088b9cniq *status = APR_EGENERAL;
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq *expbuf++ = CCEOF;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp = rcp;
f82568a780e35e8786958c49a1259434e2088b9cniq return(expbuf);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq return(NULL);
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * text
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *text(sed_commands_t *commands, char *textbuf, char *tbend)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq char *p, *q;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq p = textbuf;
f82568a780e35e8786958c49a1259434e2088b9cniq q = commands->cp;
f82568a780e35e8786958c49a1259434e2088b9cniq#ifndef S5EMUL
f82568a780e35e8786958c49a1259434e2088b9cniq /*
f82568a780e35e8786958c49a1259434e2088b9cniq * Strip off indentation from text to be inserted.
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniq while(*q == '\t' || *q == ' ') q++;
f82568a780e35e8786958c49a1259434e2088b9cniq#endif
f82568a780e35e8786958c49a1259434e2088b9cniq for(;;) {
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if(p > tbend)
f82568a780e35e8786958c49a1259434e2088b9cniq return(NULL); /* overflowed the buffer */
f82568a780e35e8786958c49a1259434e2088b9cniq if((*p = *q++) == '\\')
f82568a780e35e8786958c49a1259434e2088b9cniq *p = *q++;
f82568a780e35e8786958c49a1259434e2088b9cniq if(*p == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp = --q;
f82568a780e35e8786958c49a1259434e2088b9cniq return(++p);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq#ifndef S5EMUL
f82568a780e35e8786958c49a1259434e2088b9cniq /*
f82568a780e35e8786958c49a1259434e2088b9cniq * Strip off indentation from text to be inserted.
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniq if(*p == '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniq while(*q == '\t' || *q == ' ') q++;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq#endif
f82568a780e35e8786958c49a1259434e2088b9cniq p++;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * search
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic sed_label_t *search(sed_commands_t *commands)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq sed_label_t *rp;
f82568a780e35e8786958c49a1259434e2088b9cniq sed_label_t *ptr;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq rp = commands->labtab;
f82568a780e35e8786958c49a1259434e2088b9cniq ptr = commands->lab;
f82568a780e35e8786958c49a1259434e2088b9cniq while (rp < ptr) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (strcmp(rp->asc, ptr->asc) == 0)
f82568a780e35e8786958c49a1259434e2088b9cniq return rp;
f82568a780e35e8786958c49a1259434e2088b9cniq rp++;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq return 0;
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * ycomp
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *ycomp(sed_commands_t *commands, char *expbuf)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq char c;
f82568a780e35e8786958c49a1259434e2088b9cniq int cint; /* integer value of char c */
f82568a780e35e8786958c49a1259434e2088b9cniq char *ep, *tsp;
f82568a780e35e8786958c49a1259434e2088b9cniq int i;
f82568a780e35e8786958c49a1259434e2088b9cniq char *sp;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq ep = expbuf;
f82568a780e35e8786958c49a1259434e2088b9cniq if(ep + 0377 > &commands->respace[RESIZE-1]) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq sp = commands->cp;
f82568a780e35e8786958c49a1259434e2088b9cniq for(tsp = commands->cp; (c = *tsp) != commands->sseof; tsp++) {
f82568a780e35e8786958c49a1259434e2088b9cniq if(c == '\\')
f82568a780e35e8786958c49a1259434e2088b9cniq tsp++;
f82568a780e35e8786958c49a1259434e2088b9cniq if(c == '\0' || c == '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_EDMOSTR, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq tsp++;
f82568a780e35e8786958c49a1259434e2088b9cniq memset(ep, 0, 0400);
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq while((c = *sp++) != commands->sseof) {
f82568a780e35e8786958c49a1259434e2088b9cniq c &= 0377;
f82568a780e35e8786958c49a1259434e2088b9cniq if(c == '\\' && *sp == 'n') {
f82568a780e35e8786958c49a1259434e2088b9cniq sp++;
f82568a780e35e8786958c49a1259434e2088b9cniq c = '\n';
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq cint = (int) c;
f82568a780e35e8786958c49a1259434e2088b9cniq if((ep[cint] = *tsp++) == '\\' && *tsp == 'n') {
f82568a780e35e8786958c49a1259434e2088b9cniq ep[cint] = '\n';
f82568a780e35e8786958c49a1259434e2088b9cniq tsp++;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if(ep[cint] == commands->sseof || ep[cint] == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TSNTSS, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq if(*tsp != commands->sseof) {
f82568a780e35e8786958c49a1259434e2088b9cniq if(*tsp == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_EDMOSTR, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq else {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TSNTSS, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq return NULL;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cp = ++tsp;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq for(i = 0; i < 0400; i++)
f82568a780e35e8786958c49a1259434e2088b9cniq if(ep[i] == 0)
f82568a780e35e8786958c49a1259434e2088b9cniq ep[i] = i;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq return(ep + 0400);
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * comple
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *comple(sed_commands_t *commands, sed_comp_args *compargs,
f82568a780e35e8786958c49a1259434e2088b9cniq char *x1, char *ep, char *x3, char x4)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq char *p;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq p = sed_compile(commands, compargs, ep + 1, x3, x4);
f82568a780e35e8786958c49a1259434e2088b9cniq if(p == ep + 1)
f82568a780e35e8786958c49a1259434e2088b9cniq return(ep);
f82568a780e35e8786958c49a1259434e2088b9cniq *ep = compargs->circf;
f82568a780e35e8786958c49a1259434e2088b9cniq return(p);
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq/*
f82568a780e35e8786958c49a1259434e2088b9cniq * alloc_reptr
f82568a780e35e8786958c49a1259434e2088b9cniq */
f82568a780e35e8786958c49a1259434e2088b9cniqstatic sed_reptr_t *alloc_reptr(sed_commands_t *commands)
f82568a780e35e8786958c49a1259434e2088b9cniq{
f82568a780e35e8786958c49a1259434e2088b9cniq sed_reptr_t *var;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq var = apr_pcalloc(commands->pool, sizeof(sed_reptr_t));
f82568a780e35e8786958c49a1259434e2088b9cniq if (var == NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_OOMMES);
f82568a780e35e8786958c49a1259434e2088b9cniq return 0;
f82568a780e35e8786958c49a1259434e2088b9cniq }
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq var->nrep = commands->nrep;
f82568a780e35e8786958c49a1259434e2088b9cniq var->findex = -1;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->nrep++;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq if (commands->ptrspace == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq commands->ptrspace = var;
f82568a780e35e8786958c49a1259434e2088b9cniq else
f82568a780e35e8786958c49a1259434e2088b9cniq commands->ptrend->next = var;
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq commands->ptrend = var;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->labtab->address = var;
f82568a780e35e8786958c49a1259434e2088b9cniq return var;
f82568a780e35e8786958c49a1259434e2088b9cniq}
f82568a780e35e8786958c49a1259434e2088b9cniq
f82568a780e35e8786958c49a1259434e2088b9cniq