Blame deps/regex/regex_internal.h

Packit Service 20376f
/* Extended regular expression matching and search library.
Packit Service 20376f
   Copyright (C) 2002-2005, 2007, 2008, 2010 Free Software Foundation, Inc.
Packit Service 20376f
   This file is part of the GNU C Library.
Packit Service 20376f
   Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
Packit Service 20376f
Packit Service 20376f
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 20376f
   modify it under the terms of the GNU Lesser General Public
Packit Service 20376f
   License as published by the Free Software Foundation; either
Packit Service 20376f
   version 2.1 of the License, or (at your option) any later version.
Packit Service 20376f
Packit Service 20376f
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 20376f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 20376f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 20376f
   Lesser General Public License for more details.
Packit Service 20376f
Packit Service 20376f
   You should have received a copy of the GNU Lesser General Public
Packit Service 20376f
   License along with the GNU C Library; if not, write to the Free
Packit Service 20376f
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
Packit Service 20376f
   02111-1307 USA.  */
Packit Service 20376f
Packit Service 20376f
#ifndef _REGEX_INTERNAL_H
Packit Service 20376f
#define _REGEX_INTERNAL_H 1
Packit Service 20376f
Packit Service 20376f
#include <assert.h>
Packit Service 20376f
#include <ctype.h>
Packit Service 20376f
#include <stdio.h>
Packit Service 20376f
#include <stdlib.h>
Packit Service 20376f
#include <string.h>
Packit Service 20376f
Packit Service 20376f
#ifndef UNUSED
Packit Service 20376f
#	ifdef __GNUC__
Packit Service 20376f
#		define UNUSED __attribute__((unused))
Packit Service 20376f
#	else
Packit Service 20376f
#		define UNUSED
Packit Service 20376f
#	endif
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET || defined _LIBC
Packit Service 20376f
# include <langinfo.h>
Packit Service 20376f
#endif
Packit Service 20376f
#if defined HAVE_LOCALE_H || defined _LIBC
Packit Service 20376f
# include <locale.h>
Packit Service 20376f
#endif
Packit Service 20376f
#if defined HAVE_WCHAR_H || defined _LIBC
Packit Service 20376f
# include <wchar.h>
Packit Service 20376f
#endif /* HAVE_WCHAR_H || _LIBC */
Packit Service 20376f
#if defined HAVE_WCTYPE_H || defined _LIBC
Packit Service 20376f
# include <wctype.h>
Packit Service 20376f
#endif /* HAVE_WCTYPE_H || _LIBC */
Packit Service 20376f
#if defined HAVE_STDBOOL_H || defined _LIBC
Packit Service 20376f
# include <stdbool.h>
Packit Service 20376f
#endif /* HAVE_STDBOOL_H || _LIBC */
Packit Service 20376f
#if !defined(ZOS_USS)
Packit Service 20376f
#if defined HAVE_STDINT_H || defined _LIBC
Packit Service 20376f
# include <stdint.h>
Packit Service 20376f
#endif /* HAVE_STDINT_H || _LIBC */
Packit Service 20376f
#endif /* !ZOS_USS */
Packit Service 20376f
#if defined _LIBC
Packit Service 20376f
# include <bits/libc-lock.h>
Packit Service 20376f
#else
Packit Service 20376f
# define __libc_lock_define(CLASS,NAME)
Packit Service 20376f
# define __libc_lock_init(NAME) do { } while (0)
Packit Service 20376f
# define __libc_lock_lock(NAME) do { } while (0)
Packit Service 20376f
# define __libc_lock_unlock(NAME) do { } while (0)
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#ifndef GAWK
Packit Service 20376f
/* In case that the system doesn't have isblank().  */
Packit Service 20376f
#if !defined _LIBC && !defined HAVE_ISBLANK && !defined isblank
Packit Service 20376f
# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
Packit Service 20376f
#endif
Packit Service 20376f
#else /* GAWK */
Packit Service 20376f
/*
Packit Service 20376f
 * This is a mess. On glibc systems you have to define
Packit Service 20376f
 * a magic constant to get isblank() out of <ctype.h>, since it's
Packit Service 20376f
 * a C99 function.  To heck with all that and borrow a page from
Packit Service 20376f
 * dfa.c's book.
Packit Service 20376f
 */
Packit Service 20376f
Packit Service 20376f
static int
Packit Service 20376f
is_blank (int c)
Packit Service 20376f
{
Packit Service 20376f
   return (c == ' ' || c == '\t');
Packit Service 20376f
}
Packit Service 20376f
#endif /* GAWK */
Packit Service 20376f
Packit Service 20376f
#ifdef _LIBC
Packit Service 20376f
# ifndef _RE_DEFINE_LOCALE_FUNCTIONS
Packit Service 20376f
#  define _RE_DEFINE_LOCALE_FUNCTIONS 1
Packit Service 20376f
#   include <locale/localeinfo.h>
Packit Service 20376f
#   include <locale/elem-hash.h>
Packit Service 20376f
#   include <locale/coll-lookup.h>
Packit Service 20376f
# endif
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
/* This is for other GNU distributions with internationalized messages.  */
Packit Service 20376f
#if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
Packit Service 20376f
# include <libintl.h>
Packit Service 20376f
# ifdef _LIBC
Packit Service 20376f
#  undef gettext
Packit Service 20376f
#  define gettext(msgid) \
Packit Service 20376f
  INTUSE(__dcgettext) (_libc_intl_domainname, msgid, LC_MESSAGES)
