]> git.xolatile.top Git - public-libhl.git/commitdiff
Vector type thingie for token table...
authorxolatile <xolatile@proton.me>
Thu, 24 Aug 2023 12:58:51 +0000 (08:58 -0400)
committerxolatile <xolatile@proton.me>
Thu, 24 Aug 2023 12:58:51 +0000 (08:58 -0400)
source/hl.h

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