it no longer segfaults
This commit is contained in:
parent
1ed8286ab5
commit
2ab535a8d8
19
source/hl.h
19
source/hl.h
@ -69,7 +69,7 @@ int free_token(token_t * token) {
|
||||
}
|
||||
|
||||
int append_token(token_t * token) {
|
||||
vector_push(&token_table, token);
|
||||
vector_push(&token_table, &token);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -196,8 +196,8 @@ void render_string(const char * const string,
|
||||
int offset;
|
||||
|
||||
for (; token_index < token_table.element_count; token_index++) {
|
||||
token_t * t = vector_get(&token_table,
|
||||
token_index);
|
||||
token_t * t = *(token_t**)vector_get(&token_table,
|
||||
token_index);
|
||||
f = token_fits(t, string, s - string, &offset);
|
||||
if (f) {
|
||||
break;
|
||||
@ -211,14 +211,14 @@ void render_string(const char * const string,
|
||||
//
|
||||
if (f) {
|
||||
for (int i = 0; i < offset; i++) {
|
||||
token_t * t = vector_get(&token_table,
|
||||
token_index);
|
||||
token_t * t = *(token_t**)vector_get(&token_table,
|
||||
token_index);
|
||||
display->callback(s + i,
|
||||
0,
|
||||
t->hl->attributes);
|
||||
}
|
||||
token_t * t = vector_get(&token_table,
|
||||
token_index);
|
||||
token_t * t = *(token_t**)vector_get(&token_table,
|
||||
token_index);
|
||||
display->callback(s + offset,
|
||||
f,
|
||||
t->hl->attributes);
|
||||
@ -240,15 +240,12 @@ hl_group_t * preprocessor_hl = NULL;
|
||||
hl_group_t * symbol_hl = NULL;
|
||||
|
||||
int hl_init(void) {
|
||||
vector_init(&token_table,
|
||||
token_table.element_size,
|
||||
token_table.element_count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hl_deinit(void) {
|
||||
for (size_t i = 0; i < token_table.element_count; i++) {
|
||||
free_token(vector_get(&token_table, i));
|
||||
free_token(*(token_t**)vector_get(&token_table, i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -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)){
|
||||
|
Loading…
Reference in New Issue
Block a user