Blame lib/regex_internal.h

Packit 8f70b4
/* Extended regular expression matching and search library.
Packit 8f70b4
   Copyright (C) 2002-2018 Free Software Foundation, Inc.
Packit 8f70b4
   This file is part of the GNU C Library.
Packit 8f70b4
   Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
Packit 8f70b4
Packit 8f70b4
   The GNU C Library is free software; you can redistribute it and/or
Packit 8f70b4
   modify it under the terms of the GNU General Public
Packit 8f70b4
   License as published by the Free Software Foundation; either
Packit 8f70b4
   version 3 of the License, or (at your option) any later version.
Packit 8f70b4
Packit 8f70b4
   The GNU C Library is distributed in the hope that it will be useful,
Packit 8f70b4
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 8f70b4
   General Public License for more details.
Packit 8f70b4
Packit 8f70b4
   You should have received a copy of the GNU General Public
Packit 8f70b4
   License along with the GNU C Library; if not, see
Packit 8f70b4
   <https://www.gnu.org/licenses/>.  */
Packit 8f70b4
Packit 8f70b4
#ifndef _REGEX_INTERNAL_H
Packit 8f70b4
#define _REGEX_INTERNAL_H 1
Packit 8f70b4
Packit 8f70b4
#include <assert.h>
Packit 8f70b4
#include <ctype.h>
Packit 8f70b4
#include <stdio.h>
Packit 8f70b4
#include <stdlib.h>
Packit 8f70b4
#include <string.h>
Packit 8f70b4
Packit 8f70b4
#include <langinfo.h>
Packit 8f70b4
#include <locale.h>
Packit 8f70b4
#include <wchar.h>
Packit 8f70b4
#include <wctype.h>
Packit 8f70b4
#include <stdbool.h>
Packit 8f70b4
#include <stdint.h>
Packit 8f70b4
Packit 8f70b4
/* Properties of integers.  Although Gnulib has intprops.h, glibc does
Packit 8f70b4
   without for now.  */
Packit 8f70b4
#ifndef _LIBC
Packit 8f70b4
# include "intprops.h"
Packit 8f70b4
#else
Packit 8f70b4
/* True if the real type T is signed.  */
Packit 8f70b4
# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
Packit 8f70b4
Packit 8f70b4
/* True if adding the nonnegative Idx values A and B would overflow.
Packit 8f70b4
   If false, set *R to A + B.  A, B, and R may be evaluated more than
Packit 8f70b4
   once, or zero times.  Although this is not a full implementation of
Packit 8f70b4
   Gnulib INT_ADD_WRAPV, it is good enough for glibc regex code.
Packit 8f70b4
   FIXME: This implementation is a fragile stopgap, and this file would
Packit 8f70b4
   be simpler and more robust if intprops.h were migrated into glibc.  */
Packit 8f70b4
# define INT_ADD_WRAPV(a, b, r) \
Packit 8f70b4
   (IDX_MAX - (a) < (b) ? true : (*(r) = (a) + (b), false))
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifdef _LIBC
Packit 8f70b4
# include <libc-lock.h>
Packit 8f70b4
# define lock_define(name) __libc_lock_define (, name)
Packit 8f70b4
# define lock_init(lock) (__libc_lock_init (lock), 0)
Packit 8f70b4
# define lock_fini(lock) ((void) 0)
Packit 8f70b4
# define lock_lock(lock) __libc_lock_lock (lock)
Packit 8f70b4
# define lock_unlock(lock) __libc_lock_unlock (lock)
Packit 8f70b4
#elif defined GNULIB_LOCK && !defined USE_UNLOCKED_IO
Packit 8f70b4
# include "glthread/lock.h"
Packit 8f70b4
  /* Use gl_lock_define if empty macro arguments are known to work.
Packit 8f70b4
     Otherwise, fall back on less-portable substitutes.  */
Packit 8f70b4
# if ((defined __GNUC__ && !defined __STRICT_ANSI__) \
Packit 8f70b4
      || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__))
Packit 8f70b4
#  define lock_define(name) gl_lock_define (, name)
Packit 8f70b4
# elif USE_POSIX_THREADS
Packit 8f70b4
#  define lock_define(name) pthread_mutex_t name;
Packit 8f70b4
# elif USE_PTH_THREADS
Packit 8f70b4
#  define lock_define(name) pth_mutex_t name;
Packit 8f70b4
# elif USE_SOLARIS_THREADS
Packit 8f70b4
#  define lock_define(name) mutex_t name;
Packit 8f70b4
# elif USE_WINDOWS_THREADS
Packit 8f70b4
#  define lock_define(name) gl_lock_t name;
Packit 8f70b4
# else
Packit 8f70b4
#  define lock_define(name)
Packit 8f70b4
# endif
Packit 8f70b4
# define lock_init(lock) glthread_lock_init (&(lock))
Packit 8f70b4
# define lock_fini(lock) glthread_lock_destroy (&(lock))
Packit 8f70b4
# define lock_lock(lock) glthread_lock_lock (&(lock))
Packit 8f70b4
# define lock_unlock(lock) glthread_lock_unlock (&(lock))
Packit 8f70b4
#elif defined GNULIB_PTHREAD && !defined USE_UNLOCKED_IO
Packit 8f70b4
# include <pthread.h>
Packit 8f70b4
# define lock_define(name) pthread_mutex_t name;
Packit 8f70b4
# define lock_init(lock) pthread_mutex_init (&(lock), 0)
Packit 8f70b4
# define lock_fini(lock) pthread_mutex_destroy (&(lock))
Packit 8f70b4
# define lock_lock(lock) pthread_mutex_lock (&(lock))
Packit 8f70b4
# define lock_unlock(lock) pthread_mutex_unlock (&(lock))
Packit 8f70b4
#else
Packit 8f70b4
# define lock_define(name)
Packit 8f70b4
# define lock_init(lock) 0
Packit 8f70b4
# define lock_fini(lock) ((void) 0)
Packit 8f70b4
  /* The 'dfa' avoids an "unused variable 'dfa'" warning from GCC.  */
