xref: /csrg-svn/usr.bin/sed/defs.h (revision 59073)
1 /*-
2  * Copyright (c) 1992 Diomidis Spinellis.
3  * Copyright (c) 1992 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Diomidis Spinellis of Imperial College, University of London.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)defs.h	5.4 (Berkeley) 04/14/93
12  */
13 
14 /*
15  * Types of address specifications
16  */
17 enum e_atype {
18 	AT_RE,					/* Line that match RE */
19 	AT_LINE,				/* Specific line */
20 	AT_LAST,				/* Last line */
21 };
22 
23 /*
24  * Format of an address
25  */
26 struct s_addr {
27 	enum e_atype type;			/* Address type */
28 	union {
29 		u_long l;			/* Line number */
30 		regex_t *r;			/* Regular expression */
31 	} u;
32 };
33 
34 /*
35  * Substitution command
36  */
37 struct s_subst {
38 	int n;					/* Occurrence to subst. */
39 	int p;					/* True if p flag */
40 	char *wfile;				/* NULL if no wfile */
41 	int wfd;				/* Cached file descriptor */
42 	regex_t *re;				/* Regular expression */
43 	int maxbref;				/* Largest backreference. */
44 	u_long linenum;				/* Line number. */
45 	char *new;				/* Replacement text */
46 };
47 
48 
49 /*
50  * An internally compiled command.
51  * Initialy, label references are stored in t, on a second pass they
52  * are updated to pointers.
53  */
54 struct s_command {
55 	struct s_command *next;			/* Pointer to next command */
56 	struct s_addr *a1, *a2;			/* Start and end address */
57 	char *t;				/* Text for : a c i r w */
58 	union {
59 		struct s_command *c;		/* Command(s) for b t { */
60 		struct s_subst *s;		/* Substitute command */
61 		u_char *y;			/* Replace command array */
62 		int fd;				/* File descriptor for w */
63 	} u;
64 	char code;				/* Command code */
65 	u_int nonsel:1;				/* True if ! */
66 	u_int inrange:1;			/* True if in range */
67 	u_int lused:1;				/* True if label used. */
68 };
69 
70 /*
71  * Types of command arguments recognised by the parser
72  */
73 enum e_args {
74 	EMPTY,			/* d D g G h H l n N p P q x = \0 */
75 	TEXT,			/* a c i */
76 	NONSEL,			/* ! */
77 	GROUP,			/* { */
78 	COMMENT,		/* # */
79 	BRANCH,			/* b t */
80 	LABEL,			/* : */
81 	RFILE,			/* r */
82 	WFILE,			/* w */
83 	SUBST,			/* s */
84 	TR			/* y */
85 };
86 
87 /*
88  * Structure containing things to append before a line is read
89  */
90 struct s_appends {
91 	enum {AP_STRING, AP_FILE} type;
92 	char *s;
93 	size_t len;
94 };
95 
96 enum e_spflag {
97 	APPEND,					/* Append to the contents. */
98 	REPLACE,				/* Replace the contents. */
99 };
100 
101 /*
102  * Structure for a space (process, hold, otherwise).
103  */
104 typedef struct {
105 	char *space;		/* Current space pointer. */
106 	size_t len;		/* Current length. */
107 	int deleted;		/* If deleted. */
108 	char *back;		/* Backing memory. */
109 	size_t blen;		/* Backing memory length. */
110 } SPACE;
111 
112 /*
113  * Error severity codes:
114  */
115 #define	FATAL		0	/* Exit immediately with 1 */
116 #define	ERROR		1	/* Continue, but change exit value */
117 #define	WARNING		2	/* Just print the warning */
118 #define	COMPILE		3	/* Print error, count and finish script */
119 #define	COMPILE2	3	/* Print error, count and finish script */
120