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