Blame deps/regex/regex_internal.h

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