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