From 5c83c9e89efe214bdeeef1c0e7d76fe2dbd3829c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=ADle=20Ekaterin=20Liszka?= Date: Mon, 27 Nov 2023 15:21:09 -0800 Subject: [PATCH] src/font.c: finish implementations --- src/font.c | 27 ++++++++++++++++++++++++--- src/font.h | 5 +++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/font.c b/src/font.c index 4c22451..6db97f2 100644 --- a/src/font.c +++ b/src/font.c @@ -20,9 +20,9 @@ font_t font_create(char *name, char *filename) { toml_table_t *table = toml_parse_file(fp); fclose(fp); -#define TOML_GET_KEY((var, key, func)) toml_datum_t *(var) = func(table, key);\ - if (!var.ok) {\ - error("key '" key "' missing from", filename); \ +#define TOML_GET_KEY((var, key, func)) toml_datum_t *(var) = func(table, (key));\ + if (!(var).ok) {\ + error("key '" (key) "' missing from", filename); \ } TOML_GET_KEY(name, "name", toml_string_in) @@ -42,10 +42,17 @@ font_t font_create(char *name, char *filename) { font.width = width; font.height = height; font.map_entries = map_create(mapping, *map); + font.map = map; return font; } +void font_destroy(font_t font) { + map_destroy(font.map); + free(font.name); + free(font.filename); +} + unsigned int map_create(toml_table_t *table, map_t **map) { map_t *node; map_t *next; @@ -82,4 +89,18 @@ unsigned int map_create(toml_table_t *table, map_t **map) { node->next = next; node = next; } + node->next = NULL; + + *map = root; + return nodes; +} + +void map_destroy(map_t *map) { + map_t *node = map; + map_t *next; + + while ((next = node->next) != NULL) { + free(node); + node = next; + } } diff --git a/src/font.h b/src/font.h index 0ad152a..7ebd664 100644 --- a/src/font.h +++ b/src/font.h @@ -15,3 +15,8 @@ typedef struct { unsigned int map_entries; map_t *map; } font_t; + +font_t font_create(char *name, char *filename); +void font_destroy(font_t font); +unsigned int map_create(toml_table_t *table, map_t **map); +void map_destroy(map_t *map);