11590Srgrimes/*- 21590Srgrimes * Copyright (c) 1992 Diomidis Spinellis. 31590Srgrimes * Copyright (c) 1992, 1993 41590Srgrimes * The Regents of the University of California. All rights reserved. 51590Srgrimes * 61590Srgrimes * This code is derived from software contributed to Berkeley by 71590Srgrimes * Diomidis Spinellis of Imperial College, University of London. 81590Srgrimes * 91590Srgrimes * Redistribution and use in source and binary forms, with or without 101590Srgrimes * modification, are permitted provided that the following conditions 111590Srgrimes * are met: 121590Srgrimes * 1. Redistributions of source code must retain the above copyright 131590Srgrimes * notice, this list of conditions and the following disclaimer. 141590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151590Srgrimes * notice, this list of conditions and the following disclaimer in the 161590Srgrimes * documentation and/or other materials provided with the distribution. 171590Srgrimes * 4. Neither the name of the University nor the names of its contributors 181590Srgrimes * may be used to endorse or promote products derived from this software 191590Srgrimes * without specific prior written permission. 201590Srgrimes * 211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311590Srgrimes * SUCH DAMAGE. 321590Srgrimes * 331590Srgrimes * @(#)defs.h 8.1 (Berkeley) 6/6/93 34132145Stjr * $FreeBSD$ 351590Srgrimes */ 361590Srgrimes 371590Srgrimes/* 381590Srgrimes * Types of address specifications 391590Srgrimes */ 401590Srgrimesenum e_atype { 41192732Sbrian AT_RE = 1, /* Line that match RE */ 421590Srgrimes AT_LINE, /* Specific line */ 43192732Sbrian AT_RELLINE, /* Relative line */ 441590Srgrimes AT_LAST, /* Last line */ 451590Srgrimes}; 461590Srgrimes 471590Srgrimes/* 481590Srgrimes * Format of an address 491590Srgrimes */ 501590Srgrimesstruct s_addr { 511590Srgrimes enum e_atype type; /* Address type */ 521590Srgrimes union { 531590Srgrimes u_long l; /* Line number */ 541590Srgrimes regex_t *r; /* Regular expression */ 551590Srgrimes } u; 561590Srgrimes}; 571590Srgrimes 581590Srgrimes/* 591590Srgrimes * Substitution command 601590Srgrimes */ 611590Srgrimesstruct s_subst { 621590Srgrimes int n; /* Occurrence to subst. */ 631590Srgrimes int p; /* True if p flag */ 64171206Sssouhlal int icase; /* True if I flag */ 651590Srgrimes char *wfile; /* NULL if no wfile */ 661590Srgrimes int wfd; /* Cached file descriptor */ 671590Srgrimes regex_t *re; /* Regular expression */ 68176126Sdwmalone unsigned int maxbref; /* Largest backreference. */ 691590Srgrimes u_long linenum; /* Line number. */ 701590Srgrimes char *new; /* Replacement text */ 711590Srgrimes}; 721590Srgrimes 73132145Stjr/* 74132145Stjr * Translate command. 75132145Stjr */ 76132145Stjrstruct s_tr { 77132145Stjr unsigned char bytetab[256]; 78132145Stjr struct trmulti { 79176126Sdwmalone size_t fromlen; 80132145Stjr char from[MB_LEN_MAX]; 81176126Sdwmalone size_t tolen; 82132145Stjr char to[MB_LEN_MAX]; 83132145Stjr } *multis; 84132145Stjr int nmultis; 85132145Stjr}; 861590Srgrimes 871590Srgrimes/* 881590Srgrimes * An internally compiled command. 891590Srgrimes * Initialy, label references are stored in t, on a second pass they 901590Srgrimes * are updated to pointers. 911590Srgrimes */ 921590Srgrimesstruct s_command { 931590Srgrimes struct s_command *next; /* Pointer to next command */ 941590Srgrimes struct s_addr *a1, *a2; /* Start and end address */ 95192732Sbrian u_long startline; /* Start line number or zero */ 961590Srgrimes char *t; /* Text for : a c i r w */ 971590Srgrimes union { 981590Srgrimes struct s_command *c; /* Command(s) for b t { */ 991590Srgrimes struct s_subst *s; /* Substitute command */ 100132145Stjr struct s_tr *y; /* Replace command array */ 1011590Srgrimes int fd; /* File descriptor for w */ 1021590Srgrimes } u; 1031590Srgrimes char code; /* Command code */ 1041590Srgrimes u_int nonsel:1; /* True if ! */ 1051590Srgrimes}; 1061590Srgrimes 1071590Srgrimes/* 1081590Srgrimes * Types of command arguments recognised by the parser 1091590Srgrimes */ 1101590Srgrimesenum e_args { 1111590Srgrimes EMPTY, /* d D g G h H l n N p P q x = \0 */ 1121590Srgrimes TEXT, /* a c i */ 1131590Srgrimes NONSEL, /* ! */ 1141590Srgrimes GROUP, /* { */ 11510075Sjkh ENDGROUP, /* } */ 1161590Srgrimes COMMENT, /* # */ 1171590Srgrimes BRANCH, /* b t */ 1181590Srgrimes LABEL, /* : */ 1191590Srgrimes RFILE, /* r */ 1201590Srgrimes WFILE, /* w */ 1211590Srgrimes SUBST, /* s */ 1221590Srgrimes TR /* y */ 1231590Srgrimes}; 1241590Srgrimes 1251590Srgrimes/* 1261590Srgrimes * Structure containing things to append before a line is read 1271590Srgrimes */ 1281590Srgrimesstruct s_appends { 1291590Srgrimes enum {AP_STRING, AP_FILE} type; 1301590Srgrimes char *s; 1311590Srgrimes size_t len; 1321590Srgrimes}; 1331590Srgrimes 1341590Srgrimesenum e_spflag { 1351590Srgrimes APPEND, /* Append to the contents. */ 1361590Srgrimes REPLACE, /* Replace the contents. */ 1371590Srgrimes}; 1381590Srgrimes 1391590Srgrimes/* 1401590Srgrimes * Structure for a space (process, hold, otherwise). 1411590Srgrimes */ 1421590Srgrimestypedef struct { 1431590Srgrimes char *space; /* Current space pointer. */ 1441590Srgrimes size_t len; /* Current length. */ 1451590Srgrimes int deleted; /* If deleted. */ 146269729Sdumbbell int append_newline; /* If originally terminated by \n. */ 1471590Srgrimes char *back; /* Backing memory. */ 1481590Srgrimes size_t blen; /* Backing memory length. */ 1491590Srgrimes} SPACE; 150