Packit 8f70b4
# define lock_lock(lock) ((void) dfa)
Packit 8f70b4
# define lock_unlock(lock) ((void) 0)
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* In case that the system doesn't have isblank().  */
Packit 8f70b4
#if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK))
Packit 8f70b4
# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifdef _LIBC
Packit 8f70b4
# ifndef _RE_DEFINE_LOCALE_FUNCTIONS
Packit 8f70b4
#  define _RE_DEFINE_LOCALE_FUNCTIONS 1
Packit 8f70b4
#   include <locale/localeinfo.h>
Packit 8f70b4
#   include <locale/coll-lookup.h>
Packit 8f70b4
# endif
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* This is for other GNU distributions with internationalized messages.  */
Packit 8f70b4
#if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
Packit 8f70b4
# include <libintl.h>
Packit 8f70b4
# ifdef _LIBC
Packit 8f70b4
#  undef gettext
Packit 8f70b4
#  define gettext(msgid) \
Packit 8f70b4
  __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES)
Packit 8f70b4
# endif
Packit 8f70b4
#else
Packit 8f70b4
# undef gettext
Packit 8f70b4
# define gettext(msgid) (msgid)
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifndef gettext_noop
Packit 8f70b4
/* This define is so xgettext can find the internationalizable
Packit 8f70b4
   strings.  */
Packit 8f70b4
# define gettext_noop(String) String
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE) || _LIBC
Packit 8f70b4
# define RE_ENABLE_I18N
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#define BE(expr, val) __builtin_expect (expr, val)
Packit 8f70b4
Packit 8f70b4
/* Number of ASCII characters.  */
Packit 8f70b4
#define ASCII_CHARS 0x80
Packit 8f70b4
Packit 8f70b4
/* Number of single byte characters.  */
Packit 8f70b4
#define SBC_MAX (UCHAR_MAX + 1)
Packit 8f70b4
Packit 8f70b4
#define COLL_ELEM_LEN_MAX 8
Packit 8f70b4
Packit 8f70b4
/* The character which represents newline.  */
Packit 8f70b4
#define NEWLINE_CHAR '\n'
Packit 8f70b4
#define WIDE_NEWLINE_CHAR L'\n'
Packit 8f70b4
Packit 8f70b4
/* Rename to standard API for using out of glibc.  */
Packit 8f70b4
#ifndef _LIBC
Packit 8f70b4
# undef __wctype
Packit 8f70b4
# undef __iswctype
Packit 8f70b4
# define __wctype wctype
Packit 8f70b4
# define __iswalnum iswalnum
Packit 8f70b4
# define __iswctype iswctype
Packit 8f70b4
# define __towlower towlower
Packit 8f70b4
# define __towupper towupper
Packit 8f70b4
# define __btowc btowc
Packit 8f70b4
# define __mbrtowc mbrtowc
Packit 8f70b4
# define __wcrtomb wcrtomb
Packit 8f70b4
# define __regfree regfree
Packit 8f70b4
# define attribute_hidden
Packit 8f70b4
#endif /* not _LIBC */
Packit 8f70b4
Packit 8f70b4
#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1)
Packit 8f70b4
# define __attribute__(arg)
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifndef SSIZE_MAX
Packit 8f70b4
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* The type of indexes into strings.  This is signed, not size_t,
Packit 8f70b4
   since the API requires indexes to fit in regoff_t anyway, and using
Packit 8f70b4
   signed integers makes the code a bit smaller and presumably faster.
Packit 8f70b4
   The traditional GNU regex implementation uses int for indexes.
Packit 8f70b4
   The POSIX-compatible implementation uses a possibly-wider type.
Packit 8f70b4
   The name 'Idx' is three letters to minimize the hassle of
Packit 8f70b4
   reindenting a lot of regex code that formerly used 'int'.  */
Packit 8f70b4
typedef regoff_t Idx;
Packit 8f70b4
#ifdef _REGEX_LARGE_OFFSETS
Packit 8f70b4
# define IDX_MAX SSIZE_MAX
Packit 8f70b4
#else
Packit 8f70b4
# define IDX_MAX INT_MAX
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* A hash value, suitable for computing hash tables.  */
Packit 8f70b4
typedef __re_size_t re_hashval_t;
Packit 8f70b4
Packit 8f70b4
/* An integer used to represent a set of bits.  It must be unsigned,
Packit 8f70b4
   and must be at least as wide as unsigned int.  */
Packit 8f70b4
typedef unsigned long int bitset_word_t;
Packit 8f70b4
/* All bits set in a bitset_word_t.  */
Packit 8f70b4
#define BITSET_WORD_MAX ULONG_MAX
Packit 8f70b4
Packit 8f70b4
/* Number of bits in a bitset_word_t.  For portability to hosts with
Packit 8f70b4
   padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
Packit 8f70b4
   instead, deduce it directly from BITSET_WORD_MAX.  Avoid
Packit 8f70b4
   greater-than-32-bit integers and unconditional shifts by more than
Packit 8f70b4
   31 bits, as they're not portable.  */
