Blame support/regex.h

Packit 575503
/* Definitions for data structures and routines for the regular
Packit 575503
   expression library.
Packit 575503
   Copyright (C) 1985, 1989-2017 Free Software Foundation, Inc.
Packit 575503
   This file is part of the GNU C Library.
Packit 575503
Packit 575503
   The GNU C Library is free software; you can redistribute it and/or
Packit 575503
   modify it under the terms of the GNU Lesser General Public
Packit 575503
   License as published by the Free Software Foundation; either
Packit 575503
   version 2.1 of the License, or (at your option) any later version.
Packit 575503
Packit 575503
   The GNU C Library is distributed in the hope that it will be useful,
Packit 575503
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 575503
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 575503
   Lesser General Public License for more details.
Packit 575503
Packit 575503
   You should have received a copy of the GNU Lesser General Public
Packit 575503
   License along with the GNU C Library; if not, see
Packit 575503
   <http://www.gnu.org/licenses/>.  */
Packit 575503
Packit 575503
#ifndef _REGEX_H
Packit 575503
#define _REGEX_H 1
Packit 575503
Packit 575503
#ifdef HAVE_STDDEF_H
Packit 575503
#include <stddef.h>
Packit 575503
#endif
Packit 575503
Packit 575503
#ifdef HAVE_SYS_TYPES_H
Packit 575503
#include <sys/types.h>
Packit 575503
#endif
Packit 575503
Packit 575503
#ifndef _LIBC
Packit 575503
#define __USE_GNU	1
Packit 575503
#endif
Packit 575503
Packit 575503
/* Allow the use in C++ code.  */
Packit 575503
#ifdef __cplusplus
Packit 575503
extern "C" {
Packit 575503
#endif
Packit 575503
Packit 575503
/* The following two types have to be signed and unsigned integer type
Packit 575503
   wide enough to hold a value of a pointer.  For most ANSI compilers
Packit 575503
   ptrdiff_t and size_t should be likely OK.  Still size of these two
Packit 575503
   types is 2 for Microsoft C.  Ugh... */
Packit 575503
typedef long int s_reg_t;
Packit 575503
typedef unsigned long int active_reg_t;
Packit 575503
Packit 575503
/* The following bits are used to determine the regexp syntax we
Packit 575503
   recognize.  The set/not-set meanings are chosen so that Emacs syntax
Packit 575503
   remains the value 0.  The bits are given in alphabetical order, and
Packit 575503
   the definitions shifted by one from the previous bit; thus, when we
Packit 575503
   add or remove a bit, only one other definition need change.  */
Packit 575503
typedef unsigned long int reg_syntax_t;
Packit 575503
Packit 575503
#ifdef __USE_GNU
Packit 575503
/* If this bit is not set, then \ inside a bracket expression is literal.
Packit 575503
   If set, then such a \ quotes the following character.  */
Packit 575503
# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
Packit 575503
Packit 575503
/* If this bit is not set, then + and ? are operators, and \+ and \? are
Packit 575503
     literals.
Packit 575503
   If set, then \+ and \? are operators and + and ? are literals.  */
Packit 575503
# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
Packit 575503
Packit 575503
/* If this bit is set, then character classes are supported.  They are:
Packit 575503
     [:alpha:], [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
Packit 575503
     [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
Packit 575503
   If not set, then character classes are not supported.  */
Packit 575503
# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
Packit 575503
Packit 575503
/* If this bit is set, then ^ and $ are always anchors (outside bracket
Packit 575503
     expressions, of course).
Packit 575503
   If this bit is not set, then it depends:
Packit 575503
	^  is an anchor if it is at the beginning of a regular
Packit 575503
	   expression or after an open-group or an alternation operator;
Packit 575503
	$  is an anchor if it is at the end of a regular expression, or
Packit 575503
	   before a close-group or an alternation operator.
Packit 575503
Packit 575503
   This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
Packit 575503
   POSIX draft 11.2 says that * etc. in leading positions is undefined.
Packit 575503
   We already implemented a previous draft which made those constructs
Packit 575503
   invalid, though, so we haven't changed the code back.  */
Packit 575503
# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
Packit 575503
Packit 575503
/* If this bit is set, then special characters are always special
Packit 575503
     regardless of where they are in the pattern.
Packit 575503
   If this bit is not set, then special characters are special only in
Packit 575503
     some contexts; otherwise they are ordinary.  Specifically,
Packit 575503
     * + ? and intervals are only special when not after the beginning,
Packit 575503
     open-group, or alternation operator.  */
Packit 575503
# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
Packit 575503
Packit 575503
/* If this bit is set, then *, +, ?, and { cannot be first in an re or
Packit 575503
     immediately after an alternation or begin-group operator.  */
Packit 575503
# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
Packit 575503
Packit 575503
/* If this bit is set, then . matches newline.
Packit 575503
   If not set, then it doesn't.  */
Packit 575503
# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
Packit 575503
Packit 575503
/* If this bit is set, then . doesn't match NUL.
Packit 575503
   If not set, then it does.  */
Packit 575503
# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
Packit 575503
Packit 575503
/* If this bit is set, nonmatching lists [^...] do not match newline.
Packit 575503
   If not set, they do.  */
Packit 575503
# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
Packit 575503
Packit 575503
/* If this bit is set, either \{...\} or {...} defines an
Packit 575503
     interval, depending on RE_NO_BK_BRACES.
Packit 575503
   If not set, \{, \}, {, and } are literals.  */
Packit 575503
# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
Packit 575503
Packit 575503
/* If this bit is set, +, ? and | aren't recognized as operators.
Packit 575503
   If not set, they are.  */
Packit 575503
# define RE_LIMITED_OPS (RE_INTERVALS << 1)
Packit 575503
Packit 575503
/* If this bit is set, newline is an alternation operator.
Packit 575503
   If not set, newline is literal.  */
Packit 575503
# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
Packit 575503
Packit 575503
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
Packit 575503
     are literals.
Packit 575503
  If not set, then `\{...\}' defines an interval.  */
Packit 575503
# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
Packit 575503
Packit 575503
/* If this bit is set, (...) defines a group, and \( and \) are literals.
Packit 575503
   If not set, \(...\) defines a group, and ( and ) are literals.  */
Packit 575503
# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
Packit 575503
Packit 575503
/* If this bit is set, then \<digit> matches <digit>.
Packit 575503
   If not set, then \<digit> is a back-reference.  */
Packit 575503
# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
Packit 575503
Packit 575503
/* If this bit is set, then | is an alternation operator, and \| is literal.
Packit 575503
   If not set, then \| is an alternation operator, and | is literal.  */
Packit 575503
# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
Packit 575503
Packit 575503
/* If this bit is set, then an ending range point collating higher
Packit 575503
     than the starting range point, as in [z-a], is invalid.
Packit 575503
   If not set, then when ending range point collates higher than the
Packit 575503
     starting range point, the range is ignored.  */
Packit 575503
# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
Packit 575503
Packit 575503
/* If this bit is set, then an unmatched ) is ordinary.
Packit 575503
   If not set, then an unmatched ) is invalid.  */
Packit 575503
# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
Packit 575503
Packit 575503
/* If this bit is set, succeed as soon as we match the whole pattern,
Packit 575503
   without further backtracking.  */
Packit 575503
# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
Packit 575503
Packit 575503
/* If this bit is set, do not process the GNU regex operators.
Packit 575503
   If not set, then the GNU regex operators are recognized. */
Packit 575503
# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
Packit 575503
Packit 575503
/* If this bit is set, turn on internal regex debugging.
Packit 575503
   If not set, and debugging was on, turn it off.
Packit 575503
   This only works if regex.c is compiled -DDEBUG.
Packit 575503
   We define this bit always, so that all that's needed to turn on
Packit 575503
   debugging is to recompile regex.c; the calling code can always have
Packit 575503
   this bit set, and it won't affect anything in the normal case. */
Packit 575503
# define RE_DEBUG (RE_NO_GNU_OPS << 1)
Packit 575503
Packit 575503
/* If this bit is set, a syntactically invalid interval is treated as
Packit 575503
   a string of ordinary characters.  For example, the ERE 'a{1' is
Packit 575503
   treated as 'a\{1'.  */
Packit 575503
# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
Packit 575503
Packit 575503
/* If this bit is set, then ignore case when matching.
Packit 575503
   If not set, then case is significant.  */
Packit 575503
# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
Packit 575503
Packit 575503
/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
Packit 575503
   for ^, because it is difficult to scan the regex backwards to find
Packit 575503
   whether ^ should be special.  */
Packit 575503
# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
Packit 575503
Packit 575503
/* If this bit is set, then \{ cannot be first in an bre or
Packit 575503
   immediately after an alternation or begin-group operator.  */
Packit 575503
# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
Packit 575503
Packit 575503
/* If this bit is set, then no_sub will be set to 1 during
Packit 575503
   re_compile_pattern.  */
Packit 575503
# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
Packit 575503
#endif
Packit 575503
Packit 575503
/* This global variable defines the particular regexp syntax to use (for
Packit 575503
   some interfaces).  When a regexp is compiled, the syntax used is
Packit 575503
   stored in the pattern buffer, so changing this does not affect
Packit 575503
   already-compiled regexps.  */
Packit 575503
extern reg_syntax_t re_syntax_options;
Packit 575503

Packit 575503
#ifdef __USE_GNU
Packit 575503
/* Define combinations of the above bits for the standard possibilities.
Packit 575503
   (The [[[ comments delimit what gets put into the Texinfo file, so
Packit 575503
   don't delete them!)  */
Packit 575503
/* [[[begin syntaxes]]] */
Packit 575503
#define RE_SYNTAX_EMACS 0
Packit 575503
Packit 575503
#define RE_SYNTAX_AWK							\
Packit 575503
  (RE_BACKSLASH_ESCAPE_IN_LISTS   | RE_DOT_NOT_NULL			\
Packit 575503
   | RE_NO_BK_PARENS              | RE_NO_BK_REFS			\
Packit 575503
   | RE_NO_BK_VBAR                | RE_NO_EMPTY_RANGES			\
Packit 575503
   | RE_DOT_NEWLINE		  | RE_CONTEXT_INDEP_ANCHORS		\
Packit 575503
   | RE_CHAR_CLASSES							\
Packit 575503
   | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
Packit 575503
Packit 575503
#define RE_SYNTAX_GNU_AWK						\
Packit 575503
  ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS		\
Packit 575503
    | RE_INVALID_INTERVAL_ORD)						\
Packit 575503
   & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS				\
Packit 575503
      | RE_CONTEXT_INVALID_OPS ))
Packit 575503
Packit 575503
#define RE_SYNTAX_POSIX_AWK						\
Packit 575503
  (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS		\
Packit 575503
   | RE_INTERVALS	    | RE_NO_GNU_OPS				\
Packit 575503
   | RE_INVALID_INTERVAL_ORD)
Packit 575503
Packit 575503
#define RE_SYNTAX_GREP							\
Packit 575503
  (RE_BK_PLUS_QM              | RE_CHAR_CLASSES				\
Packit 575503
   | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS				\
Packit 575503
   | RE_NEWLINE_ALT)
Packit 575503
Packit 575503
#define RE_SYNTAX_EGREP							\
Packit 575503
  (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS			\
Packit 575503
   | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE			\
Packit 575503
   | RE_NEWLINE_ALT       | RE_NO_BK_PARENS				\
Packit 575503
   | RE_NO_BK_VBAR)
Packit 575503
Packit 575503
#define RE_SYNTAX_POSIX_EGREP						\
Packit 575503
  (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES			\
Packit 575503
   | RE_INVALID_INTERVAL_ORD)
Packit 575503
Packit 575503
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff.  */
Packit 575503
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
Packit 575503
Packit 575503
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
Packit 575503
Packit 575503
/* Syntax bits common to both basic and extended POSIX regex syntax.  */
Packit 575503
#define _RE_SYNTAX_POSIX_COMMON						\
Packit 575503
  (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL		\
Packit 575503
   | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
Packit 575503
Packit 575503
#define RE_SYNTAX_POSIX_BASIC						\
Packit 575503
  (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
Packit 575503
Packit 575503
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
Packit 575503
   RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
Packit 575503
   isn't minimal, since other operators, such as \`, aren't disabled.  */
Packit 575503
#define RE_SYNTAX_POSIX_MINIMAL_BASIC					\
Packit 575503
  (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
Packit 575503
Packit 575503
#define RE_SYNTAX_POSIX_EXTENDED					\
Packit 575503
  (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS			\
Packit 575503
   | RE_CONTEXT_INDEP_OPS   | RE_NO_BK_BRACES				\
Packit 575503
   | RE_NO_BK_PARENS        | RE_NO_BK_VBAR				\
Packit 575503
   | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
Packit 575503
Packit 575503
/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
Packit 575503
   removed and RE_NO_BK_REFS is added.  */
Packit 575503
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED				\
Packit 575503
  (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS			\
Packit 575503
   | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES				\
Packit 575503
   | RE_NO_BK_PARENS        | RE_NO_BK_REFS				\
Packit 575503
   | RE_NO_BK_VBAR	    | RE_UNMATCHED_RIGHT_PAREN_ORD)
Packit 575503
/* [[[end syntaxes]]] */
Packit 575503

Packit 575503
/* Maximum number of duplicates an interval can allow.  Some systems
Packit 575503
   (erroneously) define this in other header files, but we want our
Packit 575503
   value, so remove any previous define.  */
Packit 575503
# ifdef RE_DUP_MAX
Packit 575503
#  undef RE_DUP_MAX
Packit 575503
# endif
Packit 575503
/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows.  */
Packit 575503
# define RE_DUP_MAX (0x7fff)
Packit 575503
#endif
Packit 575503
Packit 575503
Packit 575503
/* POSIX `cflags' bits (i.e., information for `regcomp').  */
Packit 575503
Packit 575503
/* If this bit is set, then use extended regular expression syntax.
Packit 575503
   If not set, then use basic regular expression syntax.  */
