1126209Sache/* Definitions for data structures and routines for the regular 2146040Stjr expression library. 3250724Sjkim Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006,2008,2011 4146040Stjr Free Software Foundation, Inc. 5146040Stjr This file is part of the GNU C Library. 6126209Sache 7126209Sache The GNU C Library is free software; you can redistribute it and/or 8146040Stjr modify it under the terms of the GNU Lesser General Public 9146040Stjr License as published by the Free Software Foundation; either 10146040Stjr version 2.1 of the License, or (at your option) any later version. 11126209Sache 12126209Sache The GNU C Library is distributed in the hope that it will be useful, 13126209Sache but WITHOUT ANY WARRANTY; without even the implied warranty of 14126209Sache MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15146040Stjr Lesser General Public License for more details. 16126209Sache 17146040Stjr You should have received a copy of the GNU Lesser General Public 18250724Sjkim License along with the GNU C Library; if not, see 19250724Sjkim <http://www.gnu.org/licenses/>. */ 20126209Sache 21126209Sache#ifndef _REGEX_H 22126209Sache#define _REGEX_H 1 23126209Sache 24146040Stjr#include <sys/types.h> 25146040Stjr 26126209Sache/* Allow the use in C++ code. */ 27126209Sache#ifdef __cplusplus 28126209Sacheextern "C" { 29126209Sache#endif 30126209Sache 31126209Sache/* The following two types have to be signed and unsigned integer type 32126209Sache wide enough to hold a value of a pointer. For most ANSI compilers 33126209Sache ptrdiff_t and size_t should be likely OK. Still size of these two 34126209Sache types is 2 for Microsoft C. Ugh... */ 35126209Sachetypedef long int s_reg_t; 36126209Sachetypedef unsigned long int active_reg_t; 37126209Sache 38126209Sache/* The following bits are used to determine the regexp syntax we 39126209Sache recognize. The set/not-set meanings are chosen so that Emacs syntax 40126209Sache remains the value 0. The bits are given in alphabetical order, and 41126209Sache the definitions shifted by one from the previous bit; thus, when we 42126209Sache add or remove a bit, only one other definition need change. */ 43126209Sachetypedef unsigned long int reg_syntax_t; 44126209Sache 45250724Sjkim#ifdef __USE_GNU 46126209Sache/* If this bit is not set, then \ inside a bracket expression is literal. 47126209Sache If set, then such a \ quotes the following character. */ 48250724Sjkim# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) 49126209Sache 50126209Sache/* If this bit is not set, then + and ? are operators, and \+ and \? are 51126209Sache literals. 52126209Sache If set, then \+ and \? are operators and + and ? are literals. */ 53250724Sjkim# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) 54126209Sache 55126209Sache/* If this bit is set, then character classes are supported. They are: 56126209Sache [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], 57126209Sache [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. 58126209Sache If not set, then character classes are not supported. */ 59250724Sjkim# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) 60126209Sache 61126209Sache/* If this bit is set, then ^ and $ are always anchors (outside bracket 62126209Sache expressions, of course). 63126209Sache If this bit is not set, then it depends: 64250724Sjkim ^ is an anchor if it is at the beginning of a regular 65250724Sjkim expression or after an open-group or an alternation operator; 66250724Sjkim $ is an anchor if it is at the end of a regular expression, or 67250724Sjkim before a close-group or an alternation operator. 68126209Sache 69126209Sache This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because 70126209Sache POSIX draft 11.2 says that * etc. in leading positions is undefined. 71126209Sache We already implemented a previous draft which made those constructs 72126209Sache invalid, though, so we haven't changed the code back. */ 73250724Sjkim# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) 74126209Sache 75126209Sache/* If this bit is set, then special characters are always special 76126209Sache regardless of where they are in the pattern. 77126209Sache If this bit is not set, then special characters are special only in 78126209Sache some contexts; otherwise they are ordinary. Specifically, 79126209Sache * + ? and intervals are only special when not after the beginning, 80126209Sache open-group, or alternation operator. */ 81250724Sjkim# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) 82126209Sache 83126209Sache/* If this bit is set, then *, +, ?, and { cannot be first in an re or 84126209Sache immediately after an alternation or begin-group operator. */ 85250724Sjkim# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) 86126209Sache 87126209Sache/* If this bit is set, then . matches newline. 88126209Sache If not set, then it doesn't. */ 89250724Sjkim# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) 90126209Sache 91126209Sache/* If this bit is set, then . doesn't match NUL. 92126209Sache If not set, then it does. */ 93250724Sjkim# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) 94126209Sache 95126209Sache/* If this bit is set, nonmatching lists [^...] do not match newline. 96126209Sache If not set, they do. */ 97250724Sjkim# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) 98126209Sache 99126209Sache/* If this bit is set, either \{...\} or {...} defines an 100126209Sache interval, depending on RE_NO_BK_BRACES. 101126209Sache If not set, \{, \}, {, and } are literals. */ 102250724Sjkim# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) 103126209Sache 104126209Sache/* If this bit is set, +, ? and | aren't recognized as operators. 105126209Sache If not set, they are. */ 106250724Sjkim# define RE_LIMITED_OPS (RE_INTERVALS << 1) 107126209Sache 108126209Sache/* If this bit is set, newline is an alternation operator. 109126209Sache If not set, newline is literal. */ 110250724Sjkim# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) 111126209Sache 112126209Sache/* If this bit is set, then `{...}' defines an interval, and \{ and \} 113126209Sache are literals. 114126209Sache If not set, then `\{...\}' defines an interval. */ 115250724Sjkim# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) 116126209Sache 117126209Sache/* If this bit is set, (...) defines a group, and \( and \) are literals. 118126209Sache If not set, \(...\) defines a group, and ( and ) are literals. */ 119250724Sjkim# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) 120126209Sache 121126209Sache/* If this bit is set, then \<digit> matches <digit>. 122126209Sache If not set, then \<digit> is a back-reference. */ 123250724Sjkim# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) 124126209Sache 125126209Sache/* If this bit is set, then | is an alternation operator, and \| is literal. 126126209Sache If not set, then \| is an alternation operator, and | is literal. */ 127250724Sjkim# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) 128126209Sache 129126209Sache/* If this bit is set, then an ending range point collating higher 130126209Sache than the starting range point, as in [z-a], is invalid. 131126209Sache If not set, then when ending range point collates higher than the 132126209Sache starting range point, the range is ignored. */ 133250724Sjkim# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) 134126209Sache 135126209Sache/* If this bit is set, then an unmatched ) is ordinary. 136126209Sache If not set, then an unmatched ) is invalid. */ 137250724Sjkim# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) 138126209Sache 139126209Sache/* If this bit is set, succeed as soon as we match the whole pattern, 140126209Sache without further backtracking. */ 141250724Sjkim# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) 142126209Sache 143126209Sache/* If this bit is set, do not process the GNU regex operators. 144126209Sache If not set, then the GNU regex operators are recognized. */ 145250724Sjkim# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) 146126209Sache 147126209Sache/* If this bit is set, turn on internal regex debugging. 148126209Sache If not set, and debugging was on, turn it off. 149126209Sache This only works if regex.c is compiled -DDEBUG. 150126209Sache We define this bit always, so that all that's needed to turn on 151126209Sache debugging is to recompile regex.c; the calling code can always have 152126209Sache this bit set, and it won't affect anything in the normal case. */ 153250724Sjkim# define RE_DEBUG (RE_NO_GNU_OPS << 1) 154126209Sache 155131543Stjr/* If this bit is set, a syntactically invalid interval is treated as 156131543Stjr a string of ordinary characters. For example, the ERE 'a{1' is 157131543Stjr treated as 'a\{1'. */ 158250724Sjkim# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) 159131543Stjr 160146040Stjr/* If this bit is set, then ignore case when matching. 161146040Stjr If not set, then case is significant. */ 162250724Sjkim# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) 163146040Stjr 164146040Stjr/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only 165146040Stjr for ^, because it is difficult to scan the regex backwards to find 166146040Stjr whether ^ should be special. */ 167250724Sjkim# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) 168146040Stjr 169146040Stjr/* If this bit is set, then \{ cannot be first in an bre or 170146040Stjr immediately after an alternation or begin-group operator. */ 171250724Sjkim# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) 172146040Stjr 173146040Stjr/* If this bit is set, then no_sub will be set to 1 during 174146040Stjr re_compile_pattern. */ 175250724Sjkim# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) 176250724Sjkim#endif 177146040Stjr 178126209Sache/* This global variable defines the particular regexp syntax to use (for 179126209Sache some interfaces). When a regexp is compiled, the syntax used is 180126209Sache stored in the pattern buffer, so changing this does not affect 181126209Sache already-compiled regexps. */ 182126209Sacheextern reg_syntax_t re_syntax_options; 183126209Sache 184250724Sjkim#ifdef __USE_GNU 185126209Sache/* Define combinations of the above bits for the standard possibilities. 186126209Sache (The [[[ comments delimit what gets put into the Texinfo file, so 187126209Sache don't delete them!) */ 188126209Sache/* [[[begin syntaxes]]] */ 189126209Sache#define RE_SYNTAX_EMACS 0 190126209Sache 191126209Sache#define RE_SYNTAX_AWK \ 192126209Sache (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ 193126209Sache | RE_NO_BK_PARENS | RE_NO_BK_REFS \ 194126209Sache | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ 195126209Sache | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ 196250724Sjkim | RE_CHAR_CLASSES \ 197126209Sache | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) 198126209Sache 199126209Sache#define RE_SYNTAX_GNU_AWK \ 200250724Sjkim ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ 201250724Sjkim | RE_INVALID_INTERVAL_ORD) \ 202250724Sjkim & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS \ 203250724Sjkim | RE_CONTEXT_INVALID_OPS )) 204126209Sache 205250724Sjkim#define RE_SYNTAX_POSIX_AWK \ 206126209Sache (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ 207250724Sjkim | RE_INTERVALS | RE_NO_GNU_OPS \ 208250724Sjkim | RE_INVALID_INTERVAL_ORD) 209126209Sache 210126209Sache#define RE_SYNTAX_GREP \ 211126209Sache (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ 212126209Sache | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ 213126209Sache | RE_NEWLINE_ALT) 214126209Sache 215126209Sache#define RE_SYNTAX_EGREP \ 216126209Sache (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ 217126209Sache | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ 218126209Sache | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ 219126209Sache | RE_NO_BK_VBAR) 220126209Sache 221126209Sache#define RE_SYNTAX_POSIX_EGREP \ 222131543Stjr (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ 223131543Stjr | RE_INVALID_INTERVAL_ORD) 224126209Sache 225126209Sache/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ 226126209Sache#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC 227126209Sache 228126209Sache#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC 229126209Sache 230126209Sache/* Syntax bits common to both basic and extended POSIX regex syntax. */ 231126209Sache#define _RE_SYNTAX_POSIX_COMMON \ 232126209Sache (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ 233126209Sache | RE_INTERVALS | RE_NO_EMPTY_RANGES) 234126209Sache 235126209Sache#define RE_SYNTAX_POSIX_BASIC \ 236146040Stjr (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) 237126209Sache 238126209Sache/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes 239126209Sache RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this 240126209Sache isn't minimal, since other operators, such as \`, aren't disabled. */ 241126209Sache#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ 242126209Sache (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) 243126209Sache 244126209Sache#define RE_SYNTAX_POSIX_EXTENDED \ 245131543Stjr (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ 246131543Stjr | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ 247131543Stjr | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 248131543Stjr | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) 249126209Sache 250131543Stjr/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is 251131543Stjr removed and RE_NO_BK_REFS is added. */ 252126209Sache#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ 253126209Sache (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ 254126209Sache | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ 255126209Sache | RE_NO_BK_PARENS | RE_NO_BK_REFS \ 256126209Sache | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) 257126209Sache/* [[[end syntaxes]]] */ 258126209Sache 259126209Sache/* Maximum number of duplicates an interval can allow. Some systems 260126209Sache (erroneously) define this in other header files, but we want our 261126209Sache value, so remove any previous define. */ 262250724Sjkim# ifdef RE_DUP_MAX 263250724Sjkim# undef RE_DUP_MAX 264250724Sjkim# endif 265250724Sjkim/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */ 266250724Sjkim# define RE_DUP_MAX (0x7fff) 267126209Sache#endif 268126209Sache 269126209Sache 270126209Sache/* POSIX `cflags' bits (i.e., information for `regcomp'). */ 271126209Sache 272126209Sache/* If this bit is set, then use extended regular expression syntax. 273126209Sache If not set, then use basic regular expression syntax. */ 274126209Sache#define REG_EXTENDED 1 275126209Sache 276126209Sache/* If this bit is set, then ignore case when matching. 277126209Sache If not set, then case is significant. */ 278126209Sache#define REG_ICASE (REG_EXTENDED << 1) 279126209Sache 280126209Sache/* If this bit is set, then anchors do not match at newline 281126209Sache characters in the string. 282126209Sache If not set, then anchors do match at newlines. */ 283126209Sache#define REG_NEWLINE (REG_ICASE << 1) 284126209Sache 285126209Sache/* If this bit is set, then report only success or fail in regexec. 286126209Sache If not set, then returns differ between not matching and errors. */ 287126209Sache#define REG_NOSUB (REG_NEWLINE << 1) 288126209Sache 289126209Sache 290126209Sache/* POSIX `eflags' bits (i.e., information for regexec). */ 291126209Sache 292126209Sache/* If this bit is set, then the beginning-of-line operator doesn't match 293126209Sache the beginning of the string (presumably because it's not the 294126209Sache beginning of a line). 295126209Sache If not set, then the beginning-of-line operator does match the 296126209Sache beginning of the string. */ 297126209Sache#define REG_NOTBOL 1 298126209Sache 299126209Sache/* Like REG_NOTBOL, except for the end-of-line. */ 300126209Sache#define REG_NOTEOL (1 << 1) 301126209Sache 302146040Stjr/* Use PMATCH[0] to delimit the start and end of the search in the 303146040Stjr buffer. */ 304146040Stjr#define REG_STARTEND (1 << 2) 305126209Sache 306146040Stjr 307126209Sache/* If any error codes are removed, changed, or added, update the 308126209Sache `re_error_msg' table in regex.c. */ 309126209Sachetypedef enum 310126209Sache{ 311250724Sjkim#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K 312126209Sache REG_ENOSYS = -1, /* This will never happen for this implementation. */ 313126209Sache#endif 314126209Sache 315126209Sache REG_NOERROR = 0, /* Success. */ 316126209Sache REG_NOMATCH, /* Didn't find a match (for regexec). */ 317126209Sache 318126209Sache /* POSIX regcomp return error codes. (In the order listed in the 319126209Sache standard.) */ 320126209Sache REG_BADPAT, /* Invalid pattern. */ 321146040Stjr REG_ECOLLATE, /* Inalid collating element. */ 322126209Sache REG_ECTYPE, /* Invalid character class name. */ 323126209Sache REG_EESCAPE, /* Trailing backslash. */ 324126209Sache REG_ESUBREG, /* Invalid back reference. */ 325126209Sache REG_EBRACK, /* Unmatched left bracket. */ 326126209Sache REG_EPAREN, /* Parenthesis imbalance. */ 327126209Sache REG_EBRACE, /* Unmatched \{. */ 328126209Sache REG_BADBR, /* Invalid contents of \{\}. */ 329126209Sache REG_ERANGE, /* Invalid range end. */ 330126209Sache REG_ESPACE, /* Ran out of memory. */ 331126209Sache REG_BADRPT, /* No preceding re for repetition op. */ 332126209Sache 333126209Sache /* Error codes we've added. */ 334126209Sache REG_EEND, /* Premature end. */ 335126209Sache REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ 336126209Sache REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ 337126209Sache} reg_errcode_t; 338126209Sache 339126209Sache/* This data structure represents a compiled pattern. Before calling 340126209Sache the pattern compiler, the fields `buffer', `allocated', `fastmap', 341250724Sjkim and `translate' can be set. After the pattern has been compiled, 342250724Sjkim the fields `re_nsub', `not_bol' and `not_eol' are available. All 343250724Sjkim other fields are private to the regex routines. */ 344126209Sache 345126209Sache#ifndef RE_TRANSLATE_TYPE 346250724Sjkim# define __RE_TRANSLATE_TYPE unsigned char * 347250724Sjkim# ifdef __USE_GNU 348250724Sjkim# define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE 349250724Sjkim# endif 350126209Sache#endif 351126209Sache 352250724Sjkim#ifdef __USE_GNU 353250724Sjkim# define __REPB_PREFIX(name) name 354250724Sjkim#else 355250724Sjkim# define __REPB_PREFIX(name) __##name 356250724Sjkim#endif 357250724Sjkim 358126209Sachestruct re_pattern_buffer 359126209Sache{ 360250724Sjkim /* Space that holds the compiled pattern. It is declared as 361250724Sjkim `unsigned char *' because its elements are sometimes used as 362250724Sjkim array indexes. */ 363250724Sjkim unsigned char *__REPB_PREFIX(buffer); 364126209Sache 365250724Sjkim /* Number of bytes to which `buffer' points. */ 366250724Sjkim unsigned long int __REPB_PREFIX(allocated); 367126209Sache 368250724Sjkim /* Number of bytes actually used in `buffer'. */ 369250724Sjkim unsigned long int __REPB_PREFIX(used); 370126209Sache 371250724Sjkim /* Syntax setting with which the pattern was compiled. */ 372250724Sjkim reg_syntax_t __REPB_PREFIX(syntax); 373126209Sache 374250724Sjkim /* Pointer to a fastmap, if any, otherwise zero. re_search uses the 375250724Sjkim fastmap, if there is one, to skip over impossible starting points 376250724Sjkim for matches. */ 377250724Sjkim char *__REPB_PREFIX(fastmap); 378126209Sache 379250724Sjkim /* Either a translate table to apply to all characters before 380250724Sjkim comparing them, or zero for no translation. The translation is 381250724Sjkim applied to a pattern when it is compiled and to a string when it 382250724Sjkim is matched. */ 383250724Sjkim __RE_TRANSLATE_TYPE __REPB_PREFIX(translate); 384126209Sache 385250724Sjkim /* Number of subexpressions found by the compiler. */ 386126209Sache size_t re_nsub; 387126209Sache 388250724Sjkim /* Zero if this pattern cannot match the empty string, one else. 389250724Sjkim Well, in truth it's used only in `re_search_2', to see whether or 390250724Sjkim not we should use the fastmap, so we don't set this absolutely 391250724Sjkim perfectly; see `re_compile_fastmap' (the `duplicate' case). */ 392250724Sjkim unsigned __REPB_PREFIX(can_be_null) : 1; 393126209Sache 394250724Sjkim /* If REGS_UNALLOCATED, allocate space in the `regs' structure 395250724Sjkim for `max (RE_NREGS, re_nsub + 1)' groups. 396250724Sjkim If REGS_REALLOCATE, reallocate space if necessary. 397250724Sjkim If REGS_FIXED, use what's there. */ 398250724Sjkim#ifdef __USE_GNU 399250724Sjkim# define REGS_UNALLOCATED 0 400250724Sjkim# define REGS_REALLOCATE 1 401250724Sjkim# define REGS_FIXED 2 402250724Sjkim#endif 403250724Sjkim unsigned __REPB_PREFIX(regs_allocated) : 2; 404126209Sache 405250724Sjkim /* Set to zero when `regex_compile' compiles a pattern; set to one 406250724Sjkim by `re_compile_fastmap' if it updates the fastmap. */ 407250724Sjkim unsigned __REPB_PREFIX(fastmap_accurate) : 1; 408126209Sache 409250724Sjkim /* If set, `re_match_2' does not return information about 410250724Sjkim subexpressions. */ 411250724Sjkim unsigned __REPB_PREFIX(no_sub) : 1; 412126209Sache 413250724Sjkim /* If set, a beginning-of-line anchor doesn't match at the beginning 414250724Sjkim of the string. */ 415250724Sjkim unsigned __REPB_PREFIX(not_bol) : 1; 416126209Sache 417250724Sjkim /* Similarly for an end-of-line anchor. */ 418250724Sjkim unsigned __REPB_PREFIX(not_eol) : 1; 419126209Sache 420250724Sjkim /* If true, an anchor at a newline matches. */ 421250724Sjkim unsigned __REPB_PREFIX(newline_anchor) : 1; 422126209Sache}; 423126209Sache 424126209Sachetypedef struct re_pattern_buffer regex_t; 425126209Sache 426126209Sache/* Type for byte offsets within the string. POSIX mandates this. */ 427126209Sachetypedef int regoff_t; 428126209Sache 429126209Sache 430250724Sjkim#ifdef __USE_GNU 431126209Sache/* This is the structure we store register match data in. See 432126209Sache regex.texinfo for a full description of what registers match. */ 433126209Sachestruct re_registers 434126209Sache{ 435126209Sache unsigned num_regs; 436126209Sache regoff_t *start; 437126209Sache regoff_t *end; 438126209Sache}; 439126209Sache 440126209Sache 441126209Sache/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, 442126209Sache `re_match_2' returns information about at least this many registers 443126209Sache the first time a `regs' structure is passed. */ 444250724Sjkim# ifndef RE_NREGS 445250724Sjkim# define RE_NREGS 30 446250724Sjkim# endif 447126209Sache#endif 448126209Sache 449126209Sache 450126209Sache/* POSIX specification for registers. Aside from the different names than 451126209Sache `re_registers', POSIX uses an array of structures, instead of a 452126209Sache structure of arrays. */ 453126209Sachetypedef struct 454126209Sache{ 455126209Sache regoff_t rm_so; /* Byte offset from string's start to substring's start. */ 456126209Sache regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ 457126209Sache} regmatch_t; 458126209Sache 459126209Sache/* Declarations for routines. */ 460126209Sache 461250724Sjkim#ifdef __USE_GNU 462126209Sache/* Sets the current default syntax to SYNTAX, and return the old syntax. 463126209Sache You can also simply assign to the `re_syntax_options' variable. */ 464250724Sjkimextern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); 465126209Sache 466126209Sache/* Compile the regular expression PATTERN, with length LENGTH 467126209Sache and syntax given by the global `re_syntax_options', into the buffer 468250724Sjkim BUFFER. Return NULL if successful, and an error string if not. 469126209Sache 470250724Sjkim To free the allocated storage, you must call `regfree' on BUFFER. 471250724Sjkim Note that the translate table must either have been initialised by 472250724Sjkim `regcomp', with a malloc'ed value, or set to NULL before calling 473250724Sjkim `regfree'. */ 474250724Sjkimextern const char *re_compile_pattern (const char *__pattern, size_t __length, 475250724Sjkim struct re_pattern_buffer *__buffer); 476126209Sache 477250724Sjkim 478126209Sache/* Compile a fastmap for the compiled pattern in BUFFER; used to 479126209Sache accelerate searches. Return 0 if successful and -2 if was an 480126209Sache internal error. */ 481250724Sjkimextern int re_compile_fastmap (struct re_pattern_buffer *__buffer); 482126209Sache 483126209Sache 484126209Sache/* Search in the string STRING (with length LENGTH) for the pattern 485126209Sache compiled into BUFFER. Start searching at position START, for RANGE 486126209Sache characters. Return the starting position of the match, -1 for no 487126209Sache match, or -2 for an internal error. Also return register 488126209Sache information in REGS (if REGS and BUFFER->no_sub are nonzero). */ 489250724Sjkimextern int re_search (struct re_pattern_buffer *__buffer, const char *__string, 490250724Sjkim int __length, int __start, int __range, 491250724Sjkim struct re_registers *__regs); 492126209Sache 493126209Sache 494126209Sache/* Like `re_search', but search in the concatenation of STRING1 and 495126209Sache STRING2. Also, stop searching at index START + STOP. */ 496250724Sjkimextern int re_search_2 (struct re_pattern_buffer *__buffer, 497250724Sjkim const char *__string1, int __length1, 498250724Sjkim const char *__string2, int __length2, int __start, 499250724Sjkim int __range, struct re_registers *__regs, int __stop); 500126209Sache 501126209Sache 502126209Sache/* Like `re_search', but return how many characters in STRING the regexp 503126209Sache in BUFFER matched, starting at position START. */ 504250724Sjkimextern int re_match (struct re_pattern_buffer *__buffer, const char *__string, 505250724Sjkim int __length, int __start, struct re_registers *__regs); 506126209Sache 507126209Sache 508126209Sache/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ 509250724Sjkimextern int re_match_2 (struct re_pattern_buffer *__buffer, 510250724Sjkim const char *__string1, int __length1, 511250724Sjkim const char *__string2, int __length2, int __start, 512250724Sjkim struct re_registers *__regs, int __stop); 513126209Sache 514126209Sache 515126209Sache/* Set REGS to hold NUM_REGS registers, storing them in STARTS and 516126209Sache ENDS. Subsequent matches using BUFFER and REGS will use this memory 517126209Sache for recording register information. STARTS and ENDS must be 518126209Sache allocated with malloc, and must each be at least `NUM_REGS * sizeof 519126209Sache (regoff_t)' bytes long. 520126209Sache 521126209Sache If NUM_REGS == 0, then subsequent matches should allocate their own 522126209Sache register data. 523126209Sache 524126209Sache Unless this function is called, the first search or match using 525126209Sache PATTERN_BUFFER will allocate its own register data, without 526126209Sache freeing the old data. */ 527250724Sjkimextern void re_set_registers (struct re_pattern_buffer *__buffer, 528250724Sjkim struct re_registers *__regs, 529250724Sjkim unsigned int __num_regs, 530250724Sjkim regoff_t *__starts, regoff_t *__ends); 531250724Sjkim#endif /* Use GNU */ 532126209Sache 533250724Sjkim#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_BSD) 534126209Sache# ifndef _CRAY 535126209Sache/* 4.2 bsd compatibility. */ 536250724Sjkimextern char *re_comp (const char *); 537250724Sjkimextern int re_exec (const char *); 538126209Sache# endif 539126209Sache#endif 540126209Sache 541131543Stjr/* GCC 2.95 and later have "__restrict"; C99 compilers have 542131543Stjr "restrict", and "configure" may have defined "restrict". */ 543131543Stjr#ifndef __restrict 544131543Stjr# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) 545131543Stjr# if defined restrict || 199901L <= __STDC_VERSION__ 546131543Stjr# define __restrict restrict 547131543Stjr# else 548131543Stjr# define __restrict 549131543Stjr# endif 550131543Stjr# endif 551131543Stjr#endif 552146040Stjr/* gcc 3.1 and up support the [restrict] syntax. */ 553146040Stjr#ifndef __restrict_arr 554250724Sjkim# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) \ 555250724Sjkim && !defined __GNUG__ 556146040Stjr# define __restrict_arr __restrict 557146040Stjr# else 558146040Stjr# define __restrict_arr 559146040Stjr# endif 560146040Stjr#endif 561131543Stjr 562126209Sache/* POSIX compatibility. */ 563250724Sjkimextern int regcomp (regex_t *__restrict __preg, 564250724Sjkim const char *__restrict __pattern, 565250724Sjkim int __cflags); 566126209Sache 567250724Sjkimextern int regexec (const regex_t *__restrict __preg, 568250724Sjkim const char *__restrict __string, size_t __nmatch, 569250724Sjkim regmatch_t __pmatch[__restrict_arr], 570250724Sjkim int __eflags); 571126209Sache 572250724Sjkimextern size_t regerror (int __errcode, const regex_t *__restrict __preg, 573250724Sjkim char *__restrict __errbuf, size_t __errbuf_size); 574126209Sache 575250724Sjkimextern void regfree (regex_t *__preg); 576126209Sache 577126209Sache 578126209Sache#ifdef __cplusplus 579126209Sache} 580126209Sache#endif /* C++ */ 581126209Sache 582126209Sache#endif /* regex.h */ 583