From 6fdf21062d99395bf4b60d157356d6ba02072166 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 27 Oct 2021 15:49:27 +0300 Subject: [PATCH] Rulesave: Add nations.ruleset ruledit section comment See osdn #42891 Signed-off-by: Marko Lindqvist --- data/ruledit/comments.txt | 8 ++++++++ tools/ruleutil/comments.c | 13 +++++++++++++ tools/ruleutil/comments.h | 3 +++ tools/ruleutil/rulesave.c | 33 ++++++++++++++++++--------------- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/data/ruledit/comments.txt b/data/ruledit/comments.txt index 8252299aad..9b2a7ba5c9 100644 --- a/data/ruledit/comments.txt +++ b/data/ruledit/comments.txt @@ -1158,3 +1158,11 @@ nationsets = "\ ; default.\n\ ; description = Optional short user description of this set.\n\ " + +[sectiondoc] +; This section has comments documenting other sections +nations_ruledit = "\n\ +; This section contains meta information for freeciv-ruledit and freeciv-ruleup\n\ +; to recreate the ruleset file in a form wanted.\n\ +; These have no in-game effect whatsoever.\ +" diff --git a/tools/ruleutil/comments.c b/tools/ruleutil/comments.c index 2a87a7ce9d..3e9327e3e0 100644 --- a/tools/ruleutil/comments.c +++ b/tools/ruleutil/comments.c @@ -48,6 +48,9 @@ static struct { char *nations; char *nationgroups; char *nationsets; + + /* Other section entries */ + char *nations_ruledit; } comments_storage; /************************************************************************** @@ -117,6 +120,9 @@ bool comments_load(void) comment_load(comments_storage.nationsets, comment_file, "typedoc.nationsets"); + comment_load(comments_storage.nations_ruledit, comment_file, + "sectiondoc.nations_ruledit"); + secfile_check_unused(comment_file); secfile_destroy(comment_file); @@ -345,3 +351,10 @@ void comment_nationsets(struct section_file *sfile) comment_write(sfile, comments_storage.nationsets, "Nationsets"); } +/**********************************************************************//** + Write nations.ruleset [ruledit] section header. +**************************************************************************/ +void comment_nations_ruledit(struct section_file *sfile) +{ + comment_write(sfile, comments_storage.nations_ruledit, "Ruledit"); +} diff --git a/tools/ruleutil/comments.h b/tools/ruleutil/comments.h index c91b4689a9..cd8b8ab057 100644 --- a/tools/ruleutil/comments.h +++ b/tools/ruleutil/comments.h @@ -49,6 +49,9 @@ void comment_nationsets(struct section_file *sfile); void comment_nationgroups(struct section_file *sfile); void comment_nations(struct section_file *sfile); +/* Other section comments */ +void comment_nations_ruledit(struct section_file *sfile); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index a9e6281726..728ae658d1 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -1680,23 +1680,26 @@ static bool save_nations_ruleset(const char *filename, const char *name, return FALSE; } - if (data->nationlist != NULL) { - secfile_insert_str(sfile, data->nationlist, "ruledit.nationlist"); - } - if (game.server.ruledit.embedded_nations != NULL) { - int i; - const char **tmp = fc_malloc(game.server.ruledit.embedded_nations_count * sizeof(char *)); - - /* Dance around the secfile_insert_str_vec() parameter type (requires extra const) - * resrictions */ - for (i = 0; i < game.server.ruledit.embedded_nations_count; i++) { - tmp[i] = game.server.ruledit.embedded_nations[i]; + if (data->nationlist != NULL || game.server.ruledit.embedded_nations != NULL) { + comment_nations_ruledit(sfile); + if (data->nationlist != NULL) { + secfile_insert_str(sfile, data->nationlist, "ruledit.nationlist"); } + if (game.server.ruledit.embedded_nations != NULL) { + int i; + const char **tmp = fc_malloc(game.server.ruledit.embedded_nations_count * sizeof(char *)); + + /* Dance around the secfile_insert_str_vec() parameter type (requires extra const) + * resrictions */ + for (i = 0; i < game.server.ruledit.embedded_nations_count; i++) { + tmp[i] = game.server.ruledit.embedded_nations[i]; + } - secfile_insert_str_vec(sfile, tmp, - game.server.ruledit.embedded_nations_count, - "ruledit.embedded_nations"); - free(tmp); + secfile_insert_str_vec(sfile, tmp, + game.server.ruledit.embedded_nations_count, + "ruledit.embedded_nations"); + free(tmp); + } } save_traits(game.server.default_traits, NULL, sfile, -- 2.30.2