From 6431f11671fed87a7a1b83982e3ab66af9fb9bb4 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist
Date: Thu, 28 Sep 2023 23:09:46 +0300
Subject: [PATCH 22/41] Split Settings manual creation to separate source file
See osdn #48742
Signed-off-by: Marko Lindqvist
---
meson.build | 1 +
tools/manual/Makefile.am | 6 +-
tools/manual/fc_manual.c | 198 ++++++++++-----------------------
tools/manual/fc_manual.h | 68 +++++++++++
tools/manual/manual_settings.c | 139 +++++++++++++++++++++++
translations/core/POTFILES.in | 1 +
6 files changed, 274 insertions(+), 139 deletions(-)
create mode 100644 tools/manual/fc_manual.h
create mode 100644 tools/manual/manual_settings.c
diff --git a/meson.build b/meson.build
index 3593bbfe7a..832b9398f3 100644
--- a/meson.build
+++ b/meson.build
@@ -4205,6 +4205,7 @@ if get_option('tools').contains('manual')
executable('freeciv-manual',
'tools/manual/fc_manual.c',
+ 'tools/manual/manual_settings.c',
'client/helpdata.c',
link_with: [common_lib, server_lib, tool_lib, ais],
include_directories: [tool_inc,
diff --git a/tools/manual/Makefile.am b/tools/manual/Makefile.am
index 0cb2b8bc35..6f8b36dea2 100644
--- a/tools/manual/Makefile.am
+++ b/tools/manual/Makefile.am
@@ -17,8 +17,10 @@ common_cppflags = \
AM_CPPFLAGS = $(common_cppflags)
-freeciv_manual_SOURCES = \
- fc_manual.c
+freeciv_manual_SOURCES = \
+ fc_manual.c \
+ fc_manual.h \
+ manual_settings.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 32300c0d47..c122eb1642 100644
--- a/tools/manual/fc_manual.c
+++ b/tools/manual/fc_manual.c
@@ -16,7 +16,6 @@
#endif
#include
-#include
#include
#include
@@ -32,7 +31,6 @@
#include "log.h"
#include "mem.h"
#include "registry.h"
-#include "support.h"
/* common */
#include "capstr.h"
@@ -75,34 +73,9 @@
/* tools/shared */
#include "tools_fc_interface.h"
-enum manuals {
- MANUAL_SETTINGS,
- MANUAL_COMMANDS,
- MANUAL_TERRAIN,
- MANUAL_BUILDINGS,
- MANUAL_WONDERS,
- MANUAL_GOVS,
- MANUAL_UNITS,
- MANUAL_TECHS,
- MANUAL_COUNT
-};
+/* tools/manual */
+#include "fc_manual.h"
-struct tag_types {
- const char *file_ext;
- const char *header;
- const char *title_begin;
- const char *title_end;
- const char *sect_title_begin;
- const char *sect_title_end;
- const char *image_begin;
- const char *image_end;
- const char *item_begin;
- const char *item_end;
- const char *subitem_begin;
- const char *subitem_end;
- const char *tail;
- const char *hline;
-};
struct tag_types html_tags = {
/* file extension */
@@ -205,7 +178,7 @@ static char *ruleset = NULL;
/**********************************************************************//**
Replace html special characters ('&', '<' and '>').
**************************************************************************/
-static char *html_special_chars(char *str, size_t *len)
+char *html_special_chars(char *str, size_t *len)
{
char *buf;
@@ -219,7 +192,7 @@ static char *html_special_chars(char *str, size_t *len)
/*******************************************
Useless stubs for compiling client code.
-*/
+*******************************************/
/**********************************************************************//**
Client stub
@@ -321,19 +294,56 @@ bool client_nation_is_in_current_set(const struct nation_type *pnation)
return TRUE;
}
+/**********************************************************************//**
+ Create manual file, and do the generic header for it.
+
+ @param tag_info Tag set to use
+ @param manual_number Number of the manual page
+ @return Handle of the created file
+**************************************************************************/
+FILE *manual_start(struct tag_types *tag_info, int manual_number)
+{
+ char filename[40];
+ FILE *doc;
+
+ fc_snprintf(filename, sizeof(filename), "%s%d.%s",
+ game.server.rulesetdir, manual_number + 1, tag_info->file_ext);
+
+ if (!is_reg_file_for_access(filename, TRUE)
+ || !(doc = fc_fopen(filename, "w"))) {
+ log_error(_("Could not write manual file %s."), filename);
+
+ return NULL;
+ }
+
+ fprintf(doc, "%s", tag_info->header);
+ fprintf(doc, "\n\n",
+ freeciv_datafile_version());
+
+ return doc;
+}
+
+/**********************************************************************//**
+ Generic finalizing step for a manual page. Closes the file.
+
+ @param tag_info Tag set to use
+ @param doc Manual handle
+ @param manual_name Name of the manual
+**************************************************************************/
+void manual_finalize(struct tag_types *tag_info, FILE *doc,
+ const char *manual_name)
+{
+ fprintf(doc, "%s", tag_info->tail);
+ fclose(doc);
+ log_normal(_("%s manual successfully written."), manual_name);
+}
+
/**********************************************************************//**
Write a server manual, then quit.
**************************************************************************/
static bool manual_command(struct tag_types *tag_info)
{
- FILE *doc;
- char filename[40];
enum manuals manuals;
- struct connection my_conn;
-
- /* Default client access. */
- connection_common_init(&my_conn);
- my_conn.access_level = ALLOW_CTRL;
/* Reset aifill to zero */
game.info.aifill = 0;
@@ -343,111 +353,25 @@ static bool manual_command(struct tag_types *tag_info)
return FALSE;
}
- for (manuals = 0; manuals < MANUAL_COUNT; manuals++) {
+ if (!manual_settings(tag_info)) {
+ return FALSE;
+ }
+
+ for (manuals = MANUAL_COMMANDS; manuals < MANUAL_COUNT; manuals++) {
int i;
int ri;
+ char mnamebuf[20];
+ FILE *doc;
- fc_snprintf(filename, sizeof(filename), "%s%d.%s",
- game.server.rulesetdir, manuals + 1, tag_info->file_ext);
+ doc = manual_start(tag_info, manuals);
- if (!is_reg_file_for_access(filename, TRUE)
- || !(doc = fc_fopen(filename, "w"))) {
- log_error(_("Could not write manual file %s."), filename);
+ if (doc == NULL) {
return FALSE;
}
- fprintf(doc, "%s", tag_info->header);
- fprintf(doc, "\n\n",
- freeciv_datafile_version());
-
switch (manuals) {
case MANUAL_SETTINGS:
- /* TRANS: markup ... Freeciv version ... markup */
- fprintf(doc, _("%sFreeciv %s server options%s\n\n"), tag_info->title_begin,
- VERSION_STRING, tag_info->title_end);
- settings_iterate(SSET_ALL, pset) {
- char buf[256];
- const char *sethelp;
-
- fprintf(doc, tag_info->item_begin, "setting", setting_number(pset));
- fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin,
- setting_name(pset), _(setting_short_help(pset)),
- tag_info->sect_title_end);
- sethelp = _(setting_extra_help(pset, TRUE));
- if (strlen(sethelp) > 0) {
- char *help = fc_strdup(sethelp);
- size_t help_len = strlen(help) + 1;
-
- fc_break_lines(help, LINE_BREAK);
- help = html_special_chars(help, &help_len);
- fprintf(doc, "%s
\n\n", help);
- FC_FREE(help);
- }
- fprintf(doc, "");
- fprintf(doc, _("Level: %s.
"),
- _(sset_level_name(setting_level(pset))));
- fprintf(doc, _("Category: %s.
"),
- _(sset_category_name(setting_category(pset))));
-
- /* First check if the setting is locked because this is included in
- * the function setting_is_changeable() */
- if (setting_ruleset_locked(pset)) {
- fprintf(doc, _("Is locked by the ruleset."));
- } else if (!setting_is_changeable(pset, &my_conn, NULL, 0)) {
- fprintf(doc, _("Can only be used in server console."));
- }
-
- fprintf(doc, "
\n");
- setting_default_name(pset, TRUE, buf, sizeof(buf));
- switch (setting_type(pset)) {
- case SST_INT:
- fprintf(doc, "\n%s %d, %s %s, %s %d
\n",
- _("Minimum:"), setting_int_min(pset),
- _("Default:"), buf,
- _("Maximum:"), setting_int_max(pset));
- break;
- case SST_ENUM:
- {
- const char *value;
-
- fprintf(doc, "\n%s
",
- _("Possible values:"));
- for (i = 0; (value = setting_enum_val(pset, i, FALSE)); i++) {
- fprintf(doc, "\n %s: \"%s\"
",
- value, setting_enum_val(pset, i, TRUE));
- }
- }
- break;
- case SST_BITWISE:
- {
- const char *value;
-
- fprintf(doc, "\n%s
",
- _("Possible values (option can take any number of these):"));
- for (i = 0; (value = setting_bitwise_bit(pset, i, FALSE)); i++) {
- fprintf(doc, "\n %s: \"%s\"",
- value, setting_bitwise_bit(pset, i, TRUE));
- }
- }
- break;
- case SST_BOOL:
- case SST_STRING:
- break;
- case SST_COUNT:
- fc_assert(setting_type(pset) != SST_COUNT);
- break;
- }
- if (SST_INT != setting_type(pset)) {
- fprintf(doc, "\n%s %s
\n",
- _("Default:"), buf);
- }
- if (setting_non_default(pset)) {
- fprintf(doc, _("\nValue set to %s
\n"),
- setting_value_name(pset, TRUE, buf, sizeof(buf)));
- }
-
- fprintf(doc, "%s", tag_info->item_end);
- } settings_iterate_end;
+ fc_assert(FALSE);
break;
case MANUAL_COMMANDS:
@@ -808,9 +732,9 @@ static bool manual_command(struct tag_types *tag_info)
} /* switch */
- fprintf(doc, "%s", tag_info->tail);
- fclose(doc);
- log_normal(_("Manual file %s successfully written."), filename);
+ fc_snprintf(mnamebuf, sizeof(mnamebuf), "%d", manuals + 1);
+
+ manual_finalize(tag_info, doc, mnamebuf);
} /* manuals */
return TRUE;
diff --git a/tools/manual/fc_manual.h b/tools/manual/fc_manual.h
new file mode 100644
index 0000000000..efdf455799
--- /dev/null
+++ b/tools/manual/fc_manual.h
@@ -0,0 +1,68 @@
+/***********************************************************************
+ 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.
+***********************************************************************/
+#ifndef FC__FC_MANUAL_H
+#define FC__FC_MANUAL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include /* FILE */
+
+/* utility */
+#include "support.h"
+
+
+enum manuals {
+ MANUAL_SETTINGS,
+ MANUAL_COMMANDS,
+ MANUAL_TERRAIN,
+ MANUAL_BUILDINGS,
+ MANUAL_WONDERS,
+ MANUAL_GOVS,
+ MANUAL_UNITS,
+ MANUAL_TECHS,
+ MANUAL_COUNT
+};
+
+struct tag_types {
+ const char *file_ext;
+ const char *header;
+ const char *title_begin;
+ const char *title_end;
+ const char *sect_title_begin;
+ const char *sect_title_end;
+ const char *image_begin;
+ const char *image_end;
+ const char *item_begin;
+ const char *item_end;
+ const char *subitem_begin;
+ const char *subitem_end;
+ const char *tail;
+ const char *hline;
+};
+
+/* Utility functions */
+FILE *manual_start(struct tag_types *tag_info, int manual_number);
+void manual_finalize(struct tag_types *tag_info, FILE *doc,
+ const char *manual_name);
+char *html_special_chars(char *str, size_t *len);
+
+/* Individual manual pages */
+bool manual_settings(struct tag_types *tag_info);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* FC__FC_MANUAL_H */
diff --git a/tools/manual/manual_settings.c b/tools/manual/manual_settings.c
new file mode 100644
index 0000000000..83222a740b
--- /dev/null
+++ b/tools/manual/manual_settings.c
@@ -0,0 +1,139 @@
+/***********************************************************************
+ 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 "settings.h"
+
+/* tools/manual */
+#include "fc_manual.h"
+
+/**********************************************************************//**
+ Write settings manual page
+
+ @param tag_info Tag set to use
+ @return Success
+**************************************************************************/
+bool manual_settings(struct tag_types *tag_info)
+{
+ FILE *doc;
+ struct connection dummy_conn;
+ int i;
+
+ doc = manual_start(tag_info, MANUAL_SETTINGS);
+
+ if (doc == NULL) {
+ return FALSE;
+ }
+
+ /* Default client access. */
+ connection_common_init(&dummy_conn);
+ dummy_conn.access_level = ALLOW_CTRL;
+
+ /* TRANS: markup ... Freeciv version ... markup */
+ fprintf(doc, _("%sFreeciv %s server options%s\n\n"), tag_info->title_begin,
+ VERSION_STRING, tag_info->title_end);
+ settings_iterate(SSET_ALL, pset) {
+ char buf[256];
+ const char *sethelp;
+
+ fprintf(doc, tag_info->item_begin, "setting", setting_number(pset));
+ fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin,
+ setting_name(pset), _(setting_short_help(pset)),
+ tag_info->sect_title_end);
+ sethelp = _(setting_extra_help(pset, TRUE));
+ if (strlen(sethelp) > 0) {
+ char *help = fc_strdup(sethelp);
+ size_t help_len = strlen(help) + 1;
+
+ fc_break_lines(help, LINE_BREAK);
+ help = html_special_chars(help, &help_len);
+ fprintf(doc, "%s
\n\n", help);
+ FC_FREE(help);
+ }
+ fprintf(doc, "");
+ fprintf(doc, _("Level: %s.
"),
+ _(sset_level_name(setting_level(pset))));
+ fprintf(doc, _("Category: %s.
"),
+ _(sset_category_name(setting_category(pset))));
+
+ /* First check if the setting is locked because this is included in
+ * the function setting_is_changeable() */
+ if (setting_ruleset_locked(pset)) {
+ fprintf(doc, _("Is locked by the ruleset."));
+ } else if (!setting_is_changeable(pset, &dummy_conn, NULL, 0)) {
+ fprintf(doc, _("Can only be used in server console."));
+ }
+
+ fprintf(doc, "
\n");
+ setting_default_name(pset, TRUE, buf, sizeof(buf));
+ switch (setting_type(pset)) {
+ case SST_INT:
+ fprintf(doc, "\n%s %d, %s %s, %s %d
\n",
+ _("Minimum:"), setting_int_min(pset),
+ _("Default:"), buf,
+ _("Maximum:"), setting_int_max(pset));
+ break;
+ case SST_ENUM:
+ {
+ const char *value;
+
+ fprintf(doc, "\n%s
",
+ _("Possible values:"));
+ for (i = 0; (value = setting_enum_val(pset, i, FALSE)); i++) {
+ fprintf(doc, "\n %s: \"%s\"",
+ value, setting_enum_val(pset, i, TRUE));
+ }
+ }
+ break;
+ case SST_BITWISE:
+ {
+ const char *value;
+
+ fprintf(doc, "\n%s
",
+ _("Possible values (option can take any number of these):"));
+ for (i = 0; (value = setting_bitwise_bit(pset, i, FALSE)); i++) {
+ fprintf(doc, "\n %s: \"%s\"",
+ value, setting_bitwise_bit(pset, i, TRUE));
+ }
+ }
+ break;
+ case SST_BOOL:
+ case SST_STRING:
+ break;
+ case SST_COUNT:
+ fc_assert(setting_type(pset) != SST_COUNT);
+ break;
+ }
+ if (SST_INT != setting_type(pset)) {
+ fprintf(doc, "\n%s %s
\n",
+ _("Default:"), buf);
+ }
+ if (setting_non_default(pset)) {
+ fprintf(doc, _("\nValue set to %s
\n"),
+ setting_value_name(pset, TRUE, buf, sizeof(buf)));
+ }
+
+ fprintf(doc, "%s", tag_info->item_end);
+ } settings_iterate_end;
+
+ manual_finalize(tag_info, doc, _("Settings"));
+
+ return TRUE;
+}
diff --git a/translations/core/POTFILES.in b/translations/core/POTFILES.in
index 364cb02970..0494c965fa 100644
--- a/translations/core/POTFILES.in
+++ b/translations/core/POTFILES.in
@@ -391,6 +391,7 @@ tools/fcmp/mpgui_gtk4.c
tools/fcmp/mpgui_qt.cpp
tools/fcmp/mpgui_qt_worker.cpp
tools/manual/fc_manual.c
+tools/manual/manual_settings.c
tools/ruleutil/rulesave.c
server/actiontools.c
server/aiiface.c
--
2.40.1