From 5840e94f76bf6eec38880328f7376107bcc8569a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 4 Sep 2023 07:58:33 +0300 Subject: [PATCH 19/19] Add musicspec fields "name" and "version" See osdn #48567 Signed-off-by: Marko Lindqvist --- client/helpdata.c | 27 ++++----------- client/music.c | 75 ++++++++++++++++++++++++++++++---------- client/music.h | 3 ++ data/stdmusic.musicspec | 6 ++++ tools/manual/fc_manual.c | 16 +++++++++ 5 files changed, 87 insertions(+), 40 deletions(-) diff --git a/client/helpdata.c b/client/helpdata.c index daa8853033..6db0fd566d 100644 --- a/client/helpdata.c +++ b/client/helpdata.c @@ -1025,13 +1025,10 @@ void boot_help_texts(void) break; case HELP_MUSICSET: { - /* TODO: Parts related to musicset name and version - * currently commented out, untile the musicspec - * format supports them. */ int desc_len; int len; - // const char *ms_name = musicset_name_get(tileset); - // const char *version = musicset_version(tileset); + const char *ms_name = current_musicset_name(); + const char *version = current_musicset_version(); const char *summary = current_musicset_summary(); const char *description = current_musicset_description(); @@ -1045,9 +1042,8 @@ void boot_help_texts(void) desc_len = 0; } if (summary != NULL) { -#if 0 - if (version[0] != '\0') { - len = strlen(_(ts_name)) + if (version != NULL && version[0] != '\0') { + len = strlen(_(ms_name)) + strlen(" ") + strlen(version) + strlen("\n\n") @@ -1056,7 +1052,7 @@ void boot_help_texts(void) pitem->text = fc_malloc(len + desc_len); fc_snprintf(pitem->text, len, "%s %s\n\n%s", - _(ts_name), version, _(summary)); + _(ms_name), version, _(summary)); } else { len = strlen(_(ms_name)) + strlen("\n\n") @@ -1067,16 +1063,10 @@ void boot_help_texts(void) fc_snprintf(pitem->text, len, "%s\n\n%s", _(ms_name), _(summary)); } -#else - len = strlen(_(summary)) + 1; - pitem->text = fc_malloc(len + desc_len); - fc_snprintf(pitem->text, len, "%s", _(summary)); -#endif } else { const char *nodesc = _("Current musicset contains no summary."); -#if 0 - if (version[0] != '\0') { + if (version != NULL && version[0] != '\0') { len = strlen(_(ms_name)) + strlen(" ") + strlen(version) @@ -1099,11 +1089,6 @@ void boot_help_texts(void) _(ms_name), nodesc); } -#else - len = strlen(nodesc) + 1; - pitem->text = fc_malloc(len + desc_len); - fc_snprintf(pitem->text, len, "%s", nodesc); -#endif } if (description != NULL) { fc_strlcat(pitem->text, "\n\n", len + desc_len); diff --git a/client/music.c b/client/music.c index afcf7310e0..863dbe4399 100644 --- a/client/music.c +++ b/client/music.c @@ -31,8 +31,12 @@ #include "music.h" -static char *ms_summary = NULL; -static char *ms_description = NULL; +struct musicset { + char name[MAX_LEN_NAME]; + char version[MAX_LEN_NAME]; + char *summary; + char *description; +} current_ms = { .summary = NULL, .description = NULL }; /**********************************************************************//** Start music suitable for current game situation @@ -148,19 +152,32 @@ struct section_file *musicspec_load(const char *ms_filename) if (tagfile != NULL) { const char *mstr; + mstr = secfile_lookup_str(tagfile, "musicspec.name"); + /* Musicset name found */ + sz_strlcpy(current_ms.name, mstr); + + mstr = secfile_lookup_str_default(tagfile, "", "musicspec.version"); + if (mstr[0] != '\0') { + /* Musicset version found */ + sz_strlcpy(current_ms.version, mstr); + } else { + /* No version information */ + current_ms.version[0] = '\0'; + } + mstr = secfile_lookup_str_default(tagfile, "", "musicspec.summary"); if (mstr[0] != '\0') { size_t len; /* Musicset summary found */ len = strlen(mstr); - ms_summary = fc_malloc(len + 1); - fc_strlcpy(ms_summary, mstr, len + 1); + current_ms.summary = fc_malloc(len + 1); + fc_strlcpy(current_ms.summary, mstr, len + 1); } else { /* No summary */ - if (ms_summary != NULL) { - free(ms_summary); - ms_summary = NULL; + if (current_ms.summary != NULL) { + free(current_ms.summary); + current_ms.summary = NULL; } } @@ -170,13 +187,13 @@ struct section_file *musicspec_load(const char *ms_filename) /* Musicset description found */ len = strlen(mstr); - ms_description = fc_malloc(len + 1); - fc_strlcpy(ms_description, mstr, len + 1); + current_ms.description = fc_malloc(len + 1); + fc_strlcpy(current_ms.description, mstr, len + 1); } else { - /* No summary */ - if (ms_description != NULL) { - free(ms_description); - ms_description = NULL; + /* No Description */ + if (current_ms.description != NULL) { + free(current_ms.description); + current_ms.description = NULL; } } } @@ -194,21 +211,41 @@ struct section_file *musicspec_load(const char *ms_filename) void musicspec_close(struct section_file *tagfile) { if (tagfile != NULL) { - free(ms_summary); - ms_summary = NULL; - free(ms_description); - ms_description = NULL; + free(current_ms.summary); + current_ms.summary = NULL; + free(current_ms.description); + current_ms.description = NULL; secfile_destroy(tagfile); } } +/**********************************************************************//** + Return name of the current musicset. +**************************************************************************/ +const char *current_musicset_name(void) +{ + return current_ms.name; +} + +/**********************************************************************//** + Return version of the current musicset. Can be NULL. +**************************************************************************/ +const char *current_musicset_version(void) +{ + if (current_ms.version[0] == '\0') { + return NULL; + } + + return current_ms.version; +} + /**********************************************************************//** Return summary of the current musicset. Can be NULL. **************************************************************************/ const char *current_musicset_summary(void) { - return ms_summary; + return current_ms.summary; } /**********************************************************************//** @@ -216,5 +253,5 @@ const char *current_musicset_summary(void) **************************************************************************/ const char *current_musicset_description(void) { - return ms_description; + return current_ms.description; } diff --git a/client/music.h b/client/music.h index c5a2b09f2d..ede5877937 100644 --- a/client/music.h +++ b/client/music.h @@ -30,6 +30,9 @@ void musicspec_reread_callback(struct option *poption); struct section_file *musicspec_load(const char *ms_filename); void musicspec_close(struct section_file *tagfile); + +const char *current_musicset_name(void); +const char *current_musicset_version(void); const char *current_musicset_summary(void); const char *current_musicset_description(void); diff --git a/data/stdmusic.musicspec b/data/stdmusic.musicspec index 7fe35b6f48..30892affe3 100644 --- a/data/stdmusic.musicspec +++ b/data/stdmusic.musicspec @@ -2,6 +2,12 @@ ; Format and options of this spec file: options = "+Freeciv-musicspec-3.2-Devel-2023-Jun-03" +; A simple name for the musicset specified by this file: +name = "Stdmusic" + +; There`s no separate versioning in musicsets part of main freeciv distribution +;version = "" + [info] artists = "\ " diff --git a/tools/manual/fc_manual.c b/tools/manual/fc_manual.c index 09e75c575b..32300c0d47 100644 --- a/tools/manual/fc_manual.c +++ b/tools/manual/fc_manual.c @@ -271,6 +271,22 @@ const char *tileset_description(struct tileset *t) return NULL; } +/**********************************************************************//** + Client stub +**************************************************************************/ +const char *current_musicset_name(void) +{ + return NULL; +} + +/**********************************************************************//** + Client stub +**************************************************************************/ +const char *current_musicset_version(void) +{ + return NULL; +} + /**********************************************************************//** Client stub **************************************************************************/ -- 2.40.1