fixed initialization bugs
This commit is contained in:
parent
b1c912689f
commit
570f15f635
31
source/hl.h
31
source/hl.h
@ -76,21 +76,12 @@ int append_token(token_t * token) {
|
|||||||
|
|
||||||
token_t * new_symbol_token(const char * const c,
|
token_t * new_symbol_token(const char * const c,
|
||||||
hl_group_t * const g) {
|
hl_group_t * const g) {
|
||||||
char * new_word;
|
|
||||||
if (is_magic(*c)) {
|
|
||||||
new_word = (char *)malloc(sizeof(char)*3);
|
|
||||||
new_word[0] = '\\';
|
|
||||||
new_word[1] = *c;
|
|
||||||
new_word[2] = '\00';
|
|
||||||
} else {
|
|
||||||
new_word = strdup(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
token_t * mt = (token_t*)malloc(sizeof(token_t));
|
token_t * mt = (token_t*)malloc(sizeof(token_t));
|
||||||
|
|
||||||
mt->hl = g;
|
mt->hl = g;
|
||||||
mt->t = KEYSYMBOL;
|
mt->t = KEYSYMBOL;
|
||||||
mt->syntax = regex_compile(new_word);
|
mt->syntax = regex_compile(c);
|
||||||
|
|
||||||
append_token(mt);
|
append_token(mt);
|
||||||
|
|
||||||
@ -114,13 +105,14 @@ int new_symbol_tokens(const char * const * symbols,
|
|||||||
int new_char_tokens(const char * characters,
|
int new_char_tokens(const char * characters,
|
||||||
hl_group_t * const g) {
|
hl_group_t * const g) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char buffer[2] = "";
|
|
||||||
|
|
||||||
buffer[1] = '\00';
|
char buffer[3];
|
||||||
|
buffer[0] = '\\';
|
||||||
|
buffer[2] = '\0';
|
||||||
|
|
||||||
for(const char * s = characters; *s != '\0'; s++) {
|
for(const char * s = characters; *s != '\0'; s++) {
|
||||||
buffer[0] = *s;
|
buffer[1] = *s;
|
||||||
if(new_symbol_token(buffer, g)) {
|
if(new_symbol_token(is_magic(*s) ? buffer : buffer + 1, g)) {
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +122,7 @@ int new_char_tokens(const char * characters,
|
|||||||
|
|
||||||
token_t * new_keyword_token(const char * const word,
|
token_t * new_keyword_token(const char * const word,
|
||||||
hl_group_t * const g) {
|
hl_group_t * const g) {
|
||||||
char * new_word = strdup(word);
|
//char * new_word = strdup(word);
|
||||||
//size_t word_length = strlen(word);
|
//size_t word_length = strlen(word);
|
||||||
//char * new_word = (char*)malloc(word_length + 4 + 1);
|
//char * new_word = (char*)malloc(word_length + 4 + 1);
|
||||||
|
|
||||||
@ -142,7 +134,8 @@ token_t * new_keyword_token(const char * const word,
|
|||||||
|
|
||||||
mt->hl = g;
|
mt->hl = g;
|
||||||
mt->t = KEYWORD;
|
mt->t = KEYWORD;
|
||||||
mt->syntax = regex_compile(new_word);
|
//mt->syntax = regex_compile(new_word);
|
||||||
|
mt->syntax = regex_compile(word);
|
||||||
|
|
||||||
append_token(mt);
|
append_token(mt);
|
||||||
|
|
||||||
@ -198,8 +191,8 @@ int token_fits(const token_t * const token,
|
|||||||
void render_string(const char * const string,
|
void render_string(const char * const string,
|
||||||
const char * const mode) {
|
const char * const mode) {
|
||||||
for (const char * s = string; *s != '\00';) {
|
for (const char * s = string; *s != '\00';) {
|
||||||
int f;
|
int f = 0;
|
||||||
int token_index = 0;
|
size_t token_index = 0;
|
||||||
int offset;
|
int offset;
|
||||||
|
|
||||||
for (; token_index < token_table.element_count; token_index++) {
|
for (; token_index < token_table.element_count; token_index++) {
|
||||||
@ -254,7 +247,7 @@ int hl_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int hl_deinit(void) {
|
int hl_deinit(void) {
|
||||||
for (int i = 0; i < token_table.element_count; i++) {
|
for (size_t i = 0; i < token_table.element_count; i++) {
|
||||||
free_token(vector_get(&token_table, i));
|
free_token(vector_get(&token_table, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user