[3076] | 1 | /* Definitions for data structures and routines for the regular
|
---|
| 2 | expression library.
|
---|
| 3 | Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003
|
---|
| 4 | Free Software Foundation, Inc.
|
---|
| 5 | This file is part of the GNU C Library.
|
---|
| 6 |
|
---|
| 7 | The GNU C Library is free software; you can redistribute it and/or
|
---|
| 8 | modify it under the terms of the GNU Lesser General Public
|
---|
| 9 | License as published by the Free Software Foundation; either
|
---|
| 10 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 11 |
|
---|
| 12 | The GNU C Library is distributed in the hope that it will be useful,
|
---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 15 | Lesser General Public License for more details.
|
---|
| 16 |
|
---|
| 17 | You should have received a copy of the GNU Lesser General Public
|
---|
| 18 | License along with the GNU C Library; if not, write to the Free
|
---|
| 19 | Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
| 20 | 02110-1301 USA. */
|
---|
| 21 |
|
---|
| 22 | #ifndef _REGEX_H
|
---|
| 23 | #define _REGEX_H 1
|
---|
| 24 |
|
---|
| 25 | #ifdef HAVE_SYS_TYPES_H
|
---|
| 26 | #include <sys/types.h>
|
---|
| 27 | #endif
|
---|
| 28 |
|
---|
| 29 | /* Allow the use in C++ code. */
|
---|
| 30 | #ifdef __cplusplus
|
---|
| 31 | extern "C" {
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
| 34 | /* POSIX says that <sys/types.h> must be included (by the caller) before
|
---|
| 35 | <regex.h>. */
|
---|
| 36 |
|
---|
| 37 | #if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS
|
---|
| 38 | /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
|
---|
| 39 | should be there. */
|
---|
| 40 | # include <stddef.h>
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
| 43 | /* The following two types have to be signed and unsigned integer type
|
---|
| 44 | wide enough to hold a value of a pointer. For most ANSI compilers
|
---|
| 45 | ptrdiff_t and size_t should be likely OK. Still size of these two
|
---|
| 46 | types is 2 for Microsoft C. Ugh... */
|
---|
| 47 | typedef long int s_reg_t;
|
---|
| 48 | typedef unsigned long int active_reg_t;
|
---|
| 49 |
|
---|
| 50 | /* The following bits are used to determine the regexp syntax we
|
---|
| 51 | recognize. The set/not-set meanings are chosen so that Emacs syntax
|
---|
| 52 | remains the value 0. The bits are given in alphabetical order, and
|
---|
| 53 | the definitions shifted by one from the previous bit; thus, when we
|
---|
| 54 | add or remove a bit, only one other definition need change. */
|
---|
| 55 | typedef unsigned long int reg_syntax_t;
|
---|
| 56 |
|
---|
| 57 | /* If this bit is not set, then \ inside a bracket expression is literal.
|
---|
| 58 | If set, then such a \ quotes the following character. */
|
---|
| 59 | #define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
|
---|
| 60 |
|
---|
| 61 | /* If this bit is not set, then + and ? are operators, and \+ and \? are
|
---|
| 62 | literals.
|
---|
| 63 | If set, then \+ and \? are operators and + and ? are literals. */
|
---|
| 64 | #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
|
---|
| 65 |
|
---|
| 66 | /* If this bit is set, then character classes are supported. They are:
|
---|
| 67 | [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
|
---|
| 68 | [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
|
---|
| 69 | If not set, then character classes are not supported. */
|
---|
| 70 | #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
|
---|
| 71 |
|
---|
| 72 | /* If this bit is set, then ^ and $ are always anchors (outside bracket
|
---|
| 73 | expressions, of course).
|
---|
| 74 | If this bit is not set, then it depends:
|
---|
| 75 | ^ is an anchor if it is at the beginning of a regular
|
---|
| 76 | expression or after an open-group or an alternation operator;
|
---|
| 77 | $ is an anchor if it is at the end of a regular expression, or
|
---|
| 78 | before a close-group or an alternation operator.
|
---|
| 79 |
|
---|
| 80 | This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
|
---|
| 81 | POSIX draft 11.2 says that * etc. in leading positions is undefined.
|
---|
| 82 | We already implemented a previous draft which made those constructs
|
---|
| 83 | invalid, though, so we haven't changed the code back. */
|
---|
| 84 | #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
|
---|
| 85 |
|
---|
| 86 | /* If this bit is set, then special characters are always special
|
---|
| 87 | regardless of where they are in the pattern.
|
---|
| 88 | If this bit is not set, then special characters are special only in
|
---|
| 89 | some contexts; otherwise they are ordinary. Specifically,
|
---|
| 90 | * + ? and intervals are only special when not after the beginning,
|
---|
| 91 | open-group, or alternation operator. */
|
---|
| 92 | #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
|
---|
| 93 |
|
---|
| 94 | /* If this bit is set, then *, +, ?, and { cannot be first in an re or
|
---|
| 95 | immediately after an alternation or begin-group operator. */
|
---|
| 96 | #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
|
---|
| 97 |
|
---|
| 98 | /* If this bit is set, then . matches newline.
|
---|
| 99 | If not set, then it doesn't. */
|
---|
| 100 | #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
|
---|
| 101 |
|
---|
| 102 | /* If this bit is set, then . doesn't match NUL.
|
---|
| 103 | If not set, then it does. */
|
---|
| 104 | #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
|
---|
| 105 |
|
---|
| 106 | /* If this bit is set, nonmatching lists [^...] do not match newline.
|
---|
| 107 | If not set, they do. */
|
---|
| 108 | #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
|
---|
| 109 |
|
---|
| 110 | /* If this bit is set, either \{...\} or {...} defines an
|
---|
| 111 | interval, depending on RE_NO_BK_BRACES.
|
---|
| 112 | If not set, \{, \}, {, and } are literals. */
|
---|
| 113 | #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
|
---|
| 114 |
|
---|
| 115 | /* If this bit is set, +, ? and | aren't recognized as operators.
|
---|
| 116 | If not set, they are. */
|
---|
| 117 | #define RE_LIMITED_OPS (RE_INTERVALS << 1)
|
---|
| 118 |
|
---|
| 119 | /* If this bit is set, newline is an alternation operator.
|
---|
| 120 | If not set, newline is literal. */
|
---|
| 121 | #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
|
---|
| 122 |
|
---|
| 123 | /* If this bit is set, then `{...}' defines an interval, and \{ and \}
|
---|
| 124 | are literals.
|
---|
| 125 | If not set, then `\{...\}' defines an interval. */
|
---|
| 126 | #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
|
---|
| 127 |
|
---|
| 128 | /* If this bit is set, (...) defines a group, and \( and \) are literals.
|
---|
| 129 | If not set, \(...\) defines a group, and ( and ) are literals. */
|
---|
| 130 | #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
|
---|
| 131 |
|
---|
| 132 | /* If this bit is set, then \<digit> matches <digit>.
|
---|
| 133 | If not set, then \<digit> is a back-reference. */
|
---|
| 134 | #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
|
---|
| 135 |
|
---|
| 136 | /* If this bit is set, then | is an alternation operator, and \| is literal.
|
---|
| 137 | If not set, then \| is an alternation operator, and | is literal. */
|
---|
| 138 | #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
|
---|
| 139 |
|
---|
| 140 | /* If this bit is set, then an ending range point collating higher
|
---|
| 141 | than the starting range point, as in [z-a], is invalid.
|
---|
| 142 | If not set, then when ending range point collates higher than the
|
---|
| 143 | starting range point, the range is ignored. */
|
---|
| 144 | #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
|
---|
| 145 |
|
---|
| 146 | /* If this bit is set, then an unmatched ) is ordinary.
|
---|
| 147 | If not set, then an unmatched ) is invalid. */
|
---|
| 148 | #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
|
---|
| 149 |
|
---|
| 150 | /* If this bit is set, succeed as soon as we match the whole pattern,
|
---|
| 151 | without further backtracking. */
|
---|
| 152 | #define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
|
---|
| 153 |
|
---|
| 154 | /* If this bit is set, do not process the GNU regex operators.
|
---|
| 155 | If not set, then the GNU regex operators are recognized. */
|
---|
| 156 | #define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
|
---|
| 157 |
|
---|
| 158 | /* If this bit is set, turn on internal regex debugging.
|
---|
| 159 | If not set, and debugging was on, turn it off.
|
---|
| 160 | This only works if regex.c is compiled -DDEBUG.
|
---|
| 161 | We define this bit always, so that all that's needed to turn on
|
---|
| 162 | debugging is to recompile regex.c; the calling code can always have
|
---|
| 163 | this bit set, and it won't affect anything in the normal case. */
|
---|
| 164 | #define RE_DEBUG (RE_NO_GNU_OPS << 1)
|
---|
| 165 |
|
---|
| 166 | /* If this bit is set, a syntactically invalid interval is treated as
|
---|
| 167 | a string of ordinary characters. For example, the ERE 'a{1' is
|
---|
| 168 | treated as 'a\{1'. */
|
---|
| 169 | #define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
|
---|
| 170 |
|
---|
| 171 | /* If this bit is set, then ignore case when matching.
|
---|
| 172 | If not set, then case is significant. */
|
---|
| 173 | #define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
|
---|
| 174 |
|
---|
| 175 | /* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
|
---|
| 176 | for ^, because it is difficult to scan the regex backwards to find
|
---|
| 177 | whether ^ should be special. */
|
---|
| 178 | #define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
|
---|
| 179 |
|
---|
| 180 | /* If this bit is set, then \{ cannot be first in an bre or
|
---|
| 181 | immediately after an alternation or begin-group operator. */
|
---|
| 182 | #define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
|
---|
| 183 |
|
---|
| 184 | /* If this bit is set, then no_sub will be set to 1 during
|
---|
| 185 | re_compile_pattern. */
|
---|
| 186 | #define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
|
---|
| 187 |
|
---|
| 188 | /* This global variable defines the particular regexp syntax to use (for
|
---|
| 189 | some interfaces). When a regexp is compiled, the syntax used is
|
---|
| 190 | stored in the pattern buffer, so changing this does not affect
|
---|
| 191 | already-compiled regexps. */
|
---|
| 192 | extern reg_syntax_t re_syntax_options;
|
---|
| 193 | |
---|
| 194 |
|
---|
| 195 | /* Define combinations of the above bits for the standard possibilities.
|
---|
| 196 | (The [[[ comments delimit what gets put into the Texinfo file, so
|
---|
| 197 | don't delete them!) */
|
---|
| 198 | /* [[[begin syntaxes]]] */
|
---|
| 199 | #define RE_SYNTAX_EMACS 0
|
---|
| 200 |
|
---|
| 201 | #define RE_SYNTAX_AWK \
|
---|
| 202 | (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
|
---|
| 203 | | RE_NO_BK_PARENS | RE_NO_BK_REFS \
|
---|
| 204 | | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
|
---|
| 205 | | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
|
---|
| 206 | | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
|
---|
| 207 |
|
---|
| 208 | #define RE_SYNTAX_GNU_AWK \
|
---|
| 209 | ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
|
---|
| 210 | & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
|
---|
| 211 | | RE_CONTEXT_INVALID_OPS ))
|
---|
| 212 |
|
---|
| 213 | #define RE_SYNTAX_POSIX_AWK \
|
---|
| 214 | (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
|
---|
| 215 | | RE_INTERVALS | RE_NO_GNU_OPS)
|
---|
| 216 |
|
---|
| 217 | #define RE_SYNTAX_GREP \
|
---|
| 218 | (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
|
---|
| 219 | | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
|
---|
| 220 | | RE_NEWLINE_ALT)
|
---|
| 221 |
|
---|
| 222 | #define RE_SYNTAX_EGREP \
|
---|
| 223 | (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
|
---|
| 224 | | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
|
---|
| 225 | | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
|
---|
| 226 | | RE_NO_BK_VBAR)
|
---|
| 227 |
|
---|
| 228 | #define RE_SYNTAX_POSIX_EGREP \
|
---|
| 229 | (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
|
---|
| 230 | | RE_INVALID_INTERVAL_ORD)
|
---|
| 231 |
|
---|
| 232 | /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
|
---|
| 233 | #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
|
---|
| 234 |
|
---|
| 235 | #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
|
---|
| 236 |
|
---|
| 237 | /* Syntax bits common to both basic and extended POSIX regex syntax. */
|
---|
| 238 | #define _RE_SYNTAX_POSIX_COMMON \
|
---|
| 239 | (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
|
---|
| 240 | | RE_INTERVALS | RE_NO_EMPTY_RANGES)
|
---|
| 241 |
|
---|
| 242 | #define RE_SYNTAX_POSIX_BASIC \
|
---|
| 243 | (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
|
---|
| 244 |
|
---|
| 245 | /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
|
---|
| 246 | RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
|
---|
| 247 | isn't minimal, since other operators, such as \`, aren't disabled. */
|
---|
| 248 | #define RE_SYNTAX_POSIX_MINIMAL_BASIC \
|
---|
| 249 | (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
|
---|
| 250 |
|
---|
| 251 | #define RE_SYNTAX_POSIX_EXTENDED \
|
---|
| 252 | (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
|
---|
| 253 | | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
|
---|
| 254 | | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
|
---|
| 255 | | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
|
---|
| 256 |
|
---|
| 257 | /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
|
---|
| 258 | removed and RE_NO_BK_REFS is added. */
|
---|
| 259 | #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
|
---|
| 260 | (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
|
---|
| 261 | | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
|
---|
| 262 | | RE_NO_BK_PARENS | RE_NO_BK_REFS \
|
---|
| 263 | | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
|
---|
| 264 | /* [[[end syntaxes]]] */
|
---|
| 265 | |
---|
| 266 |
|
---|
| 267 | /* Maximum number of duplicates an interval can allow. Some systems
|
---|
| 268 | (erroneously) define this in other header files, but we want our
|
---|
| 269 | value, so remove any previous define. */
|
---|
| 270 | #ifdef RE_DUP_MAX
|
---|
| 271 | # undef RE_DUP_MAX
|
---|
| 272 | #endif
|
---|
| 273 | /* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */
|
---|
| 274 | #define RE_DUP_MAX (0x7fff)
|
---|
| 275 |
|
---|
| 276 |
|
---|
| 277 | /* POSIX `cflags' bits (i.e., information for `regcomp'). */
|
---|
| 278 |
|
---|
| 279 | /* If this bit is set, then use extended regular expression syntax.
|
---|
| 280 | If not set, then use basic regular expression syntax. */
|
---|
| 281 | #define REG_EXTENDED 1
|
---|
| 282 |
|
---|
| 283 | /* If this bit is set, then ignore case when matching.
|
---|
| 284 | If not set, then case is significant. */
|
---|
| 285 | #define REG_ICASE (REG_EXTENDED << 1)
|
---|
| 286 |
|
---|
| 287 | /* If this bit is set, then anchors do not match at newline
|
---|
| 288 | characters in the string.
|
---|
| 289 | If not set, then anchors do match at newlines. */
|
---|
| 290 | #define REG_NEWLINE (REG_ICASE << 1)
|
---|
| 291 |
|
---|
| 292 | /* If this bit is set, then report only success or fail in regexec.
|
---|
| 293 | If not set, then returns differ between not matching and errors. */
|
---|
| 294 | #define REG_NOSUB (REG_NEWLINE << 1)
|
---|
| 295 |
|
---|
| 296 |
|
---|
| 297 | /* POSIX `eflags' bits (i.e., information for regexec). */
|
---|
| 298 |
|
---|
| 299 | /* If this bit is set, then the beginning-of-line operator doesn't match
|
---|
| 300 | the beginning of the string (presumably because it's not the
|
---|
| 301 | beginning of a line).
|
---|
| 302 | If not set, then the beginning-of-line operator does match the
|
---|
| 303 | beginning of the string. */
|
---|
| 304 | #define REG_NOTBOL 1
|
---|
| 305 |
|
---|
| 306 | /* Like REG_NOTBOL, except for the end-of-line. */
|
---|
| 307 | #define REG_NOTEOL (1 << 1)
|
---|
| 308 |
|
---|
| 309 | /* Use PMATCH[0] to delimit the start and end of the search in the
|
---|
| 310 | buffer. */
|
---|
| 311 | #define REG_STARTEND (1 << 2)
|
---|
| 312 |
|
---|
| 313 |
|
---|
| 314 | /* If any error codes are removed, changed, or added, update the
|
---|
| 315 | `re_error_msg' table in regex.c. */
|
---|
| 316 | typedef enum
|
---|
| 317 | {
|
---|
| 318 | #ifdef _XOPEN_SOURCE
|
---|
| 319 | REG_ENOSYS = -1, /* This will never happen for this implementation. */
|
---|
| 320 | #endif
|
---|
| 321 |
|
---|
| 322 | REG_NOERROR = 0, /* Success. */
|
---|
| 323 | REG_NOMATCH, /* Didn't find a match (for regexec). */
|
---|
| 324 |
|
---|
| 325 | /* POSIX regcomp return error codes. (In the order listed in the
|
---|
| 326 | standard.) */
|
---|
| 327 | REG_BADPAT, /* Invalid pattern. */
|
---|
| 328 | REG_ECOLLATE, /* Inalid collating element. */
|
---|
| 329 | REG_ECTYPE, /* Invalid character class name. */
|
---|
| 330 | REG_EESCAPE, /* Trailing backslash. */
|
---|
| 331 | REG_ESUBREG, /* Invalid back reference. */
|
---|
| 332 | REG_EBRACK, /* Unmatched left bracket. */
|
---|
| 333 | REG_EPAREN, /* Parenthesis imbalance. */
|
---|
| 334 | REG_EBRACE, /* Unmatched \{. */
|
---|
| 335 | REG_BADBR, /* Invalid contents of \{\}. */
|
---|
| 336 | REG_ERANGE, /* Invalid range end. */
|
---|
| 337 | REG_ESPACE, /* Ran out of memory. */
|
---|
| 338 | REG_BADRPT, /* No preceding re for repetition op. */
|
---|
| 339 |
|
---|
| 340 | /* Error codes we've added. */
|
---|
| 341 | REG_EEND, /* Premature end. */
|
---|
| 342 | REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
|
---|
| 343 | REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
|
---|
| 344 | } reg_errcode_t;
|
---|
| 345 | |
---|
| 346 |
|
---|
| 347 | /* This data structure represents a compiled pattern. Before calling
|
---|
| 348 | the pattern compiler, the fields `buffer', `allocated', `fastmap',
|
---|
| 349 | `translate', and `no_sub' can be set. After the pattern has been
|
---|
| 350 | compiled, the `re_nsub' field is available. All other fields are
|
---|
| 351 | private to the regex routines. */
|
---|
| 352 |
|
---|
| 353 | #ifndef RE_TRANSLATE_TYPE
|
---|
| 354 | # define RE_TRANSLATE_TYPE char *
|
---|
| 355 | #endif
|
---|
| 356 |
|
---|
| 357 | struct re_pattern_buffer
|
---|
| 358 | {
|
---|
| 359 | /* [[[begin pattern_buffer]]] */
|
---|
| 360 | /* Space that holds the compiled pattern. It is declared as
|
---|
| 361 | `unsigned char *' because its elements are
|
---|
| 362 | sometimes used as array indexes. */
|
---|
| 363 | unsigned char *buffer;
|
---|
| 364 |
|
---|
| 365 | /* Number of bytes to which `buffer' points. */
|
---|
| 366 | unsigned long int allocated;
|
---|
| 367 |
|
---|
| 368 | /* Number of bytes actually used in `buffer'. */
|
---|
| 369 | unsigned long int used;
|
---|
| 370 |
|
---|
| 371 | /* Syntax setting with which the pattern was compiled. */
|
---|
| 372 | reg_syntax_t syntax;
|
---|
| 373 |
|
---|
| 374 | /* Pointer to a fastmap, if any, otherwise zero. re_search uses
|
---|
| 375 | the fastmap, if there is one, to skip over impossible
|
---|
| 376 | starting points for matches. */
|
---|
| 377 | char *fastmap;
|
---|
| 378 |
|
---|
| 379 | /* Either a translate table to apply to all characters before
|
---|
| 380 | comparing them, or zero for no translation. The translation
|
---|
| 381 | is applied to a pattern when it is compiled and to a string
|
---|
| 382 | when it is matched. */
|
---|
| 383 | RE_TRANSLATE_TYPE translate;
|
---|
| 384 |
|
---|
| 385 | /* Number of subexpressions found by the compiler. */
|
---|
| 386 | size_t re_nsub;
|
---|
| 387 |
|
---|
| 388 | /* Zero if this pattern cannot match the empty string, one else.
|
---|
| 389 | Well, in truth it's used only in `re_search_2', to see
|
---|
| 390 | whether or not we should use the fastmap, so we don't set
|
---|
| 391 | this absolutely perfectly; see `re_compile_fastmap' (the
|
---|
| 392 | `duplicate' case). */
|
---|
| 393 | unsigned can_be_null : 1;
|
---|
| 394 |
|
---|
| 395 | /* If REGS_UNALLOCATED, allocate space in the `regs' structure
|
---|
| 396 | for `max (RE_NREGS, re_nsub + 1)' groups.
|
---|
| 397 | If REGS_REALLOCATE, reallocate space if necessary.
|
---|
| 398 | If REGS_FIXED, use what's there. */
|
---|
| 399 | #define REGS_UNALLOCATED 0
|
---|
| 400 | #define REGS_REALLOCATE 1
|
---|
| 401 | #define REGS_FIXED 2
|
---|
| 402 | unsigned regs_allocated : 2;
|
---|
| 403 |
|
---|
| 404 | /* Set to zero when `regex_compile' compiles a pattern; set to one
|
---|
| 405 | by `re_compile_fastmap' if it updates the fastmap. */
|
---|
| 406 | unsigned fastmap_accurate : 1;
|
---|
| 407 |
|
---|
| 408 | /* If set, `re_match_2' does not return information about
|
---|
| 409 | subexpressions. */
|
---|
| 410 | unsigned no_sub : 1;
|
---|
| 411 |
|
---|
| 412 | /* If set, a beginning-of-line anchor doesn't match at the
|
---|
| 413 | beginning of the string. */
|
---|
| 414 | unsigned not_bol : 1;
|
---|
| 415 |
|
---|
| 416 | /* Similarly for an end-of-line anchor. */
|
---|
| 417 | unsigned not_eol : 1;
|
---|
| 418 |
|
---|
| 419 | /* If true, an anchor at a newline matches. */
|
---|
| 420 | unsigned newline_anchor : 1;
|
---|
| 421 |
|
---|
| 422 | /* [[[end pattern_buffer]]] */
|
---|
| 423 | };
|
---|
| 424 |
|
---|
| 425 | typedef struct re_pattern_buffer regex_t;
|
---|
| 426 | |
---|
| 427 |
|
---|
| 428 | /* Type for byte offsets within the string. POSIX mandates this. */
|
---|
| 429 | typedef int regoff_t;
|
---|
| 430 |
|
---|
| 431 |
|
---|
| 432 | /* This is the structure we store register match data in. See
|
---|
| 433 | regex.texinfo for a full description of what registers match. */
|
---|
| 434 | struct re_registers
|
---|
| 435 | {
|
---|
| 436 | unsigned num_regs;
|
---|
| 437 | regoff_t *start;
|
---|
| 438 | regoff_t *end;
|
---|
| 439 | };
|
---|
| 440 |
|
---|
| 441 |
|
---|
| 442 | /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
|
---|
| 443 | `re_match_2' returns information about at least this many registers
|
---|
| 444 | the first time a `regs' structure is passed. */
|
---|
| 445 | #ifndef RE_NREGS
|
---|
| 446 | # define RE_NREGS 30
|
---|
| 447 | #endif
|
---|
| 448 |
|
---|
| 449 |
|
---|
| 450 | /* POSIX specification for registers. Aside from the different names than
|
---|
| 451 | `re_registers', POSIX uses an array of structures, instead of a
|
---|
| 452 | structure of arrays. */
|
---|
| 453 | typedef struct
|
---|
| 454 | {
|
---|
| 455 | regoff_t rm_so; /* Byte offset from string's start to substring's start. */
|
---|
| 456 | regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
|
---|
| 457 | } regmatch_t;
|
---|
| 458 | |
---|
| 459 |
|
---|
| 460 | /* Declarations for routines. */
|
---|
| 461 |
|
---|
| 462 | /* To avoid duplicating every routine declaration -- once with a
|
---|
| 463 | prototype (if we are ANSI), and once without (if we aren't) -- we
|
---|
| 464 | use the following macro to declare argument types. This
|
---|
| 465 | unfortunately clutters up the declarations a bit, but I think it's
|
---|
| 466 | worth it. */
|
---|
| 467 |
|
---|
| 468 | #if __STDC__
|
---|
| 469 |
|
---|
| 470 | # define _RE_ARGS(args) args
|
---|
| 471 |
|
---|
| 472 | #else /* not __STDC__ */
|
---|
| 473 |
|
---|
| 474 | # define _RE_ARGS(args) ()
|
---|
| 475 |
|
---|
| 476 | #endif /* not __STDC__ */
|
---|
| 477 |
|
---|
| 478 | /* Sets the current default syntax to SYNTAX, and return the old syntax.
|
---|
| 479 | You can also simply assign to the `re_syntax_options' variable. */
|
---|
| 480 | extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
|
---|
| 481 |
|
---|
| 482 | /* Compile the regular expression PATTERN, with length LENGTH
|
---|
| 483 | and syntax given by the global `re_syntax_options', into the buffer
|
---|
| 484 | BUFFER. Return NULL if successful, and an error string if not. */
|
---|
| 485 | extern const char *re_compile_pattern
|
---|
| 486 | _RE_ARGS ((const char *pattern, size_t length,
|
---|
| 487 | struct re_pattern_buffer *buffer));
|
---|
| 488 |
|
---|
| 489 |
|
---|
| 490 | /* Compile a fastmap for the compiled pattern in BUFFER; used to
|
---|
| 491 | accelerate searches. Return 0 if successful and -2 if was an
|
---|
| 492 | internal error. */
|
---|
| 493 | extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
|
---|
| 494 |
|
---|
| 495 |
|
---|
| 496 | /* Search in the string STRING (with length LENGTH) for the pattern
|
---|
| 497 | compiled into BUFFER. Start searching at position START, for RANGE
|
---|
| 498 | characters. Return the starting position of the match, -1 for no
|
---|
| 499 | match, or -2 for an internal error. Also return register
|
---|
| 500 | information in REGS (if REGS and BUFFER->no_sub are nonzero). */
|
---|
| 501 | extern int re_search
|
---|
| 502 | _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
|
---|
| 503 | int length, int start, int range, struct re_registers *regs));
|
---|
| 504 |
|
---|
| 505 |
|
---|
| 506 | /* Like `re_search', but search in the concatenation of STRING1 and
|
---|
| 507 | STRING2. Also, stop searching at index START + STOP. */
|
---|
| 508 | extern int re_search_2
|
---|
| 509 | _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
|
---|
| 510 | int length1, const char *string2, int length2,
|
---|
| 511 | int start, int range, struct re_registers *regs, int stop));
|
---|
| 512 |
|
---|
| 513 |
|
---|
| 514 | /* Like `re_search', but return how many characters in STRING the regexp
|
---|
| 515 | in BUFFER matched, starting at position START. */
|
---|
| 516 | extern int re_match
|
---|
| 517 | _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
|
---|
| 518 | int length, int start, struct re_registers *regs));
|
---|
| 519 |
|
---|
| 520 |
|
---|
| 521 | /* Relates to `re_match' as `re_search_2' relates to `re_search'. */
|
---|
| 522 | extern int re_match_2
|
---|
| 523 | _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
|
---|
| 524 | int length1, const char *string2, int length2,
|
---|
| 525 | int start, struct re_registers *regs, int stop));
|
---|
| 526 |
|
---|
| 527 |
|
---|
| 528 | /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
|
---|
| 529 | ENDS. Subsequent matches using BUFFER and REGS will use this memory
|
---|
| 530 | for recording register information. STARTS and ENDS must be
|
---|
| 531 | allocated with malloc, and must each be at least `NUM_REGS * sizeof
|
---|
| 532 | (regoff_t)' bytes long.
|
---|
| 533 |
|
---|
| 534 | If NUM_REGS == 0, then subsequent matches should allocate their own
|
---|
| 535 | register data.
|
---|
| 536 |
|
---|
| 537 | Unless this function is called, the first search or match using
|
---|
| 538 | PATTERN_BUFFER will allocate its own register data, without
|
---|
| 539 | freeing the old data. */
|
---|
| 540 | extern void re_set_registers
|
---|
| 541 | _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
|
---|
| 542 | unsigned num_regs, regoff_t *starts, regoff_t *ends));
|
---|
| 543 |
|
---|
| 544 | #if defined _REGEX_RE_COMP || defined _LIBC
|
---|
| 545 | # ifndef _CRAY
|
---|
| 546 | /* 4.2 bsd compatibility. */
|
---|
| 547 | extern char *re_comp _RE_ARGS ((const char *));
|
---|
| 548 | extern int re_exec _RE_ARGS ((const char *));
|
---|
| 549 | # endif
|
---|
| 550 | #endif
|
---|
| 551 |
|
---|
| 552 | /* GCC 2.95 and later have "__restrict"; C99 compilers have
|
---|
| 553 | "restrict", and "configure" may have defined "restrict". */
|
---|
| 554 | #ifndef __restrict
|
---|
| 555 | # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
|
---|
| 556 | # if defined restrict || 199901L <= __STDC_VERSION__
|
---|
| 557 | # define __restrict restrict
|
---|
| 558 | # else
|
---|
| 559 | # define __restrict
|
---|
| 560 | # endif
|
---|
| 561 | # endif
|
---|
| 562 | #endif
|
---|
| 563 | /* gcc 3.1 and up support the [restrict] syntax. */
|
---|
| 564 | #ifndef __restrict_arr
|
---|
| 565 | # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
|
---|
| 566 | # define __restrict_arr __restrict
|
---|
| 567 | # else
|
---|
| 568 | # define __restrict_arr
|
---|
| 569 | # endif
|
---|
| 570 | #endif
|
---|
| 571 |
|
---|
| 572 | /* POSIX compatibility. */
|
---|
| 573 | extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
|
---|
| 574 | const char *__restrict __pattern,
|
---|
| 575 | int __cflags));
|
---|
| 576 |
|
---|
| 577 | extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
|
---|
| 578 | const char *__restrict __string, size_t __nmatch,
|
---|
| 579 | regmatch_t __pmatch[__restrict_arr],
|
---|
| 580 | int __eflags));
|
---|
| 581 |
|
---|
| 582 | extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
|
---|
| 583 | char *__errbuf, size_t __errbuf_size));
|
---|
| 584 |
|
---|
| 585 | extern void regfree _RE_ARGS ((regex_t *__preg));
|
---|
| 586 |
|
---|
| 587 |
|
---|
| 588 | #ifdef __cplusplus
|
---|
| 589 | }
|
---|
| 590 | #endif /* C++ */
|
---|
| 591 |
|
---|
| 592 | #endif /* regex.h */
|
---|
| 593 | |
---|
| 594 |
|
---|
| 595 | /*
|
---|
| 596 | Local variables:
|
---|
| 597 | make-backup-files: t
|
---|
| 598 | version-control: t
|
---|
| 599 | trim-versions-without-asking: nil
|
---|
| 600 | End:
|
---|
| 601 | */
|
---|