From 4f3ac34590b21cd299f3523553594a254c28ab5e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 4 Oct 2023 01:44:05 +0300 Subject: [PATCH 42/42] Split Improvements manuals creation to separate source file See osdn #48801 Signed-off-by: Marko Lindqvist --- meson.build | 1 + tools/manual/Makefile.am | 1 + tools/manual/fc_manual.c | 87 ++------------------ tools/manual/fc_manual.h | 17 ++-- tools/manual/manual_buildings.c | 140 ++++++++++++++++++++++++++++++++ translations/core/POTFILES.in | 2 + 6 files changed, 158 insertions(+), 90 deletions(-) create mode 100644 tools/manual/manual_buildings.c diff --git a/meson.build b/meson.build index ec3db5221c..b1d2002610 100644 --- a/meson.build +++ b/meson.build @@ -4163,6 +4163,7 @@ if get_option('tools').contains('manual') executable('freeciv-manual', 'tools/manual/fc_manual.c', + 'tools/manual/manual_buildings.c', 'tools/manual/manual_commands.c', 'tools/manual/manual_settings.c', 'tools/manual/manual_terrain.c', diff --git a/tools/manual/Makefile.am b/tools/manual/Makefile.am index 4c4a9528fa..d6d8d1a0f2 100644 --- a/tools/manual/Makefile.am +++ b/tools/manual/Makefile.am @@ -19,6 +19,7 @@ AM_CPPFLAGS = $(common_cppflags) freeciv_manual_SOURCES = \ fc_manual.c \ fc_manual.h \ + manual_buildings.c \ manual_commands.c \ manual_settings.c \ manual_terrain.c diff --git a/tools/manual/fc_manual.c b/tools/manual/fc_manual.c index c8b7670f6f..81d421f9e0 100644 --- a/tools/manual/fc_manual.c +++ b/tools/manual/fc_manual.c @@ -354,11 +354,12 @@ static bool manual_command(struct tag_types *tag_info) if (!manual_settings(tag_info) || !manual_commands(tag_info) - || !manual_terrain(tag_info)) { + || !manual_terrain(tag_info) + || !manual_buildings(tag_info)) { return FALSE; } - for (manuals = MANUAL_BUILDINGS; manuals < MANUAL_COUNT; manuals++) { + for (manuals = MANUAL_GOVS; manuals < MANUAL_COUNT; manuals++) { char mnamebuf[20]; FILE *doc; @@ -372,88 +373,10 @@ static bool manual_command(struct tag_types *tag_info) case MANUAL_SETTINGS: case MANUAL_COMMANDS: case MANUAL_TERRAIN: - /* Should be handled in separate functions */ - fc_assert(FALSE); - break; - case MANUAL_BUILDINGS: case MANUAL_WONDERS: - if (manuals == MANUAL_BUILDINGS) { - /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ - fprintf(doc, _("%sFreeciv %s buildings help (%s)%s\n\n"), tag_info->title_begin, - VERSION_STRING, game.control.name, tag_info->title_end); - } else { - /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ - fprintf(doc, _("%sFreeciv %s wonders help (%s)%s\n\n"), tag_info->title_begin, - VERSION_STRING, game.control.name, tag_info->title_end); - } - - fprintf(doc, "\n" - "\n\n", - _("Name"), _("Cost"), _("Upkeep"), - _("Requirement"), _("Obsolete by"), _("More info")); - - improvement_iterate(pimprove) { - char buf[64000]; - - if (!valid_improvement(pimprove) - || is_great_wonder(pimprove) == (manuals == MANUAL_BUILDINGS)) { - continue; - } - - helptext_building(buf, sizeof(buf), NULL, NULL, pimprove); - - fprintf(doc, "\n" - "\n\n\n\n\n", - buf); - } improvement_iterate_end; - - fprintf(doc, "
%s%s
%s
%s
%s
%s
%s%s%s%s%d
%d
", - tag_info->image_begin, pimprove->graphic_str, tag_info->image_end, - improvement_name_translation(pimprove), - pimprove->build_cost, - pimprove->upkeep); - - if (requirement_vector_size(&pimprove->reqs) == 0) { - char text[512]; - - strncpy(text, Q_("?req:None"), sizeof(text) - 1); - fprintf(doc, "%s
", text); - } else { - requirement_vector_iterate(&pimprove->reqs, req) { - char text[512], text2[512]; - - fc_snprintf(text2, sizeof(text2), - /* TRANS: Feature required to be absent. */ - req->present ? "%s" : _("no %s"), - universal_name_translation(&req->source, - text, sizeof(text))); - fprintf(doc, "%s
", text2); - } requirement_vector_iterate_end; - } - - fprintf(doc, "\n%s\n", tag_info->hline); - - if (requirement_vector_size(&pimprove->obsolete_by) == 0) { - char text[512]; - - strncpy(text, Q_("?req:None"), sizeof(text) - 1); - fprintf(doc, "%s
", text); - } else { - requirement_vector_iterate(&pimprove->obsolete_by, pobs) { - char text[512], text2[512]; - - fc_snprintf(text2, sizeof(text2), - /* TRANS: Feature required to be absent. */ - pobs->present ? "%s" : _("no %s"), - universal_name_translation(&pobs->source, - text, sizeof(text))); - fprintf(doc, "%s
", text2); - } requirement_vector_iterate_end; - } - - fprintf(doc, - "
%s

