diff --git a/chad.mk b/chad.mk index 0b30673..e5ebf78 100644 --- 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 diff --git a/source/hl.h b/source/hl.h index a831a47..985b849 100644 --- a/source/hl.h +++ b/source/hl.h @@ -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; } diff --git a/source/main.c b/source/main.c index a43c8cf..54f6348 100644 --- a/source/main.c +++ b/source/main.c @@ -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;