defs.h revision 1.7 1 /* $NetBSD: defs.h,v 1.7 1997/01/09 20:21:28 tls Exp $ */
2
3 /*-
4 * Copyright (c) 1992 Diomidis Spinellis.
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Diomidis Spinellis of Imperial College, University of London.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * from: @(#)defs.h 8.1 (Berkeley) 6/6/93
40 * $NetBSD: defs.h,v 1.7 1997/01/09 20:21:28 tls Exp $
41 */
42
43 /*
44 * Types of address specifications
45 */
46 enum e_atype {
47 AT_RE, /* Line that match RE */
48 AT_LINE, /* Specific line */
49 AT_LAST, /* Last line */
50 };
51
52 /*
53 * Format of an address
54 */
55 struct s_addr {
56 enum e_atype type; /* Address type */
57 union {
58 u_long l; /* Line number */
59 regex_t *r; /* Regular expression */
60 } u;
61 };
62
63 /*
64 * Substitution command
65 */
66 struct s_subst {
67 int n; /* Occurrence to subst. */
68 int p; /* True if p flag */
69 char *wfile; /* NULL if no wfile */
70 int wfd; /* Cached file descriptor */
71 regex_t *re; /* Regular expression */
72 int maxbref; /* Largest backreference. */
73 u_long linenum; /* Line number. */
74 char *new; /* Replacement text */
75 };
76
77
78 /*
79 * An internally compiled command.
80 * Initialy, label references are stored in t, on a second pass they
81 * are updated to pointers.
82 */
83 struct s_command {
84 struct s_command *next; /* Pointer to next command */
85 struct s_addr *a1, *a2; /* Start and end address */
86 char *t; /* Text for : a c i r w */
87 union {
88 struct s_command *c; /* Command(s) for b t { */
89 struct s_subst *s; /* Substitute command */
90 u_char *y; /* Replace command array */
91 int fd; /* File descriptor for w */
92 } u;
93 char code; /* Command code */
94 u_int nonsel:1; /* True if ! */
95 u_int inrange:1; /* True if in range */
96 };
97
98 /*
99 * Types of command arguments recognised by the parser
100 */
101 enum e_args {
102 EMPTY, /* d D g G h H l n N p P q x = \0 */
103 TEXT, /* a c i */
104 NONSEL, /* ! */
105 GROUP, /* { */
106 ENDGROUP, /* } */
107 COMMENT, /* # */
108 BRANCH, /* b t */
109 LABEL, /* : */
110 RFILE, /* r */
111 WFILE, /* w */
112 SUBST, /* s */
113 TR /* y */
114 };
115
116 /*
117 * Structure containing things to append before a line is read
118 */
119 struct s_appends {
120 enum {AP_STRING, AP_FILE} type;
121 char *s;
122 size_t len;
123 };
124
125 enum e_spflag {
126 APPEND, /* Append to the contents. */
127 REPLACE, /* Replace the contents. */
128 };
129
130 /*
131 * Structure for a space (process, hold, otherwise).
132 */
133 typedef struct {
134 char *space; /* Current space pointer. */
135 size_t len; /* Current length. */
136 int deleted; /* If deleted. */
137 char *back; /* Backing memory. */
138 size_t blen; /* Backing memory length. */
139 } SPACE;
140
141 /*
142 * Error severity codes:
143 */
144 #define FATAL 0 /* Exit immediately with 1 */
145 #define ERROR 1 /* Continue, but change exit value */
146 #define WARNING 2 /* Just print the warning */
147 #define COMPILE 3 /* Print error, count and finish script */
148 #define COMPILE2 3 /* Print error, count and finish script */
149