18
18
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20
20
static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
21
Idx n) internal_function;
21
int n) internal_function;
22
22
static void match_ctx_clean (re_match_context_t *mctx) internal_function;
23
23
static void match_ctx_free (re_match_context_t *cache) internal_function;
24
static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, Idx node,
25
Idx str_idx, Idx from, Idx to)
27
static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
29
static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node,
30
Idx str_idx) internal_function;
24
static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, int node,
25
int str_idx, int from, int to)
27
static int search_cur_bkref_entry (re_match_context_t *mctx, int str_idx)
29
static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, int node,
30
int str_idx) internal_function;
31
31
static re_sub_match_last_t * match_ctx_add_sublast (re_sub_match_top_t *subtop,
32
Idx node, Idx str_idx)
32
int node, int str_idx)
34
34
static void sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
35
re_dfastate_t **limited_sts, Idx last_node,
35
re_dfastate_t **limited_sts, int last_node,
38
38
static reg_errcode_t re_search_internal (const regex_t *preg,
39
const char *string, Idx length,
40
Idx start, Idx last_start, Idx stop,
39
const char *string, int length,
40
int start, int range, int stop,
41
41
size_t nmatch, regmatch_t pmatch[],
42
42
int eflags) internal_function;
43
static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp,
44
const char *string1, Idx length1,
45
const char *string2, Idx length2,
46
Idx start, regoff_t range,
47
struct re_registers *regs,
48
Idx stop, bool ret_len) internal_function;
49
static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
50
const char *string, Idx length, Idx start,
51
regoff_t range, Idx stop,
52
struct re_registers *regs,
53
bool ret_len) internal_function;
43
static int re_search_2_stub (struct re_pattern_buffer *bufp,
44
const char *string1, int length1,
45
const char *string2, int length2,
46
int start, int range, struct re_registers *regs,
47
int stop, int ret_len) internal_function;
48
static int re_search_stub (struct re_pattern_buffer *bufp,
49
const char *string, int length, int start,
50
int range, int stop, struct re_registers *regs,
51
int ret_len) internal_function;
54
52
static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
55
Idx nregs, int regs_allocated) internal_function;
53
int nregs, int regs_allocated) internal_function;
54
static inline re_dfastate_t *acquire_init_state_context
55
(reg_errcode_t *err, const re_match_context_t *mctx, int idx)
56
__attribute ((always_inline)) internal_function;
56
57
static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
58
static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
59
static int check_matching (re_match_context_t *mctx, int fl_longest_match,
61
static Idx check_halt_state_context (const re_match_context_t *mctx,
62
const re_dfastate_t *state, Idx idx)
62
static int check_halt_node_context (const re_dfa_t *dfa, int node,
63
unsigned int context) internal_function;
64
static int check_halt_state_context (const re_match_context_t *mctx,
65
const re_dfastate_t *state, int idx)
64
67
static void update_regs (re_dfa_t *dfa, regmatch_t *pmatch,
65
regmatch_t *prev_idx_match, Idx cur_node,
66
Idx cur_idx, Idx nmatch) internal_function;
68
regmatch_t *prev_idx_match, int cur_node,
69
int cur_idx, int nmatch) internal_function;
70
static int proceed_next_node (const re_match_context_t *mctx,
71
int nregs, regmatch_t *regs,
72
int *pidx, int node, re_node_set *eps_via_nodes,
73
struct re_fail_stack_t *fs) internal_function;
67
74
static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
68
Idx str_idx, Idx dest_node, Idx nregs,
75
int str_idx, int dest_node, int nregs,
70
77
re_node_set *eps_via_nodes) internal_function;
78
static int pop_fail_stack (struct re_fail_stack_t *fs, int *pidx, int nregs,
79
regmatch_t *regs, re_node_set *eps_via_nodes) internal_function;
71
80
static reg_errcode_t set_regs (const regex_t *preg,
72
81
const re_match_context_t *mctx,
73
82
size_t nmatch, regmatch_t *pmatch,
74
bool fl_backtrack) internal_function;
83
int fl_backtrack) internal_function;
75
84
static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function;
77
86
#ifdef RE_ENABLE_I18N
78
87
static int sift_states_iter_mb (const re_match_context_t *mctx,
79
88
re_sift_context_t *sctx,
80
Idx node_idx, Idx str_idx, Idx max_str_idx) internal_function;
89
int node_idx, int str_idx, int max_str_idx) internal_function;
81
90
#endif /* RE_ENABLE_I18N */
82
91
static reg_errcode_t sift_states_backward (re_match_context_t *mctx,
83
92
re_sift_context_t *sctx) internal_function;
84
93
static reg_errcode_t build_sifted_states (re_match_context_t *mctx,
85
re_sift_context_t *sctx, Idx str_idx,
94
re_sift_context_t *sctx, int str_idx,
86
95
re_node_set *cur_dest) internal_function;
87
96
static reg_errcode_t update_cur_sifted_state (re_match_context_t *mctx,
88
97
re_sift_context_t *sctx,
90
99
re_node_set *dest_nodes) internal_function;
91
100
static reg_errcode_t add_epsilon_src_nodes (re_dfa_t *dfa,
92
101
re_node_set *dest_nodes,
93
102
const re_node_set *candidates) internal_function;
94
static bool check_dst_limits (const re_match_context_t *mctx,
95
const re_node_set *limits,
96
Idx dst_node, Idx dst_idx, Idx src_node,
97
Idx src_idx) internal_function;
98
static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
99
int boundaries, Idx subexp_idx,
100
Idx from_node, Idx bkref_idx) internal_function;
101
static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
102
Idx limit, Idx subexp_idx,
103
Idx node, Idx str_idx,
104
Idx bkref_idx) internal_function;
103
static reg_errcode_t sub_epsilon_src_nodes (re_dfa_t *dfa, int node,
104
re_node_set *dest_nodes,
105
const re_node_set *and_nodes) internal_function;
106
static int check_dst_limits (re_match_context_t *mctx, re_node_set *limits,
107
int dst_node, int dst_idx, int src_node,
108
int src_idx) internal_function;
109
static int check_dst_limits_calc_pos_1 (re_match_context_t *mctx,
110
int boundaries, int subexp_idx,
111
int from_node, int bkref_idx) internal_function;
112
static int check_dst_limits_calc_pos (re_match_context_t *mctx,
113
int limit, int subexp_idx,
114
int node, int str_idx,
115
int bkref_idx) internal_function;
105
116
static reg_errcode_t check_subexp_limits (re_dfa_t *dfa,
106
117
re_node_set *dest_nodes,
107
118
const re_node_set *candidates,
108
119
re_node_set *limits,
109
120
struct re_backref_cache_entry *bkref_ents,
110
Idx str_idx) internal_function;
121
int str_idx) internal_function;
111
122
static reg_errcode_t sift_states_bkref (re_match_context_t *mctx,
112
123
re_sift_context_t *sctx,
113
Idx str_idx, const re_node_set *candidates) internal_function;
124
int str_idx, const re_node_set *candidates) internal_function;
125
static reg_errcode_t clean_state_log_if_needed (re_match_context_t *mctx,
126
int next_state_log_idx) internal_function;
114
127
static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst,
115
re_dfastate_t **src, Idx num) internal_function;
128
re_dfastate_t **src, int num) internal_function;
116
129
static re_dfastate_t *find_recover_state (reg_errcode_t *err,
117
130
re_match_context_t *mctx) internal_function;
118
131
static re_dfastate_t *transit_state (reg_errcode_t *err,
136
149
static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
137
150
const re_node_set *nodes) internal_function;
138
151
static reg_errcode_t get_subexp (re_match_context_t *mctx,
139
Idx bkref_node, Idx bkref_str_idx) internal_function;
152
int bkref_node, int bkref_str_idx) internal_function;
140
153
static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
141
154
const re_sub_match_top_t *sub_top,
142
155
re_sub_match_last_t *sub_last,
143
Idx bkref_node, Idx bkref_str) internal_function;
144
static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
145
Idx subexp_idx, int type) internal_function;
156
int bkref_node, int bkref_str) internal_function;
157
static int find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
158
int subexp_idx, int type) internal_function;
146
159
static reg_errcode_t check_arrival (re_match_context_t *mctx,
147
state_array_t *path, Idx top_node,
148
Idx top_str, Idx last_node, Idx last_str,
160
state_array_t *path, int top_node,
161
int top_str, int last_node, int last_str,
149
162
int type) internal_function;
150
163
static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
152
165
re_node_set *cur_nodes,
153
166
re_node_set *next_nodes) internal_function;
154
167
static reg_errcode_t check_arrival_expand_ecl (re_dfa_t *dfa,
155
168
re_node_set *cur_nodes,
156
Idx ex_subexp, int type) internal_function;
169
int ex_subexp, int type) internal_function;
157
170
static reg_errcode_t check_arrival_expand_ecl_sub (re_dfa_t *dfa,
158
171
re_node_set *dst_nodes,
159
Idx target, Idx ex_subexp,
172
int target, int ex_subexp,
160
173
int type) internal_function;
161
174
static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
162
re_node_set *cur_nodes, Idx cur_str,
163
Idx subexp_num, int type) internal_function;
164
static bool build_trtable (re_dfa_t *dfa,
165
re_dfastate_t *state) internal_function;
175
re_node_set *cur_nodes, int cur_str,
176
int subexp_num, int type) internal_function;
177
static int build_trtable (re_dfa_t *dfa,
178
re_dfastate_t *state) internal_function;
166
179
#ifdef RE_ENABLE_I18N
167
static int check_node_accept_bytes (re_dfa_t *dfa, Idx node_idx,
168
const re_string_t *input, Idx idx) internal_function;
180
static int check_node_accept_bytes (re_dfa_t *dfa, int node_idx,
181
const re_string_t *input, int idx) internal_function;
170
183
static unsigned int find_collation_sequence_value (const unsigned char *mbs,
171
184
size_t name_len) internal_function;
172
185
# endif /* _LIBC */
173
186
#endif /* RE_ENABLE_I18N */
174
static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
187
static int group_nodes_into_DFAstates (re_dfa_t *dfa,
175
188
const re_dfastate_t *state,
176
189
re_node_set *states_node,
177
190
bitset *states_ch) internal_function;
178
static bool check_node_accept (const re_match_context_t *mctx,
179
const re_token_t *node, Idx idx)
191
static int check_node_accept (const re_match_context_t *mctx,
192
const re_token_t *node, int idx) internal_function;
181
193
static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_function;
183
195
/* Entry point for POSIX code. */
280
294
return the position of the start of the match. Return value -1 means no
281
295
match was found and -2 indicates an internal error. */
284
re_match (struct re_pattern_buffer *bufp, const char *string,
285
Idx length, Idx start, struct re_registers *regs)
298
re_match (bufp, string, length, start, regs)
299
struct re_pattern_buffer *bufp;
302
struct re_registers *regs;
287
return re_search_stub (bufp, string, length, start, 0, length, regs, true);
304
return re_search_stub (bufp, string, length, start, 0, length, regs, 1);
290
307
weak_alias (__re_match, re_match)
294
re_search (struct re_pattern_buffer *bufp, const char *string,
295
Idx length, Idx start, regoff_t range, struct re_registers *regs)
311
re_search (bufp, string, length, start, range, regs)
312
struct re_pattern_buffer *bufp;
314
int length, start, range;
315
struct re_registers *regs;
297
return re_search_stub (bufp, string, length, start, range, length, regs,
317
return re_search_stub (bufp, string, length, start, range, length, regs, 0);
301
320
weak_alias (__re_search, re_search)
305
re_match_2 (struct re_pattern_buffer *bufp,
306
const char *string1, Idx length1,
307
const char *string2, Idx length2,
308
Idx start, struct re_registers *regs, Idx stop)
324
re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop)
325
struct re_pattern_buffer *bufp;
326
const char *string1, *string2;
327
int length1, length2, start, stop;
328
struct re_registers *regs;
310
330
return re_search_2_stub (bufp, string1, length1, string2, length2,
311
start, 0, regs, stop, true);
331
start, 0, regs, stop, 1);
314
334
weak_alias (__re_match_2, re_match_2)
318
re_search_2 (struct re_pattern_buffer *bufp,
319
const char *string1, Idx length1,
320
const char *string2, Idx length2,
321
Idx start, regoff_t range, struct re_registers *regs, Idx stop)
338
re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop)
339
struct re_pattern_buffer *bufp;
340
const char *string1, *string2;
341
int length1, length2, start, range, stop;
342
struct re_registers *regs;
323
344
return re_search_2_stub (bufp, string1, length1, string2, length2,
324
start, range, regs, stop, false);
345
start, range, regs, stop, 0);
327
348
weak_alias (__re_search_2, re_search_2)
332
re_search_2_stub (struct re_pattern_buffer *bufp,
333
const char *string1, Idx length1,
334
const char *string2, Idx length2,
335
Idx start, regoff_t range, struct re_registers *regs,
336
Idx stop, bool ret_len)
352
re_search_2_stub (bufp, string1, length1, string2, length2, start, range, regs,
354
struct re_pattern_buffer *bufp;
355
const char *string1, *string2;
356
int length1, length2, start, range, stop, ret_len;
357
struct re_registers *regs;
340
Idx len = length1 + length2;
361
int len = length1 + length2;
343
if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0))
364
if (BE (length1 < 0 || length2 < 0 || stop < 0, 0))
346
367
/* Concatenate the strings. */
350
s = re_malloc (char, len);
371
char *s = re_malloc (char, len);
352
373
if (BE (s == NULL, 0))
354
375
memcpy (s, string1, length1);
355
376
memcpy (s + length1, string2, length2);
363
385
rval = re_search_stub (bufp, str, len, start, range, stop, regs,
388
re_free ((char *) str);
369
392
/* The parameters have the same meaning as those of re_search.
370
393
Additional parameters:
371
If RET_LEN is true the length of the match is returned (re_match style);
394
If RET_LEN is nonzero the length of the match is returned (re_match style);
372
395
otherwise the position of the match is returned. */
376
re_search_stub (struct re_pattern_buffer *bufp,
377
const char *string, Idx length,
378
Idx start, regoff_t range, Idx stop, struct re_registers *regs,
398
re_search_stub (bufp, string, length, start, range, stop, regs, ret_len)
399
struct re_pattern_buffer *bufp;
401
int length, start, range, stop, ret_len;
402
struct re_registers *regs;
381
404
reg_errcode_t result;
382
405
regmatch_t *pmatch;
387
re_dfa_t *dfa = (re_dfa_t *) bufp->re_buffer;
389
Idx last_start = start + range;
408
re_dfa_t *dfa = (re_dfa_t *)bufp->buffer;
391
410
/* Check for out-of-range. */
392
411
if (BE (start < 0 || start > length, 0))
394
if (sizeof start < sizeof range)
396
regoff_t length_offset = length;
397
regoff_t start_offset = start;
398
if (BE (length_offset - start_offset < range, 0))
400
else if (BE (range < - start_offset, 0))
405
if (BE ((last_start < start) != (range < 0), 0))
407
/* Overflow occurred when computing last_start; substitute
408
the extreme value. */
409
last_start = range < 0 ? 0 : length;
413
if (BE (length < last_start, 0))
415
else if (BE (last_start < 0, 0))
413
if (BE (start + range > length, 0))
414
range = length - start;
415
else if (BE (start + range < 0, 0))
420
418
__libc_lock_lock (dfa->lock);
422
eflags |= (bufp->re_not_bol) ? REG_NOTBOL : 0;
423
eflags |= (bufp->re_not_eol) ? REG_NOTEOL : 0;
420
eflags |= (bufp->not_bol) ? REG_NOTBOL : 0;
421
eflags |= (bufp->not_eol) ? REG_NOTEOL : 0;
425
423
/* Compile fastmap if we haven't yet. */
426
if (start < last_start && bufp->re_fastmap != NULL
427
&& !bufp->re_fastmap_accurate)
424
if (range > 0 && bufp->fastmap != NULL && !bufp->fastmap_accurate)
428
425
re_compile_fastmap (bufp);
430
if (BE (bufp->re_no_sub, 0))
427
if (BE (bufp->no_sub, 0))
433
430
/* We need at least 1 register. */
434
431
if (regs == NULL)
436
else if (BE (bufp->re_regs_allocated == REG_FIXED
437
&& regs->rm_num_regs <= bufp->re_nsub, 0))
433
else if (BE (bufp->regs_allocated == REGS_FIXED &&
434
regs->num_regs < bufp->re_nsub + 1, 0))
439
nregs = regs->rm_num_regs;
436
nregs = regs->num_regs;
440
437
if (BE (nregs < 1, 0))
442
439
/* Nothing can be copied to regs. */
491
re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
487
re_copy_regs (regs, pmatch, nregs, regs_allocated)
488
struct re_registers *regs;
490
int nregs, regs_allocated;
494
int rval = REG_REALLOCATE;
496
Idx need_regs = nregs + 1;
497
/* We need one extra element beyond `rm_num_regs' for the `-1' marker GNU code
492
int rval = REGS_REALLOCATE;
494
int need_regs = nregs + 1;
495
/* We need one extra element beyond `num_regs' for the `-1' marker GNU code
500
498
/* Have the register data arrays been allocated? */
501
if (regs_allocated == REG_UNALLOCATED)
499
if (regs_allocated == REGS_UNALLOCATED)
502
500
{ /* No. So allocate them with malloc. */
503
regs->rm_start = re_xmalloc (regoff_t, need_regs);
504
regs->rm_end = re_malloc (regoff_t, need_regs);
505
if (BE (regs->rm_start == NULL, 0) || BE (regs->rm_end == NULL, 0))
506
return REG_UNALLOCATED;
507
regs->rm_num_regs = need_regs;
501
regs->start = re_malloc (regoff_t, need_regs);
502
regs->end = re_malloc (regoff_t, need_regs);
503
if (BE (regs->start == NULL, 0) || BE (regs->end == NULL, 0))
504
return REGS_UNALLOCATED;
505
regs->num_regs = need_regs;
509
else if (regs_allocated == REG_REALLOCATE)
507
else if (regs_allocated == REGS_REALLOCATE)
510
508
{ /* Yes. If we need more elements than were already
511
509
allocated, reallocate them. If we need fewer, just
512
510
leave it alone. */
513
if (BE (need_regs > regs->rm_num_regs, 0))
511
if (BE (need_regs > regs->num_regs, 0))
515
regoff_t *new_start =
516
re_xrealloc (regs->rm_start, regoff_t, need_regs);
517
regoff_t *new_end = re_realloc (regs->rm_end, regoff_t, need_regs);
513
regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
514
regoff_t *new_end = re_realloc (regs->end, regoff_t, need_regs);
518
515
if (BE (new_start == NULL, 0) || BE (new_end == NULL, 0))
519
return REG_UNALLOCATED;
520
regs->rm_start = new_start;
521
regs->rm_end = new_end;
522
regs->rm_num_regs = need_regs;
516
return REGS_UNALLOCATED;
517
regs->start = new_start;
519
regs->num_regs = need_regs;
527
assert (regs_allocated == REG_FIXED);
528
/* This function may not be called with REG_FIXED and nregs too big. */
529
assert (regs->rm_num_regs >= nregs);
524
assert (regs_allocated == REGS_FIXED);
525
/* This function may not be called with REGS_FIXED and nregs too big. */
526
assert (regs->num_regs >= nregs);
533
530
/* Copy the regs. */
534
531
for (i = 0; i < nregs; ++i)
536
regs->rm_start[i] = pmatch[i].rm_so;
537
regs->rm_end[i] = pmatch[i].rm_eo;
533
regs->start[i] = pmatch[i].rm_so;
534
regs->end[i] = pmatch[i].rm_eo;
539
for ( ; i < regs->rm_num_regs; ++i)
540
regs->rm_start[i] = regs->rm_end[i] = -1;
536
for ( ; i < regs->num_regs; ++i)
537
regs->start[i] = regs->end[i] = -1;
596
597
/* Searches for a compiled pattern PREG in the string STRING, whose
597
598
length is LENGTH. NMATCH, PMATCH, and EFLAGS have the same
598
meaning as with regexec. LAST_START is START + RANGE, where
599
START and RANGE have the same meaning as with re_search.
599
mingings with regexec. START, and RANGE have the same meanings
600
601
Return REG_NOERROR if we find a match, and REG_NOMATCH if not,
601
602
otherwise return the error code.
602
603
Note: We assume front end functions already check ranges.
603
(0 <= LAST_START && LAST_START <= LENGTH) */
604
(START + RANGE >= 0 && START + RANGE <= LENGTH) */
605
606
static reg_errcode_t
607
re_search_internal (const regex_t *preg,
608
const char *string, Idx length,
609
Idx start, Idx last_start, Idx stop,
610
size_t nmatch, regmatch_t pmatch[],
607
re_search_internal (preg, string, length, start, range, stop, nmatch, pmatch,
611
int length, start, range, stop, eflags;
613
615
reg_errcode_t err;
614
re_dfa_t *dfa = (re_dfa_t *) preg->re_buffer;
615
Idx left_lim, right_lim;
617
bool fl_longest_match;
619
Idx match_first, match_last = REG_MISSING;
616
re_dfa_t *dfa = (re_dfa_t *)preg->buffer;
617
int left_lim, right_lim, incr;
618
int fl_longest_match, match_first, match_kind, match_last = -1;
623
621
#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
624
622
re_match_context_t mctx = { .dfa = dfa };
626
624
re_match_context_t mctx;
628
char *fastmap = ((preg->re_fastmap != NULL && preg->re_fastmap_accurate
629
&& start != last_start && !preg->re_can_be_null)
630
? preg->re_fastmap : NULL);
631
unsigned REG_TRANSLATE_TYPE t =
632
(unsigned REG_TRANSLATE_TYPE) preg->re_translate;
626
char *fastmap = (preg->fastmap != NULL && preg->fastmap_accurate
627
&& range && !preg->can_be_null) ? preg->fastmap : NULL;
628
unsigned RE_TRANSLATE_TYPE t = (unsigned RE_TRANSLATE_TYPE) preg->translate;
634
630
#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
635
631
memset (&mctx, '\0', sizeof (re_match_context_t));
3285
3289
/* Build transition table for the state.
3286
Return true if successful. */
3290
Return 1 if succeeded, otherwise return NULL. */
3290
build_trtable (re_dfa_t *dfa, re_dfastate_t *state)
3293
build_trtable (dfa, state)
3295
re_dfastate_t *state;
3292
3297
reg_errcode_t err;
3295
bool need_word_trtable = false;
3296
bitset_word elem, mask;
3297
bool dests_node_malloced = false, dest_states_malloced = false;
3298
Idx ndests; /* Number of the destination states from `state'. */
3298
int i, j, ch, need_word_trtable = 0;
3299
unsigned int elem, mask;
3300
int dests_node_malloced = 0, dest_states_malloced = 0;
3301
int ndests; /* Number of the destination states from `state'. */
3299
3302
re_dfastate_t **trtable;
3300
3303
re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl;
3301
3304
re_node_set follows, *dests_node;
3302
3305
bitset *dests_ch;
3303
3306
bitset acceptable;
3307
re_node_set dests_node[SBC_MAX];
3308
bitset dests_ch[SBC_MAX];
3311
3308
/* We build DFA states which corresponds to the destination nodes
3312
3309
from `state'. `dests_node[i]' represents the nodes which i-th
3313
3310
destination state contains, and `dests_ch[i]' represents the
3314
3311
characters which i-th destination state accepts. */
3315
if (__libc_use_alloca (sizeof (struct dests_alloc)))
3316
dests_alloc = (struct dests_alloc *) alloca (sizeof dests_alloc[0]);
3313
if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX))
3314
dests_node = (re_node_set *)
3315
alloca ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX);
3319
dests_alloc = re_malloc (struct dests_alloc, 1);
3320
if (BE (dests_alloc == NULL, 0))
3322
dests_node_malloced = true;
3319
dests_node = (re_node_set *)
3320
malloc ((sizeof (re_node_set) + sizeof (bitset)) * SBC_MAX);
3321
if (BE (dests_node == NULL, 0))
3323
dests_node_malloced = 1;
3324
dests_node = dests_alloc->dests_node;
3325
dests_ch = dests_alloc->dests_ch;
3325
dests_ch = (bitset *) (dests_node + SBC_MAX);
3327
3327
/* Initialize transiton table. */
3328
3328
state->word_trtable = state->trtable = NULL;