token_t * new_symbol_token(const char * const c,
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));
mt->hl = g;
mt->t = KEYSYMBOL;
- mt->syntax = regex_compile(new_word);
+ mt->syntax = regex_compile(c);
append_token(mt);
int new_char_tokens(const char * characters,
hl_group_t * const g) {
- int i = 0;
- char buffer[2] = "";
+ int i = 0;
- buffer[1] = '\00';
+ char buffer[3];
+ buffer[0] = '\\';
+ buffer[2] = '\0';
for(const char * s = characters; *s != '\0'; s++) {
- buffer[0] = *s;
- if(new_symbol_token(buffer, g)) {
+ buffer[1] = *s;
+ if(new_symbol_token(is_magic(*s) ? buffer : buffer + 1, g)) {
++i;
}
}
token_t * new_keyword_token(const char * const word,
hl_group_t * const g) {
- char * new_word = strdup(word);
+ //char * new_word = strdup(word);
//size_t word_length = strlen(word);
//char * new_word = (char*)malloc(word_length + 4 + 1);
mt->hl = g;
mt->t = KEYWORD;
- mt->syntax = regex_compile(new_word);
+ //mt->syntax = regex_compile(new_word);
+ mt->syntax = regex_compile(word);
append_token(mt);
void render_string(const char * const string,
const char * const mode) {
for (const char * s = string; *s != '\00';) {
- int f;
- int token_index = 0;
+ int f = 0;
+ size_t token_index = 0;
int offset;
for (; token_index < token_table.element_count; token_index++) {
}
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));
}