Packit Service 20376f
# endif
Packit Service 20376f
#else
Packit Service 20376f
# define gettext(msgid) (msgid)
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#ifndef gettext_noop
Packit Service 20376f
/* This define is so xgettext can find the internationalizable
Packit Service 20376f
   strings.  */
Packit Service 20376f
# define gettext_noop(String) String
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
/* For loser systems without the definition.  */
Packit Service 20376f
#ifndef SIZE_MAX
Packit Service 20376f
# define SIZE_MAX ((size_t) -1)
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#ifndef NO_MBSUPPORT
Packit Service 20376f
#include "mbsupport.h" /* gawk */
Packit Service 20376f
#endif
Packit Service 20376f
#ifndef MB_CUR_MAX
Packit Service 20376f
#define MB_CUR_MAX 1
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#if (defined MBS_SUPPORT) || _LIBC
Packit Service 20376f
# define RE_ENABLE_I18N
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#if __GNUC__ >= 3
Packit Service 20376f
# define BE(expr, val) __builtin_expect (expr, val)
Packit Service 20376f
#else
Packit Service 20376f
# define BE(expr, val) (expr)
Packit Service 20376f
# ifdef inline
Packit Service 20376f
# undef inline
Packit Service 20376f
# endif
Packit Service 20376f
# define inline
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
/* Number of single byte character.  */
Packit Service 20376f
#define SBC_MAX 256
Packit Service 20376f
Packit Service 20376f
#define COLL_ELEM_LEN_MAX 8
Packit Service 20376f
Packit Service 20376f
/* The character which represents newline.  */
Packit Service 20376f
#define NEWLINE_CHAR '\n'
Packit Service 20376f
#define WIDE_NEWLINE_CHAR L'\n'
Packit Service 20376f
Packit Service 20376f
/* Rename to standard API for using out of glibc.  */
Packit Service 20376f
#ifndef _LIBC
Packit Service 20376f
# ifdef __wctype
Packit Service 20376f
# undef __wctype
Packit Service 20376f
# endif
Packit Service 20376f
# define __wctype wctype
Packit Service 20376f
# ifdef __iswctype
Packit Service 20376f
# undef __iswctype
Packit Service 20376f
# endif
Packit Service 20376f
# define __iswctype iswctype
Packit Service 20376f
# define __btowc btowc
Packit Service 20376f
# define __mbrtowc mbrtowc
Packit Service 20376f
#undef __mempcpy	/* GAWK */
Packit Service 20376f
# define __mempcpy mempcpy
Packit Service 20376f
# define __wcrtomb wcrtomb
Packit Service 20376f
# define __regfree regfree
Packit Service 20376f
# define attribute_hidden
Packit Service 20376f
#endif /* not _LIBC */
Packit Service 20376f
Packit Service 20376f
#ifdef __GNUC__
Packit Service 20376f
# define __attribute(arg) __attribute__ (arg)
Packit Service 20376f
#else
Packit Service 20376f
# define __attribute(arg)
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
extern const char __re_error_msgid[] attribute_hidden;
Packit Service 20376f
extern const size_t __re_error_msgid_idx[] attribute_hidden;
Packit Service 20376f
Packit Service 20376f
/* An integer used to represent a set of bits.  It must be unsigned,
Packit Service 20376f
   and must be at least as wide as unsigned int.  */
Packit Service 20376f
typedef unsigned long int bitset_word_t;
Packit Service 20376f
/* All bits set in a bitset_word_t.  */
Packit Service 20376f
#define BITSET_WORD_MAX ULONG_MAX
Packit Service 20376f
/* Number of bits in a bitset_word_t. Cast to int as most code use it
Packit Service 20376f
 * like that for counting */
Packit Service 20376f
#define BITSET_WORD_BITS ((int)(sizeof (bitset_word_t) * CHAR_BIT))
Packit Service 20376f
/* Number of bitset_word_t in a bit_set.  */
Packit Service 20376f
#define BITSET_WORDS (SBC_MAX / BITSET_WORD_BITS)
Packit Service 20376f
typedef bitset_word_t bitset_t[BITSET_WORDS];
Packit Service 20376f
typedef bitset_word_t *re_bitset_ptr_t;
Packit Service 20376f
typedef const bitset_word_t *re_const_bitset_ptr_t;
Packit Service 20376f
Packit Service 20376f
#define bitset_set(set,i) \
Packit Service 20376f
  (set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS)
Packit Service 20376f
#define bitset_clear(set,i) \
Packit Service 20376f
  (set[i / BITSET_WORD_BITS] &= ~((bitset_word_t) 1 << i % BITSET_WORD_BITS))
Packit Service 20376f
#define bitset_contain(set,i) \
Packit Service 20376f
  (set[i / BITSET_WORD_BITS] & ((bitset_word_t) 1 << i % BITSET_WORD_BITS))
