Back to index

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