Compare commits

...

3 Commits

View File

@ -43,8 +43,11 @@ typedef struct {
// GLOBALS // GLOBALS
token_t * token_table[1000]; vector_t token_table = {
int token_table_top = 0; .data = NULL,
.element_size = sizeof(token_t *),
.element_count = 0UL
};
display_t * display_table = NULL; display_t * display_table = NULL;
@ -66,7 +69,7 @@ int free_token(token_t * token) {
} }
int append_token(token_t * token) { int append_token(token_t * token) {
token_table[token_table_top++] = token; vector_push(&token_table, token);
return 0; return 0;
} }
@ -198,8 +201,10 @@ void render_string(const char * const string,
int token_index = 0; int token_index = 0;
int offset; int offset;
for (; token_index < token_table_top; token_index++) { for (; token_index < token_table.element_count; token_index++) {
f = token_fits(token_table[token_index], string, s - string, &offset); token_t * t = vector_get(&token_table,
token_index);
f = token_fits(t, string, s - string, &offset);
if (f) { if (f) {
break; break;
} }
@ -212,13 +217,17 @@ void render_string(const char * const string,
// //
if (f) { if (f) {
for (int i = 0; i < offset; i++) { for (int i = 0; i < offset; i++) {
token_t * t = vector_get(&token_table,
token_index);
display->callback(s + i, display->callback(s + i,
0, 0,
token_table[token_index]->hl->attributes); t->hl->attributes);
} }
token_t * t = vector_get(&token_table,
token_index);
display->callback(s + offset, display->callback(s + offset,
f, f,
token_table[token_index]->hl->attributes); t->hl->attributes);
s += f + offset; s += f + offset;
} else { } else {
display->callback(s, display->callback(s,
@ -241,8 +250,8 @@ int hl_init(void) {
} }
int hl_deinit(void) { int hl_deinit(void) {
for (int i = 0; i < token_table_top; i++) { for (int i = 0; i < token_table.element_count; i++) {
free_token(token_table[i]); free_token(vector_get(&token_table, i));
} }
return 0; return 0;