# 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
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
#include "chad.h"
#include "regex.h"
+// -------------------
+// ### Definitions ###
+// -------------------
typedef void (*attribute_callback_t)(const char * const string,
const int length,
void * const attributes);
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;
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) {
} 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) {
}
}
-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;
}
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",
NULL
};
+
//
display_t * cterm = &(display_t) {
.key = "cterm",
//
render_string(buffer, "cterm");
putchar('\n');
+ hl_deinit();
free(buffer);
return 0;