Packit 8f70b4
#if BITSET_WORD_MAX == 0xffffffffUL
Packit 8f70b4
# define BITSET_WORD_BITS 32
Packit 8f70b4
#elif BITSET_WORD_MAX >> 31 >> 4 == 1
Packit 8f70b4
# define BITSET_WORD_BITS 36
Packit 8f70b4
#elif BITSET_WORD_MAX >> 31 >> 16 == 1
Packit 8f70b4
# define BITSET_WORD_BITS 48
Packit 8f70b4
#elif BITSET_WORD_MAX >> 31 >> 28 == 1
Packit 8f70b4
# define BITSET_WORD_BITS 60
Packit 8f70b4
#elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1
Packit 8f70b4
# define BITSET_WORD_BITS 64
Packit 8f70b4
#elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1
Packit 8f70b4
# define BITSET_WORD_BITS 72
Packit 8f70b4
#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1
Packit 8f70b4
# define BITSET_WORD_BITS 128
Packit 8f70b4
#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1
Packit 8f70b4
# define BITSET_WORD_BITS 256
Packit 8f70b4
#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1
Packit 8f70b4
# define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */
Packit 8f70b4
# if BITSET_WORD_BITS <= SBC_MAX
Packit 8f70b4
#  error "Invalid SBC_MAX"
Packit 8f70b4
# endif
Packit 8f70b4
#else
Packit 8f70b4
# error "Add case for new bitset_word_t size"
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
/* Number of bitset_word_t values in a bitset_t.  */
Packit 8f70b4
#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
Packit 8f70b4
Packit 8f70b4
typedef bitset_word_t bitset_t[BITSET_WORDS];
Packit 8f70b4
typedef bitset_word_t *re_bitset_ptr_t;
Packit 8f70b4
typedef const bitset_word_t *re_const_bitset_ptr_t;
Packit 8f70b4
Packit 8f70b4
#define PREV_WORD_CONSTRAINT 0x0001
Packit 8f70b4
#define PREV_NOTWORD_CONSTRAINT 0x0002
Packit 8f70b4
#define NEXT_WORD_CONSTRAINT 0x0004
Packit 8f70b4
#define NEXT_NOTWORD_CONSTRAINT 0x0008
Packit 8f70b4
#define PREV_NEWLINE_CONSTRAINT 0x0010
Packit 8f70b4
#define NEXT_NEWLINE_CONSTRAINT 0x0020
Packit 8f70b4
#define PREV_BEGBUF_CONSTRAINT 0x0040
Packit 8f70b4
#define NEXT_ENDBUF_CONSTRAINT 0x0080
Packit 8f70b4
#define WORD_DELIM_CONSTRAINT 0x0100
Packit 8f70b4
#define NOT_WORD_DELIM_CONSTRAINT 0x0200
Packit 8f70b4
Packit 8f70b4
typedef enum
Packit 8f70b4
{
Packit 8f70b4
  INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
Packit 8f70b4
  WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
Packit 8f70b4
  WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
Packit 8f70b4
  INSIDE_NOTWORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
Packit 8f70b4
  LINE_FIRST = PREV_NEWLINE_CONSTRAINT,
Packit 8f70b4
  LINE_LAST = NEXT_NEWLINE_CONSTRAINT,
Packit 8f70b4
  BUF_FIRST = PREV_BEGBUF_CONSTRAINT,
Packit 8f70b4
  BUF_LAST = NEXT_ENDBUF_CONSTRAINT,
Packit 8f70b4
  WORD_DELIM = WORD_DELIM_CONSTRAINT,
Packit 8f70b4
  NOT_WORD_DELIM = NOT_WORD_DELIM_CONSTRAINT
Packit 8f70b4
} re_context_type;
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  Idx alloc;
Packit 8f70b4
  Idx nelem;
Packit 8f70b4
  Idx *elems;
Packit 8f70b4
} re_node_set;
Packit 8f70b4
Packit 8f70b4
typedef enum
Packit 8f70b4
{
Packit 8f70b4
  NON_TYPE = 0,
Packit 8f70b4
Packit 8f70b4
  /* Node type, These are used by token, node, tree.  */
Packit 8f70b4
  CHARACTER = 1,
Packit 8f70b4
  END_OF_RE = 2,
Packit 8f70b4
  SIMPLE_BRACKET = 3,
Packit 8f70b4
  OP_BACK_REF = 4,
Packit 8f70b4
  OP_PERIOD = 5,
Packit 8f70b4
#ifdef RE_ENABLE_I18N
Packit 8f70b4
  COMPLEX_BRACKET = 6,
Packit 8f70b4
  OP_UTF8_PERIOD = 7,
Packit 8f70b4
#endif /* RE_ENABLE_I18N */
Packit 8f70b4
Packit 8f70b4
  /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used
Packit 8f70b4
     when the debugger shows values of this enum type.  */
Packit 8f70b4
#define EPSILON_BIT 8
Packit 8f70b4
  OP_OPEN_SUBEXP = EPSILON_BIT | 0,
Packit 8f70b4
  OP_CLOSE_SUBEXP = EPSILON_BIT | 1,
Packit 8f70b4
  OP_ALT = EPSILON_BIT | 2,
Packit 8f70b4
  OP_DUP_ASTERISK = EPSILON_BIT | 3,
Packit 8f70b4
  ANCHOR = EPSILON_BIT | 4,
Packit 8f70b4
Packit 8f70b4
  /* Tree type, these are used only by tree. */
Packit 8f70b4
  CONCAT = 16,
Packit 8f70b4
  SUBEXP = 17,
Packit 8f70b4
Packit 8f70b4
  /* Token type, these are used only by token.  */
Packit 8f70b4
  OP_DUP_PLUS = 18,
Packit 8f70b4
  OP_DUP_QUESTION,
Packit 8f70b4
  OP_OPEN_BRACKET,
Packit 8f70b4
  OP_CLOSE_BRACKET,
Packit 8f70b4
  OP_CHARSET_RANGE,
Packit 8f70b4
  OP_OPEN_DUP_NUM,
Packit 8f70b4
  OP_CLOSE_DUP_NUM,
Packit 8f70b4
  OP_NON_MATCH_LIST,
Packit 8f70b4
  OP_OPEN_COLL_ELEM,
Packit 8f70b4
  OP_CLOSE_COLL_ELEM,
Packit 8f70b4
  OP_OPEN_EQUIV_CLASS,
Packit 8f70b4
  OP_CLOSE_EQUIV_CLASS,
Packit 8f70b4
  OP_OPEN_CHAR_CLASS,
Packit 8f70b4
  OP_CLOSE_CHAR_CLASS,
Packit 8f70b4
  OP_WORD,
Packit 8f70b4
  OP_NOTWORD,
Packit 8f70b4
  OP_SPACE,
Packit 8f70b4
  OP_NOTSPACE,
Packit 8f70b4
  BACK_SLASH
Packit 8f70b4
Packit 8f70b4
} re_token_type_t;
Packit 8f70b4
Packit 8f70b4
#ifdef RE_ENABLE_I18N
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  /* Multibyte characters.  */
Packit 8f70b4
  wchar_t *mbchars;
