]> git.xolatile.top Git - public-libhl.git/commitdiff
renamed token structs, hid uxhash into hl.h
authoranon <anon@anon.anon>
Sat, 19 Aug 2023 18:47:42 +0000 (20:47 +0200)
committeranon <anon@anon.anon>
Sat, 19 Aug 2023 18:47:42 +0000 (20:47 +0200)
source/hl.h
source/main.c

index a8e168ba988170657c89541081556a730e387d2d..693ee73312564338eca3912923d1d6ee4ffb609d 100644 (file)
@@ -21,26 +21,28 @@ typedef struct {
 } hl_group_t;
 
 typedef enum {
+       KEYSYMBOL,
        KEYWORD,
        MATCH,
        REGION
-} token_t;
+} token_type_t;
 
 typedef struct {
        hl_group_t * hl;
-       token_t t;
+       token_type_t t;
        char* syntax;
-} token;       // XXX: this will have to be renamed
+} token_t;
 
 /* Temp solution
+ *  this should be dynamic
  */
-token * token_table[1000];
+token_t * token_table[1000];
 int token_table_top = 0;
 
-token * new_token(const char       * const syntax,
-                  const token_t                 t,
+token_t * new_token(const char       * const syntax,
+                  const token_type_t            t,
                   const hl_group_t * const      g) {
-       token * mt = (token*)malloc(sizeof(token));
+       token_t * mt = (token_t*)malloc(sizeof(token_t));
        mt->hl = g;
        mt->t = t;
        mt->syntax = syntax;
@@ -50,10 +52,15 @@ token * new_token(const char       * const syntax,
 
 void new_keyword_tokens(const char       * const *       words,
                               hl_group_t * const             g) {
+       int i = 0;
        while (*words) {
-               new_token(*words, KEYWORD, g);
-               words = words + 1;
+               if(new_token(*words, KEYWORD, g)){
+                       ++i;
+               }
+               ++words;
        }
+
+       return i;
 }
 
 int token_fits(const char* const pattern,
@@ -89,18 +96,30 @@ void render_string(const char * const string,
                int i = 0;
                for (; i < token_table_top; i++) {
                        f = token_fits(token_table[i]->syntax, s);
-                       if(f){ break; };
+                       if(f){ break; }
                }
                //
                display_t * display;
-               HASH_FIND_STR(display_table, mode, display);
+               HASH_FIND_STR(display_table,
+                             mode,
+                             display);
                //
                if (f) {
-                       display->callback(s, f, token_table[i]->hl->attributes);
+                       display->callback(s,
+                                         f,
+                                         token_table[i]->hl->attributes);
                        s += f;
                } else {
-                       display->callback(s, 0, NULL);
+                       display->callback(s,
+                                         0,
+                                         NULL);
                        ++s;
                }
        }
 }
+
+void new_display_mode(display_t * mode) {
+       HASH_ADD_STR(display_table,
+                    key,
+                    mode);
+}
index f32673040c76d20b4226e705142b8fa414ef338a..f924641f7232250d966df0f2c50d6b697f8eb1a1 100644 (file)
@@ -79,10 +79,7 @@ int main(int      argc,
        hl_group_t mygroup = (hl_group_t) {
                .link = NULL
        };
-
-       HASH_ADD_STR(display_table,
-                       key,
-                       cterm);
+       new_display_mode(cterm);
        new_keyword_tokens(c_keywords, &mygroup);
        new_keyword_tokens(preprocessor_keywords, &mygroup);