84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Copyright (c) 1992 Diomidis Spinellis.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Copyright (c) 1992, 1993
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * The Regents of the University of California. All rights reserved.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore *
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * This code is derived from software contributed to Berkeley by
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Diomidis Spinellis of Imperial College, University of London.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore *
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Redistribution and use in source and binary forms, with or without
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * modification, are permitted provided that the following conditions
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * are met:
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * 1. Redistributions of source code must retain the above copyright
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * notice, this list of conditions and the following disclaimer.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * notice, this list of conditions and the following disclaimer in the
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * documentation and/or other materials provided with the distribution.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * 4. Neither the name of the University nor the names of its contributors
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * may be used to endorse or promote products derived from this software
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * without specific prior written permission.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore *
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * SUCH DAMAGE.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#ifndef DEFS_H
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#define DEFS_H
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Types of address specifications
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amoreenum e_atype {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore AT_RE = 1, /* Line that match RE */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore AT_LINE, /* Specific line */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore AT_RELLINE, /* Relative line */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore AT_LAST /* Last line */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore};
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Format of an address
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorestruct s_addr {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore enum e_atype type; /* Address type */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore union {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore ulong_t l; /* Line number */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore regex_t *r; /* Regular expression */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore } u;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore};
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Substitution command
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorestruct s_subst {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore int n; /* Occurrence to subst. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore int p; /* True if p flag */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore int icase; /* True if I flag */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char *wfile; /* NULL if no wfile */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore int wfd; /* Cached file descriptor */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore regex_t *re; /* Regular expression */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore unsigned int maxbref; /* Largest backreference. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore ulong_t linenum; /* Line number. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char *new; /* Replacement text */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore};
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Translate command.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorestruct s_tr {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore unsigned char bytetab[256];
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore struct trmulti {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore size_t fromlen;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char from[MB_LEN_MAX];
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore size_t tolen;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char to[MB_LEN_MAX];
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore } *multis;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore int nmultis;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore};
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * An internally compiled command.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Initialy, label references are stored in t, on a second pass they
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * are updated to pointers.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorestruct s_command {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore struct s_command *next; /* Pointer to next command */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore struct s_addr *a1, *a2; /* Start and end address */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore ulong_t startline; /* Start line number or zero */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char *t; /* Text for : a c i r w */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore union {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore struct s_command *c; /* Command(s) for b t { */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore struct s_subst *s; /* Substitute command */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore struct s_tr *y; /* Replace command array */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore int fd; /* File descriptor for w */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore } u;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char code; /* Command code */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore uint_t nonsel:1; /* True if ! */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore};
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Types of command arguments recognised by the parser
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amoreenum e_args {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore EMPTY, /* d D g G h H l n N p P q x = \0 */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore TEXT, /* a c i */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore NONSEL, /* ! */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore GROUP, /* { */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore ENDGROUP, /* } */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore COMMENT, /* # */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore BRANCH, /* b t */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore LABEL, /* : */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore RFILE, /* r */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore WFILE, /* w */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore SUBST, /* s */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore TR /* y */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore};
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Structure containing things to append before a line is read
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorestruct s_appends {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore enum {AP_STRING, AP_FILE} type;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char *s;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore size_t len;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore};
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amoreenum e_spflag {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore APPEND, /* Append to the contents. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore REPLACE /* Replace the contents. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore};
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Structure for a space (process, hold, otherwise).
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amoretypedef struct {
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char *space; /* Current space pointer. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore size_t len; /* Current length. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore int deleted; /* If deleted. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore char *back; /* Backing memory. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore size_t blen; /* Backing memory length. */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore} SPACE;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#endif /* DEFS_H */