3 union locale_data_value {
8 extern __thread struct locale_data **_nl_current_LC_CTYPE;
9 typedef unsigned long int reg_syntax_t;
10 extern reg_syntax_t re_syntax_options;
15 unsigned char *buffer;
18 unsigned char *translate;
21 extern __thread void *__libc_tsd_CTYPE_TOLOWER;
22 inline int **__ctype_tolower_loc(void)
28 u.ptr = (&__libc_tsd_CTYPE_TOLOWER);
31 ((int *)((*_nl_current_LC_CTYPE)->values[0].string) + 128);
34 inline int tolower(int __c)
36 return *__ctype_tolower_loc()[__c];
40 typedef unsigned long int *bitset_t;
41 typedef unsigned long int *re_bitset_ptr_t;
57 re_bitset_ptr_t sbcset;
62 typedef struct re_dfa_t re_dfa_t;
63 typedef struct bin_tree_t bin_tree_t;
64 struct re_dfastate_t {
67 typedef struct re_dfastate_t re_dfastate_t;
70 unsigned int nodes_len;
71 re_dfastate_t *init_state;
73 re_bitset_ptr_t sb_char;
75 unsigned int has_mb_node:1;
76 unsigned int is_utf8:1;
77 unsigned int map_notascii:1;
81 static reg_errcode_t analyze(regex_t * preg);
82 static reg_errcode_t optimize_subexps(void *extra, bin_tree_t * node);
84 static inline void re_set_fastmap(char *fastmap, int icase, int ch)
96 static void re_compile_fastmap_iter(regex_t * bufp,
97 re_dfastate_t * init_state,
100 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
102 int icase = (dfa->mb_cur_max == 1 && (bufp->syntax & 0x40000));
103 for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt) {
104 int node = init_state->nodes.elems[node_cnt];
105 re_token_type_t type = dfa->nodes[node].type;
106 if (type == CHARACTER) {
107 if ((bufp->syntax & 0x40000) && dfa->mb_cur_max > 1) {
108 void *buf = alloca(dfa->mb_cur_max);
112 for (; i < (256 / (sizeof(unsigned long int) * 8));) {
114 unsigned long int w =
115 dfa->nodes[node].opr.sbcset[i];
118 re_set_fastmap(fastmap, icase,
121 } else if (type == COMPLEX_BRACKET) {
123 re_charset_t *cset = dfa->nodes[node].opr.mbcset;
124 for (; i < cset->nmbchars;) {
127 if (__wcrtomb(buf, cset->mbchars[i], &state) !=
129 re_set_fastmap(fastmap, icase, *buf);
130 if ((bufp->syntax & 0x4000)
131 && dfa->mb_cur_max > 1) {
137 static bitset_t utf8_sb_map;
138 static reg_errcode_t re_compile_internal(regex_t * preg, const char *pattern,
145 if (dfa->is_utf8 && !(syntax & 0x400000) && preg->translate == 0)
147 unsigned int __s1_len =
148 strlen((*_nl_current_LC_CTYPE)->values[0].string);
150 (((!((int)((((*_nl_current_LC_CTYPE)->values[0].string)) ) -
151 (int)(((*_nl_current_LC_CTYPE)->values[0].string)) )
154 && (!((int)(("UTF-8") + 1) - (int)("UTF-8"))
155 )) ? strcmp(((*_nl_current_LC_CTYPE)->values[0].string),
157 : (((int)((((*_nl_current_LC_CTYPE)->values[0].string)) + 1) -
158 (int)(((*_nl_current_LC_CTYPE)->values[0].string)) )
161 ? (((int)(("UTF-8") ) - (int)("UTF-8")
162 ) ? strcmp(((*_nl_current_LC_CTYPE)->
165 : (((*_nl_current_LC_CTYPE)->values[0].
167 'U'))) : (((int)(("UTF-8") ) -
170 ((((*_nl_current_LC_CTYPE)->values[0].string)) ) - (int)(((*_nl_current_LC_CTYPE)->values[0].string))
171 ) ? strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8") : (((*_nl_current_LC_CTYPE)->values[0].string[0] - 'U'))) : strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8"))));
172 if (dfa->mb_cur_max == 6 && result == 0)
174 dfa->map_notascii = (*_nl_current_LC_CTYPE)->values[0].word != 0;
175 if (dfa->mb_cur_max > 1) {
177 dfa->sb_char = (re_bitset_ptr_t) utf8_sb_map;
183 i < (256 / (sizeof(unsigned long int) * 8));
185 unsigned int wch = __btowc(ch);
186 if (wch != (0xffffffffu))
187 dfa->sb_char[i] |= 1 << j;
195 for (; node < dfa->nodes_len;)
196 switch (dfa->nodes[node].type) {
198 if (dfa->nodes[node].opr.c >= 0x80)
200 for (; i < (256 / (sizeof(unsigned long int) * 8));)
201 if (dfa->nodes[node].opr.sbcset[i])
204 dfa->has_mb_node = dfa->nbackref > 0 || has_period;
206 static reg_errcode_t analyze(regex_t * preg)
208 re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
209 if (dfa->subexp_map != 0) {
211 for (; i < preg->re_nsub;)
212 dfa->subexp_map[i] = i;
213 preorder(dfa->str_tree, optimize_subexps, dfa);
214 for (; i < preg->re_nsub; i++)
215 if (dfa->subexp_map[i] != i)
219 const char *__re_compile_pattern(const char *pattern, unsigned int length, regex_t *bufp)
221 reg_errcode_t ret = re_compile_internal(bufp, pattern, length, re_syntax_options);
223 void __re_compile_fastmap(regex_t *bufp)
226 dfa = (re_dfa_t *) bufp->buffer;
228 fastmap = bufp->fastmap;
229 re_compile_fastmap_iter(bufp, dfa->init_state, fastmap);