Packit 575503
#define REG_EXTENDED 1
Packit 575503
Packit 575503
/* If this bit is set, then ignore case when matching.
Packit 575503
   If not set, then case is significant.  */
Packit 575503
#define REG_ICASE (REG_EXTENDED << 1)
Packit 575503
Packit 575503
/* If this bit is set, then anchors do not match at newline
Packit 575503
     characters in the string.
Packit 575503
   If not set, then anchors do match at newlines.  */
Packit 575503
#define REG_NEWLINE (REG_ICASE << 1)
Packit 575503
Packit 575503
/* If this bit is set, then report only success or fail in regexec.
Packit 575503
   If not set, then returns differ between not matching and errors.  */
Packit 575503
#define REG_NOSUB (REG_NEWLINE << 1)
Packit 575503
Packit 575503
Packit 575503
/* POSIX `eflags' bits (i.e., information for regexec).  */
Packit 575503
Packit 575503
/* If this bit is set, then the beginning-of-line operator doesn't match
Packit 575503
     the beginning of the string (presumably because it's not the
Packit 575503
     beginning of a line).
Packit 575503
   If not set, then the beginning-of-line operator does match the
Packit 575503
     beginning of the string.  */
Packit 575503
#define REG_NOTBOL 1
Packit 575503
Packit 575503
/* Like REG_NOTBOL, except for the end-of-line.  */
Packit 575503
#define REG_NOTEOL (1 << 1)
Packit 575503
Packit 575503
/* Use PMATCH[0] to delimit the start and end of the search in the
Packit 575503
   buffer.  */
