1*84441f85SGarrett D'Amore /* 2*84441f85SGarrett D'Amore * Copyright (c) 1992 Diomidis Spinellis. 3*84441f85SGarrett D'Amore * Copyright (c) 1992, 1993 4*84441f85SGarrett D'Amore * The Regents of the University of California. All rights reserved. 5*84441f85SGarrett D'Amore * 6*84441f85SGarrett D'Amore * This code is derived from software contributed to Berkeley by 7*84441f85SGarrett D'Amore * Diomidis Spinellis of Imperial College, University of London. 8*84441f85SGarrett D'Amore * 9*84441f85SGarrett D'Amore * Redistribution and use in source and binary forms, with or without 10*84441f85SGarrett D'Amore * modification, are permitted provided that the following conditions 11*84441f85SGarrett D'Amore * are met: 12*84441f85SGarrett D'Amore * 1. Redistributions of source code must retain the above copyright 13*84441f85SGarrett D'Amore * notice, this list of conditions and the following disclaimer. 14*84441f85SGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright 15*84441f85SGarrett D'Amore * notice, this list of conditions and the following disclaimer in the 16*84441f85SGarrett D'Amore * documentation and/or other materials provided with the distribution. 17*84441f85SGarrett D'Amore * 4. Neither the name of the University nor the names of its contributors 18*84441f85SGarrett D'Amore * may be used to endorse or promote products derived from this software 19*84441f85SGarrett D'Amore * without specific prior written permission. 20*84441f85SGarrett D'Amore * 21*84441f85SGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22*84441f85SGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23*84441f85SGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24*84441f85SGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25*84441f85SGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26*84441f85SGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27*84441f85SGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28*84441f85SGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29*84441f85SGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30*84441f85SGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*84441f85SGarrett D'Amore * SUCH DAMAGE. 32*84441f85SGarrett D'Amore */ 33*84441f85SGarrett D'Amore 34*84441f85SGarrett D'Amore #ifndef DEFS_H 35*84441f85SGarrett D'Amore #define DEFS_H 36*84441f85SGarrett D'Amore 37*84441f85SGarrett D'Amore /* 38*84441f85SGarrett D'Amore * Types of address specifications 39*84441f85SGarrett D'Amore */ 40*84441f85SGarrett D'Amore enum e_atype { 41*84441f85SGarrett D'Amore AT_RE = 1, /* Line that match RE */ 42*84441f85SGarrett D'Amore AT_LINE, /* Specific line */ 43*84441f85SGarrett D'Amore AT_RELLINE, /* Relative line */ 44*84441f85SGarrett D'Amore AT_LAST /* Last line */ 45*84441f85SGarrett D'Amore }; 46*84441f85SGarrett D'Amore 47*84441f85SGarrett D'Amore /* 48*84441f85SGarrett D'Amore * Format of an address 49*84441f85SGarrett D'Amore */ 50*84441f85SGarrett D'Amore struct s_addr { 51*84441f85SGarrett D'Amore enum e_atype type; /* Address type */ 52*84441f85SGarrett D'Amore union { 53*84441f85SGarrett D'Amore ulong_t l; /* Line number */ 54*84441f85SGarrett D'Amore regex_t *r; /* Regular expression */ 55*84441f85SGarrett D'Amore } u; 56*84441f85SGarrett D'Amore }; 57*84441f85SGarrett D'Amore 58*84441f85SGarrett D'Amore /* 59*84441f85SGarrett D'Amore * Substitution command 60*84441f85SGarrett D'Amore */ 61*84441f85SGarrett D'Amore struct s_subst { 62*84441f85SGarrett D'Amore int n; /* Occurrence to subst. */ 63*84441f85SGarrett D'Amore int p; /* True if p flag */ 64*84441f85SGarrett D'Amore int icase; /* True if I flag */ 65*84441f85SGarrett D'Amore char *wfile; /* NULL if no wfile */ 66*84441f85SGarrett D'Amore int wfd; /* Cached file descriptor */ 67*84441f85SGarrett D'Amore regex_t *re; /* Regular expression */ 68*84441f85SGarrett D'Amore unsigned int maxbref; /* Largest backreference. */ 69*84441f85SGarrett D'Amore ulong_t linenum; /* Line number. */ 70*84441f85SGarrett D'Amore char *new; /* Replacement text */ 71*84441f85SGarrett D'Amore }; 72*84441f85SGarrett D'Amore 73*84441f85SGarrett D'Amore /* 74*84441f85SGarrett D'Amore * Translate command. 75*84441f85SGarrett D'Amore */ 76*84441f85SGarrett D'Amore struct s_tr { 77*84441f85SGarrett D'Amore unsigned char bytetab[256]; 78*84441f85SGarrett D'Amore struct trmulti { 79*84441f85SGarrett D'Amore size_t fromlen; 80*84441f85SGarrett D'Amore char from[MB_LEN_MAX]; 81*84441f85SGarrett D'Amore size_t tolen; 82*84441f85SGarrett D'Amore char to[MB_LEN_MAX]; 83*84441f85SGarrett D'Amore } *multis; 84*84441f85SGarrett D'Amore int nmultis; 85*84441f85SGarrett D'Amore }; 86*84441f85SGarrett D'Amore 87*84441f85SGarrett D'Amore /* 88*84441f85SGarrett D'Amore * An internally compiled command. 89*84441f85SGarrett D'Amore * Initialy, label references are stored in t, on a second pass they 90*84441f85SGarrett D'Amore * are updated to pointers. 91*84441f85SGarrett D'Amore */ 92*84441f85SGarrett D'Amore struct s_command { 93*84441f85SGarrett D'Amore struct s_command *next; /* Pointer to next command */ 94*84441f85SGarrett D'Amore struct s_addr *a1, *a2; /* Start and end address */ 95*84441f85SGarrett D'Amore ulong_t startline; /* Start line number or zero */ 96*84441f85SGarrett D'Amore char *t; /* Text for : a c i r w */ 97*84441f85SGarrett D'Amore union { 98*84441f85SGarrett D'Amore struct s_command *c; /* Command(s) for b t { */ 99*84441f85SGarrett D'Amore struct s_subst *s; /* Substitute command */ 100*84441f85SGarrett D'Amore struct s_tr *y; /* Replace command array */ 101*84441f85SGarrett D'Amore int fd; /* File descriptor for w */ 102*84441f85SGarrett D'Amore } u; 103*84441f85SGarrett D'Amore char code; /* Command code */ 104*84441f85SGarrett D'Amore uint_t nonsel:1; /* True if ! */ 105*84441f85SGarrett D'Amore }; 106*84441f85SGarrett D'Amore 107*84441f85SGarrett D'Amore /* 108*84441f85SGarrett D'Amore * Types of command arguments recognised by the parser 109*84441f85SGarrett D'Amore */ 110*84441f85SGarrett D'Amore enum e_args { 111*84441f85SGarrett D'Amore EMPTY, /* d D g G h H l n N p P q x = \0 */ 112*84441f85SGarrett D'Amore TEXT, /* a c i */ 113*84441f85SGarrett D'Amore NONSEL, /* ! */ 114*84441f85SGarrett D'Amore GROUP, /* { */ 115*84441f85SGarrett D'Amore ENDGROUP, /* } */ 116*84441f85SGarrett D'Amore COMMENT, /* # */ 117*84441f85SGarrett D'Amore BRANCH, /* b t */ 118*84441f85SGarrett D'Amore LABEL, /* : */ 119*84441f85SGarrett D'Amore RFILE, /* r */ 120*84441f85SGarrett D'Amore WFILE, /* w */ 121*84441f85SGarrett D'Amore SUBST, /* s */ 122*84441f85SGarrett D'Amore TR /* y */ 123*84441f85SGarrett D'Amore }; 124*84441f85SGarrett D'Amore 125*84441f85SGarrett D'Amore /* 126*84441f85SGarrett D'Amore * Structure containing things to append before a line is read 127*84441f85SGarrett D'Amore */ 128*84441f85SGarrett D'Amore struct s_appends { 129*84441f85SGarrett D'Amore enum {AP_STRING, AP_FILE} type; 130*84441f85SGarrett D'Amore char *s; 131*84441f85SGarrett D'Amore size_t len; 132*84441f85SGarrett D'Amore }; 133*84441f85SGarrett D'Amore 134*84441f85SGarrett D'Amore enum e_spflag { 135*84441f85SGarrett D'Amore APPEND, /* Append to the contents. */ 136*84441f85SGarrett D'Amore REPLACE /* Replace the contents. */ 137*84441f85SGarrett D'Amore }; 138*84441f85SGarrett D'Amore 139*84441f85SGarrett D'Amore /* 140*84441f85SGarrett D'Amore * Structure for a space (process, hold, otherwise). 141*84441f85SGarrett D'Amore */ 142*84441f85SGarrett D'Amore typedef struct { 143*84441f85SGarrett D'Amore char *space; /* Current space pointer. */ 144*84441f85SGarrett D'Amore size_t len; /* Current length. */ 145*84441f85SGarrett D'Amore int deleted; /* If deleted. */ 146*84441f85SGarrett D'Amore char *back; /* Backing memory. */ 147*84441f85SGarrett D'Amore size_t blen; /* Backing memory length. */ 148*84441f85SGarrett D'Amore } SPACE; 149*84441f85SGarrett D'Amore 150*84441f85SGarrett D'Amore #endif /* DEFS_H */ 151