defs.h revision 1.5 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.5 cgd * from: @(#)defs.h 8.1 (Berkeley) 6/6/93
38 1.5 cgd * $Id: defs.h,v 1.5 1994/02/03 23:44:51 cgd Exp $
39 1.1 alm */
40 1.1 alm
41 1.1 alm /*
42 1.1 alm * Types of address specifications
43 1.1 alm */
44 1.1 alm enum e_atype {
45 1.1 alm AT_RE, /* Line that match RE */
46 1.1 alm AT_LINE, /* Specific line */
47 1.1 alm AT_LAST, /* Last line */
48 1.1 alm };
49 1.1 alm
50 1.1 alm /*
51 1.1 alm * Format of an address
52 1.1 alm */
53 1.1 alm struct s_addr {
54 1.1 alm enum e_atype type; /* Address type */
55 1.1 alm union {
56 1.1 alm u_long l; /* Line number */
57 1.1 alm regex_t *r; /* Regular expression */
58 1.1 alm } u;
59 1.1 alm };
60 1.1 alm
61 1.1 alm /*
62 1.1 alm * Substitution command
63 1.1 alm */
64 1.1 alm struct s_subst {
65 1.1 alm int n; /* Occurrence to subst. */
66 1.1 alm int p; /* True if p flag */
67 1.1 alm char *wfile; /* NULL if no wfile */
68 1.1 alm int wfd; /* Cached file descriptor */
69 1.1 alm regex_t *re; /* Regular expression */
70 1.1 alm int maxbref; /* Largest backreference. */
71 1.1 alm u_long linenum; /* Line number. */
72 1.1 alm char *new; /* Replacement text */
73 1.1 alm };
74 1.1 alm
75 1.1 alm
76 1.1 alm /*
77 1.1 alm * An internally compiled command.
78 1.4 cgd * Initialy, label references are stored in t, on a second pass they
79 1.1 alm * are updated to pointers.
80 1.1 alm */
81 1.1 alm struct s_command {
82 1.1 alm struct s_command *next; /* Pointer to next command */
83 1.1 alm struct s_addr *a1, *a2; /* Start and end address */
84 1.1 alm char *t; /* Text for : a c i r w */
85 1.1 alm union {
86 1.1 alm struct s_command *c; /* Command(s) for b t { */
87 1.1 alm struct s_subst *s; /* Substitute command */
88 1.1 alm u_char *y; /* Replace command array */
89 1.1 alm int fd; /* File descriptor for w */
90 1.1 alm } u;
91 1.1 alm char code; /* Command code */
92 1.1 alm u_int nonsel:1; /* True if ! */
93 1.1 alm u_int inrange:1; /* True if in range */
94 1.1 alm };
95 1.1 alm
96 1.1 alm /*
97 1.1 alm * Types of command arguments recognised by the parser
98 1.1 alm */
99 1.1 alm enum e_args {
100 1.1 alm EMPTY, /* d D g G h H l n N p P q x = \0 */
101 1.1 alm TEXT, /* a c i */
102 1.1 alm NONSEL, /* ! */
103 1.1 alm GROUP, /* { */
104 1.1 alm COMMENT, /* # */
105 1.1 alm BRANCH, /* b t */
106 1.1 alm LABEL, /* : */
107 1.1 alm RFILE, /* r */
108 1.1 alm WFILE, /* w */
109 1.1 alm SUBST, /* s */
110 1.1 alm TR /* y */
111 1.1 alm };
112 1.1 alm
113 1.1 alm /*
114 1.1 alm * Structure containing things to append before a line is read
115 1.1 alm */
116 1.1 alm struct s_appends {
117 1.1 alm enum {AP_STRING, AP_FILE} type;
118 1.1 alm char *s;
119 1.4 cgd size_t len;
120 1.1 alm };
121 1.1 alm
122 1.1 alm enum e_spflag {
123 1.1 alm APPEND, /* Append to the contents. */
124 1.1 alm REPLACE, /* Replace the contents. */
125 1.1 alm };
126 1.1 alm
127 1.1 alm /*
128 1.1 alm * Structure for a space (process, hold, otherwise).
129 1.1 alm */
130 1.1 alm typedef struct {
131 1.1 alm char *space; /* Current space pointer. */
132 1.1 alm size_t len; /* Current length. */
133 1.1 alm int deleted; /* If deleted. */
134 1.1 alm char *back; /* Backing memory. */
135 1.1 alm size_t blen; /* Backing memory length. */
136 1.1 alm } SPACE;
137 1.1 alm
138 1.1 alm /*
139 1.1 alm * Error severity codes:
140 1.1 alm */
141 1.1 alm #define FATAL 0 /* Exit immediately with 1 */
142 1.1 alm #define ERROR 1 /* Continue, but change exit value */
143 1.1 alm #define WARNING 2 /* Just print the warning */
144 1.1 alm #define COMPILE 3 /* Print error, count and finish script */
145 1.1 alm #define COMPILE2 3 /* Print error, count and finish script */
146