From c527c99392704f9c1a1a3e654c9d102283911250 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 31 May 2024 16:33:48 +0200 Subject: [PATCH] added license and description to project --- src/cfg/opt.c | 22 ++++++++++++++++------ src/cfg/opt.h | 5 ++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/cfg/opt.c b/src/cfg/opt.c index bb74e51..10d1540 100644 --- a/src/cfg/opt.c +++ b/src/cfg/opt.c @@ -4,7 +4,6 @@ #include #include -#include TargetConfig default_target_config() { TargetConfig config; @@ -74,19 +73,30 @@ static int parse_project_table(ProjectConfig *config, toml_table_t *project_tabl // author names toml_array_t *authors = toml_array_in(project_table, "authors"); if (authors) { - unsigned int len = 0; - config->authors = malloc(sizeof(const char *) * 2); + config->authors = g_array_new(FALSE, FALSE, sizeof(char*)); for (int i = 0;; i++) { toml_datum_t author = toml_string_at(authors, i); if (!author.ok) break; - char** new_authors = realloc(config->authors, sizeof(const char *) * ++len); - config->authors = new_authors; - config->authors[len] = author.u.s; + g_array_append_val(config->authors, author.u.s); } } + + // project description + toml_datum_t description = toml_string_in(project_table, "description"); + if (description.ok) { + config->desc = description.u.s; + } + + // project license + toml_datum_t license = toml_string_in(project_table, "license"); + if (license.ok) { + config->license = license.u.s; + } + + return PROJECT_OK; } int load_project_config(ProjectConfig *config) { diff --git a/src/cfg/opt.h b/src/cfg/opt.h index cf89d4f..5c9e6b5 100644 --- a/src/cfg/opt.h +++ b/src/cfg/opt.h @@ -6,6 +6,7 @@ #define GEMSTONE_OPT_H #include +#include typedef struct TargetConfig_t { char* name; @@ -21,8 +22,10 @@ typedef struct ProjectConfig_t { char* desc; // version char* version; + // license + char* license; // list of authors - char** authors; + GArray* authors; } ProjectConfig; TargetConfig default_target_config();