e91b87a3 |
1 | /* Definitions for data structures callers pass the regex library. |
4187119d |
2 | Copyright (C) 1985, 1989 Free Software Foundation, Inc. |
e91b87a3 |
3 | |
4187119d |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; either version 1, or (at your option) |
7 | any later version. |
e91b87a3 |
8 | |
4187119d |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
e91b87a3 |
13 | |
4187119d |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
e91b87a3 |
17 | |
e91b87a3 |
18 | |
4187119d |
19 | In other words, you are welcome to use, share and improve this program. |
20 | You are forbidden to forbid anyone else to use, share and improve |
21 | what you give them. Help stamp out software-hoarding! */ |
e91b87a3 |
22 | |
23 | |
24 | /* Define number of parens for which we record the beginnings and ends. |
25 | This affects how much space the `struct re_registers' type takes up. */ |
26 | #ifndef RE_NREGS |
27 | #define RE_NREGS 10 |
28 | #endif |
29 | |
30 | /* These bits are used in the obscure_syntax variable to choose among |
31 | alternative regexp syntaxes. */ |
32 | |
33 | /* 1 means plain parentheses serve as grouping, and backslash |
34 | parentheses are needed for literal searching. |
35 | 0 means backslash-parentheses are grouping, and plain parentheses |
36 | are for literal searching. */ |
37 | #define RE_NO_BK_PARENS 1 |
38 | |
39 | /* 1 means plain | serves as the "or"-operator, and \| is a literal. |
40 | 0 means \| serves as the "or"-operator, and | is a literal. */ |
41 | #define RE_NO_BK_VBAR 2 |
42 | |
43 | /* 0 means plain + or ? serves as an operator, and \+, \? are literals. |
44 | 1 means \+, \? are operators and plain +, ? are literals. */ |
45 | #define RE_BK_PLUS_QM 4 |
46 | |
47 | /* 1 means | binds tighter than ^ or $. |
48 | 0 means the contrary. */ |
49 | #define RE_TIGHT_VBAR 8 |
50 | |
51 | /* 1 means treat \n as an _OR operator |
52 | 0 means treat it as a normal character */ |
53 | #define RE_NEWLINE_OR 16 |
54 | |
55 | /* 0 means that a special characters (such as *, ^, and $) always have |
56 | their special meaning regardless of the surrounding context. |
57 | 1 means that special characters may act as normal characters in some |
58 | contexts. Specifically, this applies to: |
59 | ^ - only special at the beginning, or after ( or | |
60 | $ - only special at the end, or before ) or | |
61 | *, +, ? - only special when not after the beginning, (, or | */ |
62 | #define RE_CONTEXT_INDEP_OPS 32 |
63 | |
64 | /* Now define combinations of bits for the standard possibilities. */ |
65 | #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS) |
66 | #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR) |
67 | #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR) |
68 | #define RE_SYNTAX_EMACS 0 |
69 | |
70 | /* This data structure is used to represent a compiled pattern. */ |
71 | |
72 | struct re_pattern_buffer |
73 | { |
74 | char *buffer; /* Space holding the compiled pattern commands. */ |
75 | int allocated; /* Size of space that buffer points to */ |
76 | int used; /* Length of portion of buffer actually occupied */ |
77 | char *fastmap; /* Pointer to fastmap, if any, or zero if none. */ |
78 | /* re_search uses the fastmap, if there is one, |
79 | to skip quickly over totally implausible characters */ |
80 | char *translate; /* Translate table to apply to all characters before comparing. |
81 | Or zero for no translation. |
82 | The translation is applied to a pattern when it is compiled |
83 | and to data when it is matched. */ |
84 | char fastmap_accurate; |
85 | /* Set to zero when a new pattern is stored, |
86 | set to one when the fastmap is updated from it. */ |
87 | char can_be_null; /* Set to one by compiling fastmap |
88 | if this pattern might match the null string. |
89 | It does not necessarily match the null string |
90 | in that case, but if this is zero, it cannot. |
91 | 2 as value means can match null string |
92 | but at end of range or before a character |
93 | listed in the fastmap. */ |
94 | }; |
95 | |
96 | /* Structure to store "register" contents data in. |
97 | |
98 | Pass the address of such a structure as an argument to re_match, etc., |
99 | if you want this information back. |
100 | |
101 | start[i] and end[i] record the string matched by \( ... \) grouping i, |
102 | for i from 1 to RE_NREGS - 1. |
103 | start[0] and end[0] record the entire string matched. */ |
104 | |
105 | struct re_registers |
106 | { |
107 | int start[RE_NREGS]; |
108 | int end[RE_NREGS]; |
109 | }; |
110 | |
111 | /* These are the command codes that appear in compiled regular expressions, one per byte. |
112 | Some command codes are followed by argument bytes. |
113 | A command code can specify any interpretation whatever for its arguments. |
114 | Zero-bytes may appear in the compiled regular expression. */ |
115 | |
116 | enum regexpcode |
117 | { |
118 | unused, |
119 | exactn, /* followed by one byte giving n, and then by n literal bytes */ |
120 | begline, /* fails unless at beginning of line */ |
121 | endline, /* fails unless at end of line */ |
122 | jump, /* followed by two bytes giving relative address to jump to */ |
123 | on_failure_jump, /* followed by two bytes giving relative address of place |
124 | to resume at in case of failure. */ |
125 | finalize_jump, /* Throw away latest failure point and then jump to address. */ |
126 | maybe_finalize_jump, /* Like jump but finalize if safe to do so. |
127 | This is used to jump back to the beginning |
128 | of a repeat. If the command that follows |
129 | this jump is clearly incompatible with the |
130 | one at the beginning of the repeat, such that |
131 | we can be sure that there is no use backtracking |
132 | out of repetitions already completed, |
133 | then we finalize. */ |
134 | dummy_failure_jump, /* jump, and push a dummy failure point. |
135 | This failure point will be thrown away |
136 | if an attempt is made to use it for a failure. |
137 | A + construct makes this before the first repeat. */ |
138 | anychar, /* matches any one character */ |
139 | charset, /* matches any one char belonging to specified set. |
140 | First following byte is # bitmap bytes. |
141 | Then come bytes for a bit-map saying which chars are in. |
142 | Bits in each byte are ordered low-bit-first. |
143 | A character is in the set if its bit is 1. |
144 | A character too large to have a bit in the map |
145 | is automatically not in the set */ |
146 | charset_not, /* similar but match any character that is NOT one of those specified */ |
147 | start_memory, /* starts remembering the text that is matched |
148 | and stores it in a memory register. |
149 | followed by one byte containing the register number. |
150 | Register numbers must be in the range 0 through NREGS. */ |
151 | stop_memory, /* stops remembering the text that is matched |
152 | and stores it in a memory register. |
153 | followed by one byte containing the register number. |
154 | Register numbers must be in the range 0 through NREGS. */ |
155 | duplicate, /* match a duplicate of something remembered. |
156 | Followed by one byte containing the index of the memory register. */ |
157 | before_dot, /* Succeeds if before dot */ |
158 | at_dot, /* Succeeds if at dot */ |
159 | after_dot, /* Succeeds if after dot */ |
160 | begbuf, /* Succeeds if at beginning of buffer */ |
161 | endbuf, /* Succeeds if at end of buffer */ |
162 | wordchar, /* Matches any word-constituent character */ |
163 | notwordchar, /* Matches any char that is not a word-constituent */ |
164 | wordbeg, /* Succeeds if at word beginning */ |
165 | wordend, /* Succeeds if at word end */ |
166 | wordbound, /* Succeeds if at a word boundary */ |
167 | notwordbound, /* Succeeds if not at a word boundary */ |
168 | syntaxspec, /* Matches any character whose syntax is specified. |
169 | followed by a byte which contains a syntax code, Sword or such like */ |
170 | notsyntaxspec /* Matches any character whose syntax differs from the specified. */ |
171 | }; |
172 | \f |
173 | extern char *re_compile_pattern (); |
174 | /* Is this really advertised? */ |
175 | extern void re_compile_fastmap (); |
176 | extern int re_search (), re_search_2 (); |
177 | extern int re_match (), re_match_2 (); |
178 | |
179 | /* 4.2 bsd compatibility (yuck) */ |
180 | extern char *re_comp (); |
181 | extern int re_exec (); |
182 | |
183 | #ifdef SYNTAX_TABLE |
184 | extern char *re_syntax_table; |
185 | #endif |