xref: /original-bsd/usr.bin/sed/defs.h (revision c3e32dec)
1 /*-
2  * Copyright (c) 1992 Diomidis Spinellis.
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  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	8.1 (Berkeley) 06/06/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 };
68 
69 /*
70  * Types of command arguments recognised by the parser
71  */
72 enum e_args {
73 	EMPTY,			/* d D g G h H l n N p P q x = \0 */
74 	TEXT,			/* a c i */
75 	NONSEL,			/* ! */
76 	GROUP,			/* { */
77 	COMMENT,		/* # */
78 	BRANCH,			/* b t */
79 	LABEL,			/* : */
80 	RFILE,			/* r */
81 	WFILE,			/* w */
82 	SUBST,			/* s */
83 	TR			/* y */
84 };
85 
86 /*
87  * Structure containing things to append before a line is read
88  */
89 struct s_appends {
90 	enum {AP_STRING, AP_FILE} type;
91 	char *s;
92 	size_t len;
93 };
94 
95 enum e_spflag {
96 	APPEND,					/* Append to the contents. */
97 	REPLACE,				/* Replace the contents. */
98 };
99 
100 /*
101  * Structure for a space (process, hold, otherwise).
102  */
103 typedef struct {
104 	char *space;		/* Current space pointer. */
105 	size_t len;		/* Current length. */
106 	int deleted;		/* If deleted. */
107 	char *back;		/* Backing memory. */
108 	size_t blen;		/* Backing memory length. */
109 } SPACE;
110 
111 /*
112  * Error severity codes:
113  */
114 #define	FATAL		0	/* Exit immediately with 1 */
115 #define	ERROR		1	/* Continue, but change exit value */
116 #define	WARNING		2	/* Just print the warning */
117 #define	COMPILE		3	/* Print error, count and finish script */
118 #define	COMPILE2	3	/* Print error, count and finish script */
119