defs.h revision 132145
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
38132145Stjr * $FreeBSD: head/usr.bin/sed/defs.h 132145 2004-07-14 10:06:22Z tjr $
391590Srgrimes */
401590Srgrimes
411590Srgrimes/*
421590Srgrimes * Types of address specifications
431590Srgrimes */
441590Srgrimesenum e_atype {
451590Srgrimes	AT_RE,					/* Line that match RE */
461590Srgrimes	AT_LINE,				/* Specific line */
471590Srgrimes	AT_LAST,				/* Last line */
481590Srgrimes};
491590Srgrimes
501590Srgrimes/*
511590Srgrimes * Format of an address
521590Srgrimes */
531590Srgrimesstruct s_addr {
541590Srgrimes	enum e_atype type;			/* Address type */
551590Srgrimes	union {
561590Srgrimes		u_long l;			/* Line number */
571590Srgrimes		regex_t *r;			/* Regular expression */
581590Srgrimes	} u;
591590Srgrimes};
601590Srgrimes
611590Srgrimes/*
621590Srgrimes * Substitution command
631590Srgrimes */
641590Srgrimesstruct s_subst {
651590Srgrimes	int n;					/* Occurrence to subst. */
661590Srgrimes	int p;					/* True if p flag */
671590Srgrimes	char *wfile;				/* NULL if no wfile */
681590Srgrimes	int wfd;				/* Cached file descriptor */
691590Srgrimes	regex_t *re;				/* Regular expression */
701590Srgrimes	int maxbref;				/* Largest backreference. */
711590Srgrimes	u_long linenum;				/* Line number. */
721590Srgrimes	char *new;				/* Replacement text */
731590Srgrimes};
741590Srgrimes
75132145Stjr/*
76132145Stjr * Translate command.
77132145Stjr */
78132145Stjrstruct s_tr {
79132145Stjr	unsigned char bytetab[256];
80132145Stjr	struct trmulti {
81132145Stjr		int fromlen;
82132145Stjr		char from[MB_LEN_MAX];
83132145Stjr		int tolen;
84132145Stjr		char to[MB_LEN_MAX];
85132145Stjr	} *multis;
86132145Stjr	int nmultis;
87132145Stjr};
881590Srgrimes
891590Srgrimes/*
901590Srgrimes * An internally compiled command.
911590Srgrimes * Initialy, label references are stored in t, on a second pass they
921590Srgrimes * are updated to pointers.
931590Srgrimes */
941590Srgrimesstruct s_command {
951590Srgrimes	struct s_command *next;			/* Pointer to next command */
961590Srgrimes	struct s_addr *a1, *a2;			/* Start and end address */
971590Srgrimes	char *t;				/* Text for : a c i r w */
981590Srgrimes	union {
991590Srgrimes		struct s_command *c;		/* Command(s) for b t { */
1001590Srgrimes		struct s_subst *s;		/* Substitute command */
101132145Stjr		struct s_tr *y;			/* Replace command array */
1021590Srgrimes		int fd;				/* File descriptor for w */
1031590Srgrimes	} u;
1041590Srgrimes	char code;				/* Command code */
1051590Srgrimes	u_int nonsel:1;				/* True if ! */
1061590Srgrimes	u_int inrange:1;			/* True if in range */
1071590Srgrimes};
1081590Srgrimes
1091590Srgrimes/*
1101590Srgrimes * Types of command arguments recognised by the parser
1111590Srgrimes */
1121590Srgrimesenum e_args {
1131590Srgrimes	EMPTY,			/* d D g G h H l n N p P q x = \0 */
1141590Srgrimes	TEXT,			/* a c i */
1151590Srgrimes	NONSEL,			/* ! */
1161590Srgrimes	GROUP,			/* { */
11710075Sjkh	ENDGROUP,		/* } */
1181590Srgrimes	COMMENT,		/* # */
1191590Srgrimes	BRANCH,			/* b t */
1201590Srgrimes	LABEL,			/* : */
1211590Srgrimes	RFILE,			/* r */
1221590Srgrimes	WFILE,			/* w */
1231590Srgrimes	SUBST,			/* s */
1241590Srgrimes	TR			/* y */
1251590Srgrimes};
1261590Srgrimes
1271590Srgrimes/*
1281590Srgrimes * Structure containing things to append before a line is read
1291590Srgrimes */
1301590Srgrimesstruct s_appends {
1311590Srgrimes	enum {AP_STRING, AP_FILE} type;
1321590Srgrimes	char *s;
1331590Srgrimes	size_t len;
1341590Srgrimes};
1351590Srgrimes
1361590Srgrimesenum e_spflag {
1371590Srgrimes	APPEND,					/* Append to the contents. */
1381590Srgrimes	REPLACE,				/* Replace the contents. */
1391590Srgrimes};
1401590Srgrimes
1411590Srgrimes/*
1421590Srgrimes * Structure for a space (process, hold, otherwise).
1431590Srgrimes */
1441590Srgrimestypedef struct {
1451590Srgrimes	char *space;		/* Current space pointer. */
1461590Srgrimes	size_t len;		/* Current length. */
1471590Srgrimes	int deleted;		/* If deleted. */
1481590Srgrimes	char *back;		/* Backing memory. */
1491590Srgrimes	size_t blen;		/* Backing memory length. */
1501590Srgrimes} SPACE;
151