1 /* Definitions for data structures callers pass the regex library. 2 3 Copyright (C) 1985, 1989-92 Free Software Foundation, Inc. 4 5 This file is part of the GNU C++ Library. This library is free 6 software; you can redistribute it and/or modify it under the terms of 7 the GNU Library General Public License as published by the Free 8 Software Foundation; either version 2 of the License, or (at your 9 option) any later version. This library is distributed in the hope 10 that it will be useful, but WITHOUT ANY WARRANTY; without even the 11 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the GNU Library General Public License for more details. 13 You should have received a copy of the GNU Library General Public 14 License along with this library; if not, write to the Free Software 15 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 16 */ 17 18 #ifndef __REGEXP_LIBRARY 19 #define __REGEXP_LIBRARY 20 21 #if defined(SHORT_NAMES) || defined(VMS) 22 #define re_compile_pattern recmppat 23 #define re_pattern_buffer repatbuf 24 #define re_registers reregs 25 #endif 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /* Define number of parens for which we record the beginnings and ends. 32 This affects how much space the `struct re_registers' type takes up. */ 33 #ifndef RE_NREGS 34 #define RE_NREGS 10 35 #endif 36 37 #define BYTEWIDTH 8 38 39 40 /* Maximum number of duplicates an interval can allow. */ 41 #ifndef RE_DUP_MAX /* kludge for AIX, which defines it */ 42 #define RE_DUP_MAX ((1 << 15) - 1) 43 #endif 44 45 /* This defines the various regexp syntaxes. */ 46 extern int obscure_syntax; 47 48 49 /* The following bits are used in the obscure_syntax variable to choose among 50 alternative regexp syntaxes. */ 51 52 /* If this bit is set, plain parentheses serve as grouping, and backslash 53 parentheses are needed for literal searching. 54 If not set, backslash-parentheses are grouping, and plain parentheses 55 are for literal searching. */ 56 #define RE_NO_BK_PARENS 1 57 58 /* If this bit is set, plain | serves as the `or'-operator, and \| is a 59 literal. 60 If not set, \| serves as the `or'-operator, and | is a literal. */ 61 #define RE_NO_BK_VBAR (1 << 1) 62 63 /* If this bit is not set, plain + or ? serves as an operator, and \+, \? are 64 literals. 65 If set, \+, \? are operators and plain +, ? are literals. */ 66 #define RE_BK_PLUS_QM (1 << 2) 67 68 /* If this bit is set, | binds tighter than ^ or $. 69 If not set, the contrary. */ 70 #define RE_TIGHT_VBAR (1 << 3) 71 72 /* If this bit is set, then treat newline as an OR operator. 73 If not set, treat it as a normal character. */ 74 #define RE_NEWLINE_OR (1 << 4) 75 76 /* If this bit is set, then special characters may act as normal 77 characters in some contexts. Specifically, this applies to: 78 ^ -- only special at the beginning, or after ( or |; 79 $ -- only special at the end, or before ) or |; 80 *, +, ? -- only special when not after the beginning, (, or |. 81 If this bit is not set, special characters (such as *, ^, and $) 82 always have their special meaning regardless of the surrounding 83 context. */ 84 #define RE_CONTEXT_INDEP_OPS (1 << 5) 85 86 /* If this bit is not set, then \ before anything inside [ and ] is taken as 87 a real \. 88 If set, then such a \ escapes the following character. This is a 89 special case for awk. */ 90 #define RE_AWK_CLASS_HACK (1 << 6) 91 92 /* If this bit is set, then \{ and \} or { and } serve as interval operators. 93 If not set, then \{ and \} and { and } are treated as literals. */ 94 #define RE_INTERVALS (1 << 7) 95 96 /* If this bit is not set, then \{ and \} serve as interval operators and 97 { and } are literals. 98 If set, then { and } serve as interval operators and \{ and \} are 99 literals. */ 100 #define RE_NO_BK_CURLY_BRACES (1 << 8) 101 102 /* If this bit is set, then character classes are supported; they are: 103 [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], 104 [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. 105 If not set, then character classes are not supported. */ 106 #define RE_CHAR_CLASSES (1 << 9) 107 108 /* If this bit is set, then the dot re doesn't match a null byte. 109 If not set, it does. */ 110 #define RE_DOT_NOT_NULL (1 << 10) 111 112 /* If this bit is set, then [^...] doesn't match a newline. 113 If not set, it does. */ 114 #define RE_HAT_NOT_NEWLINE (1 << 11) 115 116 /* If this bit is set, back references are recognized. 117 If not set, they aren't. */ 118 #define RE_NO_BK_REFS (1 << 12) 119 120 /* If this bit is set, back references must refer to a preceding 121 subexpression. If not set, a back reference to a nonexistent 122 subexpression is treated as literal characters. */ 123 #define RE_NO_EMPTY_BK_REF (1 << 13) 124 125 /* If this bit is set, bracket expressions can't be empty. 126 If it is set, they can be empty. */ 127 #define RE_NO_EMPTY_BRACKETS (1 << 14) 128 129 /* If this bit is set, then *, +, ? and { cannot be first in an re or 130 immediately after a |, or a (. Furthermore, a | cannot be first or 131 last in an re, or immediately follow another | or a (. Also, a ^ 132 cannot appear in a nonleading position and a $ cannot appear in a 133 nontrailing position (outside of bracket expressions, that is). */ 134 #define RE_CONTEXTUAL_INVALID_OPS (1 << 15) 135 136 /* If this bit is set, then +, ? and | aren't recognized as operators. 137 If it's not, they are. */ 138 #define RE_LIMITED_OPS (1 << 16) 139 140 /* If this bit is set, then an ending range point has to collate higher 141 or equal to the starting range point. 142 If it's not set, then when the ending range point collates higher 143 than the starting range point, the range is just considered empty. */ 144 #define RE_NO_EMPTY_RANGES (1 << 17) 145 146 /* If this bit is set, then a hyphen (-) can't be an ending range point. 147 If it isn't, then it can. */ 148 #define RE_NO_HYPHEN_RANGE_END (1 << 18) 149 150 151 /* Define combinations of bits for the standard possibilities. */ 152 #define RE_SYNTAX_POSIX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 153 | RE_CONTEXT_INDEP_OPS) 154 #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 155 | RE_CONTEXT_INDEP_OPS | RE_AWK_CLASS_HACK) 156 #define RE_SYNTAX_EGREP (RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 157 | RE_CONTEXT_INDEP_OPS | RE_NEWLINE_OR) 158 #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR) 159 #define RE_SYNTAX_EMACS 0 160 #define RE_SYNTAX_POSIX_BASIC (RE_INTERVALS | RE_BK_PLUS_QM \ 161 | RE_CHAR_CLASSES | RE_DOT_NOT_NULL \ 162 | RE_HAT_NOT_NEWLINE | RE_NO_EMPTY_BK_REF \ 163 | RE_NO_EMPTY_BRACKETS | RE_LIMITED_OPS \ 164 | RE_NO_EMPTY_RANGES | RE_NO_HYPHEN_RANGE_END) 165 166 #define RE_SYNTAX_POSIX_EXTENDED (RE_INTERVALS | RE_NO_BK_CURLY_BRACES \ 167 | RE_NO_BK_VBAR | RE_NO_BK_PARENS \ 168 | RE_HAT_NOT_NEWLINE | RE_CHAR_CLASSES \ 169 | RE_NO_EMPTY_BRACKETS | RE_CONTEXTUAL_INVALID_OPS \ 170 | RE_NO_BK_REFS | RE_NO_EMPTY_RANGES \ 171 | RE_NO_HYPHEN_RANGE_END) 172 173 174 /* This data structure is used to represent a compiled pattern. */ 175 176 struct re_pattern_buffer 177 { 178 char *buffer; /* Space holding the compiled pattern commands. */ 179 long allocated; /* Size of space that `buffer' points to. */ 180 long used; /* Length of portion of buffer actually occupied */ 181 char *fastmap; /* Pointer to fastmap, if any, or zero if none. */ 182 /* re_search uses the fastmap, if there is one, 183 to skip over totally implausible characters. */ 184 char *translate; /* Translate table to apply to all characters before 185 comparing, or zero for no translation. 186 The translation is applied to a pattern when it is 187 compiled and to data when it is matched. */ 188 char fastmap_accurate; 189 /* Set to zero when a new pattern is stored, 190 set to one when the fastmap is updated from it. */ 191 char can_be_null; /* Set to one by compiling fastmap 192 if this pattern might match the null string. 193 It does not necessarily match the null string 194 in that case, but if this is zero, it cannot. 195 2 as value means can match null string 196 but at end of range or before a character 197 listed in the fastmap. */ 198 }; 199 200 201 /* search.c (search_buffer) needs this one value. It is defined both in 202 regex.c and here. */ 203 #define RE_EXACTN_VALUE 1 204 205 206 /* Structure to store register contents data in. 207 208 Pass the address of such a structure as an argument to re_match, etc., 209 if you want this information back. 210 211 For i from 1 to RE_NREGS - 1, start[i] records the starting index in 212 the string of where the ith subexpression matched, and end[i] records 213 one after the ending index. start[0] and end[0] are analogous, for 214 the entire pattern. */ 215 216 struct re_registers 217 { 218 int start[RE_NREGS]; 219 int end[RE_NREGS]; 220 }; 221 222 223 224 #if defined(__STDC__) || defined(__cplusplus) 225 226 extern char *re_compile_pattern (const char *, int, struct re_pattern_buffer *); 227 /* Is this really advertised? */ 228 extern void re_compile_fastmap (struct re_pattern_buffer *); 229 extern int re_search (struct re_pattern_buffer *, char*, int, int, int, 230 struct re_registers *); 231 extern int re_search_2 (struct re_pattern_buffer *, char *, int, 232 char *, int, int, int, 233 struct re_registers *, int); 234 extern int re_match (struct re_pattern_buffer *, char *, int, int, 235 struct re_registers *); 236 extern int re_match_2 (struct re_pattern_buffer *, char *, int, 237 char *, int, int, struct re_registers *, int); 238 239 /* 4.2 bsd compatibility. */ 240 extern char *re_comp (const char *); 241 extern int re_exec (const char *); 242 243 #else /* !__STDC__ */ 244 245 #define const /* nothing */ 246 extern char *re_compile_pattern (); 247 /* Is this really advertised? */ 248 extern void re_compile_fastmap (); 249 extern int re_search (), re_search_2 (); 250 extern int re_match (), re_match_2 (); 251 252 /* 4.2 bsd compatibility. */ 253 extern char *re_comp (); 254 extern int re_exec (); 255 256 #endif /* __STDC__ */ 257 258 259 #ifdef SYNTAX_TABLE 260 extern char *re_syntax_table; 261 #endif 262 263 #ifdef __cplusplus 264 extern int re_max_failures; 265 } 266 #endif 267 268 #endif /* !__REGEXP_LIBRARY */ 269