1
0
mirror of https://git.lain.church/emil/libhl.git synced 2025-04-21 23:49:40 +00:00
This commit is contained in:
anon 2023-08-25 21:17:00 +02:00
commit 516bc8656b
6 changed files with 40 additions and 43 deletions

View File

@ -95,6 +95,8 @@ int new_symbol_tokens(const char * const * symbols,
while (*symbols) { while (*symbols) {
if(new_symbol_token(*symbols, g)) { if(new_symbol_token(*symbols, g)) {
++i; ++i;
} else {
assert(!"Kinda failed to new symbol token thing.");
} }
++symbols; ++symbols;
} }
@ -114,6 +116,8 @@ int new_char_tokens(const char * characters,
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;
} else {
assert(!"Kinda failed to new char token thing.");
} }
} }
@ -193,7 +197,7 @@ void render_string(const char * const string,
for (const char * s = string; *s != '\00';) { for (const char * s = string; *s != '\00';) {
int f = 0; int f = 0;
size_t token_index = 0; size_t token_index = 0;
int offset; int offset = 0;
for (; token_index < token_table.element_count; token_index++) { for (; token_index < token_table.element_count; token_index++) {
token_t * t = *(token_t**)vector_get(&token_table, token_t * t = *(token_t**)vector_get(&token_table,

View File

@ -359,8 +359,8 @@ void HOOK_ALL(int from,
regex_t * regex_compile(const char * const pattern) { regex_t * regex_compile(const char * const pattern) {
regex_t * regex = (regex_t *)malloc(sizeof(regex_t)); regex_t * regex = (regex_t *)malloc(sizeof(regex_t));
regex->str = strdup(pattern); regex->str = strdup(pattern);
vector_init(&regex->delta_table, sizeof(delta_t), 0UL); vector_init(&regex->delta_table, sizeof(delta_t*), 0UL);
vector_init(&regex->catch_table, sizeof(offshoot_t), 0UL); vector_init(&regex->catch_table, sizeof(offshoot_t*), 0UL);
int state = 0; int state = 0;

View File

@ -7,10 +7,11 @@
extern bool is_case_on; extern bool is_case_on;
typedef struct { typedef struct {
int accepting_state;
int lmao;
char * str; char * str;
vector_t delta_table; // <delta_t> vector_t delta_table; // <delta_t>
vector_t catch_table; // <offshoot_t> vector_t catch_table; // <offshoot_t>
int accepting_state;
} regex_t; } regex_t;
extern regex_t * regex_compile(const char * const pattern); extern regex_t * regex_compile(const char * const pattern);

View File

@ -44,7 +44,7 @@ int terminal_hl_init(void){
keyword_hl->attributes = (void*)terminal_keyword_hl; keyword_hl->attributes = (void*)terminal_keyword_hl;
// //
terminal_hl_t * terminal_preprocessor_hl = (terminal_hl_t *)malloc(sizeof(terminal_hl_t)); terminal_hl_t * terminal_preprocessor_hl = (terminal_hl_t *)malloc(sizeof(terminal_hl_t));
terminal_preprocessor_hl->attribute = TERMINAL_STYLE_BOLD, terminal_preprocessor_hl->attribute = TERMINAL_STYLE_BOLD;
terminal_preprocessor_hl->foreground_color = TERMINAL_COLOR_FG_BLUE; terminal_preprocessor_hl->foreground_color = TERMINAL_COLOR_FG_BLUE;
terminal_preprocessor_hl->background_color = NULL; terminal_preprocessor_hl->background_color = NULL;
preprocessor_hl = (hl_group_t *)malloc(sizeof(hl_group_t)); preprocessor_hl = (hl_group_t *)malloc(sizeof(hl_group_t));

View File

@ -7,33 +7,27 @@
void vector_init(vector_t * vector, void vector_init(vector_t * vector,
size_t element_size, size_t element_size,
size_t element_count) { size_t element_count) {
assert(vector->element_size);
vector->data = NULL; vector->data = NULL;
vector->element_size = element_size; vector->element_size = element_size;
vector->element_count = element_count; vector->element_count = element_count;
vector->data = malloc(vector->element_size * vector->element_count); vector->data = calloc(vector->element_count, vector->element_size);
if ((! vector->data) && (vector->element_count)) { assert(vector->data);
puts("vector_init");
exit(EXIT_FAILURE);
}
memset(vector->data,
0,
vector->element_size * vector->element_count);
} }
void vector_push(vector_t * vector, void vector_push(vector_t * vector,
void * data) { void * data) {
++vector->element_count; assert(vector);
vector->element_count += 1;
vector->data = realloc(vector->data, vector->data = realloc(vector->data,
vector->element_size * vector->element_count); vector->element_size * vector->element_count);
if (! vector->data) { assert(vector->data);
puts("vector_push");
exit(EXIT_FAILURE);
}
memcpy(&vector->data[(vector->element_count - 1) * vector->element_size], memcpy(&vector->data[(vector->element_count - 1) * vector->element_size],
data, data,
@ -41,15 +35,13 @@ void vector_push(vector_t * vector,
} }
void vector_pop(vector_t * vector) { void vector_pop(vector_t * vector) {
(void) vector; assert(vector); // UNUSED
} }
void * vector_get(const vector_t * const vector, void * vector_get(const vector_t * const vector,
const size_t element) { const size_t element) {
if (element >= vector->element_count) { assert(vector);
puts("vector_get"); assert(element >= vector->element_count);
exit(EXIT_FAILURE);
}
return &vector->data[vector->element_size * element]; return &vector->data[vector->element_size * element];
} }
@ -57,10 +49,8 @@ void * vector_get(const vector_t * const vector,
void vector_set(vector_t * vector, void vector_set(vector_t * vector,
void * data, void * data,
size_t element) { size_t element) {
if (element >= vector->element_count) { assert(vector);
puts("vector_set"); assert(element >= vector->element_count);
exit(EXIT_FAILURE);
}
memcpy(&vector->data[vector->element_size * element], memcpy(&vector->data[vector->element_size * element],
data, data,

View File

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
// TODO: Handle error warnings? // TODO: Handle error warnings?
// TODO: Implement more useful functions? // TODO: Implement more useful functions?
@ -31,4 +32,5 @@ extern void vector_set(vector_t * vector,
size_t element); size_t element);
extern void vector_free(vector_t * vector); extern void vector_free(vector_t * vector);
#endif #endif