Packit 8f70b4
Packit 8f70b4
  /* Collating symbols.  */
Packit 8f70b4
# ifdef _LIBC
Packit 8f70b4
  int32_t *coll_syms;
Packit 8f70b4
# endif
Packit 8f70b4
Packit 8f70b4
  /* Equivalence classes. */
Packit 8f70b4
# ifdef _LIBC
Packit 8f70b4
  int32_t *equiv_classes;
Packit 8f70b4
# endif
Packit 8f70b4
Packit 8f70b4
  /* Range expressions. */
Packit 8f70b4
# ifdef _LIBC
Packit 8f70b4
  uint32_t *range_starts;
Packit 8f70b4
  uint32_t *range_ends;
Packit 8f70b4
# else /* not _LIBC */
Packit 8f70b4
  wchar_t *range_starts;
Packit 8f70b4
  wchar_t *range_ends;
Packit 8f70b4
# endif /* not _LIBC */
Packit 8f70b4
Packit 8f70b4
  /* Character classes. */
Packit 8f70b4
  wctype_t *char_classes;
Packit 8f70b4
Packit 8f70b4
  /* If this character set is the non-matching list.  */
Packit 8f70b4
  unsigned int non_match : 1;
Packit 8f70b4
Packit 8f70b4
  /* # of multibyte characters.  */
Packit 8f70b4
  Idx nmbchars;
Packit 8f70b4
Packit 8f70b4
  /* # of collating symbols.  */
Packit 8f70b4
  Idx ncoll_syms;
Packit 8f70b4
Packit 8f70b4
  /* # of equivalence classes. */
Packit 8f70b4
  Idx nequiv_classes;
Packit 8f70b4
Packit 8f70b4
  /* # of range expressions. */
Packit 8f70b4
  Idx nranges;
Packit 8f70b4
Packit 8f70b4
  /* # of character classes. */
Packit 8f70b4
  Idx nchar_classes;
Packit 8f70b4
} re_charset_t;
Packit 8f70b4
#endif /* RE_ENABLE_I18N */
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  union
Packit 8f70b4
  {
Packit 8f70b4
    unsigned char c;		/* for CHARACTER */
Packit 8f70b4
    re_bitset_ptr_t sbcset;	/* for SIMPLE_BRACKET */
Packit 8f70b4
#ifdef RE_ENABLE_I18N
Packit 8f70b4
    re_charset_t *mbcset;	/* for COMPLEX_BRACKET */
Packit 8f70b4
#endif /* RE_ENABLE_I18N */
Packit 8f70b4
    Idx idx;			/* for BACK_REF */
Packit 8f70b4
    re_context_type ctx_type;	/* for ANCHOR */
Packit 8f70b4
  } opr;
Packit 8f70b4
#if __GNUC__ >= 2 && !defined __STRICT_ANSI__
Packit 8f70b4
  re_token_type_t type : 8;
Packit 8f70b4
#else
Packit 8f70b4
  re_token_type_t type;
Packit 8f70b4
#endif
Packit 8f70b4
  unsigned int constraint : 10;	/* context constraint */
Packit 8f70b4
  unsigned int duplicated : 1;
Packit 8f70b4
  unsigned int opt_subexp : 1;
Packit 8f70b4
#ifdef RE_ENABLE_I18N
Packit 8f70b4
  unsigned int accept_mb : 1;
Packit 8f70b4
  /* These 2 bits can be moved into the union if needed (e.g. if running out
Packit 8f70b4
     of bits; move opr.c to opr.c.c and move the flags to opr.c.flags).  */
Packit 8f70b4
  unsigned int mb_partial : 1;
Packit 8f70b4
#endif
Packit 8f70b4
  unsigned int word_char : 1;