Packit Service 20376f
#define bitset_empty(set) memset (set, '\0', sizeof (bitset_t))
Packit Service 20376f
#define bitset_set_all(set) memset (set, '\xff', sizeof (bitset_t))
Packit Service 20376f
#define bitset_copy(dest,src) memcpy (dest, src, sizeof (bitset_t))
Packit Service 20376f
Packit Service 20376f
#define PREV_WORD_CONSTRAINT 0x0001
Packit Service 20376f
#define PREV_NOTWORD_CONSTRAINT 0x0002
Packit Service 20376f
#define NEXT_WORD_CONSTRAINT 0x0004
Packit Service 20376f
#define NEXT_NOTWORD_CONSTRAINT 0x0008
Packit Service 20376f
#define PREV_NEWLINE_CONSTRAINT 0x0010
Packit Service 20376f
#define NEXT_NEWLINE_CONSTRAINT 0x0020
Packit Service 20376f
#define PREV_BEGBUF_CONSTRAINT 0x0040
Packit Service 20376f
#define NEXT_ENDBUF_CONSTRAINT 0x0080
Packit Service 20376f
#define WORD_DELIM_CONSTRAINT 0x0100
Packit Service 20376f
#define NOT_WORD_DELIM_CONSTRAINT 0x0200
Packit Service 20376f
Packit Service 20376f
typedef enum
Packit Service 20376f
{
Packit Service 20376f
  INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
Packit Service 20376f
  WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
Packit Service 20376f
  WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
Packit Service 20376f
  INSIDE_NOTWORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
Packit Service 20376f
  LINE_FIRST = PREV_NEWLINE_CONSTRAINT,
Packit Service 20376f
  LINE_LAST = NEXT_NEWLINE_CONSTRAINT,
Packit Service 20376f
  BUF_FIRST = PREV_BEGBUF_CONSTRAINT,
Packit Service 20376f
  BUF_LAST = NEXT_ENDBUF_CONSTRAINT,
Packit Service 20376f
  WORD_DELIM = WORD_DELIM_CONSTRAINT,
Packit Service 20376f
  NOT_WORD_DELIM = NOT_WORD_DELIM_CONSTRAINT
Packit Service 20376f
} re_context_type;
Packit Service 20376f
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  int alloc;
Packit Service 20376f
  int nelem;
Packit Service 20376f
  int *elems;
Packit Service 20376f
} re_node_set;
Packit Service 20376f
Packit Service 20376f
typedef enum
Packit Service 20376f
{
Packit Service 20376f
  NON_TYPE = 0,
Packit Service 20376f
Packit Service 20376f
  /* Node type, These are used by token, node, tree.  */
Packit Service 20376f
  CHARACTER = 1,
Packit Service 20376f
  END_OF_RE = 2,
Packit Service 20376f
  SIMPLE_BRACKET = 3,
Packit Service 20376f
  OP_BACK_REF = 4,
Packit Service 20376f
  OP_PERIOD = 5,
Packit Service 20376f
#ifdef RE_ENABLE_I18N
Packit Service 20376f
  COMPLEX_BRACKET = 6,
Packit Service 20376f
  OP_UTF8_PERIOD = 7,
Packit Service 20376f
#endif /* RE_ENABLE_I18N */
Packit Service 20376f
Packit Service 20376f
  /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used
Packit Service 20376f
     when the debugger shows values of this enum type.  */
Packit Service 20376f
#define EPSILON_BIT 8
Packit Service 20376f
  OP_OPEN_SUBEXP = EPSILON_BIT | 0,
Packit Service 20376f
  OP_CLOSE_SUBEXP = EPSILON_BIT | 1,
Packit Service 20376f
  OP_ALT = EPSILON_BIT | 2,
Packit Service 20376f
  OP_DUP_ASTERISK = EPSILON_BIT | 3,
Packit Service 20376f
  ANCHOR = EPSILON_BIT | 4,
Packit Service 20376f
Packit Service 20376f
  /* Tree type, these are used only by tree. */
Packit Service 20376f
  CONCAT = 16,
Packit Service 20376f
  SUBEXP = 17,
Packit Service 20376f
Packit Service 20376f
  /* Token type, these are used only by token.  */
Packit Service 20376f
  OP_DUP_PLUS = 18,
Packit Service 20376f
  OP_DUP_QUESTION,
Packit Service 20376f
  OP_OPEN_BRACKET,
Packit Service 20376f
  OP_CLOSE_BRACKET,
Packit Service 20376f
  OP_CHARSET_RANGE,
Packit Service 20376f
  OP_OPEN_DUP_NUM,
Packit Service 20376f
  OP_CLOSE_DUP_NUM,
Packit Service 20376f
  OP_NON_MATCH_LIST,
Packit Service 20376f
  OP_OPEN_COLL_ELEM,
Packit Service 20376f
  OP_CLOSE_COLL_ELEM,
Packit Service 20376f
  OP_OPEN_EQUIV_CLASS,
Packit Service 20376f
  OP_CLOSE_EQUIV_CLASS,
Packit Service 20376f
  OP_OPEN_CHAR_CLASS,
Packit Service 20376f
  OP_CLOSE_CHAR_CLASS,
Packit Service 20376f
  OP_WORD,
Packit Service 20376f
  OP_NOTWORD,
Packit Service 20376f
  OP_SPACE,
Packit Service 20376f
  OP_NOTSPACE,
Packit Service 20376f
  BACK_SLASH
Packit Service 20376f
Packit Service 20376f
} re_token_type_t;
Packit Service 20376f
Packit Service 20376f
#ifdef RE_ENABLE_I18N
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  /* Multibyte characters.  */
Packit Service 20376f
  wchar_t *mbchars;
Packit Service 20376f
Packit Service 20376f
  /* Collating symbols.  */
Packit Service 20376f
# ifdef _LIBC
Packit Service 20376f
  int32_t *coll_syms;
