From 9f851cbf303c505dd6d99b2b79a52d2bfb403578 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 30 Sep 2023 17:20:31 +0300 Subject: [PATCH 55/55] Split Commands manual creation to separate source file See osdn #48760 Signed-off-by: Marko Lindqvist --- meson.build | 1 + tools/manual/Makefile.am | 1 + tools/manual/fc_manual.c | 49 ++----------------- tools/manual/fc_manual.h | 1 + tools/manual/manual_commands.c | 87 ++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 tools/manual/manual_commands.c diff --git a/meson.build b/meson.build index b8b0f07dd9..f780cd10de 100644 --- a/meson.build +++ b/meson.build @@ -4211,6 +4211,7 @@ if get_option('tools').contains('manual') executable('freeciv-manual', 'tools/manual/fc_manual.c', + 'tools/manual/manual_commands.c', 'tools/manual/manual_settings.c', 'client/helpdata.c', link_with: [common_lib, server_lib, tool_lib, ais], diff --git a/tools/manual/Makefile.am b/tools/manual/Makefile.am index 6f8b36dea2..7a7a6f8f67 100644 --- a/tools/manual/Makefile.am +++ b/tools/manual/Makefile.am @@ -20,6 +20,7 @@ AM_CPPFLAGS = $(common_cppflags) freeciv_manual_SOURCES = \ fc_manual.c \ fc_manual.h \ + manual_commands.c \ manual_settings.c # This is a bit of a hack. The program links in with the server lib diff --git a/tools/manual/fc_manual.c b/tools/manual/fc_manual.c index c122eb1642..ebf9650828 100644 --- a/tools/manual/fc_manual.c +++ b/tools/manual/fc_manual.c @@ -353,12 +353,12 @@ static bool manual_command(struct tag_types *tag_info) return FALSE; } - if (!manual_settings(tag_info)) { + if (!manual_settings(tag_info) + || !manual_commands(tag_info)) { return FALSE; } - for (manuals = MANUAL_COMMANDS; manuals < MANUAL_COUNT; manuals++) { - int i; + for (manuals = MANUAL_TERRAIN; manuals < MANUAL_COUNT; manuals++) { int ri; char mnamebuf[20]; FILE *doc; @@ -371,48 +371,9 @@ static bool manual_command(struct tag_types *tag_info) switch (manuals) { case MANUAL_SETTINGS: - fc_assert(FALSE); - break; - case MANUAL_COMMANDS: - /* TRANS: markup ... Freeciv version ... markup */ - fprintf(doc, _("%sFreeciv %s server commands%s\n\n"), tag_info->title_begin, - VERSION_STRING, tag_info->title_end); - for (i = 0; i < CMD_NUM; i++) { - const struct command *cmd = command_by_number(i); - - fprintf(doc, tag_info->item_begin, "cmd", i); - fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin, - command_name(cmd), command_short_help(cmd), - tag_info->sect_title_end); - if (command_synopsis(cmd)) { - char *cmdstr = fc_strdup(command_synopsis(cmd)); - size_t cmdstr_len = strlen(cmdstr) + 1; - - cmdstr = html_special_chars(cmdstr, &cmdstr_len); - fprintf(doc, _("\n\n\n
" - "
Synopsis:
")); - fprintf(doc, "
%s
", cmdstr); - FC_FREE(cmdstr); - } - fprintf(doc, _("

Level: %s

\n"), - cmdlevel_name(command_level(cmd))); - { - char *help = command_extra_help(cmd); - if (help) { - size_t help_len = strlen(help) + 1; - - fc_break_lines(help, LINE_BREAK); - help = html_special_chars(help, &help_len); - fprintf(doc, "\n"); - fprintf(doc, _("

Description:

\n\n")); - fprintf(doc, "
%s
\n", help); - FC_FREE(help); - } - } - - fprintf(doc, "%s", tag_info->item_end); - } + /* Should be handled in separate functions */ + fc_assert(FALSE); break; case MANUAL_TERRAIN: diff --git a/tools/manual/fc_manual.h b/tools/manual/fc_manual.h index efdf455799..5958a548f8 100644 --- a/tools/manual/fc_manual.h +++ b/tools/manual/fc_manual.h @@ -60,6 +60,7 @@ char *html_special_chars(char *str, size_t *len); /* Individual manual pages */ bool manual_settings(struct tag_types *tag_info); +bool manual_commands(struct tag_types *tag_info); #ifdef __cplusplus } diff --git a/tools/manual/manual_commands.c b/tools/manual/manual_commands.c new file mode 100644 index 0000000000..0b44fc0017 --- /dev/null +++ b/tools/manual/manual_commands.c @@ -0,0 +1,87 @@ +/*********************************************************************** + 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" + +/* server */ +#include "commands.h" + +/* tools/manual */ +#include "fc_manual.h" + +/**********************************************************************//** + Write commands manual page + + @param tag_info Tag set to use + @return Success +**************************************************************************/ +bool manual_commands(struct tag_types *tag_info) +{ + FILE *doc; + int i; + + doc = manual_start(tag_info, MANUAL_COMMANDS); + + if (doc == NULL) { + return FALSE; + } + + /* TRANS: markup ... Freeciv version ... markup */ + fprintf(doc, _("%sFreeciv %s server commands%s\n\n"), tag_info->title_begin, + VERSION_STRING, tag_info->title_end); + for (i = 0; i < CMD_NUM; i++) { + const struct command *cmd = command_by_number(i); + + fprintf(doc, tag_info->item_begin, "cmd", i); + fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin, + command_name(cmd), command_short_help(cmd), + tag_info->sect_title_end); + if (command_synopsis(cmd)) { + char *cmdstr = fc_strdup(command_synopsis(cmd)); + size_t cmdstr_len = strlen(cmdstr) + 1; + + cmdstr = html_special_chars(cmdstr, &cmdstr_len); + fprintf(doc, _("\n\n\n
" + "
Synopsis:
")); + fprintf(doc, "
%s
", cmdstr); + free(cmdstr); + } + fprintf(doc, _("

Level: %s

\n"), + cmdlevel_name(command_level(cmd))); + { + char *help = command_extra_help(cmd); + + if (help) { + size_t help_len = strlen(help) + 1; + + fc_break_lines(help, LINE_BREAK); + help = html_special_chars(help, &help_len); + fprintf(doc, "\n"); + fprintf(doc, _("

Description:

\n\n")); + fprintf(doc, "
%s
\n", help); + free(help); + } + } + + fprintf(doc, "%s", tag_info->item_end); + } + + manual_finalize(tag_info, doc, _("Commands")); + + return TRUE; +} -- 2.40.1