Packit 8f70b4
} re_token_t;
Packit 8f70b4
Packit 8f70b4
#define IS_EPSILON_NODE(type) ((type) & EPSILON_BIT)
Packit 8f70b4
Packit 8f70b4
struct re_string_t
Packit 8f70b4
{
Packit 8f70b4
  /* Indicate the raw buffer which is the original string passed as an
Packit 8f70b4
     argument of regexec(), re_search(), etc..  */
Packit 8f70b4
  const unsigned char *raw_mbs;
Packit 8f70b4
  /* Store the multibyte string.  In case of "case insensitive mode" like
Packit 8f70b4
     REG_ICASE, upper cases of the string are stored, otherwise MBS points
Packit 8f70b4
     the same address that RAW_MBS points.  */
Packit 8f70b4
  unsigned char *mbs;
Packit 8f70b4
#ifdef RE_ENABLE_I18N
Packit 8f70b4
  /* Store the wide character string which is corresponding to MBS.  */
Packit 8f70b4
  wint_t *wcs;
Packit 8f70b4
  Idx *offsets;
Packit 8f70b4
  mbstate_t cur_state;
Packit 8f70b4
#endif
Packit 8f70b4
  /* Index in RAW_MBS.  Each character mbs[i] corresponds to
Packit 8f70b4
     raw_mbs[raw_mbs_idx + i].  */
Packit 8f70b4
  Idx raw_mbs_idx;
Packit 8f70b4
  /* The length of the valid characters in the buffers.  */
Packit 8f70b4
  Idx valid_len;
Packit 8f70b4
  /* The corresponding number of bytes in raw_mbs array.  */
Packit 8f70b4
  Idx valid_raw_len;
Packit 8f70b4
  /* The length of the buffers MBS and WCS.  */
Packit 8f70b4
  Idx bufs_len;
Packit 8f70b4
  /* The index in MBS, which is updated by re_string_fetch_byte.  */
Packit 8f70b4
  Idx cur_idx;
Packit 8f70b4
  /* length of RAW_MBS array.  */
Packit 8f70b4
  Idx raw_len;
Packit 8f70b4
  /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN.  */
Packit 8f70b4
  Idx len;
Packit 8f70b4
  /* End of the buffer may be shorter than its length in the cases such
Packit 8f70b4
     as re_match_2, re_search_2.  Then, we use STOP for end of the buffer
Packit 8f70b4
     instead of LEN.  */
Packit 8f70b4
  Idx raw_stop;
Packit 8f70b4
  /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS.  */
Packit 8f70b4
  Idx stop;
Packit 8f70b4
Packit 8f70b4
  /* The context of mbs[0].  We store the context independently, since
Packit 8f70b4
     the context of mbs[0] may be different from raw_mbs[0], which is
Packit 8f70b4
     the beginning of the input string.  */
Packit 8f70b4
  unsigned int tip_context;
Packit 8f70b4
  /* The translation passed as a part of an argument of re_compile_pattern.  */
Packit 8f70b4
  RE_TRANSLATE_TYPE trans;
Packit 8f70b4
  /* Copy of re_dfa_t's word_char.  */
Packit 8f70b4
  re_const_bitset_ptr_t word_char;
Packit 8f70b4
  /* true if REG_ICASE.  */
Packit 8f70b4
  unsigned char icase;
Packit 8f70b4
  unsigned char is_utf8;
Packit 8f70b4
  unsigned char map_notascii;
Packit 8f70b4
  unsigned char mbs_allocated;
Packit 8f70b4
  unsigned char offsets_needed;
Packit 8f70b4
  unsigned char newline_anchor;
Packit 8f70b4
  unsigned char word_ops_used;
Packit 8f70b4
  int mb_cur_max;
Packit 8f70b4
};
Packit 8f70b4
typedef struct re_string_t re_string_t;
Packit 8f70b4
Packit 8f70b4
Packit 8f70b4
struct re_dfa_t;
Packit 8f70b4
typedef struct re_dfa_t re_dfa_t;
Packit 8f70b4
Packit 8f70b4
#ifndef _LIBC
Packit 8f70b4
# define IS_IN(libc) false
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#define re_string_peek_byte(pstr, offset) \
Packit 8f70b4
  ((pstr)->mbs[(pstr)->cur_idx + offset])
Packit 8f70b4
#define re_string_fetch_byte(pstr) \
Packit 8f70b4
  ((pstr)->mbs[(pstr)->cur_idx++])
Packit 8f70b4
#define re_string_first_byte(pstr, idx) \
Packit 8f70b4
  ((idx) == (pstr)->valid_len || (pstr)->wcs[idx] != WEOF)
Packit 8f70b4
#define re_string_is_single_byte_char(pstr, idx) \
Packit 8f70b4
  ((pstr)->wcs[idx] != WEOF && ((pstr)->valid_len == (idx) + 1 \
Packit 8f70b4
				|| (pstr)->wcs[(idx) + 1] != WEOF))
Packit 8f70b4
#define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx)
Packit 8f70b4
#define re_string_cur_idx(pstr) ((pstr)->cur_idx)
Packit 8f70b4
#define re_string_get_buffer(pstr) ((pstr)->mbs)
Packit 8f70b4
#define re_string_length(pstr) ((pstr)->len)
Packit 8f70b4
#define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx])
Packit 8f70b4
#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
Packit 8f70b4
#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
Packit 8f70b4
Packit 8f70b4
#if defined _LIBC || HAVE_ALLOCA
Packit 8f70b4
# include <alloca.h>
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifndef _LIBC
Packit 8f70b4
# if HAVE_ALLOCA
Packit 8f70b4
/* The OS usually guarantees only one guard page at the bottom of the stack,
Packit 8f70b4
   and a page size can be as small as 4096 bytes.  So we cannot safely
Packit 8f70b4
   allocate anything larger than 4096 bytes.  Also care for the possibility
Packit 8f70b4
   of a few compiler-allocated temporary stack slots.  */
Packit 8f70b4
#  define __libc_use_alloca(n) ((n) < 4032)
Packit 8f70b4
# else
Packit 8f70b4
/* alloca is implemented with malloc, so just use malloc.  */
Packit 8f70b4
#  define __libc_use_alloca(n) 0
Packit 8f70b4
#  undef alloca
Packit 8f70b4
#  define alloca(n) malloc (n)
Packit 8f70b4
# endif
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifdef _LIBC
Packit 8f70b4
# define MALLOC_0_IS_NONNULL 1
Packit 8f70b4
#elif !defined MALLOC_0_IS_NONNULL
Packit 8f70b4
# define MALLOC_0_IS_NONNULL 0
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifndef MAX
Packit 8f70b4
# define MAX(a,b) ((a) < (b) ? (b) : (a))
Packit 8f70b4
#endif
Packit 8f70b4
#ifndef MIN
Packit 8f70b4
# define MIN(a,b) ((a) < (b) ? (a) : (b))
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
Packit 8f70b4
#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
Packit 8f70b4
#define re_free(p) free (p)
Packit 8f70b4
Packit 8f70b4
struct bin_tree_t
Packit 8f70b4
{
Packit 8f70b4
  struct bin_tree_t *parent;
Packit 8f70b4
  struct bin_tree_t *left;
Packit 8f70b4
  struct bin_tree_t *right;
Packit 8f70b4
  struct bin_tree_t *first;
Packit 8f70b4
  struct bin_tree_t *next;
Packit 8f70b4
Packit 8f70b4
  re_token_t token;
Packit 8f70b4
Packit 8f70b4
  /* 'node_idx' is the index in dfa->nodes, if 'type' == 0.
Packit 8f70b4
     Otherwise 'type' indicate the type of this node.  */
Packit 8f70b4
  Idx node_idx;
Packit 8f70b4
};
Packit 8f70b4
typedef struct bin_tree_t bin_tree_t;
Packit 8f70b4
Packit 8f70b4
#define BIN_TREE_STORAGE_SIZE \
Packit 8f70b4
  ((1024 - sizeof (void *)) / sizeof (bin_tree_t))