Packit 575503
#define REG_STARTEND (1 << 2)
Packit 575503
Packit 575503
Packit 575503
/* If any error codes are removed, changed, or added, update the
Packit 575503
   `re_error_msg' table in regex.c.  */
Packit 575503
typedef enum
Packit 575503
{
Packit 575503
#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K
Packit 575503
  REG_ENOSYS = -1,	/* This will never happen for this implementation.  */
Packit 575503
#endif
Packit 575503
Packit 575503
  REG_NOERROR = 0,	/* Success.  */
Packit 575503
  REG_NOMATCH,		/* Didn't find a match (for regexec).  */
Packit 575503
Packit 575503
  /* POSIX regcomp return error codes.  (In the order listed in the
Packit 575503
     standard.)  */
Packit 575503
  REG_BADPAT,		/* Invalid pattern.  */
Packit 575503
  REG_ECOLLATE,		/* Invalid collating element.  */
Packit 575503
  REG_ECTYPE,		/* Invalid character class name.  */
Packit 575503
  REG_EESCAPE,		/* Trailing backslash.  */
Packit 575503
  REG_ESUBREG,		/* Invalid back reference.  */
Packit 575503
  REG_EBRACK,		/* Unmatched left bracket.  */
Packit 575503
  REG_EPAREN,		/* Parenthesis imbalance.  */
Packit 575503
  REG_EBRACE,		/* Unmatched \{.  */
Packit 575503
  REG_BADBR,		/* Invalid contents of \{\}.  */
Packit 575503
  REG_ERANGE,		/* Invalid range end.  */
Packit 575503
  REG_ESPACE,		/* Ran out of memory.  */
Packit 575503
  REG_BADRPT,		/* No preceding re for repetition op.  */
Packit 575503
Packit 575503
  /* Error codes we've added.  */
Packit 575503
  REG_EEND,		/* Premature end.  */
Packit 575503
  REG_ESIZE,		/* Compiled pattern bigger than 2^16 bytes.  */
Packit 575503
  REG_ERPAREN		/* Unmatched ) or \); not returned from regcomp.  */
Packit 575503
} reg_errcode_t;
Packit 575503