Packit Service 20376f
# endif
Packit Service 20376f
Packit Service 20376f
  /* Equivalence classes. */
Packit Service 20376f
# ifdef _LIBC
Packit Service 20376f
  int32_t *equiv_classes;
Packit Service 20376f
# endif
Packit Service 20376f
Packit Service 20376f
  /* Range expressions. */
Packit Service 20376f
# ifdef _LIBC
Packit Service 20376f
  uint32_t *range_starts;
Packit Service 20376f
  uint32_t *range_ends;
Packit Service 20376f
# else /* not _LIBC */
Packit Service 20376f
  wchar_t *range_starts;
Packit Service 20376f
  wchar_t *range_ends;
Packit Service 20376f
# endif /* not _LIBC */
Packit Service 20376f
Packit Service 20376f
  /* Character classes. */
Packit Service 20376f
  wctype_t *char_classes;
Packit Service 20376f
Packit Service 20376f
  /* If this character set is the non-matching list.  */
Packit Service 20376f
  unsigned int non_match : 1;
Packit Service 20376f
Packit Service 20376f
  /* # of multibyte characters.  */
Packit Service 20376f
  int nmbchars;
Packit Service 20376f
Packit Service 20376f
  /* # of collating symbols.  */
Packit Service 20376f
  int ncoll_syms;
Packit Service 20376f
Packit Service 20376f
  /* # of equivalence classes. */
Packit Service 20376f
  int nequiv_classes;
Packit Service 20376f
Packit Service 20376f
  /* # of range expressions. */
Packit Service 20376f
  int nranges;
Packit Service 20376f
Packit Service 20376f
  /* # of character classes. */
Packit Service 20376f
  int nchar_classes;
Packit Service 20376f
} re_charset_t;
Packit Service 20376f
#endif /* RE_ENABLE_I18N */
Packit Service 20376f
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  union
Packit Service 20376f
  {
Packit Service 20376f
    unsigned char c;		/* for CHARACTER */
Packit Service 20376f
    re_bitset_ptr_t sbcset;	/* for SIMPLE_BRACKET */
Packit Service 20376f
#ifdef RE_ENABLE_I18N
Packit Service 20376f
    re_charset_t *mbcset;	/* for COMPLEX_BRACKET */
Packit Service 20376f
#endif /* RE_ENABLE_I18N */
Packit Service 20376f
    int idx;			/* for BACK_REF */
Packit Service 20376f
    re_context_type ctx_type;	/* for ANCHOR */
Packit Service 20376f
  } opr;
Packit Service 20376f
#if __GNUC__ >= 2
Packit Service 20376f
  re_token_type_t type : 8;
Packit Service 20376f
#else
Packit Service 20376f
  re_token_type_t type;
Packit Service 20376f
#endif
Packit Service 20376f
  unsigned int constraint : 10;	/* context constraint */
Packit Service 20376f
  unsigned int duplicated : 1;
Packit Service 20376f
  unsigned int opt_subexp : 1;
Packit Service 20376f
#ifdef RE_ENABLE_I18N
Packit Service 20376f
  unsigned int accept_mb : 1;
Packit Service 20376f
  /* These 2 bits can be moved into the union if needed (e.g. if running out
Packit Service 20376f
     of bits; move opr.c to opr.c.c and move the flags to opr.c.flags).  */
Packit Service 20376f
  unsigned int mb_partial : 1;
Packit Service 20376f
#endif
Packit Service 20376f
  unsigned int word_char : 1;
