1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Extended regular expression matching and search library.
4 Copyright (C) 2002-2014 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 3 of the License, or (at your option) any later version.
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public
19 License along with the GNU C Library; if not, see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef _REGEX_INTERNAL_H
23 #define _REGEX_INTERNAL_H 1
39 # include <bits/libc-lock.h>
40 # define lock_define(name) __libc_lock_define (, name)
41 # define lock_init(lock) (__libc_lock_init (lock), 0)
42 # define lock_fini(lock) 0
43 # define lock_lock(lock) __libc_lock_lock (lock)
44 # define lock_unlock(lock) __libc_lock_unlock (lock)
45 #elif defined GNULIB_LOCK
46 # include "glthread/lock.h"
47 /* Use gl_lock_define if empty macro arguments are known to work.
48 Otherwise, fall back on less-portable substitutes. */
49 # if ((defined __GNUC__ && !defined __STRICT_ANSI__) \
50 || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__))
51 # define lock_define(name) gl_lock_define (, name)
52 # elif USE_POSIX_THREADS
53 # define lock_define(name) pthread_mutex_t name;
54 # elif USE_PTH_THREADS
55 # define lock_define(name) pth_mutex_t name;
56 # elif USE_SOLARIS_THREADS
57 # define lock_define(name) mutex_t name;
58 # elif USE_WINDOWS_THREADS
59 # define lock_define(name) gl_lock_t name;
61 # define lock_define(name)
63 # define lock_init(lock) glthread_lock_init (&(lock))
64 # define lock_fini(lock) glthread_lock_destroy (&(lock))
65 # define lock_lock(lock) glthread_lock_lock (&(lock))
66 # define lock_unlock(lock) glthread_lock_unlock (&(lock))
67 #elif defined GNULIB_PTHREAD
69 # define lock_define(name) pthread_mutex_t name;
70 # define lock_init(lock) pthread_mutex_init (&(lock), 0)
71 # define lock_fini(lock) pthread_mutex_destroy (&(lock))
72 # define lock_lock(lock) pthread_mutex_lock (&(lock))
73 # define lock_unlock(lock) pthread_mutex_unlock (&(lock))
75 # define lock_define(name)
76 # define lock_init(lock) 0
77 # define lock_fini(lock) ((void) 0)
78 /* The 'dfa' avoids an "unused variable 'dfa'" warning from GCC. */
79 # define lock_lock(lock) ((void) dfa)
80 # define lock_unlock(lock) ((void) 0)
83 /* In case that the system doesn't have isblank(). */
84 #if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK))
85 # define isblank(ch) ((ch) == ' ' || (ch) == '\t')
89 # ifndef _RE_DEFINE_LOCALE_FUNCTIONS
90 # define _RE_DEFINE_LOCALE_FUNCTIONS 1
91 # include <locale/localeinfo.h>
92 # include <locale/elem-hash.h>
93 # include <locale/coll-lookup.h>
97 /* This is for other GNU distributions with internationalized messages. */
98 #if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
102 # define gettext(msgid) \
103 __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES)
106 # define gettext(msgid) (msgid)
110 /* This define is so xgettext can find the internationalizable
112 # define gettext_noop(String) String
115 #if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE) || _LIBC
116 # define RE_ENABLE_I18N
120 # define BE(expr, val) __builtin_expect (expr, val)
122 # define BE(expr, val) (expr)
125 /* Number of ASCII characters. */
126 #define ASCII_CHARS 0x80
128 /* Number of single byte characters. */
129 #define SBC_MAX (UCHAR_MAX + 1)
131 #define COLL_ELEM_LEN_MAX 8
133 /* The character which represents newline. */
134 #define NEWLINE_CHAR '\n'
135 #define WIDE_NEWLINE_CHAR L'\n'
137 /* Rename to standard API for using out of glibc. */
141 # define __wctype wctype
142 # define __iswctype iswctype
143 # define __btowc btowc
144 # define __mbrtowc mbrtowc
145 # define __wcrtomb wcrtomb
146 # define __regfree regfree
147 # define attribute_hidden
148 #endif /* not _LIBC */
150 #if __GNUC__ < 3 + (__GNUC_MINOR__ < 1)
151 # define __attribute__(arg)
154 typedef __re_idx_t Idx;
155 #ifdef _REGEX_LARGE_OFFSETS
156 # define IDX_MAX (SIZE_MAX - 2)
158 # define IDX_MAX INT_MAX
161 /* Special return value for failure to match. */
162 #define REG_MISSING ((Idx) -1)
164 /* Special return value for internal error. */
165 #define REG_ERROR ((Idx) -2)
167 /* Test whether N is a valid index, and is not one of the above. */
168 #ifdef _REGEX_LARGE_OFFSETS
169 # define REG_VALID_INDEX(n) ((Idx) (n) < REG_ERROR)
171 # define REG_VALID_INDEX(n) (0 <= (n))
174 /* Test whether N is a valid nonzero index. */
175 #ifdef _REGEX_LARGE_OFFSETS
176 # define REG_VALID_NONZERO_INDEX(n) ((Idx) ((n) - 1) < (Idx) (REG_ERROR - 1))
178 # define REG_VALID_NONZERO_INDEX(n) (0 < (n))
181 /* A hash value, suitable for computing hash tables. */
182 typedef __re_size_t re_hashval_t;
184 /* An integer used to represent a set of bits. It must be unsigned,
185 and must be at least as wide as unsigned int. */
186 typedef unsigned long int bitset_word_t;
187 /* All bits set in a bitset_word_t. */
188 #define BITSET_WORD_MAX ULONG_MAX
190 /* Number of bits in a bitset_word_t. For portability to hosts with
191 padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
192 instead, deduce it directly from BITSET_WORD_MAX. Avoid
193 greater-than-32-bit integers and unconditional shifts by more than
194 31 bits, as they're not portable. */
195 #if BITSET_WORD_MAX == 0xffffffffUL
196 # define BITSET_WORD_BITS 32
197 #elif BITSET_WORD_MAX >> 31 >> 4 == 1
198 # define BITSET_WORD_BITS 36
199 #elif BITSET_WORD_MAX >> 31 >> 16 == 1
200 # define BITSET_WORD_BITS 48
201 #elif BITSET_WORD_MAX >> 31 >> 28 == 1
202 # define BITSET_WORD_BITS 60
203 #elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1
204 # define BITSET_WORD_BITS 64
205 #elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1
206 # define BITSET_WORD_BITS 72
207 #elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1
208 # define BITSET_WORD_BITS 128
209 #elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1
210 # define BITSET_WORD_BITS 256
211 #elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1
212 # define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */
213 # if BITSET_WORD_BITS <= SBC_MAX
214 # error "Invalid SBC_MAX"
217 # error "Add case for new bitset_word_t size"
220 /* Number of bitset_word_t values in a bitset_t. */
221 #define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
223 typedef bitset_word_t bitset_t[BITSET_WORDS];
224 typedef bitset_word_t *re_bitset_ptr_t;
225 typedef const bitset_word_t *re_const_bitset_ptr_t;
227 #define PREV_WORD_CONSTRAINT 0x0001
228 #define PREV_NOTWORD_CONSTRAINT 0x0002
229 #define NEXT_WORD_CONSTRAINT 0x0004
230 #define NEXT_NOTWORD_CONSTRAINT 0x0008
231 #define PREV_NEWLINE_CONSTRAINT 0x0010
232 #define NEXT_NEWLINE_CONSTRAINT 0x0020
233 #define PREV_BEGBUF_CONSTRAINT 0x0040
234 #define NEXT_ENDBUF_CONSTRAINT 0x0080
235 #define WORD_DELIM_CONSTRAINT 0x0100
236 #define NOT_WORD_DELIM_CONSTRAINT 0x0200
240 INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
241 WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
242 WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
243 INSIDE_NOTWORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
244 LINE_FIRST = PREV_NEWLINE_CONSTRAINT,
245 LINE_LAST = NEXT_NEWLINE_CONSTRAINT,
246 BUF_FIRST = PREV_BEGBUF_CONSTRAINT,
247 BUF_LAST = NEXT_ENDBUF_CONSTRAINT,
248 WORD_DELIM = WORD_DELIM_CONSTRAINT,
249 NOT_WORD_DELIM = NOT_WORD_DELIM_CONSTRAINT
263 /* Node type, These are used by token, node, tree. */
269 #ifdef RE_ENABLE_I18N
272 #endif /* RE_ENABLE_I18N */
274 /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used
275 when the debugger shows values of this enum type. */
276 #define EPSILON_BIT 8
277 OP_OPEN_SUBEXP = EPSILON_BIT | 0,
278 OP_CLOSE_SUBEXP = EPSILON_BIT | 1,
279 OP_ALT = EPSILON_BIT | 2,
280 OP_DUP_ASTERISK = EPSILON_BIT | 3,
281 ANCHOR = EPSILON_BIT | 4,
283 /* Tree type, these are used only by tree. */
287 /* Token type, these are used only by token. */
299 OP_CLOSE_EQUIV_CLASS,
310 #ifdef RE_ENABLE_I18N
313 /* Multibyte characters. */
316 /* Collating symbols. */
321 /* Equivalence classes. */
323 int32_t *equiv_classes;
326 /* Range expressions. */
328 uint32_t *range_starts;
329 uint32_t *range_ends;
330 # else /* not _LIBC */
331 wchar_t *range_starts;
333 # endif /* not _LIBC */
335 /* Character classes. */
336 wctype_t *char_classes;
338 /* If this character set is the non-matching list. */
339 unsigned int non_match : 1;
341 /* # of multibyte characters. */
344 /* # of collating symbols. */
347 /* # of equivalence classes. */
350 /* # of range expressions. */
353 /* # of character classes. */
356 #endif /* RE_ENABLE_I18N */
362 unsigned char c; /* for CHARACTER */
363 re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */
364 #ifdef RE_ENABLE_I18N
365 re_charset_t *mbcset; /* for COMPLEX_BRACKET */
366 #endif /* RE_ENABLE_I18N */
367 Idx idx; /* for BACK_REF */
368 re_context_type ctx_type; /* for ANCHOR */
370 #if __GNUC__ >= 2 && !defined __STRICT_ANSI__
371 re_token_type_t type : 8;
373 re_token_type_t type;
375 unsigned int constraint : 10; /* context constraint */
376 unsigned int duplicated : 1;
377 unsigned int opt_subexp : 1;
378 #ifdef RE_ENABLE_I18N
379 unsigned int accept_mb : 1;
380 /* These 2 bits can be moved into the union if needed (e.g. if running out
381 of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */
382 unsigned int mb_partial : 1;
384 unsigned int word_char : 1;
387 #define IS_EPSILON_NODE(type) ((type) & EPSILON_BIT)
391 /* Indicate the raw buffer which is the original string passed as an
392 argument of regexec(), re_search(), etc.. */
393 const unsigned char *raw_mbs;
394 /* Store the multibyte string. In case of "case insensitive mode" like
395 REG_ICASE, upper cases of the string are stored, otherwise MBS points
396 the same address that RAW_MBS points. */
398 #ifdef RE_ENABLE_I18N
399 /* Store the wide character string which is corresponding to MBS. */
404 /* Index in RAW_MBS. Each character mbs[i] corresponds to
405 raw_mbs[raw_mbs_idx + i]. */
407 /* The length of the valid characters in the buffers. */
409 /* The corresponding number of bytes in raw_mbs array. */
411 /* The length of the buffers MBS and WCS. */
413 /* The index in MBS, which is updated by re_string_fetch_byte. */
415 /* length of RAW_MBS array. */
417 /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN. */
419 /* End of the buffer may be shorter than its length in the cases such
420 as re_match_2, re_search_2. Then, we use STOP for end of the buffer
423 /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS. */
426 /* The context of mbs[0]. We store the context independently, since
427 the context of mbs[0] may be different from raw_mbs[0], which is
428 the beginning of the input string. */
429 unsigned int tip_context;
430 /* The translation passed as a part of an argument of re_compile_pattern. */
431 RE_TRANSLATE_TYPE trans;
432 /* Copy of re_dfa_t's word_char. */
433 re_const_bitset_ptr_t word_char;
434 /* true if REG_ICASE. */
436 unsigned char is_utf8;
437 unsigned char map_notascii;
438 unsigned char mbs_allocated;
439 unsigned char offsets_needed;
440 unsigned char newline_anchor;
441 unsigned char word_ops_used;
444 typedef struct re_string_t re_string_t;
448 typedef struct re_dfa_t re_dfa_t;
451 # define internal_function
455 static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
458 # ifdef RE_ENABLE_I18N
459 static void build_wcs_buffer (re_string_t *pstr) internal_function;
460 static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
462 # endif /* RE_ENABLE_I18N */
463 static void build_upper_buffer (re_string_t *pstr) internal_function;
464 static void re_string_translate_buffer (re_string_t *pstr) internal_function;
465 static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
467 internal_function __attribute__ ((pure));
469 #define re_string_peek_byte(pstr, offset) \
470 ((pstr)->mbs[(pstr)->cur_idx + offset])
471 #define re_string_fetch_byte(pstr) \
472 ((pstr)->mbs[(pstr)->cur_idx++])
473 #define re_string_first_byte(pstr, idx) \
474 ((idx) == (pstr)->valid_len || (pstr)->wcs[idx] != WEOF)
475 #define re_string_is_single_byte_char(pstr, idx) \
476 ((pstr)->wcs[idx] != WEOF && ((pstr)->valid_len == (idx) + 1 \
477 || (pstr)->wcs[(idx) + 1] != WEOF))
478 #define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx)
479 #define re_string_cur_idx(pstr) ((pstr)->cur_idx)
480 #define re_string_get_buffer(pstr) ((pstr)->mbs)
481 #define re_string_length(pstr) ((pstr)->len)
482 #define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx])
483 #define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
484 #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
486 #if defined _LIBC || HAVE_ALLOCA
492 /* The OS usually guarantees only one guard page at the bottom of the stack,
493 and a page size can be as small as 4096 bytes. So we cannot safely
494 allocate anything larger than 4096 bytes. Also care for the possibility
495 of a few compiler-allocated temporary stack slots. */
496 # define __libc_use_alloca(n) ((n) < 4032)
498 /* alloca is implemented with malloc, so just use malloc. */
499 # define __libc_use_alloca(n) 0
501 # define alloca(n) malloc (n)
506 # define MALLOC_0_IS_NONNULL 1
507 #elif !defined MALLOC_0_IS_NONNULL
508 # define MALLOC_0_IS_NONNULL 0
512 # define MAX(a,b) ((a) < (b) ? (b) : (a))
515 # define MIN(a,b) ((a) < (b) ? (a) : (b))
518 #define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
519 #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
520 #define re_free(p) free (p)
524 struct bin_tree_t *parent;
525 struct bin_tree_t *left;
526 struct bin_tree_t *right;
527 struct bin_tree_t *first;
528 struct bin_tree_t *next;
532 /* 'node_idx' is the index in dfa->nodes, if 'type' == 0.
533 Otherwise 'type' indicate the type of this node. */
536 typedef struct bin_tree_t bin_tree_t;
538 #define BIN_TREE_STORAGE_SIZE \
539 ((1024 - sizeof (void *)) / sizeof (bin_tree_t))
541 struct bin_tree_storage_t
543 struct bin_tree_storage_t *next;
544 bin_tree_t data[BIN_TREE_STORAGE_SIZE];
546 typedef struct bin_tree_storage_t bin_tree_storage_t;
548 #define CONTEXT_WORD 1
549 #define CONTEXT_NEWLINE (CONTEXT_WORD << 1)
550 #define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1)
551 #define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1)
553 #define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD)
554 #define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE)
555 #define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF)
556 #define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF)
557 #define IS_ORDINARY_CONTEXT(c) ((c) == 0)
559 #define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
560 #define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
561 #define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_')
562 #define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
564 #define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
565 ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
566 || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
567 || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\
568 || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context)))
570 #define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \
571 ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
572 || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
573 || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \
574 || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context)))
580 re_node_set non_eps_nodes;
581 re_node_set inveclosure;
582 re_node_set *entrance_nodes;
583 struct re_dfastate_t **trtable, **word_trtable;
584 unsigned int context : 4;
585 unsigned int halt : 1;
586 /* If this state can accept "multi byte".
587 Note that we refer to multibyte characters, and multi character
588 collating elements as "multi byte". */
589 unsigned int accept_mb : 1;
590 /* If this state has backreference node(s). */
591 unsigned int has_backref : 1;
592 unsigned int has_constraint : 1;
594 typedef struct re_dfastate_t re_dfastate_t;
596 struct re_state_table_entry
600 re_dfastate_t **array;
603 /* Array type used in re_sub_match_last_t and re_sub_match_top_t. */
609 re_dfastate_t **array;
612 /* Store information about the node NODE whose type is OP_CLOSE_SUBEXP. */
617 Idx str_idx; /* The position NODE match at. */
619 } re_sub_match_last_t;
621 /* Store information about the node NODE whose type is OP_OPEN_SUBEXP.
622 And information about the node, whose type is OP_CLOSE_SUBEXP,
623 corresponding to NODE is stored in LASTS. */
630 Idx alasts; /* Allocation size of LASTS. */
631 Idx nlasts; /* The number of LASTS. */
632 re_sub_match_last_t **lasts;
633 } re_sub_match_top_t;
635 struct re_backref_cache_entry
643 unsigned short int eps_reachable_subexps_map;
648 /* The string object corresponding to the input string. */
650 #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
651 const re_dfa_t *const dfa;
655 /* EFLAGS of the argument of regexec. */
657 /* Where the matching ends. */
660 /* The state log used by the matcher. */
661 re_dfastate_t **state_log;
663 /* Back reference cache. */
666 struct re_backref_cache_entry *bkref_ents;
670 re_sub_match_top_t **sub_tops;
671 } re_match_context_t;
675 re_dfastate_t **sifted_states;
676 re_dfastate_t **limited_states;
682 struct re_fail_stack_ent_t
687 re_node_set eps_via_nodes;
690 struct re_fail_stack_t
694 struct re_fail_stack_ent_t *stack;
705 re_node_set *eclosures;
706 re_node_set *inveclosures;
707 struct re_state_table_entry *state_table;
708 re_dfastate_t *init_state;
709 re_dfastate_t *init_state_word;
710 re_dfastate_t *init_state_nl;
711 re_dfastate_t *init_state_begbuf;
712 bin_tree_t *str_tree;
713 bin_tree_storage_t *str_tree_storage;
714 re_bitset_ptr_t sb_char;
715 int str_tree_storage_idx;
717 /* number of subexpressions 're_nsub' is in regex_t. */
718 re_hashval_t state_hash_mask;
720 Idx nbackref; /* The number of backreference in this dfa. */
722 /* Bitmap expressing which backreference is used. */
723 bitset_word_t used_bkref_map;
724 bitset_word_t completed_bkref_map;
726 unsigned int has_plural_match : 1;
727 /* If this dfa has "multibyte node", which is a backreference or
728 a node which can accept multibyte character or multi character
729 collating element. */
730 unsigned int has_mb_node : 1;
731 unsigned int is_utf8 : 1;
732 unsigned int map_notascii : 1;
733 unsigned int word_ops_used : 1;
744 #define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
745 #define re_node_set_remove(set,id) \
746 (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
747 #define re_node_set_empty(p) ((p)->nelem = 0)
748 #define re_node_set_free(set) re_free ((set)->elems)
762 bracket_elem_type type;
772 /* Functions for bitset_t operation. */
775 bitset_set (bitset_t set, Idx i)
777 set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
781 bitset_clear (bitset_t set, Idx i)
783 set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
787 bitset_contain (const bitset_t set, Idx i)
789 return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
793 bitset_empty (bitset_t set)
795 memset (set, '\0', sizeof (bitset_t));
799 bitset_set_all (bitset_t set)
801 memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
802 if (SBC_MAX % BITSET_WORD_BITS != 0)
803 set[BITSET_WORDS - 1] =
804 ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
808 bitset_copy (bitset_t dest, const bitset_t src)
810 memcpy (dest, src, sizeof (bitset_t));
813 static void __attribute__ ((unused))
814 bitset_not (bitset_t set)
817 for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i)
818 set[bitset_i] = ~set[bitset_i];
819 if (SBC_MAX % BITSET_WORD_BITS != 0)
820 set[BITSET_WORDS - 1] =
821 ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
822 & ~set[BITSET_WORDS - 1]);
825 static void __attribute__ ((unused))
826 bitset_merge (bitset_t dest, const bitset_t src)
829 for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
830 dest[bitset_i] |= src[bitset_i];
833 static void __attribute__ ((unused))
834 bitset_mask (bitset_t dest, const bitset_t src)
837 for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
838 dest[bitset_i] &= src[bitset_i];
841 #ifdef RE_ENABLE_I18N
842 /* Functions for re_string. */
844 internal_function __attribute__ ((pure, unused))
845 re_string_char_size_at (const re_string_t *pstr, Idx idx)
848 if (pstr->mb_cur_max == 1)
850 for (byte_idx = 1; idx + byte_idx < pstr->valid_len; ++byte_idx)
851 if (pstr->wcs[idx + byte_idx] != WEOF)
857 internal_function __attribute__ ((pure, unused))
858 re_string_wchar_at (const re_string_t *pstr, Idx idx)
860 if (pstr->mb_cur_max == 1)
861 return (wint_t) pstr->mbs[idx];
862 return (wint_t) pstr->wcs[idx];
867 internal_function __attribute__ ((pure, unused))
868 re_string_elem_size_at (const re_string_t *pstr, Idx idx)
871 const unsigned char *p, *extra;
872 const int32_t *table, *indirect;
873 # include <locale/weight.h>
874 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
878 table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
879 extra = (const unsigned char *)
880 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
881 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
882 _NL_COLLATE_INDIRECTMB);
884 findidx (&p, pstr->len - idx);
885 return p - pstr->mbs - idx;
892 #endif /* RE_ENABLE_I18N */
894 #ifndef __GNUC_PREREQ
895 # if defined __GNUC__ && defined __GNUC_MINOR__
896 # define __GNUC_PREREQ(maj, min) \
897 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
899 # define __GNUC_PREREQ(maj, min) 0
903 #if __GNUC_PREREQ (3,4)
904 # undef __attribute_warn_unused_result__
905 # define __attribute_warn_unused_result__ \
906 __attribute__ ((__warn_unused_result__))
908 # define __attribute_warn_unused_result__ /* empty */
911 #endif /* _REGEX_INTERNAL_H */