Packit 575503
/* This data structure represents a compiled pattern.  Before calling
Packit 575503
   the pattern compiler, the fields `buffer', `allocated', `fastmap',
Packit 575503
   and `translate' can be set.  After the pattern has been compiled,
Packit 575503
   the fields `re_nsub', `not_bol' and `not_eol' are available.  All
Packit 575503
   other fields are private to the regex routines.  */
Packit 575503
Packit 575503
#ifndef RE_TRANSLATE_TYPE
Packit 575503
# define __RE_TRANSLATE_TYPE unsigned char *
Packit 575503
# ifdef __USE_GNU
Packit 575503
#  define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE
Packit 575503
# endif
Packit 575503
#endif
Packit 575503
Packit 575503
#ifdef __USE_GNU
Packit 575503
# define __REPB_PREFIX(name) name
Packit 575503
#else
Packit 575503
# define __REPB_PREFIX(name) __##name
Packit 575503
#endif
Packit 575503
Packit 575503
struct re_pattern_buffer
Packit 575503
{
Packit 575503
  /* Space that holds the compiled pattern.  It is declared as
Packit 575503
     `unsigned char *' because its elements are sometimes used as
Packit 575503
     array indexes.  */
Packit 575503
  unsigned char *__REPB_PREFIX(buffer);
Packit 575503
Packit 575503
  /* Number of bytes to which `buffer' points.  */
Packit 575503
  unsigned long int __REPB_PREFIX(allocated);
Packit 575503
Packit 575503
  /* Number of bytes actually used in `buffer'.  */
Packit 575503
  unsigned long int __REPB_PREFIX(used);
Packit 575503
Packit 575503
  /* Syntax setting with which the pattern was compiled.  */
Packit 575503
  reg_syntax_t __REPB_PREFIX(syntax);
Packit 575503
Packit 575503
  /* Pointer to a fastmap, if any, otherwise zero.  re_search uses the
Packit 575503
     fastmap, if there is one, to skip over impossible starting points
Packit 575503
     for matches.  */
Packit 575503
  char *__REPB_PREFIX(fastmap);
Packit 575503
Packit 575503
  /* Either a translate table to apply to all characters before
Packit 575503
     comparing them, or zero for no translation.  The translation is
Packit 575503
     applied to a pattern when it is compiled and to a string when it
Packit 575503
     is matched.  */
Packit 575503
  __RE_TRANSLATE_TYPE __REPB_PREFIX(translate);
Packit 575503
Packit 575503
  /* Number of subexpressions found by the compiler.  */
Packit 575503
  size_t re_nsub;
Packit 575503
Packit 575503
  /* Zero if this pattern cannot match the empty string, one else.
Packit 575503
     Well, in truth it's used only in `re_search_2', to see whether or
Packit 575503
     not we should use the fastmap, so we don't set this absolutely
Packit 575503
     perfectly; see `re_compile_fastmap' (the `duplicate' case).  */
Packit 575503
  unsigned __REPB_PREFIX(can_be_null) : 1;
Packit 575503
Packit 575503
  /* If REGS_UNALLOCATED, allocate space in the `regs' structure
Packit 575503
     for `max (RE_NREGS, re_nsub + 1)' groups.
Packit 575503
     If REGS_REALLOCATE, reallocate space if necessary.
Packit 575503
     If REGS_FIXED, use what's there.  */
Packit 575503
#ifdef __USE_GNU
Packit 575503
# define REGS_UNALLOCATED 0
Packit 575503
# define REGS_REALLOCATE 1
Packit 575503
# define REGS_FIXED 2
Packit 575503
#endif
Packit 575503
  unsigned __REPB_PREFIX(regs_allocated) : 2;
Packit 575503
Packit 575503
  /* Set to zero when `regex_compile' compiles a pattern; set to one
Packit 575503
     by `re_compile_fastmap' if it updates the fastmap.  */
Packit 575503
  unsigned __REPB_PREFIX(fastmap_accurate) : 1;
Packit 575503
Packit 575503
  /* If set, `re_match_2' does not return information about
Packit 575503
     subexpressions.  */
Packit 575503
  unsigned __REPB_PREFIX(no_sub) : 1;
Packit 575503
Packit 575503
  /* If set, a beginning-of-line anchor doesn't match at the beginning
Packit 575503
     of the string.  */
Packit 575503
  unsigned __REPB_PREFIX(not_bol) : 1;
Packit 575503
Packit 575503
  /* Similarly for an end-of-line anchor.  */
Packit 575503
  unsigned __REPB_PREFIX(not_eol) : 1;
Packit 575503
Packit 575503
  /* If true, an anchor at a newline matches.  */
Packit 575503
  unsigned __REPB_PREFIX(newline_anchor) : 1;
Packit 575503
};
Packit 575503
Packit 575503
typedef struct re_pattern_buffer regex_t;
Packit 575503

