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