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