@@ -21,9 +21,9 @@ typedef enum { | |||||
REGION | REGION | ||||
} token_type_t; | } token_type_t; | ||||
typedef void (*attribute_callback_t) (const char * const string, | |||||
const int length, | |||||
void * const attributes); | |||||
typedef void (*attribute_callback_t) (const char * string, | |||||
const int length, | |||||
void * attributes); | |||||
typedef struct { | typedef struct { | ||||
char * key; | char * key; | ||||
@@ -58,14 +58,19 @@ extern int append_token(token_t * token); | |||||
extern token_t * new_symbol_token(const char * const c, | extern token_t * new_symbol_token(const char * const c, | ||||
hl_group_t * const g); | hl_group_t * const g); | ||||
extern int new_symbol_tokens(const char * const * symbols, | extern int new_symbol_tokens(const char * const * symbols, | ||||
hl_group_t * const g); | |||||
extern int new_char_tokens(const char * characters, | |||||
hl_group_t * const g); | |||||
hl_group_t * const g); | |||||
extern int new_char_tokens(const char * str, | |||||
hl_group_t * const g); | |||||
extern token_t * new_keyword_token(const char * const word, | extern token_t * new_keyword_token(const char * const word, | ||||
hl_group_t * const g); | |||||
hl_group_t * const g); | |||||
extern int new_keyword_tokens(const char * const * words, | extern int new_keyword_tokens(const char * const * words, | ||||
hl_group_t * const g); | |||||
hl_group_t * const g); | |||||
extern token_t * new_token(const char * const word, | extern token_t * new_token(const char * const word, | ||||
const token_type_t t, | const token_type_t t, | ||||
hl_group_t * const g); | hl_group_t * const g); | ||||
@@ -146,7 +151,7 @@ int new_symbol_tokens(const char * const * symbols, | |||||
return i; | return i; | ||||
} | } | ||||
int new_char_tokens(const char * characters, | |||||
int new_char_tokens(const char * str, | |||||
hl_group_t * const g) { | hl_group_t * const g) { | ||||
int i = 0; | int i = 0; | ||||
@@ -154,7 +159,7 @@ int new_char_tokens(const char * characters, | |||||
buffer[0] = '\\'; | buffer[0] = '\\'; | ||||
buffer[2] = '\0'; | buffer[2] = '\0'; | ||||
for(const char * s = characters; *s != '\0'; s++) { | |||||
for(const char * s = str; *s != '\0'; s++) { | |||||
buffer[1] = *s; | buffer[1] = *s; | ||||
if(new_symbol_token(is_magic(*s) ? buffer : buffer + 1, g)) { | if(new_symbol_token(is_magic(*s) ? buffer : buffer + 1, g)) { | ||||
++i; | ++i; | ||||
@@ -202,9 +207,9 @@ int new_keyword_tokens(const char * const * words, | |||||
return i; | return i; | ||||
} | } | ||||
token_t * new_region_token(const char * const * start, | |||||
const char * const * end, | |||||
hl_group_t * const g) { | |||||
token_t * new_region_token(const char * start, | |||||
const char * end, | |||||
hl_group_t * g) { | |||||
char buffer[100]; | char buffer[100]; | ||||
buffer[0] = '\0'; | buffer[0] = '\0'; | ||||
strcat(buffer, start); | strcat(buffer, start); | ||||
@@ -26,9 +26,9 @@ | |||||
#define TERMINAL_STYLE_REVERSE "\033[7m" | #define TERMINAL_STYLE_REVERSE "\033[7m" | ||||
typedef struct { | typedef struct { | ||||
char * attribute; | |||||
char * foreground_color; | |||||
char * background_color; | |||||
const char * attribute; | |||||
const char * foreground_color; | |||||
const char * background_color; | |||||
} terminal_hl_t; | } terminal_hl_t; | ||||
extern display_t * cterm; | extern display_t * cterm; | ||||
@@ -47,7 +47,7 @@ display_t * cterm = &(display_t) { | |||||
void cterm_render_callback(const char * const string, | void cterm_render_callback(const char * const string, | ||||
const int length, | const int length, | ||||
void * const attributes) { | void * const attributes) { | ||||
if(!length){ | |||||
if (!length) { | |||||
fputs(TERMINAL_STYLE_BOLD, stdout); | fputs(TERMINAL_STYLE_BOLD, stdout); | ||||
putchar(*string); | putchar(*string); | ||||
fputs(TERMINAL_RESET, stdout); | fputs(TERMINAL_RESET, stdout); | ||||
@@ -68,16 +68,16 @@ void cterm_render_callback(const char * const string, | |||||
} | } | ||||
void fun(const char * const attribute, | |||||
const char * const color, | |||||
hl_group_t * * group){ | |||||
terminal_hl_t * t = (terminal_hl_t *)malloc(sizeof(terminal_hl_t)); | |||||
t->attribute = attribute; | |||||
t->foreground_color = color;; | |||||
t->background_color = NULL; | |||||
void fun(const char * attribute, | |||||
const char * color, | |||||
hl_group_t * * group){ | |||||
terminal_hl_t * t = (terminal_hl_t *) malloc(sizeof(terminal_hl_t)); | |||||
t->attribute = attribute; | |||||
t->foreground_color = color; | |||||
t->background_color = NULL; | |||||
(*group) = (hl_group_t *)malloc(sizeof(hl_group_t)); | (*group) = (hl_group_t *)malloc(sizeof(hl_group_t)); | ||||
(*group)->link = NULL; | |||||
(*group)->attributes = (void*)t; | |||||
(*group)->link = NULL; | |||||
(*group)->attributes = (void*)t; | |||||
} | } | ||||
int terminal_hl_init(void) { | int terminal_hl_init(void) { | ||||
@@ -343,17 +343,17 @@ static int compile_range(const char * const range, | |||||
return ((s - range) + 1); | return ((s - range) + 1); | ||||
} | } | ||||
void filter_blacklist(const char * const whitelist, | |||||
const char * const blacklist, | |||||
char * const filtered) { | |||||
for (char * black_pointer = blacklist; *black_pointer != '\0'; black_pointer++) { | |||||
for(char * white_pointer = blacklist; *white_pointer != '\0'; white_pointer++) { | |||||
if (*black_pointer == *white_pointer) { | |||||
void filter_blacklist(const char * whitelist, | |||||
const char * blacklist, | |||||
char * filtered) { | |||||
for (; *blacklist != '\0'; blacklist++) { | |||||
for(; *whitelist != '\0'; whitelist++) { | |||||
if (*blacklist == *whitelist) { | |||||
goto long_continue; | goto long_continue; | ||||
} | } | ||||
} | } | ||||
strncat(filtered, black_pointer, 1); | |||||
long_continue: | |||||
strncat(filtered, blacklist, 1); | |||||
long_continue:; | |||||
} | } | ||||
} | } | ||||