Freeciv-3.4
Loading...
Searching...
No Matches
fc_manual.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Project
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#include <stdarg.h>
19#include <stdlib.h>
20#include <string.h>
21
22#ifdef HAVE_SIGNAL_H
23#include <signal.h>
24#endif
25
26/* utility */
27#include "capability.h"
28#include "executable.h"
29#include "fc_cmdline.h"
30#include "fciconv.h"
31#include "fcintl.h"
32#include "log.h"
33#include "mem.h"
34#include "registry.h"
35
36/* common */
37#include "capstr.h"
38#include "connection.h"
39#include "fc_cmdhelp.h"
40#include "fc_interface.h"
41#include "version.h"
42
43/* client */
44#include "client_main.h"
45#include "climisc.h"
46#include "helpdata.h"
47#include "music.h"
48#include "tilespec.h"
49
50/* server */
51#include "ruleload.h"
52#include "settings.h"
53#include "sernet.h"
54#include "srv_main.h"
55#include "stdinhand.h"
56
57/* tools/shared */
58#include "tools_fc_interface.h"
59
60/* tools/manual */
61#include "fc_manual.h"
62
63
65 /* file extension */
66 "html",
67
68 /* header */
69 "<html><head><link rel=\"stylesheet\" type=\"text/css\" "
70 "href=\"manual.css\"/><meta http-equiv=\"Content-Type\" "
71 "content=\"text/html; charset=UTF-8\"/></head><body>\n\n",
72
73 /* title begin */
74 "<h1>",
75
76 /* title end */
77 "</h1>",
78
79 /* section title begin */
80 "<h3 class='section'>",
81
82 /* section title end */
83 "</h3>",
84
85 /* image begin */
86 "<img src=\"",
87
88 /* image end */
89 ".png\">",
90
91 /* item begin */
92 "<div class='item' id='%s%d'>\n",
93
94 /* item end */
95 "</div>\n",
96
97 /* subitem begin */
98 "<pre class='%s'>",
99
100 /* subitem end */
101 "</pre>\n",
102
103 /* tail */
104 "</body></html>",
105
106 /* horizontal line */
107 "<hr/>"
108};
109
111 /* file extension */
112 "mediawiki",
113
114 /* header */
115 " ",
116
117 /* title begin */
118 "=",
119
120 /* title end */
121 "=",
122
123 /* section title begin */
124 "===",
125
126 /* section title end */
127 "===",
128
129 /* image begin */
130 "[[Image:",
131
132 /* image end */
133 ".png]]",
134
135 /* item begin */
136 "----\n<!-- %s %d -->\n",
137
138 /* item end */
139 "\n",
140
141 /* subitem begin */
142 "<!-- %s -->\n",
143
144 /* subitem end */
145 "\n",
146
147 /* tail */
148 " ",
149
150 /* horizontal line */
151 "----"
152};
153
154
155void insert_client_build_info(char *outbuf, size_t outlen);
156
157/* Needed for "About Freeciv" help */
158const char *client_string = "freeciv-manual";
159
160static char *ruleset = NULL;
161
162/**********************************************************************/
165char *html_special_chars(char *str, size_t *len)
166{
167 char *buf;
168
169 buf = fc_strrep_resize(str, len, "&", "&amp;");
170 buf = fc_strrep_resize(buf, len, "<", "&lt;");
171 buf = fc_strrep_resize(buf, len, ">", "&gt;");
172
173 return buf;
174}
175
176
177/*******************************************
178 Useless stubs for compiling client code.
179*******************************************/
180
181/**********************************************************************/
185{
186 /* Empty stub. */
187}
188
189/**********************************************************************/
193{
194 /* Empty stub. */
195}
196
198
199/**********************************************************************/
202const char *tileset_name_get(struct tileset *t)
203{
204 return NULL;
205}
206
207/**********************************************************************/
210const char *tileset_version(struct tileset *t)
211{
212 return NULL;
213}
214
215/**********************************************************************/
218const char *tileset_summary(struct tileset *t)
219{
220 return NULL;
221}
222
223/**********************************************************************/
226const char *tileset_description(struct tileset *t)
227{
228 return NULL;
229}
230
231/**********************************************************************/
234const char *current_musicset_name(void)
235{
236 return NULL;
237}
238
239/**********************************************************************/
243{
244 return NULL;
245}
246
247/**********************************************************************/
251{
252 return NULL;
253}
254
255/**********************************************************************/
259{
260 return NULL;
261}
262
263/**********************************************************************/
267{
268 return C_S_INITIAL;
269}
270
271/**********************************************************************/
275{
276 /* Currently, there is no way to select a nation set for freeciv-manual.
277 * Then, let's assume we want to print help for all nations. */
278 return TRUE;
279}
280
281/**********************************************************************/
289{
290 char filename[40];
291 FILE *doc;
292
293 fc_snprintf(filename, sizeof(filename), "%s%d.%s",
295
296 if (!is_reg_file_for_access(filename, TRUE)
297 || !(doc = fc_fopen(filename, "w"))) {
298 log_error(_("Could not write manual file %s."), filename);
299
300 return NULL;
301 }
302
303 fprintf(doc, "%s", tag_info->header);
304 fprintf(doc, "<!-- Generated by freeciv-manual version %s -->\n\n",
306
307 return doc;
308}
309
310/**********************************************************************/
318 enum manuals manual)
319{
320 fprintf(doc, "%s", tag_info->tail);
321 fclose(doc);
322 log_normal(_("%s (%d) manual successfully written."),
323 _(manuals_name(manual)), manual + 1);
324}
325
326/**********************************************************************/
330{
331 /* Reset aifill to zero */
332 game.info.aifill = 0;
333
335 /* Failed to load correct ruleset */
336 return FALSE;
337 }
338
347 || !manual_techs(tag_info)) {
348 return FALSE;
349 }
350
351 return TRUE;
352}
353
354/**********************************************************************/
357int main(int argc, char **argv)
358{
359 int inx;
360 bool showhelp = FALSE;
361 bool showvers = FALSE;
362 char *option = NULL;
363 int retval = EXIT_SUCCESS;
364 struct tag_types *tag_info = &html_tags;
365
367
368 /* Initialize the fc_interface functions needed to generate the help
369 * text.
370 * fc_interface_init_tool() includes low level support like
371 * guaranteeing that fc_vsnprintf() will work after it,
372 * so this need to be early. */
374
377
378 /* Set the default log level. */
380
381 /* Parse command-line arguments... */
382 inx = 1;
383 while (inx < argc) {
384 if ((option = get_option_malloc("--ruleset", argv, &inx, argc, TRUE))) {
385 if (ruleset != NULL) {
386 fc_fprintf(stderr, _("Multiple rulesets requested. Only one "
387 "ruleset at a time is supported.\n"));
388 } else {
389 ruleset = option;
390 }
391 } else if (is_option("--help", argv[inx])) {
392 showhelp = TRUE;
393 break;
394 } else if (is_option("--version", argv[inx])) {
395 showvers = TRUE;
396 } else if ((option = get_option_malloc("--log", argv, &inx, argc, TRUE))) {
398 } else if (is_option("--wiki", argv[inx])) {
400#ifndef FREECIV_NDEBUG
401 } else if (is_option("--Fatal", argv[inx])) {
402 if (inx + 1 >= argc || '-' == argv[inx + 1][0]) {
404 } else if (str_to_int(argv[inx + 1], &srvarg.fatal_assertions)) {
405 inx++;
406 } else {
407 fc_fprintf(stderr, _("Invalid signal number \"%s\".\n"),
408 argv[inx + 1]);
409 inx++;
410 showhelp = TRUE;
411 }
412#endif /* FREECIV_NDEBUG */
413 } else if ((option = get_option_malloc("--debug", argv, &inx, argc, FALSE))) {
415 showhelp = TRUE;
416 break;
417 }
418 free(option);
419 } else {
420 fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[inx]);
422 }
423 inx++;
424 }
425
427
428 /* Must be before con_log_init() */
432 /* Logging available after this point */
433
434 /* Get common code to treat us as a tool. */
435 i_am_tool();
436
437 /* Initialize game with default values */
439
440 /* Set ruleset user requested in to use */
441 if (ruleset != NULL) {
443 }
444
446
447 if (showvers && !showhelp) {
450 } else if (showhelp) {
451 struct cmdhelp *help = cmdhelp_new(argv[0]);
452
453#ifdef FREECIV_DEBUG
454 cmdhelp_add(help, "d",
455 /* TRANS: "debug" is exactly what user must type, do not translate. */
456 _("debug LEVEL"),
457 _("Set debug log level (one of f,e,w,n,v,d, or "
458 "d:file1,min,max:...)"));
459#else /* FREECIV_DEBUG */
460 cmdhelp_add(help, "d",
461 /* TRANS: "debug" is exactly what user must type, do not translate. */
462 _("debug LEVEL"),
463 _("Set debug log level (one of f,e,w,n,v)"));
464#endif /* FREECIV_DEBUG */
465#ifndef FREECIV_NDEBUG
466 cmdhelp_add(help, "F",
467 /* TRANS: "Fatal" is exactly what user must type, do not translate. */
468 _("Fatal [SIGNAL]"),
469 _("Raise a signal on failed assertion"));
470#endif /* FREECIV_NDEBUG */
471 cmdhelp_add(help, "h", "help",
472 _("Print a summary of the options"));
473 cmdhelp_add(help, "l",
474 /* TRANS: "log" is exactly what user must type, do not translate. */
475 _("log FILE"),
476 _("Use FILE as logfile"));
477 cmdhelp_add(help, "r",
478 /* TRANS: "ruleset" is exactly what user must type, do not translate. */
479 _("ruleset RULESET"),
480 _("Make manual for RULESET"));
481 cmdhelp_add(help, "v", "version",
482 _("Print the version number"));
483 cmdhelp_add(help, "w", "wiki",
484 _("Write manual in wiki format"));
485
486 /* The function below prints a header and footer for the options.
487 * Furthermore, the options are sorted. */
489 cmdhelp_destroy(help);
490
492 }
493
494 if (!manual_command(tag_info)) {
496 }
497
502
503 return retval;
504}
505
506/**********************************************************************/
510{
511 /* Nothing here */
512}
#define str
Definition astring.c:76
void init_our_capability(void)
Definition capstr.c:87
client_states
Definition client_main.h:43
@ C_S_INITIAL
Definition client_main.h:44
char * incite_cost
Definition comments.c:76
void con_log_init(const char *log_filename, enum log_level level, int fatal_assertions)
Definition console.c:150
void con_log_close(void)
Definition console.c:167
void executable_init(void)
Definition executable.c:34
void cmdhelp_destroy(struct cmdhelp *pcmdhelp)
Definition fc_cmdhelp.c:70
void cmdhelp_display(struct cmdhelp *pcmdhelp, bool sort, bool gui_options, bool report_bugs)
Definition fc_cmdhelp.c:104
struct cmdhelp * cmdhelp_new(const char *cmdname)
Definition fc_cmdhelp.c:57
void cmdhelp_add(struct cmdhelp *pcmdhelp, const char *shortarg, const char *longarg, const char *helpstr,...)
Definition fc_cmdhelp.c:86
bool is_option(const char *option_name, char *option)
Definition fc_cmdline.c:112
char * get_option_malloc(const char *option_name, char **argv, int *i, int argc, bool gc)
Definition fc_cmdline.c:50
void cmdline_option_values_free(void)
Definition fc_cmdline.c:97
void libfreeciv_free(void)
static void i_am_tool(void)
const char * client_string
Definition fc_manual.c:158
struct tileset * tileset
Definition fc_manual.c:197
void manual_finalize(struct tag_types *tag_info, FILE *doc, enum manuals manual)
Definition fc_manual.c:317
int main(int argc, char **argv)
Definition fc_manual.c:357
const char * current_musicset_version(void)
Definition fc_manual.c:242
const char * current_musicset_name(void)
Definition fc_manual.c:234
const char * current_musicset_summary(void)
Definition fc_manual.c:250
const char * tileset_description(struct tileset *t)
Definition fc_manual.c:226
const char * current_musicset_description(void)
Definition fc_manual.c:258
bool client_nation_is_in_current_set(const struct nation_type *pnation)
Definition fc_manual.c:274
void popdown_help_dialog(void)
Definition fc_manual.c:192
const char * tileset_summary(struct tileset *t)
Definition fc_manual.c:218
static char * ruleset
Definition fc_manual.c:160
void popup_help_dialog_string(const char *item)
Definition fc_manual.c:184
char * html_special_chars(char *str, size_t *len)
Definition fc_manual.c:165
FILE * manual_start(struct tag_types *tag_info, int manual_number)
Definition fc_manual.c:288
void insert_client_build_info(char *outbuf, size_t outlen)
Definition fc_manual.c:509
enum client_states client_state(void)
Definition fc_manual.c:266
static bool manual_command(struct tag_types *tag_info)
Definition fc_manual.c:329
const char * tileset_name_get(struct tileset *t)
Definition fc_manual.c:202
const char * tileset_version(struct tileset *t)
Definition fc_manual.c:210
struct tag_types html_tags
Definition fc_manual.c:64
struct tag_types wiki_tags
Definition fc_manual.c:110
bool manual_terrain(struct tag_types *tag_info)
bool manual_units(struct tag_types *tag_info)
bool manual_buildings(struct tag_types *tag_info)
bool manual_extras(struct tag_types *tag_info)
bool manual_settings(struct tag_types *tag_info)
bool manual_governments(struct tag_types *tag_info)
bool manual_commands(struct tag_types *tag_info)
bool manual_techs(struct tag_types *tag_info)
bool manual_uclasses(struct tag_types *tag_info)
static char void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Definition fciconv.c:70
#define FC_DEFAULT_DATA_ENCODING
Definition fciconv.h:89
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:62
void game_init(bool keep_ruleset_value)
Definition game.c:446
bool log_parse_level_str(const char *level_str, enum log_level *ret_level)
Definition log.c:86
#define log_normal(message,...)
Definition log.h:108
@ LOG_NORMAL
Definition log.h:33
#define log_error(message,...)
Definition log.h:104
int len
Definition packhand.c:128
void registry_module_init(void)
Definition registry.c:31
void registry_module_close(void)
Definition registry.c:41
bool load_rulesets(const char *restore, const char *alt, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Definition ruleload.c:9413
void init_connections(void)
Definition sernet.c:1362
void settings_init(bool act)
Definition settings.c:5257
bool str_to_int(const char *str, int *pint)
Definition shared.c:515
struct server_arguments srvarg
Definition srv_main.c:182
struct packet_game_info info
Definition game.h:89
char rulesetdir[MAX_LEN_NAME]
Definition game.h:246
struct civ_game::@32::@36 server
Definition climisc.h:82
enum log_level loglevel
Definition srv_main.h:40
char * log_filename
Definition srv_main.h:42
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
FILE * fc_fopen(const char *filename, const char *opentype)
Definition support.c:505
bool is_reg_file_for_access(const char *name, bool write_access)
Definition support.c:1120
char * fc_strrep_resize(char *str, size_t *len, const char *search, const char *replace)
Definition support.c:681
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void fc_interface_init_tool(void)
const char * freeciv_name_version(void)
Definition version.c:35
const char * freeciv_datafile_version(void)
Definition version.c:186