]> git.xolatile.top Git - public-libhl.git/commitdiff
code ordering
authoranon <anon@anon.anon>
Mon, 21 Aug 2023 14:13:24 +0000 (16:13 +0200)
committeranon <anon@anon.anon>
Mon, 21 Aug 2023 14:13:24 +0000 (16:13 +0200)
chad.mk
source/hl.h
source/main.c

diff --git a/chad.mk b/chad.mk
index 0b3067385dc2e2733a981dd30a722a0cb12fda3d..e5ebf78a7861006c1327cea5624da03f2d0b71a9 100644 (file)
--- a/chad.mk
+++ b/chad.mk
@@ -8,6 +8,7 @@ CHAD_DEBUG:=-Og -ggdb -pg -fno-inline
 
 # Programs to check warnings for as defined by the Chad standard
 GCC:=gcc
+D.versions:=-D_XOPEN_SOURCE=700
 GCC.warnings:=-Wall -Wextra -Wpedantic -Wvla -Wshadow -Wundef 
 CLANG:=clang
 CLANG.warnings:=-Weverything
@@ -15,8 +16,8 @@ VALGRIND:=valgrind
 VALGRIND.flags:=--track-origins=yes --leak-check=full --show-leak-kinds=all
 
 chad_test:
-       ${GCC} ${GCC.warnings} ${SRC} -o ${OUT}
-       ${CLANG} ${GCC.warnings} ${SRC} -o ${OUT}
+       ${GCC} ${D.versions} ${GCC.warnings} ${SRC} -o ${OUT}
+       ${CLANG} ${D.versions} ${GCC.warnings} ${SRC} -o ${OUT}
        ${VALGRIND} ${VALGRIND.flags} ${OUT} ${OUTARGS}
 
 .DEFAULT_GOAL:=main
index a831a477dbe46d8c7d0f4d67976c230f9e9efe80..985b84966e60ab5f8dcbade24d9d7c35b5a10053 100644 (file)
@@ -5,6 +5,9 @@
 #include "chad.h"
 #include "regex.h"
 
+// -------------------
+// ### Definitions ###
+// -------------------
 typedef void (*attribute_callback_t)(const char * const string,
                                      const int          length,
                                            void * const attributes);
@@ -40,6 +43,24 @@ typedef struct {
 token_t * token_table[1000];
 int token_table_top = 0;
 
+
+
+// --------------------------------
+// ### Constructors/Destructors ###
+// --------------------------------
+
+void new_display_mode(display_t * mode) {
+       HASH_ADD_STR(display_table,
+                    key,
+                    mode);
+}
+
+int free_token(token_t * token){
+       free(token->hl);
+       free(token->syntax);
+       return 0;
+}
+
 int append_token(token_t * token){
        token_table[token_table_top++] = token;
        return 0;
@@ -104,6 +125,19 @@ token_t * new_keyword_token(const char         * const word,
        return mt;
 }
 
+int new_keyword_tokens(const char       * const *       words,
+                             hl_group_t * const             g) {
+       int i = 0;
+       while (*words) {
+               if(new_keyword_token(*words, g)){
+                       ++i;
+               }
+               ++words;
+       }
+
+       return i;
+}
+
 token_t * new_token(const char         * const word,
                     const token_type_t            t,
                           hl_group_t   * const    g) {
@@ -120,20 +154,14 @@ token_t * new_token(const char         * const word,
                } break;
        }
        // XXX: implement the rest
+       return NULL;
 }
 
-int new_keyword_tokens(const char       * const *       words,
-                             hl_group_t * const             g) {
-       int i = 0;
-       while (*words) {
-               if(new_keyword_token(*words, g)){
-                       ++i;
-               }
-               ++words;
-       }
 
-       return i;
-}
+
+// --------------------
+// ### Highlighting ###
+// --------------------
 
 int token_fits(const token_t* const token,
                const char*    const    to) {
@@ -176,8 +204,18 @@ void render_string(const char * const string,
        }
 }
 
-void new_display_mode(display_t * mode) {
-       HASH_ADD_STR(display_table,
-                    key,
-                    mode);
+
+
+// -------------------------
+// ### Library Mangement ###
+// -------------------------
+int hl_init(void) {
+       return 0;
+}
+
+int hl_deinit(void) {
+       for(int i = 0; i < token_table_top; i++){
+               free_token(token_table[i]);
+       }
+       return 0;
 }
index a43c8cf7e1d73e8371387d1def35a7f3b36c7b69..54f6348fa6bf804e6c9863c33b2ffb6ac408de3b 100644 (file)
@@ -59,6 +59,7 @@ int main(int      argc,
        buffer[buffer_size - 1] = '\0';
 
        // Highlight init
+       hl_init();
        const char * c_keywords[] = {
          "register",     "volatile",     "auto",         "const",        "static",       "extern",       "if",           "else",
          "do",           "while",        "for",          "continue",     "switch",       "case",         "default",      "break",
@@ -73,6 +74,7 @@ int main(int      argc,
          NULL
        };
 
+
        //
        display_t * cterm = &(display_t) {
                .key = "cterm",
@@ -116,6 +118,7 @@ int main(int      argc,
        //
        render_string(buffer, "cterm");
        putchar('\n');
+       hl_deinit();
        free(buffer);
 
        return 0;