xref: /csrg-svn/usr.bin/sed/defs.h (revision 56019)
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.2 (Berkeley) 08/24/92
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 	regmatch_t *pmatch;			/* Array of match strucs */
44 	int maxbref;				/* Largest backreference. */
45 	u_long linenum;				/* Line number. */
46 	char *new;				/* Replacement text */
47 };
48 
49 
50 /*
51  * An internally compiled command.
52  * Initialy, label references are stored in u.t, on a second pass they
53  * are updated to pointers.
54  */
55 struct s_command {
56 	struct s_command *next;			/* Pointer to next command */
57 	struct s_addr *a1, *a2;			/* Start and end address */
58 	char *t;				/* Text for : a c i r w */
59 	union {
60 		struct s_command *c;		/* Command(s) for b t { */
61 		struct s_subst *s;		/* Substitute command */
62 		u_char *y;			/* Replace command array */
63 		int fd;				/* File descriptor for w */
64 	} u;
65 	char code;				/* Command code */
66 	u_int nonsel:1;				/* True if ! */
67 	u_int inrange:1;			/* True if in range */
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 };
94 
95 /*
96  * Error severity codes:
97  */
98 #define	FATAL		0	/* Exit immediately with 1 */
99 #define	ERROR		1	/* Continue, but change exit value */
100 #define	WARNING		2	/* Just print the warning */
101 #define	COMPILE		3	/* Print error, count and finish script */
102 #define	COMPILE2	3	/* Print error, count and finish script */
103