Blame gnulib/lib/regex.h

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