Packit Service 20376f
} re_token_t;
Packit Service 20376f
Packit Service 20376f
#define IS_EPSILON_NODE(type) ((type) & EPSILON_BIT)
Packit Service 20376f
Packit Service 20376f
struct re_string_t
Packit Service 20376f
{
Packit Service 20376f
  /* Indicate the raw buffer which is the original string passed as an
Packit Service 20376f
     argument of regexec(), re_search(), etc..  */
Packit Service 20376f
  const unsigned char *raw_mbs;
Packit Service 20376f
  /* Store the multibyte string.  In case of "case insensitive mode" like
Packit Service 20376f
     REG_ICASE, upper cases of the string are stored, otherwise MBS points
Packit Service 20376f
     the same address that RAW_MBS points.  */
Packit Service 20376f
  unsigned char *mbs;
Packit Service 20376f
#ifdef RE_ENABLE_I18N
Packit Service 20376f
  /* Store the wide character string which is corresponding to MBS.  */
Packit Service 20376f
  wint_t *wcs;
Packit Service 20376f
  int *offsets;
Packit Service 20376f
  mbstate_t cur_state;
Packit Service 20376f
#endif
Packit Service 20376f
  /* Index in RAW_MBS.  Each character mbs[i] corresponds to
Packit Service 20376f
     raw_mbs[raw_mbs_idx + i].  */
Packit Service 20376f
  int raw_mbs_idx;
Packit Service 20376f
  /* The length of the valid characters in the buffers.  */
Packit Service 20376f
  int valid_len;
Packit Service 20376f
  /* The corresponding number of bytes in raw_mbs array.  */
Packit Service 20376f
  int valid_raw_len;
Packit Service 20376f
  /* The length of the buffers MBS and WCS.  */
Packit Service 20376f
  int bufs_len;
Packit Service 20376f
  /* The index in MBS, which is updated by re_string_fetch_byte.  */
Packit Service 20376f
  int cur_idx;
Packit Service 20376f
  /* length of RAW_MBS array.  */
Packit Service 20376f
  int raw_len;
Packit Service 20376f
  /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN.  */
Packit Service 20376f
  int len;
Packit Service 20376f
  /* End of the buffer may be shorter than its length in the cases such
Packit Service 20376f
     as re_match_2, re_search_2.  Then, we use STOP for end of the buffer
Packit Service 20376f
     instead of LEN.  */
Packit Service 20376f
  int raw_stop;
Packit Service 20376f
  /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS.  */
Packit Service 20376f
  int stop;
Packit Service 20376f
Packit Service 20376f
  /* The context of mbs[0].  We store the context independently, since
Packit Service 20376f
     the context of mbs[0] may be different from raw_mbs[0], which is
Packit Service 20376f
     the beginning of the input string.  */
Packit Service 20376f
  unsigned int tip_context;
Packit Service 20376f
  /* The translation passed as a part of an argument of re_compile_pattern.  */
Packit Service 20376f
  RE_TRANSLATE_TYPE trans;
Packit Service 20376f
  /* Copy of re_dfa_t's word_char.  */
Packit Service 20376f
  re_const_bitset_ptr_t word_char;
Packit Service 20376f
  /* 1 if REG_ICASE.  */
Packit Service 20376f
  unsigned char icase;
Packit Service 20376f
  unsigned char is_utf8;
Packit Service 20376f
  unsigned char map_notascii;
Packit Service 20376f
  unsigned char mbs_allocated;
Packit Service 20376f
  unsigned char offsets_needed;
Packit Service 20376f
  unsigned char newline_anchor;
Packit Service 20376f
  unsigned char word_ops_used;
Packit Service 20376f
  int mb_cur_max;
Packit Service 20376f
};
Packit Service 20376f
typedef struct re_string_t re_string_t;
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
struct re_dfa_t;
Packit Service 20376f
typedef struct re_dfa_t re_dfa_t;
Packit Service 20376f
Packit Service 20376f
#ifndef _LIBC
Packit Service 20376f
# ifdef __i386__
Packit Service 20376f
#  define internal_function   __attribute ((regparm (3), stdcall))
Packit Service 20376f
# else
Packit Service 20376f
#  define internal_function
Packit Service 20376f
# endif
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#ifndef NOT_IN_libc
Packit Service 20376f
static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
Packit Service 20376f
						int new_buf_len)
Packit Service 20376f
     internal_function;
Packit Service 20376f
# ifdef RE_ENABLE_I18N
Packit Service 20376f
static void build_wcs_buffer (re_string_t *pstr) internal_function;
Packit Service 20376f
static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
Packit Service 20376f
  internal_function;
Packit Service 20376f
# endif /* RE_ENABLE_I18N */
Packit Service 20376f
static void build_upper_buffer (re_string_t *pstr) internal_function;
Packit Service 20376f
static void re_string_translate_buffer (re_string_t *pstr) internal_function;
Packit Service 20376f
static unsigned int re_string_context_at (const re_string_t *input, int idx,
Packit Service 20376f
					  int eflags)
Packit Service 20376f
     internal_function __attribute ((pure));
Packit Service 20376f
#endif
Packit Service 20376f
#define re_string_peek_byte(pstr, offset) \
Packit Service 20376f
  ((pstr)->mbs[(pstr)->cur_idx + offset])
Packit Service 20376f
#define re_string_fetch_byte(pstr) \
Packit Service 20376f
  ((pstr)->mbs[(pstr)->cur_idx++])
Packit Service 20376f
#define re_string_first_byte(pstr, idx) \
Packit Service 20376f
  ((idx) == (pstr)->valid_len || (pstr)->wcs[idx] != WEOF)
Packit Service 20376f
#define re_string_is_single_byte_char(pstr, idx) \
Packit Service 20376f
  ((pstr)->wcs[idx] != WEOF && ((pstr)->valid_len == (idx) + 1 \
Packit Service 20376f
				|| (pstr)->wcs[(idx) + 1] != WEOF))
Packit Service 20376f
#define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx)
Packit Service 20376f
#define re_string_cur_idx(pstr) ((pstr)->cur_idx)
Packit Service 20376f
#define re_string_get_buffer(pstr) ((pstr)->mbs)
Packit Service 20376f
#define re_string_length(pstr) ((pstr)->len)
Packit Service 20376f
#define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx])
Packit Service 20376f
#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
Packit Service 20376f
#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
Packit Service 20376f
Packit Service 20376f
#ifndef _LIBC
Packit Service 20376f
# if HAVE_ALLOCA
Packit Service 20376f
#  if (_MSC_VER)
Packit Service 20376f
#   include <malloc.h>
Packit Service 20376f
#   define __libc_use_alloca(n) 0
Packit Service 20376f
#  else
Packit Service 20376f
#   include <alloca.h>
Packit Service 20376f
/* The OS usually guarantees only one guard page at the bottom of the stack,
Packit Service 20376f
   and a page size can be as small as 4096 bytes.  So we cannot safely
Packit Service 20376f
   allocate anything larger than 4096 bytes.  Also care for the possibility
Packit Service 20376f
   of a few compiler-allocated temporary stack slots.  */
