Freeciv-3.3
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 "fc_cmdline.h"
29#include "fciconv.h"
30#include "fcintl.h"
31#include "log.h"
32#include "mem.h"
33#include "registry.h"
34
35/* common */
36#include "capstr.h"
37#include "connection.h"
38#include "fc_cmdhelp.h"
39#include "fc_interface.h"
40#include "version.h"
41
42/* client */
43#include "client_main.h"
44#include "climisc.h"
45#include "helpdata.h"
46#include "music.h"
47#include "tilespec.h"
48
49/* server */
50#include "ruleload.h"
51#include "settings.h"
52#include "sernet.h"
53#include "srv_main.h"
54#include "stdinhand.h"
55
56/* tools/shared */
57#include "tools_fc_interface.h"
58
59/* tools/manual */
60#include "fc_manual.h"
61
62
64 /* file extension */
65 "html",
66
67 /* header */
68 "<html><head><link rel=\"stylesheet\" type=\"text/css\" "
69 "href=\"manual.css\"/><meta http-equiv=\"Content-Type\" "
70 "content=\"text/html; charset=UTF-8\"/></head><body>\n\n",
71
72 /* title begin */
73 "<h1>",
74
75 /* title end */
76 "</h1>",
77
78 /* section title begin */
79 "<h3 class='section'>",
80
81 /* section title end */
82 "</h3>",
83
84 /* image begin */
85 "<img src=\"",
86
87 /* image end */
88 ".png\">",
89
90 /* item begin */
91 "<div class='item' id='%s%d'>\n",
92
93 /* item end */
94 "</div>\n",
95
96 /* subitem begin */
97 "<pre class='%s'>",
98
99 /* subitem end */
100 "</pre>\n",
101
102 /* tail */
103 "</body></html>",
104
105 /* horizontal line */
106 "<hr/>"
107};
108
110 /* file extension */
111 "mediawiki",
112
113 /* header */
114 " ",
115
116 /* title begin */
117 "=",
118
119 /* title end */
120 "=",
121
122 /* section title begin */
123 "===",
124
125 /* section title end */
126 "===",
127
128 /* image begin */
129 "[[Image:",
130
131 /* image end */
132 ".png]]",
133
134 /* item begin */
135 "----\n<!-- %s %d -->\n",
136
137 /* item end */
138 "\n",
139
140 /* subitem begin */
141 "<!-- %s -->\n",
142
143 /* subitem end */
144 "\n",
145
146 /* tail */
147 " ",
148
149 /* horizontal line */
150 "----"
151};
152
153
154void insert_client_build_info(char *outbuf, size_t outlen);
155
156/* Needed for "About Freeciv" help */
157const char *client_string = "freeciv-manual";
158
159static char *ruleset = NULL;
160
161/**********************************************************************/
164char *html_special_chars(char *str, size_t *len)
165{
166 char *buf;
167
168 buf = fc_strrep_resize(str, len, "&", "&amp;");
169 buf = fc_strrep_resize(buf, len, "<", "&lt;");
170 buf = fc_strrep_resize(buf, len, ">", "&gt;");
171
172 return buf;
173}
174
175
176/*******************************************
177 Useless stubs for compiling client code.
178*******************************************/
179
180/**********************************************************************/
184{
185 /* Empty stub. */
186}
187
188/**********************************************************************/
192{
193 /* Empty stub. */
194}
195
197
198/**********************************************************************/
201const char *tileset_name_get(struct tileset *t)
202{
203 return NULL;
204}
205
206/**********************************************************************/
209const char *tileset_version(struct tileset *t)
210{
211 return NULL;
212}
213
214/**********************************************************************/
217const char *tileset_summary(struct tileset *t)
218{
219 return NULL;
220}
221
222/**********************************************************************/
225const char *tileset_description(struct tileset *t)
226{
227 return NULL;
228}
229
230/**********************************************************************/
233const char *current_musicset_name(void)
234{
235 return NULL;
236}
237
238/**********************************************************************/
242{
243 return NULL;
244}
245
246/**********************************************************************/
250{
251 return NULL;
252}
253
254/**********************************************************************/
258{
259 return NULL;
260}
261
262/**********************************************************************/
266{
267 return C_S_INITIAL;
268}
269
270/**********************************************************************/
274{
275 /* Currently, there is no way to select a nation set for freeciv-manual.
276 * Then, let's assume we want to print help for all nations. */
277 return TRUE;
278}
279
280/**********************************************************************/
288{
289 char filename[40];
290 FILE *doc;
291
292 fc_snprintf(filename, sizeof(filename), "%s%d.%s",
294
295 if (!is_reg_file_for_access(filename, TRUE)
296 || !(doc = fc_fopen(filename, "w"))) {
297 log_error(_("Could not write manual file %s."), filename);
298
299 return NULL;
300 }
301
302 fprintf(doc, "%s", tag_info->header);
303 fprintf(doc, "<!-- Generated by freeciv-manual version %s -->\n\n",
305
306 return doc;
307}
308
309/**********************************************************************/
317 enum manuals manual)
318{
319 fprintf(doc, "%s", tag_info->tail);
320 fclose(doc);
321 log_normal(_("%s (%d) manual successfully written."),
322 _(manuals_name(manual)), manual + 1);
323}
324
325/**********************************************************************/
329{
330 /* Reset aifill to zero */
331 game.info.aifill = 0;
332
334 /* Failed to load correct ruleset */
335 return FALSE;
336 }
337
345 || !manual_techs(tag_info)) {
346 return FALSE;
347 }
348
349 return TRUE;
350}
351
352/**********************************************************************/
355int main(int argc, char **argv)
356{
357 int inx;
358 bool showhelp = FALSE;
359 bool showvers = FALSE;
360 char *option = NULL;
361 int retval = EXIT_SUCCESS;
362 struct tag_types *tag_info = &html_tags;
363
364 /* Initialize the fc_interface functions needed to generate the help
365 * text.
366 * fc_interface_init_tool() includes low level support like
367 * guaranteeing that fc_vsnprintf() will work after it,
368 * so this need to be early. */
370
373
374 /* Set the default log level. */
376
377 /* parse command-line arguments... */
378 inx = 1;
379 while (inx < argc) {
380 if ((option = get_option_malloc("--ruleset", argv, &inx, argc, TRUE))) {
381 if (ruleset != NULL) {
382 fc_fprintf(stderr, _("Multiple rulesets requested. Only one "
383 "ruleset at a time is supported.\n"));
384 } else {
385 ruleset = option;
386 }
387 } else if (is_option("--help", argv[inx])) {
388 showhelp = TRUE;
389 break;
390 } else if (is_option("--version", argv[inx])) {
391 showvers = TRUE;
392 } else if ((option = get_option_malloc("--log", argv, &inx, argc, TRUE))) {
394 } else if (is_option("--wiki", argv[inx])) {
396#ifndef FREECIV_NDEBUG
397 } else if (is_option("--Fatal", argv[inx])) {
398 if (inx + 1 >= argc || '-' == argv[inx + 1][0]) {
400 } else if (str_to_int(argv[inx + 1], &srvarg.fatal_assertions)) {
401 inx++;
402 } else {
403 fc_fprintf(stderr, _("Invalid signal number \"%s\".\n"),
404 argv[inx + 1]);
405 inx++;
406 showhelp = TRUE;
407 }
408#endif /* FREECIV_NDEBUG */
409 } else if ((option = get_option_malloc("--debug", argv, &inx, argc, FALSE))) {
411 showhelp = TRUE;
412 break;
413 }
414 free(option);
415 } else {
416 fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[inx]);
418 }
419 inx++;
420 }
421
423
424 /* must be before con_log_init() */
428 /* logging available after this point */
429
430 /* Get common code to treat us as a tool. */
431 i_am_tool();
432
433 /* Initialize game with default values */
435
436 /* Set ruleset user requested in to use */
437 if (ruleset != NULL) {
439 }
440
442
443 if (showvers && !showhelp) {
446 } else if (showhelp) {
447 struct cmdhelp *help = cmdhelp_new(argv[0]);
448
449#ifdef FREECIV_DEBUG
450 cmdhelp_add(help, "d",
451 /* TRANS: "debug" is exactly what user must type, do not translate. */
452 _("debug LEVEL"),
453 _("Set debug log level (one of f,e,w,n,v,d, or "
454 "d:file1,min,max:...)"));
455#else /* FREECIV_DEBUG */
456 cmdhelp_add(help, "d",
457 /* TRANS: "debug" is exactly what user must type, do not translate. */
458 _("debug LEVEL"),
459 _("Set debug log level (one of f,e,w,n,v)"));
460#endif /* FREECIV_DEBUG */
461#ifndef FREECIV_NDEBUG
462 cmdhelp_add(help, "F",
463 /* TRANS: "Fatal" is exactly what user must type, do not translate. */
464 _("Fatal [SIGNAL]"),
465 _("Raise a signal on failed assertion"));
466#endif /* FREECIV_NDEBUG */
467 cmdhelp_add(help, "h", "help",
468 _("Print a summary of the options"));
469 cmdhelp_add(help, "l",
470 /* TRANS: "log" is exactly what user must type, do not translate. */
471 _("log FILE"),
472 _("Use FILE as logfile"));
473 cmdhelp_add(help, "r",
474 /* TRANS: "ruleset" is exactly what user must type, do not translate. */
475 _("ruleset RULESET"),
476 _("Make manual for RULESET"));
477 cmdhelp_add(help, "v", "version",
478 _("Print the version number"));
479 cmdhelp_add(help, "w", "wiki",
480 _("Write manual in wiki format"));
481
482 /* The function below prints a header and footer for the options.
483 * Furthermore, the options are sorted. */
485 cmdhelp_destroy(help);
486
488 }
489
490 if (!manual_command(tag_info)) {
492 }
493
498
499 return retval;
500}
501
502/**********************************************************************/
506{
507 /* Nothing here */
508}
#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:74
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:157
struct tileset * tileset
Definition fc_manual.c:196
void manual_finalize(struct tag_types *tag_info, FILE *doc, enum manuals manual)
Definition fc_manual.c:316
int main(int argc, char **argv)
Definition fc_manual.c:355
const char * current_musicset_version(void)
Definition fc_manual.c:241
const char * current_musicset_name(void)
Definition fc_manual.c:233
const char * current_musicset_summary(void)
Definition fc_manual.c:249
const char * tileset_description(struct tileset *t)
Definition fc_manual.c:225
const char * current_musicset_description(void)
Definition fc_manual.c:257
bool client_nation_is_in_current_set(const struct nation_type *pnation)
Definition fc_manual.c:273
void popdown_help_dialog(void)
Definition fc_manual.c:191
const char * tileset_summary(struct tileset *t)
Definition fc_manual.c:217
static char * ruleset
Definition fc_manual.c:159
void popup_help_dialog_string(const char *item)
Definition fc_manual.c:183
char * html_special_chars(char *str, size_t *len)
Definition fc_manual.c:164
FILE * manual_start(struct tag_types *tag_info, int manual_number)
Definition fc_manual.c:287
void insert_client_build_info(char *outbuf, size_t outlen)
Definition fc_manual.c:505
enum client_states client_state(void)
Definition fc_manual.c:265
static bool manual_command(struct tag_types *tag_info)
Definition fc_manual.c:328
const char * tileset_name_get(struct tileset *t)
Definition fc_manual.c:201
const char * tileset_version(struct tileset *t)
Definition fc_manual.c:209
struct tag_types html_tags
Definition fc_manual.c:63
struct tag_types wiki_tags
Definition fc_manual.c:109
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)
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:61
void game_init(bool keep_ruleset_value)
Definition game.c:443
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: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:9115
void init_connections(void)
Definition sernet.c:1362
void settings_init(bool act)
Definition settings.c:5205
bool str_to_int(const char *str, int *pint)
Definition shared.c:515
struct server_arguments srvarg
Definition srv_main.c:181
struct packet_game_info info
Definition game.h:89
char rulesetdir[MAX_LEN_NAME]
Definition game.h:239
struct civ_game::@31::@35 server
Definition climisc.h:80
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:189
#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