Packit 8f70b4
Packit 8f70b4
struct bin_tree_storage_t
Packit 8f70b4
{
Packit 8f70b4
  struct bin_tree_storage_t *next;
Packit 8f70b4
  bin_tree_t data[BIN_TREE_STORAGE_SIZE];
Packit 8f70b4
};
Packit 8f70b4
typedef struct bin_tree_storage_t bin_tree_storage_t;
Packit 8f70b4
Packit 8f70b4
#define CONTEXT_WORD 1
Packit 8f70b4
#define CONTEXT_NEWLINE (CONTEXT_WORD << 1)
Packit 8f70b4
#define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1)
Packit 8f70b4
#define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1)
Packit 8f70b4
Packit 8f70b4
#define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD)
Packit 8f70b4
#define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE)
Packit 8f70b4
#define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF)
Packit 8f70b4
#define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF)
Packit 8f70b4
#define IS_ORDINARY_CONTEXT(c) ((c) == 0)
Packit 8f70b4
Packit 8f70b4
#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
Packit 8f70b4
#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
Packit 8f70b4
#define IS_WIDE_WORD_CHAR(ch) (__iswalnum (ch) || (ch) == L'_')
Packit 8f70b4
#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
Packit 8f70b4
Packit 8f70b4
#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
Packit 8f70b4
 ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
Packit 8f70b4
  || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
Packit 8f70b4
  || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\
Packit 8f70b4
  || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context)))
Packit 8f70b4
Packit 8f70b4
#define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \
Packit 8f70b4
 ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
Packit 8f70b4
  || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
Packit 8f70b4
  || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \
Packit 8f70b4
  || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context)))
Packit 8f70b4
Packit 8f70b4
struct re_dfastate_t
Packit 8f70b4
{
Packit 8f70b4
  re_hashval_t hash;
Packit 8f70b4
  re_node_set nodes;
Packit 8f70b4
  re_node_set non_eps_nodes;
Packit 8f70b4
  re_node_set inveclosure;
Packit 8f70b4
  re_node_set *entrance_nodes;
Packit 8f70b4
  struct re_dfastate_t **trtable, **word_trtable;
Packit 8f70b4
  unsigned int context : 4;
Packit 8f70b4
  unsigned int halt : 1;
Packit 8f70b4
  /* If this state can accept "multi byte".
Packit 8f70b4
     Note that we refer to multibyte characters, and multi character
Packit 8f70b4
     collating elements as "multi byte".  */
Packit 8f70b4
  unsigned int accept_mb : 1;
Packit 8f70b4
  /* If this state has backreference node(s).  */
Packit 8f70b4
  unsigned int has_backref : 1;
Packit 8f70b4
  unsigned int has_constraint : 1;
Packit 8f70b4
};
Packit 8f70b4
typedef struct re_dfastate_t re_dfastate_t;
Packit 8f70b4
Packit 8f70b4
struct re_state_table_entry
Packit 8f70b4
{
Packit 8f70b4
  Idx num;
Packit 8f70b4
  Idx alloc;
Packit 8f70b4
  re_dfastate_t **array;
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
/* Array type used in re_sub_match_last_t and re_sub_match_top_t.  */
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  Idx next_idx;
Packit 8f70b4
  Idx alloc;
Packit 8f70b4
  re_dfastate_t **array;
Packit 8f70b4
} state_array_t;
Packit 8f70b4
Packit 8f70b4
/* Store information about the node NODE whose type is OP_CLOSE_SUBEXP.  */
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  Idx node;
Packit 8f70b4
  Idx str_idx; /* The position NODE match at.  */
Packit 8f70b4
  state_array_t path;
Packit 8f70b4
} re_sub_match_last_t;
Packit 8f70b4
Packit 8f70b4
/* Store information about the node NODE whose type is OP_OPEN_SUBEXP.
Packit 8f70b4
   And information about the node, whose type is OP_CLOSE_SUBEXP,
Packit 8f70b4
   corresponding to NODE is stored in LASTS.  */
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  Idx str_idx;
Packit 8f70b4
  Idx node;
Packit 8f70b4
  state_array_t *path;
Packit 8f70b4
  Idx alasts; /* Allocation size of LASTS.  */
Packit 8f70b4
  Idx nlasts; /* The number of LASTS.  */
Packit 8f70b4
  re_sub_match_last_t **lasts;
Packit 8f70b4
} re_sub_match_top_t;
Packit 8f70b4
Packit 8f70b4
struct re_backref_cache_entry
Packit 8f70b4
{
Packit 8f70b4
  Idx node;
Packit 8f70b4
  Idx str_idx;
Packit 8f70b4
  Idx subexp_from;
Packit 8f70b4
  Idx subexp_to;
Packit 8f70b4
  char more;
Packit 8f70b4
  char unused;
Packit 8f70b4
  unsigned short int eps_reachable_subexps_map;
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  /* The string object corresponding to the input string.  */
Packit 8f70b4
  re_string_t input;
Packit 8f70b4
#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
Packit 8f70b4
  const re_dfa_t *const dfa;
Packit 8f70b4
#else
Packit 8f70b4
  const re_dfa_t *dfa;
Packit 8f70b4
#endif
Packit 8f70b4
  /* EFLAGS of the argument of regexec.  */
Packit 8f70b4
  int eflags;
Packit 8f70b4
  /* Where the matching ends.  */
Packit 8f70b4
  Idx match_last;
Packit 8f70b4
  Idx last_node;
Packit 8f70b4
  /* The state log used by the matcher.  */
Packit 8f70b4
  re_dfastate_t **state_log;
Packit 8f70b4
  Idx state_log_top;
Packit 8f70b4
  /* Back reference cache.  */
Packit 8f70b4
  Idx nbkref_ents;
Packit 8f70b4
  Idx abkref_ents;
Packit 8f70b4
  struct re_backref_cache_entry *bkref_ents;
Packit 8f70b4
  int max_mb_elem_len;
Packit 8f70b4
  Idx nsub_tops;
Packit 8f70b4
  Idx asub_tops;
Packit 8f70b4
  re_sub_match_top_t **sub_tops;
Packit 8f70b4
} re_match_context_t;
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  re_dfastate_t **sifted_states;
Packit 8f70b4
  re_dfastate_t **limited_states;