Packit Service 20376f
#  define __libc_use_alloca(n) ((n) < 4032)
Packit Service 20376f
#  endif
Packit Service 20376f
# else
Packit Service 20376f
/* alloca is implemented with malloc, so just use malloc.  */
Packit Service 20376f
#  define __libc_use_alloca(n) 0
Packit Service 20376f
# endif
Packit Service 20376f
#endif
Packit Service 20376f
Packit Service 20376f
#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
Packit Service 20376f
/* SunOS 4.1.x realloc doesn't accept null pointers: pre-Standard C. Sigh. */
Packit Service 20376f
#define re_realloc(p,t,n) ((p != NULL) ? (t *) realloc (p,(n)*sizeof(t)) : (t *) calloc(n,sizeof(t)))
Packit Service 20376f
#define re_free(p) free (p)
Packit Service 20376f
Packit Service 20376f
struct bin_tree_t
Packit Service 20376f
{
Packit Service 20376f
  struct bin_tree_t *parent;
Packit Service 20376f
  struct bin_tree_t *left;
Packit Service 20376f
  struct bin_tree_t *right;
Packit Service 20376f
  struct bin_tree_t *first;
Packit Service 20376f
  struct bin_tree_t *next;
Packit Service 20376f
Packit Service 20376f
  re_token_t token;
Packit Service 20376f
Packit Service 20376f
  /* `node_idx' is the index in dfa->nodes, if `type' == 0.
Packit Service 20376f
     Otherwise `type' indicate the type of this node.  */
Packit Service 20376f
  int node_idx;
Packit Service 20376f
};
Packit Service 20376f
typedef struct bin_tree_t bin_tree_t;
Packit Service 20376f
Packit Service 20376f
#define BIN_TREE_STORAGE_SIZE \
Packit Service 20376f
  ((1024 - sizeof (void *)) / sizeof (bin_tree_t))
Packit Service 20376f
Packit Service 20376f
struct bin_tree_storage_t
Packit Service 20376f
{
Packit Service 20376f
  struct bin_tree_storage_t *next;
Packit Service 20376f
  bin_tree_t data[BIN_TREE_STORAGE_SIZE];
Packit Service 20376f
};
Packit Service 20376f
typedef struct bin_tree_storage_t bin_tree_storage_t;
Packit Service 20376f
Packit Service 20376f
#define CONTEXT_WORD 1
Packit Service 20376f
#define CONTEXT_NEWLINE (CONTEXT_WORD << 1)
Packit Service 20376f
#define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1)
Packit Service 20376f
#define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1)
Packit Service 20376f
Packit Service 20376f
#define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD)
Packit Service 20376f
#define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE)
Packit Service 20376f
#define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF)
Packit Service 20376f
#define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF)
Packit Service 20376f
#define IS_ORDINARY_CONTEXT(c) ((c) == 0)
Packit Service 20376f
Packit Service 20376f
#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
Packit Service 20376f
#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
Packit Service 20376f
#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_')
Packit Service 20376f
#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
Packit Service 20376f
Packit Service 20376f
#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
Packit Service 20376f
 ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
Packit Service 20376f
  || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
Packit Service 20376f
  || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\
Packit Service 20376f
  || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context)))
Packit Service 20376f
Packit Service 20376f
#define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \
Packit Service 20376f
 ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
Packit Service 20376f
  || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
Packit Service 20376f
  || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \
Packit Service 20376f
  || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context)))
Packit Service 20376f
Packit Service 20376f
struct re_dfastate_t
Packit Service 20376f
{
Packit Service 20376f
  unsigned int hash;
Packit Service 20376f
  re_node_set nodes;
Packit Service 20376f
  re_node_set non_eps_nodes;
Packit Service 20376f
  re_node_set inveclosure;
Packit Service 20376f
  re_node_set *entrance_nodes;
Packit Service 20376f
  struct re_dfastate_t **trtable, **word_trtable;
Packit Service 20376f
  unsigned int context : 4;
Packit Service 20376f
  unsigned int halt : 1;
Packit Service 20376f
  /* If this state can accept `multi byte'.
Packit Service 20376f
     Note that we refer to multibyte characters, and multi character
Packit Service 20376f
     collating elements as `multi byte'.  */
Packit Service 20376f
  unsigned int accept_mb : 1;
Packit Service 20376f
  /* If this state has backreference node(s).  */
Packit Service 20376f
  unsigned int has_backref : 1;
Packit Service 20376f
  unsigned int has_constraint : 1;
Packit Service 20376f
};
Packit Service 20376f
typedef struct re_dfastate_t re_dfastate_t;
Packit Service 20376f
Packit Service 20376f
struct re_state_table_entry
Packit Service 20376f
{
Packit Service 20376f
  int num;
Packit Service 20376f
  int alloc;
Packit Service 20376f
  re_dfastate_t **array;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
/* Array type used in re_sub_match_last_t and re_sub_match_top_t.  */
Packit Service 20376f
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  int next_idx;
Packit Service 20376f
  int alloc;
Packit Service 20376f
  re_dfastate_t **array;
Packit Service 20376f
} state_array_t;
Packit Service 20376f
Packit Service 20376f
/* Store information about the node NODE whose type is OP_CLOSE_SUBEXP.  */
Packit Service 20376f
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  int node;
Packit Service 20376f
  int str_idx; /* The position NODE match at.  */
Packit Service 20376f
  state_array_t path;
