so. close.

This commit is contained in:
anon 2023-09-21 09:06:40 +02:00
parent 7983caee10
commit 3649153542

View File

@ -97,20 +97,18 @@ int new_char_tokens(const char * str,
token_t * new_keyword_token(const char * const word,
hl_group_t * const g) {
//char * new_word = strdup(word);
//size_t word_length = strlen(word);
//char * new_word = (char*)malloc(word_length + 4 + 1);
size_t word_length = strlen(word);
char * new_word = (char*)malloc(word_length + 4 + 1);
//memcpy(new_word, "\\<", 2);
//memcpy(new_word + 2, word, word_length);
//strcpy(new_word + 2 + word_length, "\\>");
memcpy(new_word, "\\<", 2);
memcpy(new_word + 2, word, word_length);
strcpy(new_word + 2 + word_length, "\\>");
token_t * mt = (token_t*)malloc(sizeof(token_t));
mt->hl = g;
mt->t = KEYWORD;
//mt->syntax = regex_compile(new_word);
mt->syntax = regex_compile(word);
mt->syntax = regex_compile(new_word);
append_token(mt);
@ -178,29 +176,6 @@ token_t * new_token(const char * const word,
// --------------------
// ### Highlighting ###
// --------------------
int token_fits(const token_t * const token,
const char * const to,
const int string_offset,
const bool is_start_of_line,
int * match_offset) {
return 0;
UNUSED(match_offset);
match_t * matches = regex_match(token->syntax, to, is_start_of_line);
if (matches->position == -1) {
return 0;
}
const int r = matches->width;
match_offset = matches->position;
free(matches);
return r;
}
void render_string(const char * const string,
const char * const mode) {
display_t * display;
@ -220,9 +195,6 @@ void render_string(const char * const string,
token_t * t = *(token_t**)vector_get(&token_table,
i);
match_t * match = regex_match(t->syntax, string, true);
for(match_t * m = match; m->position != -1; m++){
printf("%s: %d %d\n", t->syntax->str, m->position, m->width);
}
if (match->position == -1) {
free(match);
continue;