f82568a780e35e8786958c49a1259434e2088b9cniq * Copyright (c) 2005, 2008 Sun Microsystems, Inc. All Rights Reserved.
f82568a780e35e8786958c49a1259434e2088b9cniq * Use is subject to license terms.
11e076839c8d5a82d55e710194d0daac51390dbdsf * Copyright (c) 1984 AT&T
11e076839c8d5a82d55e710194d0daac51390dbdsf * All Rights Reserved
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 * 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.
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int fcomp(sed_commands_t *commands, apr_file_t *fin);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int rline(sed_commands_t *commands, apr_file_t *fin,
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *address(sed_commands_t *commands, char *expbuf,
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *text(sed_commands_t *commands, char *textbuf, char *endbuf);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *ycomp(sed_commands_t *commands, char *expbuf);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *comple(sed_commands_t *commands, sed_comp_args *compargs,
f82568a780e35e8786958c49a1259434e2088b9cniqstatic sed_reptr_t *alloc_reptr(sed_commands_t *commands);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int check_finalized(const sed_commands_t *commands);
f82568a780e35e8786958c49a1259434e2088b9cniqvoid command_errf(sed_commands_t *commands, const char *fmt, ...)
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_init_commands
f82568a780e35e8786958c49a1259434e2088b9cniqapr_status_t sed_init_commands(sed_commands_t *commands, sed_err_fn_t *errfn, void *data,
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_destroy_commands
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_compile_string
f82568a780e35e8786958c49a1259434e2088b9cniqapr_status_t sed_compile_string(sed_commands_t *commands, const char *s)
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_compile_file
f82568a780e35e8786958c49a1259434e2088b9cniqapr_status_t sed_compile_file(sed_commands_t *commands, apr_file_t *fin)
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_get_finalize_error
f82568a780e35e8786958c49a1259434e2088b9cniqchar* sed_get_finalize_error(const sed_commands_t *commands, apr_pool_t* pool)
f82568a780e35e8786958c49a1259434e2088b9cniq /* Empty branch chain is not a issue */
f82568a780e35e8786958c49a1259434e2088b9cniq for (lab = commands->labtab + 1; lab < commands->lab; lab++) {
f82568a780e35e8786958c49a1259434e2088b9cniq * sed_canbe_finalized
f82568a780e35e8786958c49a1259434e2088b9cniq * check_finalized
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int check_finalized(const sed_commands_t *commands)
f82568a780e35e8786958c49a1259434e2088b9cniq /* Empty branch chain is not a issue */
f82568a780e35e8786958c49a1259434e2088b9cniq for (lab = commands->labtab + 1; lab < commands->lab; lab++) {
f82568a780e35e8786958c49a1259434e2088b9cniqstatic void dechain(sed_label_t *lpt, sed_reptr_t *address)
f82568a780e35e8786958c49a1259434e2088b9cniq if ((lpt == NULL) || (lpt->chain == NULL) || (address == NULL))
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int fcomp(sed_commands_t *commands, apr_file_t *fin)
f82568a780e35e8786958c49a1259434e2088b9cniq commands->linebuf = apr_pcalloc(commands->pool, LBSIZE + 1);
f82568a780e35e8786958c49a1259434e2088b9cniq for (;;) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq } else if (p == 0) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
4c6374798c9e6c0fc3b42dbc5a7225f67d27cb9fjailletc command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_UCMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq commands->cmpend[commands->depth++] = &commands->rep->lb1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD0MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD0MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_LTLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_DLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq p = text(commands, commands->rep->re1, commands->reend);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq p = text(commands, commands->rep->re1, commands->reend);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq p = text(commands, commands->rep->re1, commands->reend);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_LTLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMLMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq p = text(commands, commands->rep->re1, commands->reend);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_AD1MES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq p = comple(commands, &compargs, (char *) 0, commands->rep->re1,
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq if ((p) == NULL)
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq while (1) {
f82568a780e35e8786958c49a1259434e2088b9cniq if (i > 512) {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TOOBIG, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_SMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq if (text(commands, fnamebuf, &fnamebuf[APR_PATH_MAX]) == NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_SMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq if (text(commands, fnamebuf, &fnamebuf[APR_PATH_MAX]) == NULL) {
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_CGMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq char *p, *q;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq if((*p = *q++) == '\\') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq *p = *q++;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_DOORNG, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq *p++ = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq return(p);
f82568a780e35e8786958c49a1259434e2088b9cniq if(*p++ == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_EDMOSUB, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic int rline(sed_commands_t *commands, apr_file_t *fin,
f82568a780e35e8786958c49a1259434e2088b9cniq const char *q;
f82568a780e35e8786958c49a1259434e2088b9cniq while((t = *q++) != '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\\') {
f82568a780e35e8786958c49a1259434e2088b9cniq if((t = *q++) == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq return(-1);
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == lbend) {
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq *p = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq return(1);
f82568a780e35e8786958c49a1259434e2088b9cniq while((t = *q++) != '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\\') {
f82568a780e35e8786958c49a1259434e2088b9cniq if((t = *q++) == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq return(-1);
f82568a780e35e8786958c49a1259434e2088b9cniq if (p == lbend) {
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq *p = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq return(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) {
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq *p = '\0';
f82568a780e35e8786958c49a1259434e2088b9cniq return(1);
f82568a780e35e8786958c49a1259434e2088b9cniq if(t == '\\') {
f82568a780e35e8786958c49a1259434e2088b9cniq if (apr_file_read(fin, &t, &bytes_read) != APR_SUCCESS) {
f82568a780e35e8786958c49a1259434e2088b9cniq return -1;
f82568a780e35e8786958c49a1259434e2088b9cniq return(-1);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *address(sed_commands_t *commands, char *expbuf,
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq return(comple(commands, &compargs, (char *) 0, expbuf, commands->reend,
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *text(sed_commands_t *commands, char *textbuf, char *tbend)
f82568a780e35e8786958c49a1259434e2088b9cniq char *p, *q;
f82568a780e35e8786958c49a1259434e2088b9cniq * Strip off indentation from text to be inserted.
f82568a780e35e8786958c49a1259434e2088b9cniq if((*p = *q++) == '\\')
f82568a780e35e8786958c49a1259434e2088b9cniq *p = *q++;
f82568a780e35e8786958c49a1259434e2088b9cniq if(*p == '\0') {
f82568a780e35e8786958c49a1259434e2088b9cniq return(++p);
f82568a780e35e8786958c49a1259434e2088b9cniq * Strip off indentation from text to be inserted.
f82568a780e35e8786958c49a1259434e2088b9cniq if(*p == '\n') {
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *ycomp(sed_commands_t *commands, char *expbuf)
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TMMES, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq for(tsp = commands->cp; (c = *tsp) != commands->sseof; tsp++) {
f82568a780e35e8786958c49a1259434e2088b9cniq if(c == '\\')
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_EDMOSTR, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq c &= 0377;
f82568a780e35e8786958c49a1259434e2088b9cniq cint = (int) c;
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TSNTSS, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_EDMOSTR, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq command_errf(commands, SEDERR_TSNTSS, commands->linebuf);
f82568a780e35e8786958c49a1259434e2088b9cniq for(i = 0; i < 0400; i++)
f82568a780e35e8786958c49a1259434e2088b9cniq if(ep[i] == 0)
f82568a780e35e8786958c49a1259434e2088b9cniqstatic char *comple(sed_commands_t *commands, sed_comp_args *compargs,
f82568a780e35e8786958c49a1259434e2088b9cniq return(p);
f82568a780e35e8786958c49a1259434e2088b9cniq * alloc_reptr