it compiles
This commit is contained in:
parent
e41ff28910
commit
ed22849143
@ -3,7 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "hl.h"
|
#include "terminal_hl.h"
|
||||||
|
|
||||||
#define ALLOCATION_CHUNK (10UL)
|
#define ALLOCATION_CHUNK (10UL)
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ int main(int argc,
|
|||||||
// Highlight init
|
// Highlight init
|
||||||
terminal_hl_init();
|
terminal_hl_init();
|
||||||
//
|
//
|
||||||
#include "hl_c.inc";
|
#include "hl_c.inc"
|
||||||
//
|
//
|
||||||
render_string(buffer, "cterm");
|
render_string(buffer, "cterm");
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
@ -19,12 +19,12 @@ typedef struct {
|
|||||||
#define HOOK_ALL(from, str, to) do { \
|
#define HOOK_ALL(from, str, to) do { \
|
||||||
for (char * s = str; *s != '\00'; s++) { \
|
for (char * s = str; *s != '\00'; s++) { \
|
||||||
vector_push(®ex->delta_table, \
|
vector_push(®ex->delta_table, \
|
||||||
(delta_t *){state + from, *s, state + to} \
|
&(delta_t){state + from, *s, state + to} \
|
||||||
); \
|
); \
|
||||||
} \
|
} \
|
||||||
if (do_catch) { \
|
if (do_catch) { \
|
||||||
vector_push(®ex->catch_table, \
|
vector_push(®ex->catch_table, \
|
||||||
(offshoot_t *){state + from, state + to} \
|
&(offshoot_t){state + from, state + to} \
|
||||||
); \
|
); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include "hl.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char * attribute;
|
char * attribute;
|
||||||
char * foreground_color;
|
char * foreground_color;
|
||||||
@ -38,7 +40,7 @@ int terminal_hl_init(void){
|
|||||||
.foreground_color = TERMINAL_COLOR_FG_GREEN,
|
.foreground_color = TERMINAL_COLOR_FG_GREEN,
|
||||||
.background_color = NULL
|
.background_color = NULL
|
||||||
};
|
};
|
||||||
keyword_hl = (hl_group_t) {
|
keyword_hl = &(hl_group_t) {
|
||||||
.link = NULL,
|
.link = NULL,
|
||||||
.attributes = (void*)&terminal_keyword_hl
|
.attributes = (void*)&terminal_keyword_hl
|
||||||
};
|
};
|
||||||
@ -48,7 +50,7 @@ int terminal_hl_init(void){
|
|||||||
.foreground_color = TERMINAL_COLOR_FG_BLUE,
|
.foreground_color = TERMINAL_COLOR_FG_BLUE,
|
||||||
.background_color = NULL
|
.background_color = NULL
|
||||||
};
|
};
|
||||||
preprocessor_hl = (hl_group_t) {
|
preprocessor_hl = &(hl_group_t) {
|
||||||
.link = NULL,
|
.link = NULL,
|
||||||
.attributes = (void*)&terminal_preprocessor_hl
|
.attributes = (void*)&terminal_preprocessor_hl
|
||||||
};
|
};
|
||||||
@ -58,7 +60,7 @@ int terminal_hl_init(void){
|
|||||||
.foreground_color = TERMINAL_COLOR_FG_YELLOW,
|
.foreground_color = TERMINAL_COLOR_FG_YELLOW,
|
||||||
.background_color = NULL
|
.background_color = NULL
|
||||||
};
|
};
|
||||||
symbol_hl = (hl_group_t) {
|
symbol_hl = &(hl_group_t) {
|
||||||
.link = NULL,
|
.link = NULL,
|
||||||
.attributes = (void*)&terminal_symbol_hl
|
.attributes = (void*)&terminal_symbol_hl
|
||||||
};
|
};
|
||||||
|
69
source/vector.c
Normal file
69
source/vector.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include "vector.h"
|
||||||
|
|
||||||
|
void vector_init(vector_t * vector,
|
||||||
|
size_t element_size,
|
||||||
|
size_t element_count) {
|
||||||
|
vector->data = NULL;
|
||||||
|
vector->element_size = element_size;
|
||||||
|
vector->element_count = element_count;
|
||||||
|
|
||||||
|
vector->data = malloc(vector->element_size * vector->element_count);
|
||||||
|
|
||||||
|
if ((! vector->data) && (vector->element_count)) {
|
||||||
|
puts("vector_init");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(vector->data,
|
||||||
|
0,
|
||||||
|
vector->element_size * vector->element_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vector_push(vector_t * vector,
|
||||||
|
void * data) {
|
||||||
|
++vector->element_count;
|
||||||
|
|
||||||
|
vector->data = realloc(vector->data,
|
||||||
|
vector->element_size * vector->element_count);
|
||||||
|
|
||||||
|
if (! vector->data) {
|
||||||
|
puts("vector_push");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&vector->data[(vector->element_count - 1) * vector->element_size],
|
||||||
|
data,
|
||||||
|
vector->element_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vector_pop(vector_t * vector) {
|
||||||
|
(void) vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
void * vector_get(const vector_t * const vector,
|
||||||
|
const size_t element) {
|
||||||
|
if (element >= vector->element_count) {
|
||||||
|
puts("vector_get");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return &vector->data[vector->element_size * element];
|
||||||
|
}
|
||||||
|
|
||||||
|
void vector_set(vector_t * vector,
|
||||||
|
void * data,
|
||||||
|
size_t element) {
|
||||||
|
if (element >= vector->element_count) {
|
||||||
|
puts("vector_set");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&vector->data[vector->element_size * element],
|
||||||
|
data,
|
||||||
|
vector->element_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vector_free(vector_t * vector) {
|
||||||
|
free(vector->data);
|
||||||
|
}
|
||||||
|
|
@ -31,72 +31,4 @@ 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);
|
||||||
|
|
||||||
void vector_init(vector_t * vector,
|
|
||||||
size_t element_size,
|
|
||||||
size_t element_count) {
|
|
||||||
vector->data = NULL;
|
|
||||||
vector->element_size = element_size;
|
|
||||||
vector->element_count = element_count;
|
|
||||||
|
|
||||||
vector->data = malloc(vector->element_size * vector->element_count);
|
|
||||||
|
|
||||||
if ((! vector->data) && (vector->element_count)) {
|
|
||||||
puts("vector_init");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(vector->data,
|
|
||||||
0,
|
|
||||||
vector->element_size * vector->element_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vector_push(vector_t * vector,
|
|
||||||
void * data) {
|
|
||||||
++vector->element_count;
|
|
||||||
|
|
||||||
vector->data = realloc(vector->data,
|
|
||||||
vector->element_size * vector->element_count);
|
|
||||||
|
|
||||||
if (! vector->data) {
|
|
||||||
puts("vector_push");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(&vector->data[(vector->element_count - 1) * vector->element_size],
|
|
||||||
data,
|
|
||||||
vector->element_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vector_pop(vector_t * vector) {
|
|
||||||
(void) vector;
|
|
||||||
}
|
|
||||||
|
|
||||||
void * vector_get(const vector_t * const vector,
|
|
||||||
const size_t element) {
|
|
||||||
if (element >= vector->element_count) {
|
|
||||||
puts("vector_get");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return &vector->data[vector->element_size * element];
|
|
||||||
}
|
|
||||||
|
|
||||||
void vector_set(vector_t * vector,
|
|
||||||
void * data,
|
|
||||||
size_t element) {
|
|
||||||
if (element >= vector->element_count) {
|
|
||||||
puts("vector_set");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(&vector->data[vector->element_size * element],
|
|
||||||
data,
|
|
||||||
vector->element_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vector_free(vector_t * vector) {
|
|
||||||
free(vector->data);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user