From fcfe212257d423db632903cb231372c3c4a16282 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 10 Oct 2023 00:27:44 +0300 Subject: [PATCH 33/33] Split Units manuals creation to separate source file See osdn #48824 Signed-off-by: Marko Lindqvist --- meson.build | 1 + tools/manual/Makefile.am | 3 +- tools/manual/fc_manual.c | 123 ++++++---------------------------- tools/manual/fc_manual.h | 1 + tools/manual/manual_units.c | 111 ++++++++++++++++++++++++++++++ translations/core/POTFILES.in | 1 + 6 files changed, 136 insertions(+), 104 deletions(-) create mode 100644 tools/manual/manual_units.c diff --git a/meson.build b/meson.build index c25b4dfc78..97646d5ddb 100644 --- a/meson.build +++ b/meson.build @@ -4288,6 +4288,7 @@ executable('freeciv-manual', 'tools/manual/manual_governments.c', 'tools/manual/manual_settings.c', 'tools/manual/manual_terrain.c', + 'tools/manual/manual_units.c', 'client/helpdata.c', sources: [enum_targets['manual']], link_with: [common_lib, server_lib, tool_lib, ais], diff --git a/tools/manual/Makefile.am b/tools/manual/Makefile.am index 72ade631f4..bc7c41c4d8 100644 --- a/tools/manual/Makefile.am +++ b/tools/manual/Makefile.am @@ -24,7 +24,8 @@ freeciv_manual_SOURCES = \ manual_commands.c \ manual_governments.c \ manual_settings.c \ - manual_terrain.c + manual_terrain.c \ + manual_units.c # This is a bit of a hack. The program links in with the server lib # but also uses some files from the client. diff --git a/tools/manual/fc_manual.c b/tools/manual/fc_manual.c index bc2d182459..0f7fef7b3a 100644 --- a/tools/manual/fc_manual.c +++ b/tools/manual/fc_manual.c @@ -37,7 +37,6 @@ #include "connection.h" #include "fc_cmdhelp.h" #include "fc_interface.h" -#include "movement.h" #include "version.h" /* client */ @@ -335,8 +334,6 @@ void manual_finalize(struct tag_types *tag_info, FILE *doc, **************************************************************************/ static bool manual_command(struct tag_types *tag_info) { - enum manuals manuals; - /* Reset aifill to zero */ game.info.aifill = 0; @@ -349,124 +346,44 @@ static bool manual_command(struct tag_types *tag_info) || !manual_commands(tag_info) || !manual_terrain(tag_info) || !manual_buildings(tag_info) - || !manual_governments(tag_info)) { + || !manual_governments(tag_info) + || !manual_units(tag_info)) { return FALSE; } - for (manuals = MANUAL_UNITS; manuals < MANUAL_COUNT; manuals++) { + { FILE *doc; - doc = manual_start(tag_info, manuals); + doc = manual_start(tag_info, MANUAL_TECHS); if (doc == NULL) { return FALSE; } - switch (manuals) { - case MANUAL_SETTINGS: - case MANUAL_COMMANDS: - case MANUAL_TERRAIN: - case MANUAL_BUILDINGS: - case MANUAL_WONDERS: - case MANUAL_GOVS: - /* Should be handled in separate functions */ - fc_assert(FALSE); - break; - - case MANUAL_UNITS: - /* Freeciv-web uses (parts of) the unit type HTML output in its own - * manual pages. */ - /* FIXME: this doesn't resemble the wiki manual at all. */ - /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ - fprintf(doc, _("%sFreeciv %s unit types help (%s)%s\n\n"), - tag_info->title_begin, VERSION_STRING, game.control.name, - tag_info->title_end); - unit_type_iterate(putype) { + /* FIXME: this doesn't resemble the wiki manual at all. */ + /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ + fprintf(doc, _("%sFreeciv %s tech help (%s)%s\n\n"), + tag_info->title_begin, VERSION_STRING, game.control.name, + tag_info->title_end); + advance_iterate(ptech) { + if (valid_advance(ptech)) { char buf[64000]; - fprintf(doc, tag_info->item_begin, "utype", putype->item_number); + fprintf(doc, tag_info->item_begin, "tech", ptech->item_number); fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin, - utype_name_translation(putype), tag_info->sect_title_end); - fprintf(doc, tag_info->subitem_begin, "cost"); - fprintf(doc, - PL_("Cost: %d shield", - "Cost: %d shields", - utype_build_shield_cost_base(putype)), - utype_build_shield_cost_base(putype)); - fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, tag_info->subitem_begin, "upkeep"); - fprintf(doc, _("Upkeep: %s"), - helptext_unit_upkeep_str(putype)); - fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, tag_info->subitem_begin, "moves"); - fprintf(doc, _("Moves: %s"), - move_points_text(putype->move_rate, TRUE)); - fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, tag_info->subitem_begin, "vision"); - fprintf(doc, _("Vision: %d"), - (int)sqrt((double)putype->vision_radius_sq)); - fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, tag_info->subitem_begin, "attack"); - fprintf(doc, _("Attack: %d"), - putype->attack_strength); - fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, tag_info->subitem_begin, "defense"); - fprintf(doc, _("Defense: %d"), - putype->defense_strength); - fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, tag_info->subitem_begin, "firepower"); - fprintf(doc, _("Firepower: %d"), - putype->firepower); - fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, tag_info->subitem_begin, "hitpoints"); - fprintf(doc, _("Hitpoints: %d"), - putype->hp); - fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, tag_info->subitem_begin, "obsolete"); - fprintf(doc, _("Obsolete by: %s"), - U_NOT_OBSOLETED == putype->obsoleted_by ? - Q_("?utype:None") : - utype_name_translation(putype->obsoleted_by)); - fprintf(doc, "%s", tag_info->subitem_end); + advance_name_translation(ptech), tag_info->sect_title_end); + fprintf(doc, tag_info->subitem_begin, "helptext"); - helptext_unit(buf, sizeof(buf), NULL, "", putype); + helptext_advance(buf, sizeof(buf), NULL, "", ptech->item_number); fprintf(doc, "%s", buf); fprintf(doc, "%s", tag_info->subitem_end); - fprintf(doc, "%s", tag_info->item_end); - } unit_type_iterate_end; - break; - - case MANUAL_TECHS: - /* FIXME: this doesn't resemble the wiki manual at all. */ - /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ - fprintf(doc, _("%sFreeciv %s tech help (%s)%s\n\n"), - tag_info->title_begin, VERSION_STRING, game.control.name, - tag_info->title_end); - advance_iterate(ptech) { - if (valid_advance(ptech)) { - char buf[64000]; - - fprintf(doc, tag_info->item_begin, "tech", ptech->item_number); - fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin, - advance_name_translation(ptech), tag_info->sect_title_end); - - fprintf(doc, tag_info->subitem_begin, "helptext"); - helptext_advance(buf, sizeof(buf), NULL, "", ptech->item_number); - fprintf(doc, "%s", buf); - fprintf(doc, "%s", tag_info->subitem_end); - - fprintf(doc, "%s", tag_info->item_end); - } - } advance_iterate_end; - break; - case MANUAL_COUNT: - break; - - } /* switch */ + fprintf(doc, "%s", tag_info->item_end); + } + } advance_iterate_end; - manual_finalize(tag_info, doc, manuals); - } /* manuals */ + manual_finalize(tag_info, doc, MANUAL_TECHS); + } return TRUE; } diff --git a/tools/manual/fc_manual.h b/tools/manual/fc_manual.h index a3ba1dd99a..7dce80dffb 100644 --- a/tools/manual/fc_manual.h +++ b/tools/manual/fc_manual.h @@ -54,6 +54,7 @@ bool manual_commands(struct tag_types *tag_info); bool manual_terrain(struct tag_types *tag_info); bool manual_buildings(struct tag_types *tag_info); bool manual_governments(struct tag_types *tag_info); +bool manual_units(struct tag_types *tag_info); #ifdef __cplusplus } diff --git a/tools/manual/manual_units.c b/tools/manual/manual_units.c new file mode 100644 index 0000000000..aaef2dfe5f --- /dev/null +++ b/tools/manual/manual_units.c @@ -0,0 +1,111 @@ +/*********************************************************************** + 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" +#include "movement.h" + +/* client */ +#include "helpdata.h" + +/* tools/manual */ +#include "fc_manual.h" + +/**********************************************************************//** + Write units manual page + + @param tag_info Tag set to use + @return Success +**************************************************************************/ +bool manual_units(struct tag_types *tag_info) +{ + FILE *doc; + + doc = manual_start(tag_info, MANUAL_UNITS); + + if (doc == NULL) { + return FALSE; + } + + /* Freeciv-web uses (parts of) the unit type HTML output in its own + * manual pages. */ + /* FIXME: this doesn't resemble the wiki manual at all. */ + /* TRANS: markup ... Freeciv version ... ruleset name ... markup */ + fprintf(doc, _("%sFreeciv %s unit types help (%s)%s\n\n"), + tag_info->title_begin, VERSION_STRING, game.control.name, + tag_info->title_end); + unit_type_iterate(putype) { + char buf[64000]; + + fprintf(doc, tag_info->item_begin, "utype", putype->item_number); + fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin, + utype_name_translation(putype), tag_info->sect_title_end); + fprintf(doc, tag_info->subitem_begin, "cost"); + fprintf(doc, + PL_("Cost: %d shield", + "Cost: %d shields", + utype_build_shield_cost_base(putype)), + utype_build_shield_cost_base(putype)); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "upkeep"); + fprintf(doc, _("Upkeep: %s"), + helptext_unit_upkeep_str(putype)); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "moves"); + fprintf(doc, _("Moves: %s"), + move_points_text(putype->move_rate, TRUE)); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "vision"); + fprintf(doc, _("Vision: %d"), + (int)sqrt((double)putype->vision_radius_sq)); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "attack"); + fprintf(doc, _("Attack: %d"), + putype->attack_strength); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "defense"); + fprintf(doc, _("Defense: %d"), + putype->defense_strength); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "firepower"); + fprintf(doc, _("Firepower: %d"), + putype->firepower); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "hitpoints"); + fprintf(doc, _("Hitpoints: %d"), + putype->hp); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "obsolete"); + fprintf(doc, _("Obsolete by: %s"), + U_NOT_OBSOLETED == putype->obsoleted_by ? + Q_("?utype:None") : + utype_name_translation(putype->obsoleted_by)); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, tag_info->subitem_begin, "helptext"); + helptext_unit(buf, sizeof(buf), NULL, "", putype); + fprintf(doc, "%s", buf); + fprintf(doc, "%s", tag_info->subitem_end); + fprintf(doc, "%s", tag_info->item_end); + } unit_type_iterate_end; + + manual_finalize(tag_info, doc, MANUAL_UNITS); + + return TRUE; +} diff --git a/translations/core/POTFILES.in b/translations/core/POTFILES.in index b6c251545b..68247a3963 100644 --- a/translations/core/POTFILES.in +++ b/translations/core/POTFILES.in @@ -398,6 +398,7 @@ tools/manual/manual_commands.c tools/manual/manual_governments.c tools/manual/manual_settings.c tools/manual/manual_terrain.c +tools/manual/manual_units.c tools/ruleutil/rulesave.c server/actiontools.c server/aiiface.c -- 2.42.0