19b50d902SRodney W. Grimes /*- 28a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 38a16b7a1SPedro F. Giffuni * 49b50d902SRodney W. Grimes * Copyright (c) 1992 Diomidis Spinellis. 59b50d902SRodney W. Grimes * Copyright (c) 1992, 1993 69b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 79b50d902SRodney W. Grimes * 89b50d902SRodney W. Grimes * This code is derived from software contributed to Berkeley by 99b50d902SRodney W. Grimes * Diomidis Spinellis of Imperial College, University of London. 109b50d902SRodney W. Grimes * 119b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 129b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 139b50d902SRodney W. Grimes * are met: 149b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 159b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 169b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 179b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 189b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 19fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 209b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 219b50d902SRodney W. Grimes * without specific prior written permission. 229b50d902SRodney W. Grimes * 239b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 249b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 259b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 269b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 279b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 289b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 299b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 309b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 319b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 329b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 339b50d902SRodney W. Grimes * SUCH DAMAGE. 349b50d902SRodney W. Grimes */ 359b50d902SRodney W. Grimes 369b50d902SRodney W. Grimes /* 379b50d902SRodney W. Grimes * Types of address specifications 389b50d902SRodney W. Grimes */ 399b50d902SRodney W. Grimes enum e_atype { 40f879e8d9SBrian Somers AT_RE = 1, /* Line that match RE */ 419b50d902SRodney W. Grimes AT_LINE, /* Specific line */ 42f879e8d9SBrian Somers AT_RELLINE, /* Relative line */ 439b50d902SRodney W. Grimes AT_LAST, /* Last line */ 449b50d902SRodney W. Grimes }; 459b50d902SRodney W. Grimes 469b50d902SRodney W. Grimes /* 479b50d902SRodney W. Grimes * Format of an address 489b50d902SRodney W. Grimes */ 499b50d902SRodney W. Grimes struct s_addr { 509b50d902SRodney W. Grimes enum e_atype type; /* Address type */ 519b50d902SRodney W. Grimes union { 529b50d902SRodney W. Grimes u_long l; /* Line number */ 53249a8a80SPedro F. Giffuni regex_t *r; /* Regular expression */ 549b50d902SRodney W. Grimes } u; 559b50d902SRodney W. Grimes }; 569b50d902SRodney W. Grimes 579b50d902SRodney W. Grimes /* 589b50d902SRodney W. Grimes * Substitution command 599b50d902SRodney W. Grimes */ 609b50d902SRodney W. Grimes struct s_subst { 619b50d902SRodney W. Grimes int n; /* Occurrence to subst. */ 629b50d902SRodney W. Grimes int p; /* True if p flag */ 63bdd72b70SSuleiman Souhlal int icase; /* True if I flag */ 649b50d902SRodney W. Grimes char *wfile; /* NULL if no wfile */ 659b50d902SRodney W. Grimes int wfd; /* Cached file descriptor */ 66249a8a80SPedro F. Giffuni regex_t *re; /* Regular expression */ 67d3e5e11cSDavid Malone unsigned int maxbref; /* Largest backreference. */ 689b50d902SRodney W. Grimes u_long linenum; /* Line number. */ 699b50d902SRodney W. Grimes char *new; /* Replacement text */ 709b50d902SRodney W. Grimes }; 719b50d902SRodney W. Grimes 7281a8648aSTim J. Robbins /* 7381a8648aSTim J. Robbins * Translate command. 7481a8648aSTim J. Robbins */ 7581a8648aSTim J. Robbins struct s_tr { 7681a8648aSTim J. Robbins unsigned char bytetab[256]; 7781a8648aSTim J. Robbins struct trmulti { 78d3e5e11cSDavid Malone size_t fromlen; 7981a8648aSTim J. Robbins char from[MB_LEN_MAX]; 80d3e5e11cSDavid Malone size_t tolen; 8181a8648aSTim J. Robbins char to[MB_LEN_MAX]; 8281a8648aSTim J. Robbins } *multis; 8381a8648aSTim J. Robbins int nmultis; 8481a8648aSTim J. Robbins }; 859b50d902SRodney W. Grimes 869b50d902SRodney W. Grimes /* 879b50d902SRodney W. Grimes * An internally compiled command. 88*bb0e2103SGordon Bergling * Initially, label references are stored in t, on a second pass they 899b50d902SRodney W. Grimes * are updated to pointers. 909b50d902SRodney W. Grimes */ 919b50d902SRodney W. Grimes struct s_command { 929b50d902SRodney W. Grimes struct s_command *next; /* Pointer to next command */ 939b50d902SRodney W. Grimes struct s_addr *a1, *a2; /* Start and end address */ 94f879e8d9SBrian Somers u_long startline; /* Start line number or zero */ 959b50d902SRodney W. Grimes char *t; /* Text for : a c i r w */ 969b50d902SRodney W. Grimes union { 979b50d902SRodney W. Grimes struct s_command *c; /* Command(s) for b t { */ 989b50d902SRodney W. Grimes struct s_subst *s; /* Substitute command */ 9981a8648aSTim J. Robbins struct s_tr *y; /* Replace command array */ 1009b50d902SRodney W. Grimes int fd; /* File descriptor for w */ 1019b50d902SRodney W. Grimes } u; 1029b50d902SRodney W. Grimes char code; /* Command code */ 1039b50d902SRodney W. Grimes u_int nonsel:1; /* True if ! */ 1049b50d902SRodney W. Grimes }; 1059b50d902SRodney W. Grimes 1069b50d902SRodney W. Grimes /* 1079b50d902SRodney W. Grimes * Types of command arguments recognised by the parser 1089b50d902SRodney W. Grimes */ 1099b50d902SRodney W. Grimes enum e_args { 1109b50d902SRodney W. Grimes EMPTY, /* d D g G h H l n N p P q x = \0 */ 1119b50d902SRodney W. Grimes TEXT, /* a c i */ 1129b50d902SRodney W. Grimes NONSEL, /* ! */ 1139b50d902SRodney W. Grimes GROUP, /* { */ 114ce19262dSJordan K. Hubbard ENDGROUP, /* } */ 1159b50d902SRodney W. Grimes COMMENT, /* # */ 1169b50d902SRodney W. Grimes BRANCH, /* b t */ 1179b50d902SRodney W. Grimes LABEL, /* : */ 1189b50d902SRodney W. Grimes RFILE, /* r */ 1199b50d902SRodney W. Grimes WFILE, /* w */ 1209b50d902SRodney W. Grimes SUBST, /* s */ 1219b50d902SRodney W. Grimes TR /* y */ 1229b50d902SRodney W. Grimes }; 1239b50d902SRodney W. Grimes 1249b50d902SRodney W. Grimes /* 1259b50d902SRodney W. Grimes * Structure containing things to append before a line is read 1269b50d902SRodney W. Grimes */ 1279b50d902SRodney W. Grimes struct s_appends { 1289b50d902SRodney W. Grimes enum {AP_STRING, AP_FILE} type; 1299b50d902SRodney W. Grimes char *s; 1309b50d902SRodney W. Grimes size_t len; 1319b50d902SRodney W. Grimes }; 1329b50d902SRodney W. Grimes 1339b50d902SRodney W. Grimes enum e_spflag { 1349b50d902SRodney W. Grimes APPEND, /* Append to the contents. */ 1359b50d902SRodney W. Grimes REPLACE, /* Replace the contents. */ 1369b50d902SRodney W. Grimes }; 1379b50d902SRodney W. Grimes 1389b50d902SRodney W. Grimes /* 1399b50d902SRodney W. Grimes * Structure for a space (process, hold, otherwise). 1409b50d902SRodney W. Grimes */ 1419b50d902SRodney W. Grimes typedef struct { 1429b50d902SRodney W. Grimes char *space; /* Current space pointer. */ 1439b50d902SRodney W. Grimes size_t len; /* Current length. */ 1449b50d902SRodney W. Grimes int deleted; /* If deleted. */ 14596d68291SJean-Sébastien Pédron int append_newline; /* If originally terminated by \n. */ 1469b50d902SRodney W. Grimes char *back; /* Backing memory. */ 1479b50d902SRodney W. Grimes size_t blen; /* Backing memory length. */ 1489b50d902SRodney W. Grimes } SPACE; 149