1 /* ed.h: type and constant definitions for the ed editor. */
3 * Copyright (c) 1993 Andrew Moore
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * @(#)ed.h,v 1.5 1994/02/01 00:34:39 alm Exp
28 * $FreeBSD: src/bin/ed/ed.h,v 1.13.2.1 2001/08/01 02:36:03 obrien Exp $
31 #include <sys/param.h>
45 #define MINBUFSZ 512 /* minimum buffer size - must be > 0 */
46 #define SE_MAX 30 /* max subexpressions in a regular expression */
48 # define LINECHARS INT_MAX /* max chars per line */
50 # define LINECHARS MAXINT /* max chars per line */
54 #define GLB 001 /* global command */
55 #define GPR 002 /* print after command */
56 #define GLS 004 /* list after command */
57 #define GNP 010 /* enumerate after command */
58 #define GSG 020 /* global substitute */
60 typedef regex_t pattern_t;
66 off_t seek; /* address of line in scratch buffer */
67 int len; /* length of line */
73 /* type of undo nodes */
79 int type; /* command type */
80 line_t *h; /* head of list */
81 line_t *t; /* tail of list */
85 # define max(a,b) ((a) > (b) ? (a) : (b))
88 # define min(a,b) ((a) < (b) ? (a) : (b))
91 #define INC_MOD(l, k) ((l) + 1 > (k) ? 0 : (l) + 1)
92 #define DEC_MOD(l, k) ((l) - 1 < 0 ? (k) : (l) - 1)
94 /* SPL1: disable some interrupts (requires reliable signals) */
95 #define SPL1() mutex++
97 /* SPL0: enable all interrupts; check sigflags (requires reliable signals) */
100 if (sigflags & (1 << (SIGHUP - 1))) handle_hup(SIGHUP); \
101 if (sigflags & (1 << (SIGINT - 1))) handle_int(SIGINT); \
104 /* STRTOL: convert a string to long */
105 #define STRTOL(i, p) { \
106 if (((i = strtol(p, &p, 10)) == LONG_MIN || i == LONG_MAX) && \
108 sprintf(errmsg, "number out of range"); \
114 #if defined(sun) || defined(NO_REALLOC_NULL)
115 /* REALLOC: assure at least a minimum size for buffer b */
116 #define REALLOC(b,n,i,err) \
122 if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
123 fprintf(stderr, "%s\n", strerror(errno)); \
124 sprintf(errmsg, "out of memory"); \
129 if ((ts = (char *) malloc(ti += max((i), MINBUFSZ))) == NULL) { \
130 fprintf(stderr, "%s\n", strerror(errno)); \
131 sprintf(errmsg, "out of memory"); \
140 #else /* NO_REALLOC_NULL */
141 /* REALLOC: assure at least a minimum size for buffer b */
142 #define REALLOC(b,n,i,err) \
147 if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
148 fprintf(stderr, "%s\n", strerror(errno)); \
149 sprintf(errmsg, "out of memory"); \
157 #endif /* NO_REALLOC_NULL */
159 /* REQUE: link pred before succ */
160 #define REQUE(pred, succ) (pred)->q_forw = (succ), (succ)->q_back = (pred)
162 /* INSQUE: insert elem in circular queue after pred */
163 #define INSQUE(elem, pred) \
165 REQUE((elem), (pred)->q_forw); \
166 REQUE((pred), elem); \
169 /* REMQUE: remove_lines elem from circular queue */
170 #define REMQUE(elem) REQUE((elem)->q_back, (elem)->q_forw);
172 /* NUL_TO_NEWLINE: overwrite ASCII NULs with newlines */
173 #define NUL_TO_NEWLINE(s, l) translit_text(s, l, '\0', '\n')
175 /* NEWLINE_TO_NUL: overwrite newlines with ASCII NULs */
176 #define NEWLINE_TO_NUL(s, l) translit_text(s, l, '\n', '\0')
179 # define strerror(n) sys_errlist[n]
184 # define __P(proto) ()
186 # define __P(proto) proto
190 /* Local Function Declarations */
191 void add_line_node __P((line_t *));
192 int append_lines __P((long));
193 int apply_subst_template __P((char *, regmatch_t *, int, int));
194 int build_active_list __P((int));
195 int cbc_decode __P((char *, FILE *));
196 int cbc_encode __P((char *, int, FILE *));
197 int check_addr_range __P((long, long));
198 void clear_active_list __P((void));
199 void clear_undo_stack __P((void));
200 int close_sbuf __P((void));
201 int copy_lines __P((long));
202 int delete_lines __P((long, long));
203 void des_error __P((char *));
204 int display_lines __P((long, long, int));
205 line_t *dup_line_node __P((line_t *));
206 int exec_command __P((void));
207 long exec_global __P((int, int));
208 void expand_des_key __P((char *, char *));
209 int extract_addr_range __P((void));
210 char *extract_pattern __P((int));
211 int extract_subst_tail __P((int *, long *));
212 char *extract_subst_template __P((void));
213 int filter_lines __P((long, long, char *));
214 int flush_des_file __P((FILE *));
215 line_t *get_addressed_line_node __P((long));
216 pattern_t *get_compiled_pattern __P((void));
217 int get_des_char __P((FILE *));
218 char *get_extended_line __P((int *, int));
219 char *get_filename __P((void));
220 int get_keyword __P((void));
221 long get_line_node_addr __P((line_t *));
222 long get_matching_node_addr __P((pattern_t *, int));
223 long get_marked_node_addr __P((int));
224 char *get_sbuf_line __P((line_t *));
225 int get_shell_command __P((void));
226 int get_stream_line __P((FILE *));
227 int get_tty_line __P((void));
228 void handle_hup __P((int));
229 void handle_int __P((int));
230 void handle_winch __P((int));
231 int has_trailing_escape __P((char *, char *));
232 int hex_to_binary __P((int, int));
233 void init_buffers __P((void));
234 void init_des_cipher __P((void));
235 int is_legal_filename __P((char *));
236 int join_lines __P((long, long));
237 int mark_line_node __P((line_t *, int));
238 int move_lines __P((long));
239 line_t *next_active_node __P(());
240 long next_addr __P((void));
241 int open_sbuf __P((void));
242 char *parse_char_class __P((char *));
243 int pop_undo_stack __P((void));
244 undo_t *push_undo_stack __P((int, long, long));
245 int put_des_char __P((int, FILE *));
246 char *put_sbuf_line __P((char *));
247 int put_stream_line __P((FILE *, char *, int));
248 int put_tty_line __P((char *, int, long, int));
249 void quit __P((int));
250 long read_file __P((char *, long));
251 long read_stream __P((FILE *, long));
252 int search_and_replace __P((pattern_t *, int, int));
253 int set_active_node __P((line_t *));
254 void set_des_key __P((char *));
255 void signal_hup __P((int));
256 void signal_int __P((int));
257 char *strip_escapes __P((char *));
258 int substitute_matching_text __P((pattern_t *, line_t *, int, int));
259 char *translit_text __P((char *, int, int, int));
260 void unmark_line_node __P((line_t *));
261 void unset_active_nodes __P((line_t *, line_t *));
262 long write_file __P((char *, char *, long, long));
263 long write_stream __P((FILE *, long, long));
266 extern char stdinbuf[];
279 extern long addr_last;
280 extern long current_addr;
281 extern char errmsg[];
282 extern long first_addr;
284 extern long second_addr;
286 extern char *sys_errlist[];