3 union locale_data_value {
8 extern __thread struct locale_data *const *_nl_current_LC_CTYPE
9 __attribute__ ((tls_model("initial-exec")));
10 typedef unsigned long int reg_syntax_t;
11 extern reg_syntax_t re_syntax_options;
13 REG_ENOSYS = -1, REG_NOERROR =
14 0, REG_NOMATCH, REG_BADPAT, REG_ECOLLATE, REG_ECTYPE, REG_EESCAPE,
15 REG_ESUBREG, REG_EBRACK, REG_EPAREN, REG_EBRACE, REG_BADBR,
16 REG_ERANGE, REG_ESPACE, REG_BADRPT, REG_EEND, REG_ESIZE, REG_ERPAREN
19 unsigned char *buffer;
22 unsigned char *translate;
24 unsigned fastmap_accurate:1;
28 extern __thread void *__libc_tsd_CTYPE_TOLOWER
29 __attribute__ ((tls_model("initial-exec")));
30 extern inline const int ** __attribute__ ((const))__ctype_tolower_loc(void)
36 u.ptr = (&__libc_tsd_CTYPE_TOLOWER);
37 if (__builtin_expect(*u.tablep == 0, 0))
39 ((int *)((*_nl_current_LC_CTYPE)->
49 return __c >= -128 && __c < 256 ? (*__ctype_tolower_loc())[__c] : __c;
53 typedef unsigned long int *bitset_t;
54 typedef unsigned long int *re_bitset_ptr_t;
60 NON_TYPE = 0, CHARACTER = 1, END_OF_RE = 2, SIMPLE_BRACKET =
61 3, OP_BACK_REF = 4, OP_PERIOD = 5, COMPLEX_BRACKET =
62 6, OP_UTF8_PERIOD = 7, OP_OPEN_SUBEXP = 8 | 0, OP_CLOSE_SUBEXP =
63 8 | 1, OP_ALT = 8 | 2, OP_DUP_ASTERISK = 8 | 3, ANCHOR =
64 8 | 4, CONCAT = 16, SUBEXP = 17, OP_DUP_PLUS =
65 18, OP_DUP_QUESTION, OP_OPEN_BRACKET, OP_CLOSE_BRACKET,
66 OP_CHARSET_RANGE, OP_OPEN_DUP_NUM, OP_CLOSE_DUP_NUM,
67 OP_NON_MATCH_LIST, OP_OPEN_COLL_ELEM, OP_CLOSE_COLL_ELEM,
68 OP_OPEN_EQUIV_CLASS, OP_CLOSE_EQUIV_CLASS, OP_OPEN_CHAR_CLASS,
69 OP_CLOSE_CHAR_CLASS, OP_WORD, OP_NOTWORD, OP_SPACE, OP_NOTSPACE,
79 re_bitset_ptr_t sbcset;
83 re_token_type_t type:8;
85 typedef struct re_dfa_t re_dfa_t;
86 typedef struct bin_tree_t bin_tree_t;
87 struct re_dfastate_t {
90 typedef struct re_dfastate_t re_dfastate_t;
93 unsigned int nodes_len;
97 re_node_set *eclosures;
98 re_dfastate_t *init_state;
100 re_bitset_ptr_t sb_char;
102 unsigned int has_mb_node:1;
103 unsigned int is_utf8:1;
104 unsigned int map_notascii:1;
108 static reg_errcode_t re_compile_internal(regex_t * preg, const char *pattern,
110 reg_syntax_t syntax);
111 static void re_compile_fastmap_iter(regex_t * bufp,
112 const re_dfastate_t * init_state,
114 static reg_errcode_t analyze(regex_t * preg);
115 static reg_errcode_t optimize_subexps(void *extra, bin_tree_t * node);
116 const char *__re_compile_pattern(pattern, length, bufp)
120 ret = re_compile_internal(bufp, pattern, length, re_syntax_options);
123 int __re_compile_fastmap(bufp)
126 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
127 char *fastmap = bufp->fastmap;
128 re_compile_fastmap_iter(bufp, dfa->init_state, fastmap);
131 __attribute__ ((always_inline)) re_set_fastmap(char *fastmap, int icase,
136 if (sizeof(ch) > 1) {
137 if (__builtin_constant_p(ch)) {
144 static void re_compile_fastmap_iter(regex_t * bufp,
145 const re_dfastate_t * init_state,
148 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
150 int icase = (dfa->mb_cur_max == 1
154 for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt) {
155 int node = init_state->nodes.elems[node_cnt];
156 re_token_type_t type = dfa->nodes[node].type;
157 if (type == CHARACTER) {
160 && dfa->mb_cur_max > 1) {
162 __builtin_alloca(dfa->mb_cur_max);
167 i < (256 / (sizeof(unsigned long int) * 8)); ++i) {
169 unsigned long int w =
170 dfa->nodes[node].opr.sbcset[i];
171 for (j = 0; j < (sizeof(unsigned long int) * 8);
173 if (w & ((unsigned long int)1 << j))
174 re_set_fastmap(fastmap, icase,
177 } else if (type == COMPLEX_BRACKET) {
179 re_charset_t *cset = dfa->nodes[node].opr.mbcset;
180 for (i = 0; i < cset->nmbchars; ++i) {
183 if (__wcrtomb(buf, cset->mbchars[i], &state) !=
185 re_set_fastmap(fastmap, icase,
186 *(unsigned char *)buf);
190 && dfa->mb_cur_max > 1) {
192 (buf, towlower(cset->mbchars[i]),
193 &state) != (unsigned int)-1)
194 re_set_fastmap(fastmap, 0,
202 static const bitset_t utf8_sb_map;
203 static reg_errcode_t re_compile_internal(regex_t * preg, const char *pattern,
209 preg->fastmap_accurate = 0;
210 preg->not_bol = preg->not_eol = 0;
215 && preg->translate == 0)
217 if (dfa->mb_cur_max == 6 && __extension__( {
218 unsigned int __s1_len;
219 unsigned int __s2_len;
220 (__builtin_constant_p
221 (((*_nl_current_LC_CTYPE)->
224 __builtin_constant_p("UTF-8")
226 strlen(((*_nl_current_LC_CTYPE)->values[
228 ].string)), __s2_len = strlen("UTF-8"), (!((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[
229 0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[
231 ].string)) == 1) || __s1_len >= 4) && (!((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) || __s2_len >= 4)) ? __builtin_strcmp(((*_nl_current_LC_CTYPE)->values[
233 ].string), "UTF-8") : (__builtin_constant_p(((*_nl_current_LC_CTYPE)->values[
235 ].string)) && ((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[
236 0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[
237 0].string)) == 1) && (__s1_len = strlen(((*_nl_current_LC_CTYPE)->values[
238 0].string)), __s1_len < 4) ? (__builtin_constant_p("UTF-8") && ((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) ? __builtin_strcmp(((*_nl_current_LC_CTYPE)->values[
240 ].string), "UTF-8") : (__extension__( {
258 (((__const unsigned char *)(__const char *)(((*_nl_current_LC_CTYPE)->values[
260 ].string)))[0] - __s2[0]); __result;}
261 ))): (__builtin_constant_p("UTF-8") && ((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) && (__s2_len = strlen("UTF-8"), __s2_len < 4) ? (__builtin_constant_p(((*_nl_current_LC_CTYPE)->values[
262 0].string)) && ((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[
263 0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[
264 0].string)) == 1) ? __builtin_strcmp(((*_nl_current_LC_CTYPE)->values[
265 0].string), "UTF-8") : (__extension__( {
278 (((*_nl_current_LC_CTYPE)->values[
280 ].string)); register int __result = __s1[0] - ((__const unsigned char *)(__const char *)("UTF-8"))[0]; __result;}
281 ))): __builtin_strcmp(((*_nl_current_LC_CTYPE)->values[
283 ].string), "UTF-8"))));}
287 (((unsigned int)(*_nl_current_LC_CTYPE)->
291 if (dfa->mb_cur_max > 1) {
293 dfa->sb_char = (re_bitset_ptr_t) utf8_sb_map;
299 (re_bitset_ptr_t) calloc(sizeof(bitset_t), 1);
301 i < (256 / (sizeof(unsigned long int) * 8)); ++i)
302 for (j = 0; j < (sizeof(unsigned long int) * 8);
304 unsigned int wch = __btowc(ch);
305 if (wch != (0xffffffffu))
307 (unsigned long int)1 << j;
315 for (node = 0; node < dfa->nodes_len; ++node)
316 switch (dfa->nodes[node].type) {
318 if (dfa->nodes[node].opr.c >= 0x80)
321 switch (dfa->nodes[node].opr.idx) {
325 for (i = 0x80 / (sizeof(unsigned long int) * 8);
326 i < (256 / (sizeof(unsigned long int) * 8)); ++i)
327 if (dfa->nodes[node].opr.sbcset[i])
330 dfa->has_mb_node = dfa->nbackref > 0 || has_period;
332 static reg_errcode_t analyze(regex_t * preg)
334 re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
336 (dfa->nexts == 0 || dfa->org_indices == 0 || dfa->edests == 0
337 || dfa->eclosures == 0, 0))
339 if (dfa->subexp_map != 0) {
341 for (i = 0; i < preg->re_nsub; i++)
342 dfa->subexp_map[i] = i;
343 preorder(dfa->str_tree, optimize_subexps, dfa);
344 for (i = 0; i < preg->re_nsub; i++)
345 if (dfa->subexp_map[i] != i)