Packit Service 20376f
} re_sub_match_last_t;
Packit Service 20376f
Packit Service 20376f
/* Store information about the node NODE whose type is OP_OPEN_SUBEXP.
Packit Service 20376f
   And information about the node, whose type is OP_CLOSE_SUBEXP,
Packit Service 20376f
   corresponding to NODE is stored in LASTS.  */
Packit Service 20376f
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  int str_idx;
Packit Service 20376f
  int node;
Packit Service 20376f
  state_array_t *path;
Packit Service 20376f
  int alasts; /* Allocation size of LASTS.  */
Packit Service 20376f
  int nlasts; /* The number of LASTS.  */
Packit Service 20376f
  re_sub_match_last_t **lasts;
Packit Service 20376f
} re_sub_match_top_t;
Packit Service 20376f
Packit Service 20376f
struct re_backref_cache_entry
Packit Service 20376f
{
Packit Service 20376f
  int node;
Packit Service 20376f
  int str_idx;
Packit Service 20376f
  int subexp_from;
Packit Service 20376f
  int subexp_to;
Packit Service 20376f
  char more;
Packit Service 20376f
  char unused;
Packit Service 20376f
  unsigned short int eps_reachable_subexps_map;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  /* The string object corresponding to the input string.  */
Packit Service 20376f
  re_string_t input;
Packit Service 20376f
#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
Packit Service 20376f
  const re_dfa_t *const dfa;
Packit Service 20376f
#else
Packit Service 20376f
  const re_dfa_t *dfa;
Packit Service 20376f
#endif
Packit Service 20376f
  /* EFLAGS of the argument of regexec.  */
Packit Service 20376f
  int eflags;
Packit Service 20376f
  /* Where the matching ends.  */
Packit Service 20376f
  int match_last;
Packit Service 20376f
  int last_node;
Packit Service 20376f
  /* The state log used by the matcher.  */
Packit Service 20376f
  re_dfastate_t **state_log;
Packit Service 20376f
  int state_log_top;
Packit Service 20376f
  /* Back reference cache.  */
Packit Service 20376f
  int nbkref_ents;
Packit Service 20376f
  int abkref_ents;
Packit Service 20376f
  struct re_backref_cache_entry *bkref_ents;
Packit Service 20376f
  int max_mb_elem_len;
Packit Service 20376f
  int nsub_tops;
Packit Service 20376f
  int asub_tops;
Packit Service 20376f
  re_sub_match_top_t **sub_tops;
Packit Service 20376f
} re_match_context_t;
Packit Service 20376f
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  re_dfastate_t **sifted_states;
Packit Service 20376f
  re_dfastate_t **limited_states;
Packit Service 20376f
  int last_node;
Packit Service 20376f
  int last_str_idx;
Packit Service 20376f
  re_node_set limits;