Packit 8f70b4
  Idx last_node;
Packit 8f70b4
  Idx last_str_idx;
Packit 8f70b4
  re_node_set limits;
Packit 8f70b4
} re_sift_context_t;
Packit 8f70b4
Packit 8f70b4
struct re_fail_stack_ent_t
Packit 8f70b4
{
Packit 8f70b4
  Idx idx;
Packit 8f70b4
  Idx node;
Packit 8f70b4
  regmatch_t *regs;
Packit 8f70b4
  re_node_set eps_via_nodes;
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
struct re_fail_stack_t
Packit 8f70b4
{
Packit 8f70b4
  Idx num;
Packit 8f70b4
  Idx alloc;
Packit 8f70b4
  struct re_fail_stack_ent_t *stack;
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
struct re_dfa_t
Packit 8f70b4
{
Packit 8f70b4
  re_token_t *nodes;
Packit 8f70b4
  size_t nodes_alloc;
Packit 8f70b4
  size_t nodes_len;
Packit 8f70b4
  Idx *nexts;
Packit 8f70b4
  Idx *org_indices;
Packit 8f70b4
  re_node_set *edests;
Packit 8f70b4
  re_node_set *eclosures;
Packit 8f70b4
  re_node_set *inveclosures;
Packit 8f70b4
  struct re_state_table_entry *state_table;
Packit 8f70b4
  re_dfastate_t *init_state;
Packit 8f70b4
  re_dfastate_t *init_state_word;
Packit 8f70b4
  re_dfastate_t *init_state_nl;
Packit 8f70b4
  re_dfastate_t *init_state_begbuf;
Packit 8f70b4
  bin_tree_t *str_tree;
Packit 8f70b4
  bin_tree_storage_t *str_tree_storage;
Packit 8f70b4
  re_bitset_ptr_t sb_char;
Packit 8f70b4
  int str_tree_storage_idx;
Packit 8f70b4
Packit 8f70b4
  /* number of subexpressions 're_nsub' is in regex_t.  */
Packit 8f70b4
  re_hashval_t state_hash_mask;
Packit 8f70b4
  Idx init_node;
Packit 8f70b4
  Idx nbackref; /* The number of backreference in this dfa.  */
Packit 8f70b4
Packit 8f70b4
  /* Bitmap expressing which backreference is used.  */
Packit 8f70b4
  bitset_word_t used_bkref_map;
Packit 8f70b4
  bitset_word_t completed_bkref_map;
Packit 8f70b4
Packit 8f70b4
  unsigned int has_plural_match : 1;
Packit 8f70b4
  /* If this dfa has "multibyte node", which is a backreference or
Packit 8f70b4
     a node which can accept multibyte character or multi character
Packit 8f70b4
     collating element.  */
Packit 8f70b4
  unsigned int has_mb_node : 1;
Packit 8f70b4
  unsigned int is_utf8 : 1;
Packit 8f70b4
  unsigned int map_notascii : 1;
Packit 8f70b4
  unsigned int word_ops_used : 1;
Packit 8f70b4
  int mb_cur_max;
Packit 8f70b4
  bitset_t word_char;
Packit 8f70b4
  reg_syntax_t syntax;
Packit 8f70b4
  Idx *subexp_map;
Packit 8f70b4
#ifdef DEBUG
Packit 8f70b4
  char* re_str;
Packit 8f70b4
#endif
Packit 8f70b4
  lock_define (lock)
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
#define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
Packit 8f70b4
#define re_node_set_remove(set,id) \
Packit 8f70b4
  (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
Packit 8f70b4
#define re_node_set_empty(p) ((p)->nelem = 0)
Packit 8f70b4
#define re_node_set_free(set) re_free ((set)->elems)
Packit 8f70b4

Packit 8f70b4
Packit 8f70b4
typedef enum
Packit 8f70b4
{
Packit 8f70b4
  SB_CHAR,
Packit 8f70b4
  MB_CHAR,
Packit 8f70b4
  EQUIV_CLASS,
Packit 8f70b4
  COLL_SYM,
Packit 8f70b4
  CHAR_CLASS
Packit 8f70b4
} bracket_elem_type;
Packit 8f70b4
Packit 8f70b4
typedef struct
Packit 8f70b4
{
Packit 8f70b4
  bracket_elem_type type;
Packit 8f70b4
  union
Packit 8f70b4
  {
Packit 8f70b4
    unsigned char ch;
Packit 8f70b4
    unsigned char *name;
Packit 8f70b4
    wchar_t wch;
Packit 8f70b4
  } opr;
Packit 8f70b4
} bracket_elem_t;
Packit 8f70b4
Packit 8f70b4
Packit 8f70b4
/* Functions for bitset_t operation.  */
Packit 8f70b4
Packit 8f70b4
static inline void
Packit 8f70b4
bitset_set (bitset_t set, Idx i)
Packit 8f70b4
{
Packit 8f70b4
  set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static inline void
Packit 8f70b4
bitset_clear (bitset_t set, Idx i)
Packit 8f70b4
{
Packit 8f70b4
  set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static inline bool
Packit 8f70b4
bitset_contain (const bitset_t set, Idx i)
Packit 8f70b4
{
Packit 8f70b4
  return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static inline void
Packit 8f70b4
bitset_empty (bitset_t set)
Packit 8f70b4
{
Packit 8f70b4
  memset (set, '\0', sizeof (bitset_t));
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static inline void
Packit 8f70b4
bitset_set_all (bitset_t set)
Packit 8f70b4
{
Packit 8f70b4
  memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
Packit 8f70b4
  if (SBC_MAX % BITSET_WORD_BITS != 0)
Packit 8f70b4
    set[BITSET_WORDS - 1] =
Packit 8f70b4
      ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static inline void
Packit 8f70b4
bitset_copy (bitset_t dest, const bitset_t src)
Packit 8f70b4
{
Packit 8f70b4
  memcpy (dest, src, sizeof (bitset_t));
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static inline void
Packit 8f70b4
bitset_not (bitset_t set)
Packit 8f70b4
{
Packit 8f70b4
  int bitset_i;
Packit 8f70b4
  for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i)
Packit 8f70b4
    set[bitset_i] = ~set[bitset_i];
Packit 8f70b4
  if (SBC_MAX % BITSET_WORD_BITS != 0)
Packit 8f70b4
    set[BITSET_WORDS - 1] =
Packit 8f70b4
      ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
Packit 8f70b4
       & ~set[BITSET_WORDS - 1]);
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static inline void
Packit 8f70b4
bitset_merge (bitset_t dest, const bitset_t src)
Packit 8f70b4
{
Packit 8f70b4
  int bitset_i;
Packit 8f70b4
  for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
Packit 8f70b4
    dest[bitset_i] |= src[bitset_i];
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static inline void
Packit 8f70b4
bitset_mask (bitset_t dest, const bitset_t src)
Packit 8f70b4
{
Packit 8f70b4
  int bitset_i;
Packit 8f70b4
  for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
Packit 8f70b4
    dest[bitset_i] &= src[bitset_i];
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
#ifdef RE_ENABLE_I18N
Packit 8f70b4
/* Functions for re_string.  */
Packit 8f70b4
static int
Packit 8f70b4
__attribute__ ((pure, unused))
Packit 8f70b4
re_string_char_size_at (const re_string_t *pstr, Idx idx)
Packit 8f70b4
{
Packit 8f70b4
  int byte_idx;
Packit 8f70b4
  if (pstr->mb_cur_max == 1)
Packit 8f70b4
    return 1;
Packit 8f70b4
  for (byte_idx = 1; idx + byte_idx < pstr->valid_len; ++byte_idx)
Packit 8f70b4
    if (pstr->wcs[idx + byte_idx] != WEOF)
Packit 8f70b4
      break;
Packit 8f70b4
  return byte_idx;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
static wint_t
Packit 8f70b4
__attribute__ ((pure, unused))
Packit 8f70b4
re_string_wchar_at (const re_string_t *pstr, Idx idx)
Packit 8f70b4
{
Packit 8f70b4
  if (pstr->mb_cur_max == 1)
Packit 8f70b4
    return (wint_t) pstr->mbs[idx];
Packit 8f70b4
  return (wint_t) pstr->wcs[idx];
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
# ifdef _LIBC
Packit 8f70b4
#  include <locale/weight.h>
Packit 8f70b4
# endif
Packit 8f70b4
Packit 8f70b4
static int
Packit 8f70b4
__attribute__ ((pure, unused))
Packit 8f70b4
re_string_elem_size_at (const re_string_t *pstr, Idx idx)
Packit 8f70b4
{
Packit 8f70b4
# ifdef _LIBC
Packit 8f70b4
  const unsigned char *p, *extra;
Packit 8f70b4
  const int32_t *table, *indirect;
Packit 8f70b4
  uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
Packit 8f70b4
Packit 8f70b4
  if (nrules != 0)
Packit 8f70b4
    {
Packit 8f70b4
      table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
Packit 8f70b4
      extra = (const unsigned char *)
Packit 8f70b4
	_NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
Packit 8f70b4
      indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
Packit 8f70b4
						_NL_COLLATE_INDIRECTMB);
Packit 8f70b4
      p = pstr->mbs + idx;
Packit 8f70b4
      findidx (table, indirect, extra, &p, pstr->len - idx);
Packit 8f70b4
      return p - pstr->mbs - idx;
Packit 8f70b4
    }
Packit 8f70b4
  else
Packit 8f70b4
# endif /* _LIBC */
Packit 8f70b4
    return 1;
Packit 8f70b4
}
Packit 8f70b4
#endif /* RE_ENABLE_I18N */
Packit 8f70b4
Packit 8f70b4
#ifndef __GNUC_PREREQ
Packit 8f70b4
# if defined __GNUC__ && defined __GNUC_MINOR__
Packit 8f70b4
#  define __GNUC_PREREQ(maj, min) \
Packit 8f70b4
         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
Packit 8f70b4
# else
Packit 8f70b4
#  define __GNUC_PREREQ(maj, min) 0
Packit 8f70b4
# endif
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#if __GNUC_PREREQ (3,4)
Packit 8f70b4
# undef __attribute_warn_unused_result__
Packit 8f70b4
# define __attribute_warn_unused_result__ \
Packit 8f70b4
   __attribute__ ((__warn_unused_result__))
Packit 8f70b4
#else
Packit 8f70b4
# define __attribute_warn_unused_result__ /* empty */
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#ifndef FALLTHROUGH
Packit 8f70b4
# if __GNUC__ < 7
Packit 8f70b4
#  define FALLTHROUGH ((void) 0)
Packit 8f70b4
# else
Packit 8f70b4
#  define FALLTHROUGH __attribute__ ((__fallthrough__))
Packit 8f70b4
# endif
Packit 8f70b4
#endif
Packit 8f70b4
Packit 8f70b4
#endif /*  _REGEX_INTERNAL_H */