Freeciv-3.2
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#ifdef FREECIV_MSWINDOWS
27#include <windows.h>
28#endif
29
30/* utility */
31#include "capability.h"
32#include "fc_cmdline.h"
33#include "fciconv.h"
34#include "fcintl.h"
35#include "log.h"
36#include "mem.h"
37#include "registry.h"
38
39/* common */
40#include "capstr.h"
41#include "connection.h"
42#include "fc_cmdhelp.h"
43#include "fc_interface.h"
44#include "version.h"
45
46/* client */
47#include "client_main.h"
48#include "climisc.h"
49#include "helpdata.h"
50#include "music.h"
51#include "tilespec.h"
52
53/* server */
54#include "ruleset.h"
55#include "settings.h"
56#include "sernet.h"
57#include "srv_main.h"
58#include "stdinhand.h"
59
60/* tools/shared */
61#include "tools_fc_interface.h"
62
63/* tools/manual */
64#include "fc_manual.h"
65
66
68 /* file extension */
69 "html",
70
71 /* header */
72 "<html><head><link rel=\"stylesheet\" type=\"text/css\" "
73 "href=\"manual.css\"/><meta http-equiv=\"Content-Type\" "
74 "content=\"text/html; charset=UTF-8\"/></head><body>\n\n",
75
76 /* title begin */
77 "<h1>",
78
79 /* title end */
80 "</h1>",
81
82 /* section title begin */
83 "<h3 class='section'>",
84
85 /* section title end */
86 "</h3>",
87
88 /* image begin */
89 "<img src=\"",
90
91 /* image end */
92 ".png\">",
93
94 /* item begin */
95 "<div class='item' id='%s%d'>\n",
96
97 /* item end */
98 "</div>\n",
99
100 /* subitem begin */
101 "<pre class='%s'>",
102
103 /* subitem end */
104 "</pre>\n",
105
106 /* tail */
107 "</body></html>",
108
109 /* horizontal line */
110 "<hr/>"
111};
112
114 /* file extension */
115 "mediawiki",
116
117 /* header */
118 " ",
119
120 /* title begin */
121 "=",
122
123 /* title end */
124 "=",
125
126 /* section title begin */
127 "===",
128
129 /* section title end */
130 "===",
131
132 /* image begin */
133 "[[Image:",
134
135 /* image end */
136 ".png]]",
137
138 /* item begin */
139 "----\n<!-- %s %d -->\n",
140
141 /* item end */
142 "\n",
143
144 /* subitem begin */
145 "<!-- %s -->\n",
146
147 /* subitem end */
148 "\n",
149
150 /* tail */
151 " ",
152
153 /* horizontal line */
154 "----"
155};
156
157
158void insert_client_build_info(char *outbuf, size_t outlen);
159
160/* Needed for "About Freeciv" help */
161const char *client_string = "freeciv-manual";
162
163static char *ruleset = NULL;
164
165/**********************************************************************/
168char *html_special_chars(char *str, size_t *len)
169{
170 char *buf;
171
172 buf = fc_strrep_resize(str, len, "&", "&amp;");
173 buf = fc_strrep_resize(buf, len, "<", "&lt;");
174 buf = fc_strrep_resize(buf, len, ">", "&gt;");
175
176 return buf;
177}
178
179
180/*******************************************
181 Useless stubs for compiling client code.
182*******************************************/
183
184/**********************************************************************/
188{
189 /* Empty stub. */
190}
191
192/**********************************************************************/
196{
197 /* Empty stub. */
198}
199
201
202/**********************************************************************/
205const char *tileset_name_get(struct tileset *t)
206{
207 return NULL;
208}
209
210/**********************************************************************/
213const char *tileset_version(struct tileset *t)
214{
215 return NULL;
216}
217
218/**********************************************************************/
221const char *tileset_summary(struct tileset *t)
222{
223 return NULL;
224}
225
226/**********************************************************************/
229const char *tileset_description(struct tileset *t)
230{
231 return NULL;
232}
233
234/**********************************************************************/
237const char *current_musicset_name(void)
238{
239 return NULL;
240}
241
242/**********************************************************************/
246{
247 return NULL;
248}
249
250/**********************************************************************/
254{
255 return NULL;
256}
257
258/**********************************************************************/
262{
263 return NULL;
264}
265
266/**********************************************************************/
270{
271 return C_S_INITIAL;
272}
273
274/**********************************************************************/
278{
279 /* Currently, there is no way to select a nation set for freeciv-manual.
280 * Then, let's assume we want to print help for all nations. */
281 return TRUE;
282}
283
284/**********************************************************************/
292{
293 char filename[40];
294 FILE *doc;
295
296 fc_snprintf(filename, sizeof(filename), "%s%d.%s",
298
299 if (!is_reg_file_for_access(filename, TRUE)
300 || !(doc = fc_fopen(filename, "w"))) {
301 log_error(_("Could not write manual file %s."), filename);
302
303 return NULL;
304 }
305
306 fprintf(doc, "%s", tag_info->header);
307 fprintf(doc, "<!-- Generated by freeciv-manual version %s -->\n\n",
309
310 return doc;
311}
312
313/**********************************************************************/
321 enum manuals manual)
322{
323 fprintf(doc, "%s", tag_info->tail);
324 fclose(doc);
325 log_normal(_("%s (%d) manual successfully written."),
326 _(manuals_name(manual)), manual + 1);
327}
328
329/**********************************************************************/
333{
334 /* Reset aifill to zero */
335 game.info.aifill = 0;
336
338 /* Failed to load correct ruleset */
339 return FALSE;
340 }
341
350 || !manual_techs(tag_info)) {
351 return FALSE;
352 }
353
354 return TRUE;
355}
356
357/**********************************************************************/
360int main(int argc, char **argv)
361{
362 int inx;
363 bool showhelp = FALSE;
364 bool showvers = FALSE;
365 char *option = NULL;
366 int retval = EXIT_SUCCESS;
367 struct tag_types *tag_info = &html_tags;
368
369 /* Load Windows post-crash debugger */
370#ifdef FREECIV_MSWINDOWS
371# ifndef FREECIV_NDEBUG
372 if (LoadLibrary("exchndl.dll") == NULL) {
373# ifdef FREECIV_DEBUG
374 fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n");
375# endif /* FREECIV_DEBUG */
376 }
377# endif /* FREECIV_NDEBUG */
378#endif /* FREECIV_MSWINDOWS */
379
380 /* Initialize the fc_interface functions needed to generate the help
381 * text.
382 * fc_interface_init_tool() includes low level support like
383 * guaranteeing that fc_vsnprintf() will work after it,
384 * so this need to be early. */
386
389
390 /* Set the default log level. */
392
393 /* Parse command-line arguments... */
394 inx = 1;
395 while (inx < argc) {
396 if ((option = get_option_malloc("--ruleset", argv, &inx, argc, TRUE))) {
397 if (ruleset != NULL) {
398 fc_fprintf(stderr, _("Multiple rulesets requested. Only one "
399 "ruleset at a time is supported.\n"));
400 } else {
401 ruleset = option;
402 }
403 } else if (is_option("--help", argv[inx])) {
404 showhelp = TRUE;
405 break;
406 } else if (is_option("--version", argv[inx])) {
407 showvers = TRUE;
408 } else if ((option = get_option_malloc("--log", argv, &inx, argc, TRUE))) {
410 } else if (is_option("--wiki", argv[inx])) {
412#ifndef FREECIV_NDEBUG
413 } else if (is_option("--Fatal", argv[inx])) {
414 if (inx + 1 >= argc || '-' == argv[inx + 1][0]) {
416 } else if (str_to_int(argv[inx + 1], &srvarg.fatal_assertions)) {
417 inx++;
418 } else {
419 fc_fprintf(stderr, _("Invalid signal number \"%s\".\n"),
420 argv[inx + 1]);
421 inx++;
422 showhelp = TRUE;
423 }
424#endif /* FREECIV_NDEBUG */
425 } else if ((option = get_option_malloc("--debug", argv, &inx, argc, FALSE))) {
427 showhelp = TRUE;
428 break;
429 }
430 free(option);
431 } else {
432 fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[inx]);
434 }
435 inx++;
436 }
437
439
440 /* Must be before con_log_init() */
444 /* Logging available after this point */
445
446 /* Get common code to treat us as a tool. */
447 i_am_tool();
448
449 /* Initialize game with default values */
451
452 /* Set ruleset user requested in to use */
453 if (ruleset != NULL) {
455 }
456
458
459 if (showvers && !showhelp) {
462 } else if (showhelp) {
463 struct cmdhelp *help = cmdhelp_new(argv[0]);
464
465#ifdef FREECIV_DEBUG
466 cmdhelp_add(help, "d",
467 /* TRANS: "debug" is exactly what user must type, do not translate. */
468 _("debug LEVEL"),
469 _("Set debug log level (one of f,e,w,n,v,d, or "
470 "d:file1,min,max:...)"));
471#else /* FREECIV_DEBUG */
472 cmdhelp_add(help, "d",
473 /* TRANS: "debug" is exactly what user must type, do not translate. */
474 _("debug LEVEL"),
475 _("Set debug log level (one of f,e,w,n,v)"));
476#endif /* FREECIV_DEBUG */
477#ifndef FREECIV_NDEBUG
478 cmdhelp_add(help, "F",
479 /* TRANS: "Fatal" is exactly what user must type, do not translate. */
480 _("Fatal [SIGNAL]"),
481 _("Raise a signal on failed assertion"));
482#endif /* FREECIV_NDEBUG */
483 cmdhelp_add(help, "h", "help",
484 _("Print a summary of the options"));
485 cmdhelp_add(help, "l",
486 /* TRANS: "log" is exactly what user must type, do not translate. */
487 _("log FILE"),
488 _("Use FILE as logfile"));
489 cmdhelp_add(help, "r",
490 /* TRANS: "ruleset" is exactly what user must type, do not translate. */
491 _("ruleset RULESET"),
492 _("Make manual for RULESET"));
493 cmdhelp_add(help, "v", "version",
494 _("Print the version number"));
495 cmdhelp_add(help, "w", "wiki",
496 _("Write manual in wiki format"));
497
498 /* The function below prints a header and footer for the options.
499 * Furthermore, the options are sorted. */
501 cmdhelp_destroy(help);
502
504 }
505
506 if (!manual_command(tag_info)) {
508 }
509
514
515 return retval;
516}
517
518/**********************************************************************/
522{
523 /* Nothing here */
524}
#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:75
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 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:161
struct tileset * tileset
Definition fc_manual.c:200
void manual_finalize(struct tag_types *tag_info, FILE *doc, enum manuals manual)
Definition fc_manual.c:320
int main(int argc, char **argv)
Definition fc_manual.c:360
const char * current_musicset_version(void)
Definition fc_manual.c:245
const char * current_musicset_name(void)
Definition fc_manual.c:237
const char * current_musicset_summary(void)
Definition fc_manual.c:253
const char * tileset_description(struct tileset *t)
Definition fc_manual.c:229
const char * current_musicset_description(void)
Definition fc_manual.c:261
bool client_nation_is_in_current_set(const struct nation_type *pnation)
Definition fc_manual.c:277
void popdown_help_dialog(void)
Definition fc_manual.c:195
const char * tileset_summary(struct tileset *t)
Definition fc_manual.c:221
static char * ruleset
Definition fc_manual.c:163
void popup_help_dialog_string(const char *item)
Definition fc_manual.c:187
char * html_special_chars(char *str, size_t *len)
Definition fc_manual.c:168
FILE * manual_start(struct tag_types *tag_info, int manual_number)
Definition fc_manual.c:291
void insert_client_build_info(char *outbuf, size_t outlen)
Definition fc_manual.c:521
enum client_states client_state(void)
Definition fc_manual.c:269
static bool manual_command(struct tag_types *tag_info)
Definition fc_manual.c:332
const char * tileset_name_get(struct tileset *t)
Definition fc_manual.c:205
const char * tileset_version(struct tileset *t)
Definition fc_manual.c:213
struct tag_types html_tags
Definition fc_manual.c:67
struct tag_types wiki_tags
Definition fc_manual.c:113
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:438
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:107
@ LOG_NORMAL
Definition log.h:32
#define log_error(message,...)
Definition log.h:103
int len
Definition packhand.c:127
void registry_module_init(void)
Definition registry.c:30
void registry_module_close(void)
Definition registry.c:40
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 ruleset.c:9358
void init_connections(void)
Definition sernet.c:1366
void settings_init(bool act)
Definition settings.c:5245
bool str_to_int(const char *str, int *pint)
Definition shared.c:517
struct server_arguments srvarg
Definition srv_main.c:176
struct packet_game_info info
Definition game.h:89
char rulesetdir[MAX_LEN_NAME]
Definition game.h:242
struct civ_game::@31::@35 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:974
FILE * fc_fopen(const char *filename, const char *opentype)
Definition support.c:507
bool is_reg_file_for_access(const char *name, bool write_access)
Definition support.c:1134
char * fc_strrep_resize(char *str, size_t *len, const char *search, const char *replace)
Definition support.c:695
#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