Packit 575503
/* Type for byte offsets within the string.  POSIX mandates this.  */
Packit 575503
typedef int regoff_t;
Packit 575503
Packit 575503
Packit 575503
#ifdef __USE_GNU
Packit 575503
/* This is the structure we store register match data in.  See
Packit 575503
   regex.texinfo for a full description of what registers match.  */
Packit 575503
struct re_registers
Packit 575503
{
Packit 575503
  unsigned num_regs;
Packit 575503
  regoff_t *start;
Packit 575503
  regoff_t *end;
Packit 575503
};
Packit 575503
Packit 575503
Packit 575503
/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
Packit 575503
   `re_match_2' returns information about at least this many registers
Packit 575503
   the first time a `regs' structure is passed.  */
Packit 575503
# ifndef RE_NREGS
Packit 575503
#  define RE_NREGS 30
Packit 575503
# endif
Packit 575503
#endif
Packit 575503
Packit 575503
Packit 575503
/* POSIX specification for registers.  Aside from the different names than
Packit 575503
   `re_registers', POSIX uses an array of structures, instead of a
Packit 575503
   structure of arrays.  */
Packit 575503
typedef struct
Packit 575503
{
Packit 575503
  regoff_t rm_so;  /* Byte offset from string's start to substring's start.  */
Packit 575503
  regoff_t rm_eo;  /* Byte offset from string's start to substring's end.  */
Packit 575503
} regmatch_t;
Packit 575503

