From 620dc6fdc13e83a8ae3e5feb6f636dbb2b31d95b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 27 Oct 2021 15:44:03 +0300 Subject: [PATCH] Rulesave: Add nations.ruleset ruledit section comment See osdn #42891 Signed-off-by: Marko Lindqvist --- data/ruledit/comments-3.1.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.1.txt b/data/ruledit/comments-3.1.txt index 0c3018a972..c08bf48d82 100644 --- a/data/ruledit/comments-3.1.txt +++ b/data/ruledit/comments-3.1.txt @@ -1186,3 +1186,11 @@ clauses = "\ ;\n\ ; */ <-- 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.\ +" diff --git a/tools/ruleutil/comments.c b/tools/ruleutil/comments.c index c6c3f64a9b..7675c4cb08 100644 --- a/tools/ruleutil/comments.c +++ b/tools/ruleutil/comments.c @@ -49,6 +49,9 @@ static struct { char *nationgroups; char *nationsets; char *clauses; + + /* Other section entries */ + char *nations_ruledit; } comments_storage; /**********************************************************************//** @@ -121,6 +124,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"); + secfile_check_unused(comment_file); secfile_destroy(comment_file); @@ -356,3 +362,11 @@ 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"); +} diff --git a/tools/ruleutil/comments.h b/tools/ruleutil/comments.h index 5e9192723e..c69e177a6d 100644 --- a/tools/ruleutil/comments.h +++ b/tools/ruleutil/comments.h @@ -52,6 +52,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); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 5065694081..469189f1d8 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -1973,23 +1973,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