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