"); + /* Should be handled in separate functions */ + fc_assert(FALSE); break; case MANUAL_GOVS: diff --git a/tools/manual/fc_manual.h b/tools/manual/fc_manual.h index e17cec4baf..4ab8ec742a 100644 --- a/tools/manual/fc_manual.h +++ b/tools/manual/fc_manual.h @@ -24,21 +24,21 @@ extern "C" { #define SPECENUM_NAME manuals #define SPECENUM_VALUE0 MANUAL_SETTINGS -#define SPECENUM_VALUE0NAME "Settings" +#define SPECENUM_VALUE0NAME N_("Settings") #define SPECENUM_VALUE1 MANUAL_COMMANDS -#define SPECENUM_VALUE1NAME "Commands" +#define SPECENUM_VALUE1NAME N_("Commands") #define SPECENUM_VALUE2 MANUAL_TERRAIN -#define SPECENUM_VALUE2NAME "Terrain" +#define SPECENUM_VALUE2NAME N_("Terrain") #define SPECENUM_VALUE3 MANUAL_BUILDINGS -#define SPECENUM_VALUE3NAME "Buildings" +#define SPECENUM_VALUE3NAME N_("Buildings") #define SPECENUM_VALUE4 MANUAL_WONDERS -#define SPECENUM_VALUE4NAME "Wonders" +#define SPECENUM_VALUE4NAME N_("Wonders") #define SPECENUM_VALUE5 MANUAL_GOVS -#define SPECENUM_VALUE5NAME "Governments" +#define SPECENUM_VALUE5NAME N_("Governments") #define SPECENUM_VALUE6 MANUAL_UNITS -#define SPECENUM_VALUE6NAME "Units" +#define SPECENUM_VALUE6NAME N_("Units") #define SPECENUM_VALUE7 MANUAL_TECHS -#define SPECENUM_VALUE7NAME "Techs" +#define SPECENUM_VALUE7NAME N_("Techs") #define SPECENUM_COUNT MANUAL_COUNT #include "specenum_gen.h" @@ -69,6 +69,7 @@ char *html_special_chars(char *str, size_t *len); bool manual_settings(struct tag_types *tag_info); bool manual_commands(struct tag_types *tag_info); bool manual_terrain(struct tag_types *tag_info); +bool manual_buildings(struct tag_types *tag_info); #ifdef __cplusplus } diff --git a/tools/manual/manual_buildings.c b/tools/manual/manual_buildings.c new file mode 100644 index 0000000000..eb1b225564 --- /dev/null +++ b/tools/manual/manual_buildings.c @@ -0,0 +1,140 @@ +/*********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/* utility */ +#include "fcintl.h" + +/* common */ +#include "game.h" + +/* client */ +#include "helpdata.h" + +/* tools/manual */ +#include "fc_manual.h" + +/**********************************************************************//** + Write improvements manual page + + @param tag_info Tag set to use + @param manual Exact manual page + @return Success +**************************************************************************/ +static bool manual_improvements(struct tag_types *tag_info, + enum manuals manual) +{ + FILE *doc; + + doc = manual_start(tag_info, manual); + + if (doc == NULL) { + return FALSE; + } + + if (manual == MANUAL_BUILDINGS) { + /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ + fprintf(doc, _("%sFreeciv %s buildings help (%s)%s\n\n"), tag_info->title_begin, + VERSION_STRING, game.control.name, tag_info->title_end); + } else { + /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ + fprintf(doc, _("%sFreeciv %s wonders help (%s)%s\n\n"), tag_info->title_begin, + VERSION_STRING, game.control.name, tag_info->title_end); + } + + fprintf(doc, "\n" + "\n\n", + _("Name"), _("Cost"), _("Upkeep"), + _("Requirement"), _("Obsolete by"), _("More info")); + + improvement_iterate(pimprove) { + char buf[64000]; + + if (!valid_improvement(pimprove) + || is_great_wonder(pimprove) == (manual == MANUAL_BUILDINGS)) { + continue; + } + + helptext_building(buf, sizeof(buf), NULL, NULL, pimprove); + + fprintf(doc, "\n" + "\n\n\n\n\n", + buf); + } improvement_iterate_end; + + fprintf(doc, "
%s%s
%s
%s
%s
%s
%s%s%s%s%d
%d
", + tag_info->image_begin, pimprove->graphic_str, tag_info->image_end, + improvement_name_translation(pimprove), + pimprove->build_cost, + pimprove->upkeep); + + if (requirement_vector_size(&pimprove->reqs) == 0) { + char text[512]; + + strncpy(text, Q_("?req:None"), sizeof(text) - 1); + fprintf(doc, "%s
", text); + } else { + requirement_vector_iterate(&pimprove->reqs, req) { + char text[512], text2[512]; + + fc_snprintf(text2, sizeof(text2), + /* TRANS: Feature required to be absent. */ + req->present ? "%s" : _("no %s"), + universal_name_translation(&req->source, + text, sizeof(text))); + fprintf(doc, "%s
", text2); + } requirement_vector_iterate_end; + } + + fprintf(doc, "\n%s\n", tag_info->hline); + + if (requirement_vector_size(&pimprove->obsolete_by) == 0) { + char text[512]; + + strncpy(text, Q_("?req:None"), sizeof(text) - 1); + fprintf(doc, "%s
", text); + } else { + requirement_vector_iterate(&pimprove->obsolete_by, pobs) { + char text[512], text2[512]; + + fc_snprintf(text2, sizeof(text2), + /* TRANS: Feature required to be absent. */ + pobs->present ? "%s" : _("no %s"), + universal_name_translation(&pobs->source, + text, sizeof(text))); + fprintf(doc, "%s
", text2); + } requirement_vector_iterate_end; + } + + fprintf(doc, + "
%s

"); + + manual_finalize(tag_info, doc, _(manuals_name(manual))); + + return TRUE; +} + +/**********************************************************************//** + Write improvements manual page + + @param tag_info Tag set to use + @return Success +**************************************************************************/ +bool manual_buildings(struct tag_types *tag_info) +{ + return manual_improvements(tag_info, MANUAL_BUILDINGS) + && manual_improvements(tag_info, MANUAL_WONDERS); +} diff --git a/translations/core/POTFILES.in b/translations/core/POTFILES.in index a68259acc6..2041abb01a 100644 --- a/translations/core/POTFILES.in +++ b/translations/core/POTFILES.in @@ -389,6 +389,8 @@ tools/fcmp/mpgui_gtk4.c tools/fcmp/mpgui_qt.cpp tools/fcmp/mpgui_qt_worker.cpp tools/manual/fc_manual.c +tools/manual/fc_manual.h +tools/manual/manual_buildings.c tools/manual/manual_commands.c tools/manual/manual_settings.c tools/manual/manual_terrain.c -- 2.40.1