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);
39 ((int *)((*_nl_current_LC_CTYPE)->values[0].string) + 128);
42 extern __inline int tolower(int __c)
47 __c < 256 ? (*__ctype_tolower_loc())[__c] : __c;
51 typedef unsigned long int *bitset_t;
52 typedef unsigned long int *re_bitset_ptr_t;
58 NON_TYPE = 0, CHARACTER = 1, END_OF_RE = 2, SIMPLE_BRACKET =
59 3, OP_BACK_REF = 4, OP_PERIOD = 5, COMPLEX_BRACKET =
60 6, OP_UTF8_PERIOD = 7, OP_OPEN_SUBEXP = 8 | 0, OP_CLOSE_SUBEXP =
61 8 | 1, OP_ALT = 8 | 2, OP_DUP_ASTERISK = 8 | 3, ANCHOR =
62 8 | 4, CONCAT = 16, SUBEXP = 17, OP_DUP_PLUS =
63 18, OP_DUP_QUESTION, OP_OPEN_BRACKET, OP_CLOSE_BRACKET,
64 OP_CHARSET_RANGE, OP_OPEN_DUP_NUM, OP_CLOSE_DUP_NUM,
65 OP_NON_MATCH_LIST, OP_OPEN_COLL_ELEM, OP_CLOSE_COLL_ELEM,
66 OP_OPEN_EQUIV_CLASS, OP_CLOSE_EQUIV_CLASS, OP_OPEN_CHAR_CLASS,
67 OP_CLOSE_CHAR_CLASS, OP_WORD, OP_NOTWORD, OP_SPACE, OP_NOTSPACE,
77 re_bitset_ptr_t sbcset;
81 re_token_type_t type:8;
83 typedef struct re_dfa_t re_dfa_t;
84 typedef struct bin_tree_t bin_tree_t;
85 struct re_dfastate_t {
88 typedef struct re_dfastate_t re_dfastate_t;
91 unsigned int nodes_len;
95 re_node_set *eclosures;
96 re_dfastate_t *init_state;
98 re_bitset_ptr_t sb_char;
100 unsigned int has_mb_node:1;
101 unsigned int is_utf8:1;
102 unsigned int map_notascii:1;
106 static reg_errcode_t re_compile_internal(regex_t * preg, const char *pattern,
108 reg_syntax_t syntax);
109 static void re_compile_fastmap_iter(regex_t * bufp,
110 const re_dfastate_t * init_state,
112 static reg_errcode_t analyze(regex_t * preg);
113 static reg_errcode_t optimize_subexps(void *extra, bin_tree_t * node);
114 const char *__re_compile_pattern(pattern, length, bufp)
118 ret = re_compile_internal(bufp, pattern, length, re_syntax_options);
121 int __re_compile_fastmap(bufp)
124 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
125 char *fastmap = bufp->fastmap;
126 re_compile_fastmap_iter(bufp, dfa->init_state, fastmap);
129 __attribute__ ((always_inline)) re_set_fastmap(char *fastmap, int icase,
134 if (sizeof(ch) > 1) {
142 static void re_compile_fastmap_iter(regex_t * bufp,
143 const re_dfastate_t * init_state,
146 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
148 int icase = (dfa->mb_cur_max == 1 && (bufp->syntax & 0x40000));
149 for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt) {
150 int node = init_state->nodes.elems[node_cnt];
151 re_token_type_t type = dfa->nodes[node].type;
152 if (type == CHARACTER) {
153 if ((bufp->syntax & 0x40000) && dfa->mb_cur_max > 1) {
156 alloca(dfa->mb_cur_max);
161 i < (256 / (sizeof(unsigned long int) * 8)); ) {
163 unsigned long int w =
164 dfa->nodes[node].opr.sbcset[i];
165 for (; j < (sizeof(unsigned long int) * 8);)
166 if (w & ((unsigned long int)1 << j))
167 re_set_fastmap(fastmap, icase,
170 } else if (type == COMPLEX_BRACKET) {
172 re_charset_t *cset = dfa->nodes[node].opr.mbcset;
173 for (i = 0; i < cset->nmbchars; ++i) {
176 if (__wcrtomb(buf, cset->mbchars[i], &state) !=
178 re_set_fastmap(fastmap, icase,
179 *(unsigned char *)buf);
180 if ((bufp->syntax & 0x4000)
181 && dfa->mb_cur_max > 1) {
183 (buf, towlower(cset->mbchars[i]),
184 &state) != (unsigned int)-1)
185 re_set_fastmap(fastmap, 0,
193 static const bitset_t utf8_sb_map;
194 static reg_errcode_t re_compile_internal(regex_t * preg, const char *pattern,
200 preg->fastmap_accurate = 0;
201 preg->not_bol = preg->not_eol = 0;
203 if (dfa->is_utf8 && !(syntax & 0x400000) && preg->translate == 0)
205 if (dfa->mb_cur_max == 6 && __extension__( {
206 unsigned int __s1_len;
207 unsigned int __s2_len;
210 strlen(((*_nl_current_LC_CTYPE)->values[0].string)), __s2_len = strlen("UTF-8"), (!((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[0].string)) == 1) || __s1_len >= 4) && (!((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) || __s2_len >= 4)) ? strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8") : (
211 ((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[0].string)) == 1) && (__s1_len = strlen(((*_nl_current_LC_CTYPE)->values[0].string)), __s1_len < 4) ? (
212 ((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) ?
213 strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8") : (__extension__( {
231 (((__const unsigned char *)(__const char *)(((*_nl_current_LC_CTYPE)->values[0].string)))[0] - __s2[0]); __result;}
233 ((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) && (__s2_len = strlen("UTF-8"), __s2_len < 4) ? (
234 ((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[0].string)) == 1) ?
235 strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8") : (__extension__( {
248 (((*_nl_current_LC_CTYPE)->values[0].string)); register int __result = __s1[0] - ((__const unsigned char *)(__const char *)("UTF-8"))[0]; __result;}
249 ))): strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8"))));}
253 (((unsigned int)(*_nl_current_LC_CTYPE)->values[0].word) != 0);
254 if (dfa->mb_cur_max > 1) {
256 dfa->sb_char = (re_bitset_ptr_t) utf8_sb_map;
262 (re_bitset_ptr_t) calloc(sizeof(bitset_t), 1);
264 i < (256 / (sizeof(unsigned long int) * 8)); ++i)
265 for (j = 0; j < (sizeof(unsigned long int) * 8);
267 unsigned int wch = __btowc(ch);
268 if (wch != (0xffffffffu))
270 (unsigned long int)1 << j;
278 for (node = 0; node < dfa->nodes_len; ++node)
279 switch (dfa->nodes[node].type) {
281 if (dfa->nodes[node].opr.c >= 0x80)
284 switch (dfa->nodes[node].opr.idx) {
288 for (i = 0x80 / (sizeof(unsigned long int) * 8);
289 i < (256 / (sizeof(unsigned long int) * 8)); ++i)
290 if (dfa->nodes[node].opr.sbcset[i])
293 dfa->has_mb_node = dfa->nbackref > 0 || has_period;
295 static reg_errcode_t analyze(regex_t * preg)
297 re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
299 (dfa->nexts == 0 || dfa->org_indices == 0 || dfa->edests == 0
300 || dfa->eclosures == 0))
302 if (dfa->subexp_map != 0) {
304 for (i = 0; i < preg->re_nsub; i++)
305 dfa->subexp_map[i] = i;
306 preorder(dfa->str_tree, optimize_subexps, dfa);
307 for (i = 0; i < preg->re_nsub; i++)
308 if (dfa->subexp_map[i] != i)