xref: /csrg-svn/usr.bin/sed/defs.h (revision 56075)
155993Sbostic /*-
255993Sbostic  * Copyright (c) 1992 Diomidis Spinellis.
355993Sbostic  * Copyright (c) 1992 The Regents of the University of California.
455993Sbostic  * All rights reserved.
555993Sbostic  *
655993Sbostic  * This code is derived from software contributed to Berkeley by
755993Sbostic  * Diomidis Spinellis of Imperial College, University of London.
855993Sbostic  *
955993Sbostic  * %sccs.include.redist.c%
1055993Sbostic  *
11*56075Sbostic  *	@(#)defs.h	5.3 (Berkeley) 08/28/92
1255993Sbostic  */
1355993Sbostic 
1455993Sbostic /*
1555993Sbostic  * Types of address specifications
1655993Sbostic  */
1755993Sbostic enum e_atype {
1855993Sbostic 	AT_RE,					/* Line that match RE */
1955993Sbostic 	AT_LINE,				/* Specific line */
2055993Sbostic 	AT_LAST,				/* Last line */
2155993Sbostic };
2255993Sbostic 
2355993Sbostic /*
2455993Sbostic  * Format of an address
2555993Sbostic  */
2655993Sbostic struct s_addr {
2755993Sbostic 	enum e_atype type;			/* Address type */
2855993Sbostic 	union {
2955993Sbostic 		u_long l;			/* Line number */
3055993Sbostic 		regex_t *r;			/* Regular expression */
3155993Sbostic 	} u;
3255993Sbostic };
3355993Sbostic 
3455993Sbostic /*
3555993Sbostic  * Substitution command
3655993Sbostic  */
3755993Sbostic struct s_subst {
3856019Sbostic 	int n;					/* Occurrence to subst. */
3955993Sbostic 	int p;					/* True if p flag */
4055993Sbostic 	char *wfile;				/* NULL if no wfile */
4155993Sbostic 	int wfd;				/* Cached file descriptor */
4256019Sbostic 	regex_t *re;				/* Regular expression */
4356019Sbostic 	int maxbref;				/* Largest backreference. */
4456019Sbostic 	u_long linenum;				/* Line number. */
4555993Sbostic 	char *new;				/* Replacement text */
4655993Sbostic };
4755993Sbostic 
4855993Sbostic 
4955993Sbostic /*
5055993Sbostic  * An internally compiled command.
5155993Sbostic  * Initialy, label references are stored in u.t, on a second pass they
5255993Sbostic  * are updated to pointers.
5355993Sbostic  */
5455993Sbostic struct s_command {
5555993Sbostic 	struct s_command *next;			/* Pointer to next command */
5655993Sbostic 	struct s_addr *a1, *a2;			/* Start and end address */
5755993Sbostic 	char *t;				/* Text for : a c i r w */
5855993Sbostic 	union {
5955993Sbostic 		struct s_command *c;		/* Command(s) for b t { */
6055993Sbostic 		struct s_subst *s;		/* Substitute command */
6155993Sbostic 		u_char *y;			/* Replace command array */
6255993Sbostic 		int fd;				/* File descriptor for w */
6355993Sbostic 	} u;
6455993Sbostic 	char code;				/* Command code */
6555993Sbostic 	u_int nonsel:1;				/* True if ! */
6655993Sbostic 	u_int inrange:1;			/* True if in range */
6755993Sbostic };
6855993Sbostic 
6955993Sbostic /*
7055993Sbostic  * Types of command arguments recognised by the parser
7155993Sbostic  */
7255993Sbostic enum e_args {
7355993Sbostic 	EMPTY,			/* d D g G h H l n N p P q x = \0 */
7455993Sbostic 	TEXT,			/* a c i */
7555993Sbostic 	NONSEL,			/* ! */
7655993Sbostic 	GROUP,			/* { */
7755993Sbostic 	COMMENT,		/* # */
7855993Sbostic 	BRANCH,			/* b t */
7955993Sbostic 	LABEL,			/* : */
8055993Sbostic 	RFILE,			/* r */
8155993Sbostic 	WFILE,			/* w */
8255993Sbostic 	SUBST,			/* s */
8355993Sbostic 	TR			/* y */
8455993Sbostic };
8555993Sbostic 
8655993Sbostic /*
8755993Sbostic  * Structure containing things to append before a line is read
8855993Sbostic  */
8955993Sbostic struct s_appends {
9055993Sbostic 	enum {AP_STRING, AP_FILE} type;
9155993Sbostic 	char *s;
9255993Sbostic };
9355993Sbostic 
94*56075Sbostic enum e_spflag {
95*56075Sbostic 	APPEND,					/* Append to the contents. */
96*56075Sbostic 	APPENDNL,				/* Append, with newline. */
97*56075Sbostic 	REPLACE,				/* Replace the contents. */
98*56075Sbostic };
99*56075Sbostic 
10055993Sbostic /*
101*56075Sbostic  * Structure for a space (process, hold, otherwise).
102*56075Sbostic  */
103*56075Sbostic typedef struct {
104*56075Sbostic 	char *space;		/* Current space pointer. */
105*56075Sbostic 	size_t len;		/* Current length. */
106*56075Sbostic 	int deleted;		/* If deleted. */
107*56075Sbostic 	char *back;		/* Backing memory. */
108*56075Sbostic 	size_t blen;		/* Backing memory length. */
109*56075Sbostic } SPACE;
110*56075Sbostic 
111*56075Sbostic /*
11255993Sbostic  * Error severity codes:
11355993Sbostic  */
11455993Sbostic #define	FATAL		0	/* Exit immediately with 1 */
11555993Sbostic #define	ERROR		1	/* Continue, but change exit value */
11655993Sbostic #define	WARNING		2	/* Just print the warning */
11755993Sbostic #define	COMPILE		3	/* Print error, count and finish script */
11855993Sbostic #define	COMPILE2	3	/* Print error, count and finish script */
119