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