Freeciv-3.3: /fast/freeciv/nightly/main/tools/manual/manual_settings.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
manual_settings.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20
21/* server */
22#include "settings.h"
23
24/* tools/manual */
25#include "fc_manual.h"
26
27/**********************************************************************/
33 bool manual_settings(struct tag_types *tag_info)
34{
35 FILE *doc;
36 struct connection dummy_conn;
37 int i;
38
39 doc = manual_start(tag_info, MANUAL_SETTINGS);
40
41 if (doc == NULL) {
42 return FALSE;
43 }
44
45 /* Default client access. */
46 connection_common_init(&dummy_conn);
47 dummy_conn.access_level = ALLOW_CTRL;
48
49 /* TRANS: markup ... Freeciv version ... markup */
50 fprintf(doc, _("%sFreeciv %s server settings%s\n\n"), tag_info->title_begin,
51 VERSION_STRING, tag_info->title_end);
52 settings_iterate(SSET_ALL, pset) {
53 char buf[256];
54 const char *sethelp;
55
56 fprintf(doc, tag_info->item_begin, "setting", setting_number(pset));
57 fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin,
58 setting_name(pset), _(setting_short_help(pset)),
59 tag_info->sect_title_end);
60 sethelp = _(setting_extra_help(pset, TRUE));
61 if (strlen(sethelp) > 0) {
62 char *help = fc_strdup(sethelp);
63 size_t help_len = strlen(help) + 1;
64
65 fc_break_lines(help, LINE_BREAK);
66 help = html_special_chars(help, &help_len);
67 fprintf(doc, "<pre>%s</pre>\n\n", help);
68 FC_FREE(help);
69 }
70 fprintf(doc, "<p class=\"misc\">");
71 fprintf(doc, _("Level: %s.<br>"),
72 _(sset_level_name(setting_level(pset))));
73 fprintf(doc, _("Category: %s.<br>"),
74 _(sset_category_name(setting_category(pset))));
75
76 /* First check if the setting is locked because this is included in
77 * the function setting_is_changeable() */
78 if (setting_ruleset_locked(pset)) {
79 fprintf(doc, _("Is locked by the ruleset."));
80 } else if (!setting_is_changeable(pset, &dummy_conn, NULL, 0)) {
81 fprintf(doc, _("Can only be used in server console."));
82 }
83
84 fprintf(doc, "</p>\n");
85 setting_default_name(pset, TRUE, buf, sizeof(buf));
86 switch (setting_type(pset)) {
87 case SST_INT:
88 fprintf(doc, "\n<p class=\"bounds\">%s %d, %s %s, %s %d</p>\n",
89 _("Minimum:"), setting_int_min(pset),
90 _("Default:"), buf,
91 _("Maximum:"), setting_int_max(pset));
92 break;
93 case SST_ENUM:
94 {
95 const char *value;
96
97 fprintf(doc, "\n<p class=\"bounds\">%s</p><ul>",
98 _("Possible values:"));
99 for (i = 0; (value = setting_enum_val(pset, i, FALSE)); i++) {
100 fprintf(doc, "\n<li><p class=\"bounds\"> %s: \"%s\"</p>",
101 value, setting_enum_val(pset, i, TRUE));
102 }
103 fprintf(doc, "</ul>\n");
104 }
105 break;
106 case SST_BITWISE:
107 {
108 const char *value;
109
110 fprintf(doc, "\n<p class=\"bounds\">%s</p><ul>",
111 _("Possible values (option can take any number of these):"));
112 for (i = 0; (value = setting_bitwise_bit(pset, i, FALSE)); i++) {
113 fprintf(doc, "\n<li><p class=\"bounds\"> %s: \"%s\"</p>",
114 value, setting_bitwise_bit(pset, i, TRUE));
115 }
116 fprintf(doc, "</ul>\n");
117 }
118 break;
119 case SST_BOOL:
120 case SST_STRING:
121 break;
122 case SST_COUNT:
123 fc_assert(setting_type(pset) != SST_COUNT);
124 break;
125 }
126 if (SST_INT != setting_type(pset)) {
127 fprintf(doc, "\n<p class=\"bounds\">%s %s</p>\n",
128 _("Default:"), buf);
129 }
130 if (setting_non_default(pset)) {
131 fprintf(doc, _("\n<p class=\"changed\">Value set to %s</p>\n"),
132 setting_value_name(pset, TRUE, buf, sizeof(buf)));
133 }
134
135 fprintf(doc, "%s", tag_info->item_end);
136 } settings_iterate_end;
137
138 manual_finalize(tag_info, doc, MANUAL_SETTINGS);
139
140 return TRUE;
141}
incite_cost
char * incite_cost
Definition comments.c:74
connection_common_init
void connection_common_init(struct connection *pconn)
Definition connection.c:603
manual_finalize
void manual_finalize(struct tag_types *tag_info, FILE *doc, enum manuals manual)
Definition fc_manual.c:316
html_special_chars
char * html_special_chars(char *str, size_t *len)
Definition fc_manual.c:164
manual_start
FILE * manual_start(struct tag_types *tag_info, int manual_number)
Definition fc_manual.c:287
fc_manual.h
LINE_BREAK
#define LINE_BREAK
Definition fc_types.h:77
fcintl.h
_
#define _(String)
Definition fcintl.h:67
fc_assert
#define fc_assert(condition)
Definition log.h:176
manual_settings
bool manual_settings(struct tag_types *tag_info)
Definition manual_settings.c:33
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_strdup
#define fc_strdup(str)
Definition mem.h:43
setting_ruleset_locked
bool setting_ruleset_locked(const struct setting *pset)
Definition settings.c:4641
setting_default_name
const char * setting_default_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4296
setting_value_name
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4260
setting_extra_help
const char * setting_extra_help(const struct setting *pset, bool constant)
Definition settings.c:3343
setting_number
int setting_number(const struct setting *pset)
Definition settings.c:3317
setting_category
enum sset_category setting_category(const struct setting *pset)
Definition settings.c:3371
setting_non_default
bool setting_non_default(const struct setting *pset)
Definition settings.c:4607
setting_type
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3355
setting_int_max
int setting_int_max(const struct setting *pset)
Definition settings.c:3726
setting_level
enum sset_level setting_level(const struct setting *pset)
Definition settings.c:3363
setting_enum_val
const char * setting_enum_val(const struct setting *pset, int val, bool pretty)
Definition settings.c:3886
setting_short_help
const char * setting_short_help(const struct setting *pset)
Definition settings.c:3334
setting_bitwise_bit
const char * setting_bitwise_bit(const struct setting *pset, int bit, bool pretty)
Definition settings.c:4081
setting_int_min
int setting_int_min(const struct setting *pset)
Definition settings.c:3717
setting_is_changeable
bool setting_is_changeable(const struct setting *pset, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3453
setting_name
const char * setting_name(const struct setting *pset)
Definition settings.c:3326
settings.h
settings_iterate
#define settings_iterate(_level, _pset)
Definition settings.h:188
settings_iterate_end
#define settings_iterate_end
Definition settings.h:194
connection
Definition connection.h:136
tag_types
Definition fc_manual.h:28
fc_break_lines
int fc_break_lines(char *str, size_t desired_len)
Definition support.c:1135
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47