defs.h revision 1590
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 * 3. All advertising materials mentioning features or use of this software 181590Srgrimes * must display the following acknowledgement: 191590Srgrimes * This product includes software developed by the University of 201590Srgrimes * California, Berkeley and its contributors. 211590Srgrimes * 4. Neither the name of the University nor the names of its contributors 221590Srgrimes * may be used to endorse or promote products derived from this software 231590Srgrimes * without specific prior written permission. 241590Srgrimes * 251590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 261590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 331590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 341590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 351590Srgrimes * SUCH DAMAGE. 361590Srgrimes * 371590Srgrimes * @(#)defs.h 8.1 (Berkeley) 6/6/93 381590Srgrimes */ 391590Srgrimes 401590Srgrimes/* 411590Srgrimes * Types of address specifications 421590Srgrimes */ 431590Srgrimesenum e_atype { 441590Srgrimes AT_RE, /* Line that match RE */ 451590Srgrimes AT_LINE, /* Specific line */ 461590Srgrimes AT_LAST, /* Last line */ 471590Srgrimes}; 481590Srgrimes 491590Srgrimes/* 501590Srgrimes * Format of an address 511590Srgrimes */ 521590Srgrimesstruct s_addr { 531590Srgrimes enum e_atype type; /* Address type */ 541590Srgrimes union { 551590Srgrimes u_long l; /* Line number */ 561590Srgrimes regex_t *r; /* Regular expression */ 571590Srgrimes } u; 581590Srgrimes}; 591590Srgrimes 601590Srgrimes/* 611590Srgrimes * Substitution command 621590Srgrimes */ 631590Srgrimesstruct s_subst { 641590Srgrimes int n; /* Occurrence to subst. */ 651590Srgrimes int p; /* True if p flag */ 661590Srgrimes char *wfile; /* NULL if no wfile */ 671590Srgrimes int wfd; /* Cached file descriptor */ 681590Srgrimes regex_t *re; /* Regular expression */ 691590Srgrimes int maxbref; /* Largest backreference. */ 701590Srgrimes u_long linenum; /* Line number. */ 711590Srgrimes char *new; /* Replacement text */ 721590Srgrimes}; 731590Srgrimes 741590Srgrimes 751590Srgrimes/* 761590Srgrimes * An internally compiled command. 771590Srgrimes * Initialy, label references are stored in t, on a second pass they 781590Srgrimes * are updated to pointers. 791590Srgrimes */ 801590Srgrimesstruct s_command { 811590Srgrimes struct s_command *next; /* Pointer to next command */ 821590Srgrimes struct s_addr *a1, *a2; /* Start and end address */ 831590Srgrimes char *t; /* Text for : a c i r w */ 841590Srgrimes union { 851590Srgrimes struct s_command *c; /* Command(s) for b t { */ 861590Srgrimes struct s_subst *s; /* Substitute command */ 871590Srgrimes u_char *y; /* Replace command array */ 881590Srgrimes int fd; /* File descriptor for w */ 891590Srgrimes } u; 901590Srgrimes char code; /* Command code */ 911590Srgrimes u_int nonsel:1; /* True if ! */ 921590Srgrimes u_int inrange:1; /* True if in range */ 931590Srgrimes}; 941590Srgrimes 951590Srgrimes/* 961590Srgrimes * Types of command arguments recognised by the parser 971590Srgrimes */ 981590Srgrimesenum e_args { 991590Srgrimes EMPTY, /* d D g G h H l n N p P q x = \0 */ 1001590Srgrimes TEXT, /* a c i */ 1011590Srgrimes NONSEL, /* ! */ 1021590Srgrimes GROUP, /* { */ 1031590Srgrimes COMMENT, /* # */ 1041590Srgrimes BRANCH, /* b t */ 1051590Srgrimes LABEL, /* : */ 1061590Srgrimes RFILE, /* r */ 1071590Srgrimes WFILE, /* w */ 1081590Srgrimes SUBST, /* s */ 1091590Srgrimes TR /* y */ 1101590Srgrimes}; 1111590Srgrimes 1121590Srgrimes/* 1131590Srgrimes * Structure containing things to append before a line is read 1141590Srgrimes */ 1151590Srgrimesstruct s_appends { 1161590Srgrimes enum {AP_STRING, AP_FILE} type; 1171590Srgrimes char *s; 1181590Srgrimes size_t len; 1191590Srgrimes}; 1201590Srgrimes 1211590Srgrimesenum e_spflag { 1221590Srgrimes APPEND, /* Append to the contents. */ 1231590Srgrimes REPLACE, /* Replace the contents. */ 1241590Srgrimes}; 1251590Srgrimes 1261590Srgrimes/* 1271590Srgrimes * Structure for a space (process, hold, otherwise). 1281590Srgrimes */ 1291590Srgrimestypedef struct { 1301590Srgrimes char *space; /* Current space pointer. */ 1311590Srgrimes size_t len; /* Current length. */ 1321590Srgrimes int deleted; /* If deleted. */ 1331590Srgrimes char *back; /* Backing memory. */ 1341590Srgrimes size_t blen; /* Backing memory length. */ 1351590Srgrimes} SPACE; 1361590Srgrimes 1371590Srgrimes/* 1381590Srgrimes * Error severity codes: 1391590Srgrimes */ 1401590Srgrimes#define FATAL 0 /* Exit immediately with 1 */ 1411590Srgrimes#define ERROR 1 /* Continue, but change exit value */ 1421590Srgrimes#define WARNING 2 /* Just print the warning */ 1431590Srgrimes#define COMPILE 3 /* Print error, count and finish script */ 1441590Srgrimes#define COMPILE2 3 /* Print error, count and finish script */ 145