Packit 575503
/* Declarations for routines.  */
Packit 575503
Packit 575503
#ifdef __USE_GNU
Packit 575503
/* Sets the current default syntax to SYNTAX, and return the old syntax.
Packit 575503
   You can also simply assign to the `re_syntax_options' variable.  */
Packit 575503
extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
Packit 575503
Packit 575503
/* Compile the regular expression PATTERN, with length LENGTH
Packit 575503
   and syntax given by the global `re_syntax_options', into the buffer
Packit 575503
   BUFFER.  Return NULL if successful, and an error string if not.
Packit 575503
Packit 575503
   To free the allocated storage, you must call `regfree' on BUFFER.
Packit 575503
   Note that the translate table must either have been initialised by
Packit 575503
   `regcomp', with a malloc'ed value, or set to NULL before calling
Packit 575503
   `regfree'.  */
Packit 575503
extern const char *re_compile_pattern (const char *__pattern, size_t __length,
Packit 575503
				       struct re_pattern_buffer *__buffer);
Packit 575503
Packit 575503
Packit 575503
/* Compile a fastmap for the compiled pattern in BUFFER; used to
Packit 575503
   accelerate searches.  Return 0 if successful and -2 if was an
Packit 575503
   internal error.  */
Packit 575503
extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
Packit 575503
Packit 575503
Packit 575503
/* Search in the string STRING (with length LENGTH) for the pattern
Packit 575503
   compiled into BUFFER.  Start searching at position START, for RANGE
Packit 575503
   characters.  Return the starting position of the match, -1 for no
Packit 575503
   match, or -2 for an internal error.  Also return register
Packit 575503
   information in REGS (if REGS and BUFFER->no_sub are nonzero).  */
Packit 575503
extern int re_search (struct re_pattern_buffer *__buffer, const char *__string,
Packit 575503
		      int __length, int __start, int __range,
Packit 575503
		      struct re_registers *__regs);
