Back to index

nagios-plugins  1.4.16
regex.h
Go to the documentation of this file.
00001 /* Definitions for data structures and routines for the regular
00002    expression library.
00003    Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993, 1995, 1996, 1997, 1998,
00004    2000, 2001, 2002, 2003, 2005, 2006, 2009, 2010 Free Software Foundation,
00005    Inc.
00006    This file is part of the GNU C Library.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 3, or (at your option)
00011    any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License along
00019    with this program; if not, write to the Free Software Foundation,
00020    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
00021 
00022 #ifndef _REGEX_H
00023 #define _REGEX_H 1
00024 
00025 #include <sys/types.h>
00026 
00027 /* Allow the use in C++ code.  */
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032 /* Define __USE_GNU_REGEX to declare GNU extensions that violate the
00033    POSIX name space rules.  */
00034 #undef __USE_GNU_REGEX
00035 #if (defined _GNU_SOURCE                                \
00036      || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE    \
00037         && !defined _XOPEN_SOURCE))
00038 # define __USE_GNU_REGEX 1
00039 #endif
00040 
00041 #ifdef _REGEX_LARGE_OFFSETS
00042 
00043 /* Use types and values that are wide enough to represent signed and
00044    unsigned byte offsets in memory.  This currently works only when
00045    the regex code is used outside of the GNU C library; it is not yet
00046    supported within glibc itself, and glibc users should not define
00047    _REGEX_LARGE_OFFSETS.  */
00048 
00049 /* The type of the offset of a byte within a string.
00050    For historical reasons POSIX 1003.1-2004 requires that regoff_t be
00051    at least as wide as off_t.  However, many common POSIX platforms set
00052    regoff_t to the more-sensible ssize_t and the Open Group has
00053    signalled its intention to change the requirement to be that
00054    regoff_t be at least as wide as ptrdiff_t and ssize_t; see XBD ERN
00055    60 (2005-08-25).  We don't know of any hosts where ssize_t or
00056    ptrdiff_t is wider than ssize_t, so ssize_t is safe.  */
00057 typedef ssize_t regoff_t;
00058 
00059 /* The type of nonnegative object indexes.  Traditionally, GNU regex
00060    uses 'int' for these.  Code that uses __re_idx_t should work
00061    regardless of whether the type is signed.  */
00062 typedef size_t __re_idx_t;
00063 
00064 /* The type of object sizes.  */
00065 typedef size_t __re_size_t;
00066 
00067 /* The type of object sizes, in places where the traditional code
00068    uses unsigned long int.  */
00069 typedef size_t __re_long_size_t;
00070 
00071 #else
00072 
00073 /* Use types that are binary-compatible with the traditional GNU regex
00074    implementation, which mishandles strings longer than INT_MAX.  */
00075 
00076 typedef int regoff_t;
00077 typedef int __re_idx_t;
00078 typedef unsigned int __re_size_t;
00079 typedef unsigned long int __re_long_size_t;
00080 
00081 #endif
00082 
00083 /* The following two types have to be signed and unsigned integer type
00084    wide enough to hold a value of a pointer.  For most ANSI compilers
00085    ptrdiff_t and size_t should be likely OK.  Still size of these two
00086    types is 2 for Microsoft C.  Ugh... */
00087 typedef long int s_reg_t;
00088 typedef unsigned long int active_reg_t;
00089 
00090 /* The following bits are used to determine the regexp syntax we
00091    recognize.  The set/not-set meanings are chosen so that Emacs syntax
00092    remains the value 0.  The bits are given in alphabetical order, and
00093    the definitions shifted by one from the previous bit; thus, when we
00094    add or remove a bit, only one other definition need change.  */
00095 typedef unsigned long int reg_syntax_t;
00096 
00097 #ifdef __USE_GNU_REGEX
00098 
00099 /* If this bit is not set, then \ inside a bracket expression is literal.
00100    If set, then such a \ quotes the following character.  */
00101 # define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
00102 
00103 /* If this bit is not set, then + and ? are operators, and \+ and \? are
00104      literals.
00105    If set, then \+ and \? are operators and + and ? are literals.  */
00106 # define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
00107 
00108 /* If this bit is set, then character classes are supported.  They are:
00109      [:alpha:], [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
00110      [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
00111    If not set, then character classes are not supported.  */
00112 # define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
00113 
00114 /* If this bit is set, then ^ and $ are always anchors (outside bracket
00115      expressions, of course).
00116    If this bit is not set, then it depends:
00117         ^  is an anchor if it is at the beginning of a regular
00118            expression or after an open-group or an alternation operator;
00119         $  is an anchor if it is at the end of a regular expression, or
00120            before a close-group or an alternation operator.
00121 
00122    This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
00123    POSIX draft 11.2 says that * etc. in leading positions is undefined.
00124    We already implemented a previous draft which made those constructs
00125    invalid, though, so we haven't changed the code back.  */
00126 # define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
00127 
00128 /* If this bit is set, then special characters are always special
00129      regardless of where they are in the pattern.
00130    If this bit is not set, then special characters are special only in
00131      some contexts; otherwise they are ordinary.  Specifically,
00132      * + ? and intervals are only special when not after the beginning,
00133      open-group, or alternation operator.  */
00134 # define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
00135 
00136 /* If this bit is set, then *, +, ?, and { cannot be first in an re or
00137      immediately after an alternation or begin-group operator.  */
00138 # define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
00139 
00140 /* If this bit is set, then . matches newline.
00141    If not set, then it doesn't.  */
00142 # define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
00143 
00144 /* If this bit is set, then . doesn't match NUL.
00145    If not set, then it does.  */
00146 # define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
00147 
00148 /* If this bit is set, nonmatching lists [^...] do not match newline.
00149    If not set, they do.  */
00150 # define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
00151 
00152 /* If this bit is set, either \{...\} or {...} defines an
00153      interval, depending on RE_NO_BK_BRACES.
00154    If not set, \{, \}, {, and } are literals.  */
00155 # define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
00156 
00157 /* If this bit is set, +, ? and | aren't recognized as operators.
00158    If not set, they are.  */
00159 # define RE_LIMITED_OPS (RE_INTERVALS << 1)
00160 
00161 /* If this bit is set, newline is an alternation operator.
00162    If not set, newline is literal.  */
00163 # define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
00164 
00165 /* If this bit is set, then `{...}' defines an interval, and \{ and \}
00166      are literals.
00167   If not set, then `\{...\}' defines an interval.  */
00168 # define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
00169 
00170 /* If this bit is set, (...) defines a group, and \( and \) are literals.
00171    If not set, \(...\) defines a group, and ( and ) are literals.  */
00172 # define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
00173 
00174 /* If this bit is set, then <digit> matches <digit>.
00175    If not set, then <digit> is a back-reference.  */
00176 # define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
00177 
00178 /* If this bit is set, then | is an alternation operator, and \| is literal.
00179    If not set, then \| is an alternation operator, and | is literal.  */
00180 # define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
00181 
00182 /* If this bit is set, then an ending range point collating higher
00183      than the starting range point, as in [z-a], is invalid.
00184    If not set, then when ending range point collates higher than the
00185      starting range point, the range is ignored.  */
00186 # define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
00187 
00188 /* If this bit is set, then an unmatched ) is ordinary.
00189    If not set, then an unmatched ) is invalid.  */
00190 # define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
00191 
00192 /* If this bit is set, succeed as soon as we match the whole pattern,
00193    without further backtracking.  */
00194 # define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
00195 
00196 /* If this bit is set, do not process the GNU regex operators.
00197    If not set, then the GNU regex operators are recognized. */
00198 # define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
00199 
00200 /* If this bit is set, turn on internal regex debugging.
00201    If not set, and debugging was on, turn it off.
00202    This only works if regex.c is compiled -DDEBUG.
00203    We define this bit always, so that all that's needed to turn on
00204    debugging is to recompile regex.c; the calling code can always have
00205    this bit set, and it won't affect anything in the normal case. */
00206 # define RE_DEBUG (RE_NO_GNU_OPS << 1)
00207 
00208 /* If this bit is set, a syntactically invalid interval is treated as
00209    a string of ordinary characters.  For example, the ERE 'a{1' is
00210    treated as 'a\{1'.  */
00211 # define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
00212 
00213 /* If this bit is set, then ignore case when matching.
00214    If not set, then case is significant.  */
00215 # define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
00216 
00217 /* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
00218    for ^, because it is difficult to scan the regex backwards to find
00219    whether ^ should be special.  */
00220 # define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
00221 
00222 /* If this bit is set, then \{ cannot be first in an bre or
00223    immediately after an alternation or begin-group operator.  */
00224 # define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
00225 
00226 /* If this bit is set, then no_sub will be set to 1 during
00227    re_compile_pattern.  */
00228 # define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
00229 
00230 #endif /* defined __USE_GNU_REGEX */
00231 
00232 /* This global variable defines the particular regexp syntax to use (for
00233    some interfaces).  When a regexp is compiled, the syntax used is
00234    stored in the pattern buffer, so changing this does not affect
00235    already-compiled regexps.  */
00236 extern reg_syntax_t re_syntax_options;
00237 
00238 #ifdef __USE_GNU_REGEX
00239 /* Define combinations of the above bits for the standard possibilities.
00240    (The [[[ comments delimit what gets put into the Texinfo file, so
00241    don't delete them!)  */
00242 /* [[[begin syntaxes]]] */
00243 # define RE_SYNTAX_EMACS 0
00244 
00245 # define RE_SYNTAX_AWK                                                \
00246   (RE_BACKSLASH_ESCAPE_IN_LISTS   | RE_DOT_NOT_NULL                   \
00247    | RE_NO_BK_PARENS              | RE_NO_BK_REFS                     \
00248    | RE_NO_BK_VBAR                | RE_NO_EMPTY_RANGES                \
00249    | RE_DOT_NEWLINE           | RE_CONTEXT_INDEP_ANCHORS              \
00250    | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
00251 
00252 # define RE_SYNTAX_GNU_AWK                                     \
00253   ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG)      \
00254    & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS          \
00255        | RE_CONTEXT_INVALID_OPS ))
00256 
00257 # define RE_SYNTAX_POSIX_AWK                                          \
00258   (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS            \
00259    | RE_INTERVALS        | RE_NO_GNU_OPS)
00260 
00261 # define RE_SYNTAX_GREP                                               \
00262   (RE_BK_PLUS_QM              | RE_CHAR_CLASSES                       \
00263    | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS                          \
00264    | RE_NEWLINE_ALT)
00265 
00266 # define RE_SYNTAX_EGREP                                       \
00267   (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS                  \
00268    | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE                  \
00269    | RE_NEWLINE_ALT       | RE_NO_BK_PARENS                           \
00270    | RE_NO_BK_VBAR)
00271 
00272 # define RE_SYNTAX_POSIX_EGREP                                        \
00273   (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES                   \
00274    | RE_INVALID_INTERVAL_ORD)
00275 
00276 /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff.  */
00277 # define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
00278 
00279 # define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
00280 
00281 /* Syntax bits common to both basic and extended POSIX regex syntax.  */
00282 # define _RE_SYNTAX_POSIX_COMMON                               \
00283   (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL            \
00284    | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
00285 
00286 # define RE_SYNTAX_POSIX_BASIC                                        \
00287   (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
00288 
00289 /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
00290    RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
00291    isn't minimal, since other operators, such as \`, aren't disabled.  */
00292 # define RE_SYNTAX_POSIX_MINIMAL_BASIC                                \
00293   (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
00294 
00295 # define RE_SYNTAX_POSIX_EXTENDED                              \
00296   (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS                \
00297    | RE_CONTEXT_INDEP_OPS   | RE_NO_BK_BRACES                         \
00298    | RE_NO_BK_PARENS        | RE_NO_BK_VBAR                           \
00299    | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
00300 
00301 /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
00302    removed and RE_NO_BK_REFS is added.  */
00303 # define RE_SYNTAX_POSIX_MINIMAL_EXTENDED                      \
00304   (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS                \
00305    | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES                         \
00306    | RE_NO_BK_PARENS        | RE_NO_BK_REFS                           \
00307    | RE_NO_BK_VBAR       | RE_UNMATCHED_RIGHT_PAREN_ORD)
00308 /* [[[end syntaxes]]] */
00309 
00310 #endif /* defined __USE_GNU_REGEX */
00311 
00312 #ifdef __USE_GNU_REGEX
00313 
00314 /* Maximum number of duplicates an interval can allow.  POSIX-conforming
00315    systems might define this in <limits.h>, but we want our
00316    value, so remove any previous define.  */
00317 # ifdef RE_DUP_MAX
00318 #  undef RE_DUP_MAX
00319 # endif
00320 
00321 /* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored
00322    the counter as a 2-byte signed integer.  This is no longer true, so
00323    RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to
00324    ((SIZE_MAX - 2) / 10 - 1) if _REGEX_LARGE_OFFSETS is defined.
00325    However, there would be a huge performance problem if someone
00326    actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains
00327    its historical value.  */
00328 # define RE_DUP_MAX (0x7fff)
00329 
00330 #endif /* defined __USE_GNU_REGEX */
00331 
00332 
00333 /* POSIX `cflags' bits (i.e., information for `regcomp').  */
00334 
00335 /* If this bit is set, then use extended regular expression syntax.
00336    If not set, then use basic regular expression syntax.  */
00337 #define REG_EXTENDED 1
00338 
00339 /* If this bit is set, then ignore case when matching.
00340    If not set, then case is significant.  */
00341 #define REG_ICASE (1 << 1)
00342 
00343 /* If this bit is set, then anchors do not match at newline
00344      characters in the string.
00345    If not set, then anchors do match at newlines.  */
00346 #define REG_NEWLINE (1 << 2)
00347 
00348 /* If this bit is set, then report only success or fail in regexec.
00349    If not set, then returns differ between not matching and errors.  */
00350 #define REG_NOSUB (1 << 3)
00351 
00352 
00353 /* POSIX `eflags' bits (i.e., information for regexec).  */
00354 
00355 /* If this bit is set, then the beginning-of-line operator doesn't match
00356      the beginning of the string (presumably because it's not the
00357      beginning of a line).
00358    If not set, then the beginning-of-line operator does match the
00359      beginning of the string.  */
00360 #define REG_NOTBOL 1
00361 
00362 /* Like REG_NOTBOL, except for the end-of-line.  */
00363 #define REG_NOTEOL (1 << 1)
00364 
00365 /* Use PMATCH[0] to delimit the start and end of the search in the
00366    buffer.  */
00367 #define REG_STARTEND (1 << 2)
00368 
00369 
00370 /* If any error codes are removed, changed, or added, update the
00371    `__re_error_msgid' table in regcomp.c.  */
00372 
00373 typedef enum
00374 {
00375   _REG_ENOSYS = -1,  /* This will never happen for this implementation.  */
00376   _REG_NOERROR = 0,  /* Success.  */
00377   _REG_NOMATCH,             /* Didn't find a match (for regexec).  */
00378 
00379   /* POSIX regcomp return error codes.  (In the order listed in the
00380      standard.)  */
00381   _REG_BADPAT,              /* Invalid pattern.  */
00382   _REG_ECOLLATE,     /* Invalid collating element.  */
00383   _REG_ECTYPE,              /* Invalid character class name.  */
00384   _REG_EESCAPE,             /* Trailing backslash.  */
00385   _REG_ESUBREG,             /* Invalid back reference.  */
00386   _REG_EBRACK,              /* Unmatched left bracket.  */
00387   _REG_EPAREN,              /* Parenthesis imbalance.  */
00388   _REG_EBRACE,              /* Unmatched \{.  */
00389   _REG_BADBR,        /* Invalid contents of \{\}.  */
00390   _REG_ERANGE,              /* Invalid range end.  */
00391   _REG_ESPACE,              /* Ran out of memory.  */
00392   _REG_BADRPT,              /* No preceding re for repetition op.  */
00393 
00394   /* Error codes we've added.  */
00395   _REG_EEND,         /* Premature end.  */
00396   _REG_ESIZE,        /* Compiled pattern bigger than 2^16 bytes.  */
00397   _REG_ERPAREN              /* Unmatched ) or \); not returned from regcomp.  */
00398 } reg_errcode_t;
00399 
00400 #ifdef _XOPEN_SOURCE
00401 # define REG_ENOSYS  _REG_ENOSYS
00402 #endif
00403 #define REG_NOERROR  _REG_NOERROR
00404 #define REG_NOMATCH  _REG_NOMATCH
00405 #define REG_BADPAT   _REG_BADPAT
00406 #define REG_ECOLLATE _REG_ECOLLATE
00407 #define REG_ECTYPE   _REG_ECTYPE
00408 #define REG_EESCAPE  _REG_EESCAPE
00409 #define REG_ESUBREG  _REG_ESUBREG
00410 #define REG_EBRACK   _REG_EBRACK
00411 #define REG_EPAREN   _REG_EPAREN
00412 #define REG_EBRACE   _REG_EBRACE
00413 #define REG_BADBR    _REG_BADBR
00414 #define REG_ERANGE   _REG_ERANGE
00415 #define REG_ESPACE   _REG_ESPACE
00416 #define REG_BADRPT   _REG_BADRPT
00417 #define REG_EEND     _REG_EEND
00418 #define REG_ESIZE    _REG_ESIZE
00419 #define REG_ERPAREN  _REG_ERPAREN
00420 
00421 /* struct re_pattern_buffer normally uses member names like `buffer'
00422    that POSIX does not allow.  In POSIX mode these members have names
00423    with leading `re_' (e.g., `re_buffer').  */
00424 #ifdef __USE_GNU_REGEX
00425 # define _REG_RE_NAME(id) id
00426 # define _REG_RM_NAME(id) id
00427 #else
00428 # define _REG_RE_NAME(id) re_##id
00429 # define _REG_RM_NAME(id) rm_##id
00430 #endif
00431 
00432 /* The user can specify the type of the re_translate member by
00433    defining the macro RE_TRANSLATE_TYPE, which defaults to unsigned
00434    char *.  This pollutes the POSIX name space, so in POSIX mode just
00435    use unsigned char *.  */
00436 #ifdef __USE_GNU_REGEX
00437 # ifndef RE_TRANSLATE_TYPE
00438 #  define RE_TRANSLATE_TYPE unsigned char *
00439 # endif
00440 # define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE
00441 #else
00442 # define REG_TRANSLATE_TYPE unsigned char *
00443 #endif
00444 
00445 /* This data structure represents a compiled pattern.  Before calling
00446    the pattern compiler, the fields `buffer', `allocated', `fastmap',
00447    `translate', and `no_sub' can be set.  After the pattern has been
00448    compiled, the `re_nsub' field is available.  All other fields are
00449    private to the regex routines.  */
00450 
00451 struct re_pattern_buffer
00452 {
00453   /* Space that holds the compiled pattern.  It is declared as
00454      `unsigned char *' because its elements are sometimes used as
00455      array indexes.  */
00456   unsigned char *_REG_RE_NAME (buffer);
00457 
00458   /* Number of bytes to which `buffer' points.  */
00459   __re_long_size_t _REG_RE_NAME (allocated);
00460 
00461   /* Number of bytes actually used in `buffer'.  */
00462   __re_long_size_t _REG_RE_NAME (used);
00463 
00464   /* Syntax setting with which the pattern was compiled.  */
00465   reg_syntax_t _REG_RE_NAME (syntax);
00466 
00467   /* Pointer to a fastmap, if any, otherwise zero.  re_search uses the
00468      fastmap, if there is one, to skip over impossible starting points
00469      for matches.  */
00470   char *_REG_RE_NAME (fastmap);
00471 
00472   /* Either a translate table to apply to all characters before
00473      comparing them, or zero for no translation.  The translation is
00474      applied to a pattern when it is compiled and to a string when it
00475      is matched.  */
00476   REG_TRANSLATE_TYPE _REG_RE_NAME (translate);
00477 
00478   /* Number of subexpressions found by the compiler.  */
00479   size_t re_nsub;
00480 
00481   /* Zero if this pattern cannot match the empty string, one else.
00482      Well, in truth it's used only in `re_search_2', to see whether or
00483      not we should use the fastmap, so we don't set this absolutely
00484      perfectly; see `re_compile_fastmap' (the `duplicate' case).  */
00485   unsigned int _REG_RE_NAME (can_be_null) : 1;
00486 
00487   /* If REGS_UNALLOCATED, allocate space in the `regs' structure
00488      for `max (RE_NREGS, re_nsub + 1)' groups.
00489      If REGS_REALLOCATE, reallocate space if necessary.
00490      If REGS_FIXED, use what's there.  */
00491 #ifdef __USE_GNU_REGEX
00492 # define REGS_UNALLOCATED 0
00493 # define REGS_REALLOCATE 1
00494 # define REGS_FIXED 2
00495 #endif
00496   unsigned int _REG_RE_NAME (regs_allocated) : 2;
00497 
00498   /* Set to zero when `regex_compile' compiles a pattern; set to one
00499      by `re_compile_fastmap' if it updates the fastmap.  */
00500   unsigned int _REG_RE_NAME (fastmap_accurate) : 1;
00501 
00502   /* If set, `re_match_2' does not return information about
00503      subexpressions.  */
00504   unsigned int _REG_RE_NAME (no_sub) : 1;
00505 
00506   /* If set, a beginning-of-line anchor doesn't match at the beginning
00507      of the string.  */
00508   unsigned int _REG_RE_NAME (not_bol) : 1;
00509 
00510   /* Similarly for an end-of-line anchor.  */
00511   unsigned int _REG_RE_NAME (not_eol) : 1;
00512 
00513   /* If true, an anchor at a newline matches.  */
00514   unsigned int _REG_RE_NAME (newline_anchor) : 1;
00515 
00516 /* [[[end pattern_buffer]]] */
00517 };
00518 
00519 typedef struct re_pattern_buffer regex_t;
00520 
00521 /* This is the structure we store register match data in.  See
00522    regex.texinfo for a full description of what registers match.  */
00523 struct re_registers
00524 {
00525   __re_size_t _REG_RM_NAME (num_regs);
00526   regoff_t *_REG_RM_NAME (start);
00527   regoff_t *_REG_RM_NAME (end);
00528 };
00529 
00530 
00531 /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
00532    `re_match_2' returns information about at least this many registers
00533    the first time a `regs' structure is passed.  */
00534 #if !defined RE_NREGS && defined __USE_GNU_REGEX
00535 # define RE_NREGS 30
00536 #endif
00537 
00538 
00539 /* POSIX specification for registers.  Aside from the different names than
00540    `re_registers', POSIX uses an array of structures, instead of a
00541    structure of arrays.  */
00542 typedef struct
00543 {
00544   regoff_t rm_so;  /* Byte offset from string's start to substring's start.  */
00545   regoff_t rm_eo;  /* Byte offset from string's start to substring's end.  */
00546 } regmatch_t;
00547 
00548 /* Declarations for routines.  */
00549 
00550 /* Sets the current default syntax to SYNTAX, and return the old syntax.
00551    You can also simply assign to the `re_syntax_options' variable.  */
00552 extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
00553 
00554 /* Compile the regular expression PATTERN, with length LENGTH
00555    and syntax given by the global `re_syntax_options', into the buffer
00556    BUFFER.  Return NULL if successful, and an error string if not.  */
00557 extern const char *re_compile_pattern (const char *__pattern, size_t __length,
00558                                    struct re_pattern_buffer *__buffer);
00559 
00560 
00561 /* Compile a fastmap for the compiled pattern in BUFFER; used to
00562    accelerate searches.  Return 0 if successful and -2 if was an
00563    internal error.  */
00564 extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
00565 
00566 
00567 /* Search in the string STRING (with length LENGTH) for the pattern
00568    compiled into BUFFER.  Start searching at position START, for RANGE
00569    characters.  Return the starting position of the match, -1 for no
00570    match, or -2 for an internal error.  Also return register
00571    information in REGS (if REGS and BUFFER->no_sub are nonzero).  */
00572 extern regoff_t re_search (struct re_pattern_buffer *__buffer,
00573                         const char *__string, __re_idx_t __length,
00574                         __re_idx_t __start, regoff_t __range,
00575                         struct re_registers *__regs);
00576 
00577 
00578 /* Like `re_search', but search in the concatenation of STRING1 and
00579    STRING2.  Also, stop searching at index START + STOP.  */
00580 extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer,
00581                           const char *__string1, __re_idx_t __length1,
00582                           const char *__string2, __re_idx_t __length2,
00583                           __re_idx_t __start, regoff_t __range,
00584                           struct re_registers *__regs,
00585                           __re_idx_t __stop);
00586 
00587 
00588 /* Like `re_search', but return how many characters in STRING the regexp
00589    in BUFFER matched, starting at position START.  */
00590 extern regoff_t re_match (struct re_pattern_buffer *__buffer,
00591                        const char *__string, __re_idx_t __length,
00592                        __re_idx_t __start, struct re_registers *__regs);
00593 
00594 
00595 /* Relates to `re_match' as `re_search_2' relates to `re_search'.  */
00596 extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
00597                          const char *__string1, __re_idx_t __length1,
00598                          const char *__string2, __re_idx_t __length2,
00599                          __re_idx_t __start, struct re_registers *__regs,
00600                          __re_idx_t __stop);
00601 
00602 
00603 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
00604    ENDS.  Subsequent matches using BUFFER and REGS will use this memory
00605    for recording register information.  STARTS and ENDS must be
00606    allocated with malloc, and must each be at least `NUM_REGS * sizeof
00607    (regoff_t)' bytes long.
00608 
00609    If NUM_REGS == 0, then subsequent matches should allocate their own
00610    register data.
00611 
00612    Unless this function is called, the first search or match using
00613    PATTERN_BUFFER will allocate its own register data, without
00614    freeing the old data.  */
00615 extern void re_set_registers (struct re_pattern_buffer *__buffer,
00616                            struct re_registers *__regs,
00617                            __re_size_t __num_regs,
00618                            regoff_t *__starts, regoff_t *__ends);
00619 
00620 #if defined _REGEX_RE_COMP || defined _LIBC
00621 # ifndef _CRAY
00622 /* 4.2 bsd compatibility.  */
00623 extern char *re_comp (const char *);
00624 extern int re_exec (const char *);
00625 # endif
00626 #endif
00627 
00628 /* GCC 2.95 and later have "__restrict"; C99 compilers have
00629    "restrict", and "configure" may have defined "restrict".
00630    Other compilers use __restrict, __restrict__, and _Restrict, and
00631    'configure' might #define 'restrict' to those words, so pick a
00632    different name.  */
00633 #ifndef _Restrict_
00634 # if 199901L <= __STDC_VERSION__
00635 #  define _Restrict_ restrict
00636 # elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
00637 #  define _Restrict_ __restrict
00638 # else
00639 #  define _Restrict_
00640 # endif
00641 #endif
00642 /* gcc 3.1 and up support the [restrict] syntax.  Don't trust
00643    sys/cdefs.h's definition of __restrict_arr, though, as it
00644    mishandles gcc -ansi -pedantic.  */
00645 #ifndef _Restrict_arr_
00646 # if ((199901L <= __STDC_VERSION__                             \
00647        || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__))   \
00648           && !__STRICT_ANSI__))                                \
00649       && !defined __GNUG__)
00650 #  define _Restrict_arr_ _Restrict_
00651 # else
00652 #  define _Restrict_arr_
00653 # endif
00654 #endif
00655 
00656 /* POSIX compatibility.  */
00657 extern int regcomp (regex_t *_Restrict_ __preg,
00658                   const char *_Restrict_ __pattern,
00659                   int __cflags);
00660 
00661 extern int regexec (const regex_t *_Restrict_ __preg,
00662                   const char *_Restrict_ __string, size_t __nmatch,
00663                   regmatch_t __pmatch[_Restrict_arr_],
00664                   int __eflags);
00665 
00666 extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
00667                      char *_Restrict_ __errbuf, size_t __errbuf_size);
00668 
00669 extern void regfree (regex_t *__preg);
00670 
00671 
00672 #ifdef __cplusplus
00673 }
00674 #endif /* C++ */
00675 
00676 #endif /* regex.h */