Blame lib/regex.h

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