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