Packit 575503
Packit 575503
Packit 575503
/* Like `re_search', but search in the concatenation of STRING1 and
Packit 575503
   STRING2.  Also, stop searching at index START + STOP.  */
Packit 575503
extern int re_search_2 (struct re_pattern_buffer *__buffer,
Packit 575503
			const char *__string1, int __length1,
Packit 575503
			const char *__string2, int __length2, int __start,
Packit 575503
			int __range, struct re_registers *__regs, int __stop);
Packit 575503
Packit 575503
Packit 575503
/* Like `re_search', but return how many characters in STRING the regexp
Packit 575503
   in BUFFER matched, starting at position START.  */
Packit 575503
extern int re_match (struct re_pattern_buffer *__buffer, const char *__string,
Packit 575503
		     int __length, int __start, struct re_registers *__regs);
Packit 575503
Packit 575503
Packit 575503
/* Relates to `re_match' as `re_search_2' relates to `re_search'.  */
Packit 575503
extern int re_match_2 (struct re_pattern_buffer *__buffer,
Packit 575503
		       const char *__string1, int __length1,
Packit 575503
		       const char *__string2, int __length2, int __start,
Packit 575503
		       struct re_registers *__regs, int __stop);
Packit 575503
Packit 575503
Packit 575503
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
Packit 575503
   ENDS.  Subsequent matches using BUFFER and REGS will use this memory
Packit 575503
   for recording register information.  STARTS and ENDS must be
Packit 575503
   allocated with malloc, and must each be at least `NUM_REGS * sizeof
Packit 575503
   (regoff_t)' bytes long.
Packit 575503
Packit 575503
   If NUM_REGS == 0, then subsequent matches should allocate their own
Packit 575503
   register data.
Packit 575503
Packit 575503
   Unless this function is called, the first search or match using
Packit 575503
   PATTERN_BUFFER will allocate its own register data, without
Packit 575503
   freeing the old data.  */
Packit 575503
extern void re_set_registers (struct re_pattern_buffer *__buffer,
Packit 575503
			      struct re_registers *__regs,
Packit 575503
			      unsigned int __num_regs,
Packit 575503
			      regoff_t *__starts, regoff_t *__ends);
Packit 575503
#endif	/* Use GNU */
Packit 575503
Packit 575503
#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_MISC)
Packit 575503
# ifndef _CRAY
Packit 575503
/* 4.2 bsd compatibility.  */
Packit 575503
extern char *re_comp (const char *);
Packit 575503
extern int re_exec (const char *);
Packit 575503
# endif
Packit 575503
#endif
Packit 575503
Packit 575503
/* GCC 2.95 and later have "__restrict"; C99 compilers have
Packit 575503
   "restrict", and "configure" may have defined "restrict".  */
Packit 575503
#ifndef __restrict
Packit 575503
# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
Packit 575503
#  if defined restrict || 199901L <= __STDC_VERSION__
Packit 575503
#   define __restrict restrict
Packit 575503
#  else
Packit 575503
#   define __restrict
Packit 575503
#  endif
Packit 575503
# endif
Packit 575503
#endif
Packit 575503
/* gcc 3.1 and up support the [restrict] syntax.  */
Packit 575503
#ifndef __restrict_arr
Packit 575503
# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) \
Packit 575503
     && !defined __GNUG__
Packit 575503
#  define __restrict_arr __restrict
Packit 575503
# else
Packit 575503
#  define __restrict_arr
Packit 575503
# endif
Packit 575503
#endif
Packit 575503
Packit 575503
/* POSIX compatibility.  */
Packit 575503
extern int regcomp (regex_t *__restrict __preg,
Packit 575503
		    const char *__restrict __pattern,
Packit 575503
		    int __cflags);
Packit 575503
Packit 575503
extern int regexec (const regex_t *__restrict __preg,
Packit 575503
		    const char *__restrict __string, size_t __nmatch,
Packit 575503
		    regmatch_t __pmatch[__restrict_arr],
Packit 575503
		    int __eflags);
Packit 575503
Packit 575503
extern size_t regerror (int __errcode, const regex_t *__restrict __preg,
Packit 575503
			char *__restrict __errbuf, size_t __errbuf_size);
Packit 575503
Packit 575503
extern void regfree (regex_t *__preg);
Packit 575503
Packit 575503
Packit 575503
#ifdef __cplusplus
Packit 575503
}
Packit 575503
#endif	/* C++ */
Packit 575503
Packit 575503
#endif /* regex.h */