From 92bc41827e695f60e1e7e3c8bea681807225da70 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 27 Oct 2021 15:37:41 +0300 Subject: [PATCH] Rulesave: Add nations.ruleset ruledit section comment See osdn #42891 Signed-off-by: Marko Lindqvist --- data/ruledit/comments-3.2.txt | 8 ++++++++ tools/ruleutil/comments.c | 14 ++++++++++++++ tools/ruleutil/comments.h | 3 +++ tools/ruleutil/rulesave.c | 33 ++++++++++++++++++--------------- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/data/ruledit/comments-3.2.txt b/data/ruledit/comments-3.2.txt index 4cb940627e..2d2856f8a5 100644 --- a/data/ruledit/comments-3.2.txt +++ b/data/ruledit/comments-3.2.txt @@ -1190,6 +1190,14 @@ clauses = "\ ; */ <-- avoid gettext warnings\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.\ +" + [entrydoc] ; This section has comments documenting individual entries diff --git a/tools/ruleutil/comments.c b/tools/ruleutil/comments.c index 9f37b39547..eec307f6b4 100644 --- a/tools/ruleutil/comments.c +++ b/tools/ruleutil/comments.c @@ -51,6 +51,9 @@ static struct { char *nationsets; char *clauses; + /* Other section entries */ + char *nations_ruledit; + /* Comment entries */ char *civstyle_granary; char *civstyle_ransom_gold; @@ -144,6 +147,9 @@ bool comments_load(void) comment_file, "typedoc.nationsets"); comment_load(comments_storage.clauses, comment_file, "typedoc.clauses"); + comment_load(comments_storage.nations_ruledit, comment_file, + "sectiondoc.nations_ruledit"); + comment_load(comments_storage.civstyle_granary, comment_file, "entrydoc.granary"); comment_load(comments_storage.civstyle_ransom_gold, comment_file, @@ -436,6 +442,14 @@ void comment_clauses(struct section_file *sfile) comment_write(sfile, comments_storage.clauses, "Clauses"); } +/**********************************************************************//** + Write nations.ruleset [ruledit] section header. +**************************************************************************/ +void comment_nations_ruledit(struct section_file *sfile) +{ + comment_write(sfile, comments_storage.nations_ruledit, "Ruledit"); +} + /**********************************************************************//** Write civstyle granary settings header. **************************************************************************/ diff --git a/tools/ruleutil/comments.h b/tools/ruleutil/comments.h index 8fc997c90b..a1951193fa 100644 --- a/tools/ruleutil/comments.h +++ b/tools/ruleutil/comments.h @@ -54,6 +54,9 @@ void comment_nationgroups(struct section_file *sfile); void comment_nations(struct section_file *sfile); void comment_clauses(struct section_file *sfile); +/* Other section comments */ +void comment_nations_ruledit(struct section_file *sfile); + /* Entry comments */ void comment_civstyle_granary(struct section_file *sfile); void comment_civstyle_ransom_gold(struct section_file *sfile); diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 7072500456..366477dd9c 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -2025,23 +2025,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