Packit Service 20376f
} re_sift_context_t;
Packit Service 20376f
Packit Service 20376f
struct re_fail_stack_ent_t
Packit Service 20376f
{
Packit Service 20376f
  int idx;
Packit Service 20376f
  int node;
Packit Service 20376f
  regmatch_t *regs;
Packit Service 20376f
  re_node_set eps_via_nodes;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
struct re_fail_stack_t
Packit Service 20376f
{
Packit Service 20376f
  int num;
Packit Service 20376f
  int alloc;
Packit Service 20376f
  struct re_fail_stack_ent_t *stack;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
struct re_dfa_t
Packit Service 20376f
{
Packit Service 20376f
  re_token_t *nodes;
Packit Service 20376f
  size_t nodes_alloc;
Packit Service 20376f
  size_t nodes_len;
Packit Service 20376f
  int *nexts;
Packit Service 20376f
  int *org_indices;
Packit Service 20376f
  re_node_set *edests;
Packit Service 20376f
  re_node_set *eclosures;
Packit Service 20376f
  re_node_set *inveclosures;
Packit Service 20376f
  struct re_state_table_entry *state_table;
Packit Service 20376f
  re_dfastate_t *init_state;
Packit Service 20376f
  re_dfastate_t *init_state_word;
Packit Service 20376f
  re_dfastate_t *init_state_nl;
Packit Service 20376f
  re_dfastate_t *init_state_begbuf;
Packit Service 20376f
  bin_tree_t *str_tree;
Packit Service 20376f
  bin_tree_storage_t *str_tree_storage;
Packit Service 20376f
  re_bitset_ptr_t sb_char;
Packit Service 20376f
  int str_tree_storage_idx;
Packit Service 20376f
Packit Service 20376f
  /* number of subexpressions `re_nsub' is in regex_t.  */
Packit Service 20376f
  unsigned int state_hash_mask;
Packit Service 20376f
  int init_node;
Packit Service 20376f
  int nbackref; /* The number of backreference in this dfa.  */
Packit Service 20376f
Packit Service 20376f
  /* Bitmap expressing which backreference is used.  */
Packit Service 20376f
  bitset_word_t used_bkref_map;
Packit Service 20376f
  bitset_word_t completed_bkref_map;
Packit Service 20376f
Packit Service 20376f
  unsigned int has_plural_match : 1;
Packit Service 20376f
  /* If this dfa has "multibyte node", which is a backreference or
Packit Service 20376f
     a node which can accept multibyte character or multi character
Packit Service 20376f
     collating element.  */
Packit Service 20376f
  unsigned int has_mb_node : 1;
Packit Service 20376f
  unsigned int is_utf8 : 1;
Packit Service 20376f
  unsigned int map_notascii : 1;
Packit Service 20376f
  unsigned int word_ops_used : 1;
Packit Service 20376f
  int mb_cur_max;
Packit Service 20376f
  bitset_t word_char;
Packit Service 20376f
  reg_syntax_t syntax;
Packit Service 20376f
  int *subexp_map;
Packit Service 20376f
#ifdef DEBUG
Packit Service 20376f
  char* re_str;
Packit Service 20376f
#endif
Packit Service 20376f
#if defined _LIBC
Packit Service 20376f
  __libc_lock_define (, lock)
Packit Service 20376f
#endif
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
#define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
Packit Service 20376f
#define re_node_set_remove(set,id) \
Packit Service 20376f
  (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
Packit Service 20376f
#define re_node_set_empty(p) ((p)->nelem = 0)
Packit Service 20376f
#define re_node_set_free(set) re_free ((set)->elems)
Packit Service 20376f

Packit Service 20376f
Packit Service 20376f
typedef enum
Packit Service 20376f
{
Packit Service 20376f
  SB_CHAR,
Packit Service 20376f
  MB_CHAR,
Packit Service 20376f
  EQUIV_CLASS,
Packit Service 20376f
  COLL_SYM,
Packit Service 20376f
  CHAR_CLASS
Packit Service 20376f
} bracket_elem_type;
Packit Service 20376f
Packit Service 20376f
typedef struct
Packit Service 20376f
{
Packit Service 20376f
  bracket_elem_type type;
Packit Service 20376f
  union
Packit Service 20376f
  {
Packit Service 20376f
    unsigned char ch;
Packit Service 20376f
    unsigned char *name;
Packit Service 20376f
    wchar_t wch;
Packit Service 20376f
  } opr;
Packit Service 20376f
} bracket_elem_t;
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/* Inline functions for bitset operation.  */
Packit Service 20376f
static inline void
Packit Service 20376f
bitset_not (bitset_t set)
Packit Service 20376f
{
Packit Service 20376f
  int bitset_i;
Packit Service 20376f
  for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
Packit Service 20376f
    set[bitset_i] = ~set[bitset_i];
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static inline void
Packit Service 20376f
bitset_merge (bitset_t dest, const bitset_t src)
Packit Service 20376f
{
Packit Service 20376f
  int bitset_i;
Packit Service 20376f
  for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
Packit Service 20376f
    dest[bitset_i] |= src[bitset_i];
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static inline void
Packit Service 20376f
bitset_mask (bitset_t dest, const bitset_t src)
Packit Service 20376f
{
Packit Service 20376f
  int bitset_i;
Packit Service 20376f
  for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
Packit Service 20376f
    dest[bitset_i] &= src[bitset_i];
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
#ifdef RE_ENABLE_I18N
Packit Service 20376f
/* Inline functions for re_string.  */
Packit Service 20376f
static inline int
Packit Service 20376f
internal_function __attribute ((pure))
Packit Service 20376f
re_string_char_size_at (const re_string_t *pstr, int idx)
Packit Service 20376f
{
Packit Service 20376f
  int byte_idx;
Packit Service 20376f
  if (pstr->mb_cur_max == 1)
Packit Service 20376f
    return 1;
Packit Service 20376f
  for (byte_idx = 1; idx + byte_idx < pstr->valid_len; ++byte_idx)
Packit Service 20376f
    if (pstr->wcs[idx + byte_idx] != WEOF)
Packit Service 20376f
      break;
Packit Service 20376f
  return byte_idx;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static inline wint_t
Packit Service 20376f
internal_function __attribute ((pure))
Packit Service 20376f
re_string_wchar_at (const re_string_t *pstr, int idx)
Packit Service 20376f
{
Packit Service 20376f
  if (pstr->mb_cur_max == 1)
Packit Service 20376f
    return (wint_t) pstr->mbs[idx];
Packit Service 20376f
  return (wint_t) pstr->wcs[idx];
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
# ifndef NOT_IN_libc
Packit Service 20376f
static int
Packit Service 20376f
internal_function __attribute ((pure))
Packit Service 20376f
re_string_elem_size_at (const re_string_t *pstr, int idx)
Packit Service 20376f
{
Packit Service 20376f
#  ifdef _LIBC
Packit Service 20376f
  const unsigned char *p, *extra;
Packit Service 20376f
  const int32_t *table, *indirect;
Packit Service 20376f
  int32_t tmp;
Packit Service 20376f
#   include <locale/weight.h>
Packit Service 20376f
  uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
Packit Service 20376f
Packit Service 20376f
  if (nrules != 0)
Packit Service 20376f
    {
Packit Service 20376f
      table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
Packit Service 20376f
      extra = (const unsigned char *)
Packit Service 20376f
	_NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
Packit Service 20376f
      indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
Packit Service 20376f
						_NL_COLLATE_INDIRECTMB);
Packit Service 20376f
      p = pstr->mbs + idx;
Packit Service 20376f
      tmp = findidx (&p);
Packit Service 20376f
      return p - pstr->mbs - idx;
Packit Service 20376f
    }
Packit Service 20376f
  else
Packit Service 20376f
#  endif /* _LIBC */
Packit Service 20376f
    return 1;
Packit Service 20376f
}
Packit Service 20376f
# endif
Packit Service 20376f
#endif /* RE_ENABLE_I18N */
Packit Service 20376f
Packit Service 20376f
#endif /*  _REGEX_INTERNAL_H */