|
|
@@ -315,7 +315,7 @@ static bool catch_(const regex_t * const regex, |
|
|
|
int * const state) { |
|
|
|
|
|
|
|
for (size_t i = 0; i < regex->catch_table.element_size; i++){ |
|
|
|
const offshoot_t * const offshoot = (vector_get(®ex->catch_table, i)); |
|
|
|
const offshoot_t * const offshoot = *(offshoot_t**)vector_get(®ex->catch_table, i); |
|
|
|
if (offshoot->in == *state) { |
|
|
|
*state = offshoot->to; |
|
|
|
return true; |
|
|
@@ -333,15 +333,22 @@ void HOOK_ALL(int from, |
|
|
|
|
|
|
|
int hook_to = (*cs->is_negative) ? HALT_AND_CATCH_FIRE : *cs->state + to; |
|
|
|
|
|
|
|
|
|
|
|
for (const char * s = str; *s != '\0'; s++) { |
|
|
|
delta_t * delta = malloc(sizeof(delta_t)); |
|
|
|
delta->in = *cs->state + from; |
|
|
|
delta->input = *s; |
|
|
|
delta->to = hook_to; |
|
|
|
delta->width = *cs->width; |
|
|
|
vector_push(&cs->regex->delta_table, |
|
|
|
&(delta_t){*cs->state + from, *s, hook_to, *cs->width} |
|
|
|
); |
|
|
|
&delta); |
|
|
|
} |
|
|
|
if (cs->do_catch || cs->is_negative) { |
|
|
|
offshoot_t * offshoot = malloc(sizeof(offshoot_t)); |
|
|
|
offshoot->in = *cs->state + from; |
|
|
|
offshoot->to = hook_to; |
|
|
|
vector_push(&cs->regex->catch_table, |
|
|
|
&(offshoot_t){*cs->state + from, hook_to} |
|
|
|
); |
|
|
|
&offshoot); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -352,8 +359,8 @@ void HOOK_ALL(int from, |
|
|
|
regex_t * regex_compile(const char * const pattern) { |
|
|
|
regex_t * regex = (regex_t *)malloc(sizeof(regex_t)); |
|
|
|
regex->str = strdup(pattern); |
|
|
|
vector_init(®ex->delta_table, sizeof(delta_t), 0); |
|
|
|
vector_init(®ex->catch_table, sizeof(offshoot_t), 0); |
|
|
|
vector_init(®ex->delta_table, sizeof(delta_t), 0UL); |
|
|
|
vector_init(®ex->catch_table, sizeof(offshoot_t), 0UL); |
|
|
|
|
|
|
|
int state = 0; |
|
|
|
|
|
|
@@ -454,7 +461,7 @@ static bool regex_assert(const regex_t * const regex, |
|
|
|
for (const char * s = string; *s != '\00'; s++) { |
|
|
|
// delta |
|
|
|
for (size_t i = 0; i < regex->delta_table.element_count; i++) { |
|
|
|
const delta_t * const delta = (delta_t *)(vector_get(®ex->delta_table, i)); |
|
|
|
const delta_t * const delta = *(delta_t**)vector_get(®ex->delta_table, i); |
|
|
|
if ((delta->in == state) |
|
|
|
&& (delta->input == *s)) { |
|
|
|
if(regex_assert(regex, s + delta->width, delta->to)){ |
|
|
|