Freeciv-3.1
Loading...
Searching...
No Matches
civmanual.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 <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
23#ifdef HAVE_SIGNAL_H
24#include <signal.h>
25#endif
26
27#ifdef FREECIV_MSWINDOWS
28#include <windows.h>
29#endif
30
31/* utility */
32#include "capability.h"
33#include "fc_cmdline.h"
34#include "fciconv.h"
35#include "fcintl.h"
36#include "log.h"
37#include "mem.h"
38#include "registry.h"
39#include "support.h"
40
41/* common */
42#include "capstr.h"
43#include "connection.h"
44#include "events.h"
45#include "fc_cmdhelp.h"
46#include "fc_interface.h"
47#include "fc_types.h" /* LINE_BREAK */
48#include "game.h"
49#include "government.h"
50#include "improvement.h"
51#include "map.h"
52#include "movement.h"
53#include "player.h"
54#include "version.h"
55
56/* client */
57#include "client_main.h"
58#include "climisc.h"
59#include "helpdata.h"
60#include "helpdlg_g.h"
61#include "tilespec.h"
62
63/* server */
64#include "citytools.h"
65#include "commands.h"
66#include "connecthand.h"
67#include "console.h"
68#include "diplhand.h"
69#include "gamehand.h"
70#include "plrhand.h"
71#include "report.h"
72#include "ruleset.h"
73#include "settings.h"
74#include "sernet.h"
75#include "srv_main.h"
76#include "stdinhand.h"
77
78/* tools/shared */
79#include "tools_fc_interface.h"
80
92
93struct tag_types {
94 const char *file_ext;
95 const char *header;
96 const char *title_begin;
97 const char *title_end;
98 const char *sect_title_begin;
99 const char *sect_title_end;
100 const char *image_begin;
101 const char *image_end;
102 const char *item_begin;
103 const char *item_end;
104 const char *subitem_begin;
105 const char *subitem_end;
106 const char *tail;
107 const char *hline;
108};
109
111 /* file extension */
112 "html",
113
114 /* header */
115 "<html><head><link rel=\"stylesheet\" type=\"text/css\" "
116 "href=\"manual.css\"/><meta http-equiv=\"Content-Type\" "
117 "content=\"text/html; charset=UTF-8\"/></head><body>\n\n",
118
119 /* title begin */
120 "<h1>",
121
122 /* title end */
123 "</h1>",
124
125 /* section title begin */
126 "<h3 class='section'>",
127
128 /* section title end */
129 "</h3>",
130
131 /* image begin */
132 "<img src=\"",
133
134 /* image end */
135 ".png\">",
136
137 /* item begin */
138 "<div class='item' id='%s%d'>\n",
139
140 /* item end */
141 "</div>\n",
142
143 /* subitem begin */
144 "<pre class='%s'>",
145
146 /* subitem end */
147 "</pre>\n",
148
149 /* tail */
150 "</body></html>",
151
152 /* horizontal line */
153 "<hr/>"
154};
155
157 /* file extension */
158 "mediawiki",
159
160 /* header */
161 " ",
162
163 /* title begin */
164 "=",
165
166 /* title end */
167 "=",
168
169 /* section title begin */
170 "===",
171
172 /* section title end */
173 "===",
174
175 /* image begin */
176 "[[Image:",
177
178 /* image end */
179 ".png]]",
180
181 /* item begin */
182 "----\n<!-- %s %d -->\n",
183
184 /* item end */
185 "\n",
186
187 /* subitem begin */
188 "<!-- %s -->\n",
189
190 /* subitem end */
191 "\n",
192
193 /* tail */
194 " ",
195
196 /* horizontal line */
197 "----"
198};
199
200
201void insert_client_build_info(char *outbuf, size_t outlen);
202
203/* Needed for "About Freeciv" help */
204const char *client_string = "freeciv-manual";
205
206static char *ruleset = NULL;
207
208/**********************************************************************/
211static char *html_special_chars(char *str, size_t *len)
212{
213 char *buf;
214
215 buf = fc_strrep_resize(str, len, "&", "&amp;");
216 buf = fc_strrep_resize(buf, len, "<", "&lt;");
217 buf = fc_strrep_resize(buf, len, ">", "&gt;");
218
219 return buf;
220}
221
222
223/*******************************************
224 Useless stubs for compiling client code.
225*/
226
227/**********************************************************************/
231{
232 /* Empty stub. */
233}
234
235/**********************************************************************/
239{
240 /* Empty stub. */
241}
242
244
245/**********************************************************************/
248const char *tileset_name_get(struct tileset *t)
249{
250 return NULL;
251}
252
253/**********************************************************************/
256const char *tileset_version(struct tileset *t)
257{
258 return NULL;
259}
260
261/**********************************************************************/
264const char *tileset_summary(struct tileset *t)
265{
266 return NULL;
267}
268
269/**********************************************************************/
272const char *tileset_description(struct tileset *t)
273{
274 return NULL;
275}
276
277/**********************************************************************/
281{
282 return C_S_INITIAL;
283}
284
285/**********************************************************************/
289{
290 /* Currently, there is no way to select a nation set for freeciv-manual.
291 * Then, let's assume we want to print help for all nations. */
292 return TRUE;
293}
294
295/**********************************************************************/
298static bool manual_command(struct tag_types *tag_info)
299{
300 FILE *doc;
301 char filename[40];
302 enum manuals manuals;
303 struct connection my_conn;
304
305 /* Default client access. */
306 connection_common_init(&my_conn);
307 my_conn.access_level = ALLOW_CTRL;
308
309 /* Reset aifill to zero */
310 game.info.aifill = 0;
311
312 if (!load_rulesets(NULL, NULL, FALSE, NULL, FALSE, FALSE, FALSE)) {
313 /* Failed to load correct ruleset */
314 return FALSE;
315 }
316
317 for (manuals = 0; manuals < MANUAL_COUNT; manuals++) {
318 int i;
319 int ri;
320
321 fc_snprintf(filename, sizeof(filename), "%s%d.%s",
322 game.server.rulesetdir, manuals + 1, tag_info->file_ext);
323
324 if (!is_reg_file_for_access(filename, TRUE)
325 || !(doc = fc_fopen(filename, "w"))) {
326 log_error(_("Could not write manual file %s."), filename);
327 return FALSE;
328 }
329
330 fprintf(doc, "%s", tag_info->header);
331 fprintf(doc, "<!-- Generated by freeciv-manual version %s -->\n\n",
333
334 switch (manuals) {
335 case MANUAL_SETTINGS:
336 /* TRANS: markup ... Freeciv version ... markup */
337 fprintf(doc, _("%sFreeciv %s server settings%s\n\n"), tag_info->title_begin,
338 VERSION_STRING, tag_info->title_end);
339 settings_iterate(SSET_ALL, pset) {
340 char buf[256];
341 const char *sethelp;
342
343 fprintf(doc, tag_info->item_begin, "setting", setting_number(pset));
344 fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin,
345 setting_name(pset), _(setting_short_help(pset)),
346 tag_info->sect_title_end);
347 sethelp = _(setting_extra_help(pset, TRUE));
348 if (strlen(sethelp) > 0) {
349 char *help = fc_strdup(sethelp);
350 size_t help_len = strlen(help) + 1;
351
353 help = html_special_chars(help, &help_len);
354 fprintf(doc, "<pre>%s</pre>\n\n", help);
355 FC_FREE(help);
356 }
357 fprintf(doc, "<p class=\"misc\">");
358 fprintf(doc, _("Level: %s.<br>"),
359 _(sset_level_name(setting_level(pset))));
360 fprintf(doc, _("Category: %s.<br>"),
361 _(sset_category_name(setting_category(pset))));
362
363 /* first check if the setting is locked because this is included in
364 * the function setting_is_changeable() */
365 if (setting_locked(pset)) {
366 fprintf(doc, _("Is locked by the ruleset."));
367 } else if (!setting_is_changeable(pset, &my_conn, NULL, 0)) {
368 fprintf(doc, _("Can only be used in server console."));
369 }
370
371 fprintf(doc, "</p>\n");
372 setting_default_name(pset, TRUE, buf, sizeof(buf));
373 switch (setting_type(pset)) {
374 case SST_INT:
375 fprintf(doc, "\n<p class=\"bounds\">%s %d, %s %s, %s %d</p>\n",
376 _("Minimum:"), setting_int_min(pset),
377 _("Default:"), buf,
378 _("Maximum:"), setting_int_max(pset));
379 break;
380 case SST_ENUM:
381 {
382 const char *value;
383
384 fprintf(doc, "\n<p class=\"bounds\">%s</p><ul>",
385 _("Possible values:"));
386 for (i = 0; (value = setting_enum_val(pset, i, FALSE)); i++) {
387 fprintf(doc, "\n<li><p class=\"bounds\"> %s: \"%s\"</p>",
388 value, setting_enum_val(pset, i, TRUE));
389 }
390 fprintf(doc, "</ul>\n");
391 }
392 break;
393 case SST_BITWISE:
394 {
395 const char *value;
396
397 fprintf(doc, "\n<p class=\"bounds\">%s</p><ul>",
398 _("Possible values (option can take any number of these):"));
399 for (i = 0; (value = setting_bitwise_bit(pset, i, FALSE)); i++) {
400 fprintf(doc, "\n<li><p class=\"bounds\"> %s: \"%s\"</p>",
401 value, setting_bitwise_bit(pset, i, TRUE));
402 }
403 fprintf(doc, "</ul>\n");
404 }
405 break;
406 case SST_BOOL:
407 case SST_STRING:
408 break;
409 case SST_COUNT:
410 fc_assert(setting_type(pset) != SST_COUNT);
411 break;
412 }
413 if (SST_INT != setting_type(pset)) {
414 fprintf(doc, "\n<p class=\"bounds\">%s %s</p>\n",
415 _("Default:"), buf);
416 }
417 if (setting_non_default(pset)) {
418 fprintf(doc, _("\n<p class=\"changed\">Value set to %s</p>\n"),
419 setting_value_name(pset, TRUE, buf, sizeof(buf)));
420 }
421
422 fprintf(doc, "%s", tag_info->item_end);
424 break;
425
426 case MANUAL_COMMANDS:
427 /* TRANS: markup ... Freeciv version ... markup */
428 fprintf(doc, _("%sFreeciv %s server commands%s\n\n"), tag_info->title_begin,
429 VERSION_STRING, tag_info->title_end);
430 for (i = 0; i < CMD_NUM; i++) {
431 const struct command *cmd = command_by_number(i);
432
433 fprintf(doc, tag_info->item_begin, "cmd", i);
434 fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin,
436 tag_info->sect_title_end);
437 if (command_synopsis(cmd)) {
438 char *cmdstr = fc_strdup(command_synopsis(cmd));
439 size_t cmdstr_len = strlen(cmdstr) + 1;
440
441 cmdstr = html_special_chars(cmdstr, &cmdstr_len);
442 fprintf(doc, _("<table>\n<tr>\n<td valign=\"top\">"
443 "<pre>Synopsis:</pre></td>\n<td>"));
444 fprintf(doc, "<pre>%s</pre></td></tr></table>", cmdstr);
445 FC_FREE(cmdstr);
446 }
447 fprintf(doc, _("<p class=\"level\">Level: %s</p>\n"),
448 cmdlevel_name(command_level(cmd)));
449 {
450 char *help = command_extra_help(cmd);
451 if (help) {
452 size_t help_len = strlen(help) + 1;
453
455 help = html_special_chars(help, &help_len);
456 fprintf(doc, "\n");
457 fprintf(doc, _("<p>Description:</p>\n\n"));
458 fprintf(doc, "<pre>%s</pre>\n", help);
459 FC_FREE(help);
460 }
461 }
462
463 fprintf(doc, "%s", tag_info->item_end);
464 }
465 break;
466
467 case MANUAL_TERRAIN:
468 /* TRANS: Markup ... Freeciv version ... ruleset name ... markup */
469 fprintf(doc, _("%sFreeciv %s terrain help (%s)%s\n\n"), tag_info->title_begin,
470 VERSION_STRING, game.control.name, tag_info->title_end);
471 fprintf(doc, "<table><tr bgcolor=#9bc3d1><th>%s</th>", _("Terrain"));
472 fprintf(doc, "<th>F/P/T</th><th>%s</th>", _("Resources"));
473 fprintf(doc, "<th>%s<br/>%s</th>", _("Move cost"), _("Defense bonus"));
474 fprintf(doc, "<th>%s<br/>%s<br/>%s<br/>%s<br/>%s<br/>%s<br/>(%s)</th>",
475 _("Irrigation"), _("Cultivate"), _("Mining"), _("Plant"), _("Transform"),
476 /* xgettext:no-c-format */
477 _("% of Road bonus"), _("turns"));
478 fprintf(doc, "<th>%s<br/>%s</th>",
479 _("Clean pollution"), _("Clean fallout"));
480 ri = 0;
481 if (game.control.num_road_types > 0) {
482 fprintf(doc, "<th>");
483 }
484 extra_type_by_cause_iterate(EC_ROAD, pextra) {
485 if (++ri < game.control.num_road_types) {
486 fprintf(doc, "%s<br/>", extra_name_translation(pextra));
487 } else {
488 /* Last one */
489 fprintf(doc, "%s</th>", extra_name_translation(pextra));
490 }
492 fprintf(doc, "</tr>\n\n");
493 terrain_type_iterate(pterrain) {
494 struct extra_type **r;
495 struct universal for_terr
496 = { .kind = VUT_TERRAIN, .value = { .terrain = pterrain }};
497
498 if (0 == strlen(terrain_rule_name(pterrain))) {
499 /* Must be a disabled piece of terrain */
500 continue;
501 }
502
503 fprintf(doc, "<tr><td>%s%s%s<br/>%s</td>",
504 tag_info->image_begin, pterrain->graphic_str,
505 tag_info->image_end,
506 terrain_name_translation(pterrain));
507 fprintf(doc, "<td>%d/%d/%d</td>\n",
508 pterrain->output[O_FOOD], pterrain->output[O_SHIELD],
509 pterrain->output[O_TRADE]);
510
511 fprintf(doc, "<td><table width=\"100%%\">\n");
512 for (r = pterrain->resources; *r; r++) {
513 fprintf(doc, "<tr><td>%s%s%s</td><td>%s</td>"
514 "<td align=\"right\">%d/%d/%d</td></tr>\n",
515 tag_info->image_begin, (*r)->graphic_str, tag_info->image_end,
517 (*r)->data.resource->output[O_FOOD],
518 (*r)->data.resource->output[O_SHIELD],
519 (*r)->data.resource->output[O_TRADE]);
520 }
521 fprintf(doc, "</table></td>\n");
522
523 fprintf(doc, "<td align=\"center\">%d<br/>+%d%%</td>\n",
524 pterrain->movement_cost, pterrain->defense_bonus);
525
526 fprintf(doc, "<td><table width=\"100%%\">\n");
527 if (action_id_univs_not_blocking(ACTION_IRRIGATE,
528 NULL, &for_terr)) {
529 fprintf(doc, "<tr><td>+%d F</td>", pterrain->irrigation_food_incr);
530 if (pterrain->irrigation_time == 0) {
531 fprintf(doc, "<td align=\"right\">(-)</td></tr>\n");
532 } else {
533 fprintf(doc, "<td align=\"right\">(%d)</td></tr>\n",
534 pterrain->irrigation_time);
535 }
536 } else {
537 fprintf(doc, "<tr><td>%s</td></tr>\n", _("impossible"));
538 }
539 if (pterrain->cultivate_result != NULL
540 && action_id_univs_not_blocking(ACTION_CULTIVATE,
541 NULL, &for_terr)) {
542 fprintf(doc, "<tr><td>%s</td>",
543 terrain_name_translation(pterrain->cultivate_result));
544 if (pterrain->cultivate_time == 0) {
545 fprintf(doc, "<td align=\"right\">(-)</td></tr>\n");
546 } else {
547 fprintf(doc, "<td align=\"right\">(%d)</td></tr>\n",
548 pterrain->cultivate_time);
549 }
550 } else {
551 fprintf(doc, "<tr><td>%s</td></tr>\n", _("impossible"));
552 }
553 if (action_id_univs_not_blocking(ACTION_MINE, NULL, &for_terr)) {
554 fprintf(doc, "<tr><td>+%d P</td>", pterrain->mining_shield_incr);
555 if (pterrain->mining_time == 0) {
556 fprintf(doc, "<td align=\"right\">(-)</td></tr>\n");
557 } else {
558 fprintf(doc, "<td align=\"right\">(%d)</td></tr>\n",
559 pterrain->mining_time);
560 }
561 } else {
562 fprintf(doc, "<tr><td>%s</td></tr>\n", _("impossible"));
563 }
564 if (pterrain->plant_result != NULL
565 && action_id_univs_not_blocking(ACTION_PLANT,
566 NULL, &for_terr)) {
567 fprintf(doc, "<tr><td>%s</td>",
568 terrain_name_translation(pterrain->plant_result));
569 if (pterrain->plant_time == 0) {
570 fprintf(doc, "<td align=\"right\">(-)</td></tr>\n");
571 } else {
572 fprintf(doc, "<td align=\"right\">(%d)</td></tr>\n",
573 pterrain->plant_time);
574 }
575 } else {
576 fprintf(doc, "<tr><td>%s</td></tr>\n", _("impossible"));
577 }
578
579 if (pterrain->transform_result
580 && action_id_univs_not_blocking(ACTION_TRANSFORM_TERRAIN,
581 NULL, &for_terr)) {
582 fprintf(doc, "<tr><td>%s</td>",
583 terrain_name_translation(pterrain->transform_result));
584 if (pterrain->transform_time == 0) {
585 fprintf(doc, "<td align=\"right\">(-)</td></tr>\n");
586 } else {
587 fprintf(doc, "<td align=\"right\">(%d)</td></tr>\n",
588 pterrain->transform_time);
589 }
590 } else {
591 fprintf(doc, "<tr><td>-</td><td align=\"right\">(-)</td></tr>\n");
592 }
593 fprintf(doc, "<tr><td>%d / %d / %d</td></tr>\n</table></td>\n",
594 pterrain->road_output_incr_pct[O_FOOD],
595 pterrain->road_output_incr_pct[O_SHIELD],
596 pterrain->road_output_incr_pct[O_TRADE]);
597
598 fprintf(doc, "<td align=\"center\">%d / %d</td>",
599 pterrain->clean_pollution_time, pterrain->clean_fallout_time);
600
601 ri = 0;
602 if (game.control.num_road_types > 0) {
603 fprintf(doc, "<td>");
604 }
605 extra_type_by_cause_iterate(EC_ROAD, pextra) {
606 int btime = terrain_extra_build_time(pterrain, ACTIVITY_GEN_ROAD, pextra);
607
608 if (++ri < game.control.num_road_types) {
609 if (btime == 0) {
610 fprintf(doc, "- / ");
611 } else {
612 fprintf(doc, "%d / ", btime);
613 }
614 } else {
615 if (btime == 0) {
616 fprintf(doc, "-</td>");
617 } else {
618 fprintf(doc, "%d</td>", btime);
619 }
620 }
622 fprintf(doc, "</tr><tr><td colspan=\"7\">\n%s\n</td></tr>\n\n", tag_info->hline);
624
625 fprintf(doc, "</table>\n");
626
627 break;
628
629 case MANUAL_BUILDINGS:
630 case MANUAL_WONDERS:
631 if (manuals == MANUAL_BUILDINGS) {
632 /* TRANS: markup ... Freeciv version ... ruleset name ... markup */
633 fprintf(doc, _("%sFreeciv %s buildings help (%s)%s\n\n"), tag_info->title_begin,
634 VERSION_STRING, game.control.name, tag_info->title_end);
635 } else {
636 /* TRANS: markup ... Freeciv version ... ruleset name ... markup */
637 fprintf(doc, _("%sFreeciv %s wonders help (%s)%s\n\n"), tag_info->title_begin,
638 VERSION_STRING, game.control.name, tag_info->title_end);
639 }
640
641 fprintf(doc, "<table>\n<tr bgcolor=#9bc3d1><th colspan=2>%s</th>"
642 "<th>%s<br/>%s</th><th>%s<br/>%s</th><th>%s</th></tr>\n\n",
643 _("Name"), _("Cost"), _("Upkeep"),
644 _("Requirement"), _("Obsolete by"), _("More info"));
645
646 improvement_iterate(pimprove) {
647 char buf[64000];
648
649 if (!valid_improvement(pimprove)
650 || is_great_wonder(pimprove) == (manuals == MANUAL_BUILDINGS)) {
651 continue;
652 }
653
654 helptext_building(buf, sizeof(buf), NULL, NULL, pimprove);
655
656 fprintf(doc, "<tr><td>%s%s%s</td><td>%s</td>\n"
657 "<td align=\"center\"><b>%d</b><br/>%d</td>\n<td>",
658 tag_info->image_begin, pimprove->graphic_str, tag_info->image_end,
660 pimprove->build_cost,
661 pimprove->upkeep);
662
663 if (requirement_vector_size(&pimprove->reqs) == 0) {
664 char text[512];
665
666 strncpy(text, Q_("?req:None"), sizeof(text) - 1);
667 fprintf(doc, "%s<br/>", text);
668 } else {
669 requirement_vector_iterate(&pimprove->reqs, req) {
670 char text[512], text2[512];
671
672 fc_snprintf(text2, sizeof(text2),
673 /* TRANS: Feature required to be absent. */
674 req->present ? "%s" : _("no %s"),
675 universal_name_translation(&req->source,
676 text, sizeof(text)));
677 fprintf(doc, "%s<br/>", text2);
679 }
680
681 fprintf(doc, "\n%s\n", tag_info->hline);
682
683 if (requirement_vector_size(&pimprove->obsolete_by) == 0) {
684 char text[512];
685
686 strncpy(text, Q_("?req:None"), sizeof(text) - 1);
687 fprintf(doc, "<em>%s</em><br/>", text);
688 } else {
689 requirement_vector_iterate(&pimprove->obsolete_by, pobs) {
690 char text[512], text2[512];
691
692 fc_snprintf(text2, sizeof(text2),
693 /* TRANS: Feature required to be absent. */
694 pobs->present ? "%s" : _("no %s"),
695 universal_name_translation(&pobs->source,
696 text, sizeof(text)));
697 fprintf(doc, "<em>%s</em><br/>", text2);
699 }
700
701 fprintf(doc,
702 "</td>\n<td>%s</td>\n</tr><tr><td colspan=\"5\">\n%s\n</td></tr>\n\n",
703 buf, tag_info->hline);
705
706 fprintf(doc, "</table>");
707 break;
708
709 case MANUAL_GOVS:
710 /* Freeciv-web uses (parts of) the government HTML output in its own
711 * manual pages. */
712 /* FIXME: this doesn't resemble the wiki manual at all. */
713 /* TRANS: markup ... Freeciv version ... ruleset name ... markup */
714 fprintf(doc, _("%sFreeciv %s governments help (%s)%s\n\n"), tag_info->title_begin,
715 VERSION_STRING, game.control.name, tag_info->title_end);
716 governments_iterate(pgov) {
717 char buf[64000];
718 fprintf(doc, tag_info->item_begin, "gov", pgov->item_number);
719 fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin,
721 fprintf(doc, tag_info->subitem_begin, "helptext");
722 helptext_government(buf, sizeof(buf), NULL, NULL, pgov);
723 fprintf(doc, "%s\n\n", buf);
724 fprintf(doc, "%s", tag_info->subitem_end);
725 fprintf(doc, "%s", tag_info->item_end);
727 break;
728
729 case MANUAL_UNITS:
730 /* Freeciv-web uses (parts of) the unit type HTML output in its own
731 * manual pages. */
732 /* FIXME: this doesn't resemble the wiki manual at all. */
733 /* TRANS: markup ... Freeciv version ... ruleset name ... markup */
734 fprintf(doc, _("%sFreeciv %s unit types help (%s)%s\n\n"),
735 tag_info->title_begin, VERSION_STRING, game.control.name,
736 tag_info->title_end);
737 unit_type_iterate(putype) {
738 char buf[64000];
739
740 fprintf(doc, tag_info->item_begin, "utype", putype->item_number);
741 fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin,
742 utype_name_translation(putype), tag_info->sect_title_end);
743 fprintf(doc, tag_info->subitem_begin, "cost");
744 fprintf(doc,
745 PL_("Cost: %d shield",
746 "Cost: %d shields",
749 fprintf(doc, "%s", tag_info->subitem_end);
750 fprintf(doc, tag_info->subitem_begin, "upkeep");
751 fprintf(doc, _("Upkeep: %s"),
753 fprintf(doc, "%s", tag_info->subitem_end);
754 fprintf(doc, tag_info->subitem_begin, "moves");
755 fprintf(doc, _("Moves: %s"),
756 move_points_text(putype->move_rate, TRUE));
757 fprintf(doc, "%s", tag_info->subitem_end);
758 fprintf(doc, tag_info->subitem_begin, "vision");
759 fprintf(doc, _("Vision: %d"),
760 (int)sqrt((double)putype->vision_radius_sq));
761 fprintf(doc, "%s", tag_info->subitem_end);
762 fprintf(doc, tag_info->subitem_begin, "attack");
763 fprintf(doc, _("Attack: %d"),
764 putype->attack_strength);
765 fprintf(doc, "%s", tag_info->subitem_end);
766 fprintf(doc, tag_info->subitem_begin, "defense");
767 fprintf(doc, _("Defense: %d"),
768 putype->defense_strength);
769 fprintf(doc, "%s", tag_info->subitem_end);
770 fprintf(doc, tag_info->subitem_begin, "firepower");
771 fprintf(doc, _("Firepower: %d"),
772 putype->firepower);
773 fprintf(doc, "%s", tag_info->subitem_end);
774 fprintf(doc, tag_info->subitem_begin, "hitpoints");
775 fprintf(doc, _("Hitpoints: %d"),
776 putype->hp);
777 fprintf(doc, "%s", tag_info->subitem_end);
778 fprintf(doc, tag_info->subitem_begin, "obsolete");
779 fprintf(doc, _("Obsolete by: %s"),
780 U_NOT_OBSOLETED == putype->obsoleted_by ?
781 Q_("?utype:None") :
782 utype_name_translation(putype->obsoleted_by));
783 fprintf(doc, "%s", tag_info->subitem_end);
784 fprintf(doc, tag_info->subitem_begin, "helptext");
785 helptext_unit(buf, sizeof(buf), NULL, "", putype);
786 fprintf(doc, "%s", buf);
787 fprintf(doc, "%s", tag_info->subitem_end);
788 fprintf(doc, "%s", tag_info->item_end);
790 break;
791
792 case MANUAL_TECHS:
793 /* FIXME: this doesn't resemble the wiki manual at all. */
794 /* TRANS: markup ... Freeciv version ... ruleset name ... markup */
795 fprintf(doc, _("%sFreeciv %s tech help (%s)%s\n\n"),
796 tag_info->title_begin, VERSION_STRING, game.control.name,
797 tag_info->title_end);
798 advance_iterate(A_FIRST, ptech) {
799 if (valid_advance(ptech)) {
800 char buf[64000];
801
802 fprintf(doc, tag_info->item_begin, "tech", ptech->item_number);
803 fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin,
804 advance_name_translation(ptech), tag_info->sect_title_end);
805
806 fprintf(doc, tag_info->subitem_begin, "helptext");
807 helptext_advance(buf, sizeof(buf), NULL, "", ptech->item_number);
808 fprintf(doc, "%s", buf);
809 fprintf(doc, "%s", tag_info->subitem_end);
810
811 fprintf(doc, "%s", tag_info->item_end);
812 }
814 break;
815
816 case MANUAL_COUNT:
817 break;
818
819 } /* switch */
820
821 fprintf(doc, "%s", tag_info->tail);
822 fclose(doc);
823 log_normal(_("Manual file %s successfully written."), filename);
824 } /* manuals */
825
826 return TRUE;
827}
828
829/**********************************************************************/
832int main(int argc, char **argv)
833{
834 int inx;
835 bool showhelp = FALSE;
836 bool showvers = FALSE;
837 char *option = NULL;
838 int retval = EXIT_SUCCESS;
839 struct tag_types *tag_info = &html_tags;
840
841 /* Load Windows post-crash debugger */
842#ifdef FREECIV_MSWINDOWS
843# ifndef FREECIV_NDEBUG
844 if (LoadLibrary("exchndl.dll") == NULL) {
845# ifdef FREECIV_DEBUG
846 fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n");
847# endif /* FREECIV_DEBUG */
848 }
849# endif /* FREECIV_NDEBUG */
850#endif /* FREECIV_MSWINDOWS */
851
852 /* Initialize the fc_interface functions needed to generate the help
853 * text.
854 * fc_interface_init_tool() includes low level support like
855 * guaranteeing that fc_vsnprintf() will work after it,
856 * so this need to be early. */
858
861
862 /* Set the default log level. */
864
865 /* parse command-line arguments... */
866 inx = 1;
867 while (inx < argc) {
868 if ((option = get_option_malloc("--ruleset", argv, &inx, argc, TRUE))) {
869 if (ruleset != NULL) {
870 fc_fprintf(stderr, _("Multiple rulesets requested. Only one "
871 "ruleset at a time is supported.\n"));
872 } else {
873 ruleset = option;
874 }
875 } else if (is_option("--help", argv[inx])) {
876 showhelp = TRUE;
877 break;
878 } else if (is_option("--version", argv[inx])) {
879 showvers = TRUE;
880 } else if ((option = get_option_malloc("--log", argv, &inx, argc, TRUE))) {
882 } else if (is_option("--wiki", argv[inx])) {
883 tag_info = &wiki_tags;
884#ifndef FREECIV_NDEBUG
885 } else if (is_option("--Fatal", argv[inx])) {
886 if (inx + 1 >= argc || '-' == argv[inx + 1][0]) {
887 srvarg.fatal_assertions = SIGABRT;
888 } else if (str_to_int(argv[inx + 1], &srvarg.fatal_assertions)) {
889 inx++;
890 } else {
891 fc_fprintf(stderr, _("Invalid signal number \"%s\".\n"),
892 argv[inx + 1]);
893 inx++;
894 showhelp = TRUE;
895 }
896#endif /* FREECIV_NDEBUG */
897 } else if ((option = get_option_malloc("--debug", argv, &inx, argc, FALSE))) {
899 showhelp = TRUE;
900 break;
901 }
902 free(option);
903 } else {
904 fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[inx]);
905 exit(EXIT_FAILURE);
906 }
907 inx++;
908 }
909
911
912 /* must be before con_log_init() */
916 /* logging available after this point */
917
918 /* Get common code to treat us as a tool. */
919 i_am_tool();
920
921 /* Initialize game with default values */
923
924 /* Set ruleset user requested in to use */
925 if (ruleset != NULL) {
927 }
928
930
931 if (showvers && !showhelp) {
932 fc_fprintf(stderr, "%s \n", freeciv_name_version());
933 exit(EXIT_SUCCESS);
934 } else if (showhelp) {
935 struct cmdhelp *help = cmdhelp_new(argv[0]);
936
937#ifdef FREECIV_DEBUG
938 cmdhelp_add(help, "d",
939 /* TRANS: "debug" is exactly what user must type, do not translate. */
940 _("debug LEVEL"),
941 _("Set debug log level (one of f,e,w,n,v,d, or "
942 "d:file1,min,max:...)"));
943#else /* FREECIV_DEBUG */
944 cmdhelp_add(help, "d",
945 /* TRANS: "debug" is exactly what user must type, do not translate. */
946 _("debug LEVEL"),
947 _("Set debug log level (one of f,e,w,n,v)"));
948#endif /* FREECIV_DEBUG */
949#ifndef FREECIV_NDEBUG
950 cmdhelp_add(help, "F",
951 /* TRANS: "Fatal" is exactly what user must type, do not translate. */
952 _("Fatal [SIGNAL]"),
953 _("Raise a signal on failed assertion"));
954#endif /* FREECIV_NDEBUG */
955 cmdhelp_add(help, "h", "help",
956 _("Print a summary of the options"));
957 cmdhelp_add(help, "l",
958 /* TRANS: "log" is exactly what user must type, do not translate. */
959 _("log FILE"),
960 _("Use FILE as logfile"));
961 cmdhelp_add(help, "r",
962 /* TRANS: "ruleset" is exactly what user must type, do not translate. */
963 _("ruleset RULESET"),
964 _("Make manual for RULESET"));
965 cmdhelp_add(help, "v", "version",
966 _("Print the version number"));
967 cmdhelp_add(help, "w", "wiki",
968 _("Write manual in wiki format"));
969
970 /* The function below prints a header and footer for the options.
971 * Furthermore, the options are sorted. */
973 cmdhelp_destroy(help);
974
975 exit(EXIT_SUCCESS);
976 }
977
978 if (!manual_command(tag_info)) {
979 retval = EXIT_FAILURE;
980 }
981
986
987 return retval;
988}
989
990/**********************************************************************/
993void insert_client_build_info(char *outbuf, size_t outlen)
994{
995 /* Nothing here */
996}
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
Definition actions.h:962
#define str
Definition astring.c:76
void init_our_capability(void)
Definition capstr.c:87
const char * client_string
Definition civmanual.c:204
struct tileset * tileset
Definition civmanual.c:243
static char * html_special_chars(char *str, size_t *len)
Definition civmanual.c:211
int main(int argc, char **argv)
Definition civmanual.c:832
const char * tileset_description(struct tileset *t)
Definition civmanual.c:272
bool client_nation_is_in_current_set(const struct nation_type *pnation)
Definition civmanual.c:288
manuals
Definition civmanual.c:81
@ MANUAL_COUNT
Definition civmanual.c:90
@ MANUAL_COMMANDS
Definition civmanual.c:83
@ MANUAL_SETTINGS
Definition civmanual.c:82
@ MANUAL_WONDERS
Definition civmanual.c:86
@ MANUAL_TERRAIN
Definition civmanual.c:84
@ MANUAL_TECHS
Definition civmanual.c:89
@ MANUAL_UNITS
Definition civmanual.c:88
@ MANUAL_GOVS
Definition civmanual.c:87
@ MANUAL_BUILDINGS
Definition civmanual.c:85
void popdown_help_dialog(void)
Definition civmanual.c:238
const char * tileset_summary(struct tileset *t)
Definition civmanual.c:264
static char * ruleset
Definition civmanual.c:206
void popup_help_dialog_string(const char *item)
Definition civmanual.c:230
void insert_client_build_info(char *outbuf, size_t outlen)
Definition civmanual.c:993
enum client_states client_state(void)
Definition civmanual.c:280
static bool manual_command(struct tag_types *tag_info)
Definition civmanual.c:298
const char * tileset_name_get(struct tileset *t)
Definition civmanual.c:248
const char * tileset_version(struct tileset *t)
Definition civmanual.c:256
struct tag_types html_tags
Definition civmanual.c:110
struct tag_types wiki_tags
Definition civmanual.c:156
client_states
Definition client_main.h:43
@ C_S_INITIAL
Definition client_main.h:44
const char * command_name(const struct command *pcommand)
Definition commands.c:731
const struct command * command_by_number(int i)
Definition commands.c:722
const char * command_short_help(const struct command *pcommand)
Definition commands.c:755
char * command_extra_help(const struct command *pcommand)
Definition commands.c:764
enum cmdlevel command_level(const struct command *pcommand)
Definition commands.c:779
const char * command_synopsis(const struct command *pcommand)
Definition commands.c:747
@ CMD_NUM
Definition commands.h:105
void connection_common_init(struct connection *pconn)
Definition connection.c:602
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
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
#define extra_type_by_cause_iterate_end
Definition extras.h:315
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
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)
@ O_SHIELD
Definition fc_types.h:91
@ O_FOOD
Definition fc_types.h:91
@ O_TRADE
Definition fc_types.h:91
#define LINE_BREAK
Definition fc_types.h:77
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 Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:57
void game_init(bool keep_ruleset_value)
Definition game.c:429
const char * government_name_translation(const struct government *pgovern)
Definition government.c:142
#define governments_iterate(NAME_pgov)
Definition government.h:121
#define governments_iterate_end
Definition government.h:124
void helptext_government(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct government *gov)
Definition helpdata.c:4175
void helptext_advance(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, int i)
Definition helpdata.c:3115
char * helptext_unit_upkeep_str(const struct unit_type *utype)
Definition helpdata.c:4834
char * helptext_building(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct impr_type *pimprove)
Definition helpdata.c:1316
char * helptext_unit(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct unit_type *utype)
Definition helpdata.c:1763
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
bool log_parse_level_str(const char *level_str, enum log_level *ret_level)
Definition log.c:86
#define fc_assert(condition)
Definition log.h:176
#define log_normal(message,...)
Definition log.h:107
@ LOG_NORMAL
Definition log.h:32
#define log_error(message,...)
Definition log.h:103
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
const char * move_points_text(int mp, bool reduce)
Definition movement.c:973
int len
Definition packhand.c:125
void registry_module_init(void)
Definition registry.c:30
void registry_module_close(void)
Definition registry.c:40
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
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:9227
void init_connections(void)
Definition sernet.c:1355
void settings_init(bool act)
Definition settings.c:4952
const char * setting_default_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4102
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4066
const char * setting_extra_help(const struct setting *pset, bool constant)
Definition settings.c:3179
int setting_number(const struct setting *pset)
Definition settings.c:3153
enum sset_category setting_category(const struct setting *pset)
Definition settings.c:3207
bool setting_locked(const struct setting *pset)
Definition settings.c:4420
bool setting_non_default(const struct setting *pset)
Definition settings.c:4394
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3191
int setting_int_max(const struct setting *pset)
Definition settings.c:3553
enum sset_level setting_level(const struct setting *pset)
Definition settings.c:3199
const char * setting_enum_val(const struct setting *pset, int val, bool pretty)
Definition settings.c:3702
const char * setting_short_help(const struct setting *pset)
Definition settings.c:3170
const char * setting_bitwise_bit(const struct setting *pset, int bit, bool pretty)
Definition settings.c:3887
int setting_int_min(const struct setting *pset)
Definition settings.c:3544
bool setting_is_changeable(const struct setting *pset, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3289
const char * setting_name(const struct setting *pset)
Definition settings.c:3162
#define settings_iterate(_level, _pset)
Definition settings.h:177
#define settings_iterate_end
Definition settings.h:183
bool str_to_int(const char *str, int *pint)
Definition shared.c:512
struct server_arguments srvarg
Definition srv_main.c:173
struct civ_game::@30::@34 server
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
char rulesetdir[MAX_LEN_NAME]
Definition game.h:236
enum cmdlevel access_level
Definition connection.h:182
Definition climisc.h:82
char name[MAX_LEN_NAME]
enum log_level loglevel
Definition srv_main.h:40
char * log_filename
Definition srv_main.h:42
const char * tail
Definition civmanual.c:106
const char * subitem_begin
Definition civmanual.c:104
const char * header
Definition civmanual.c:95
const char * item_begin
Definition civmanual.c:102
const char * file_ext
Definition civmanual.c:94
const char * sect_title_end
Definition civmanual.c:99
const char * title_begin
Definition civmanual.c:96
const char * image_end
Definition civmanual.c:101
const char * hline
Definition civmanual.c:107
const char * item_end
Definition civmanual.c:103
const char * sect_title_begin
Definition civmanual.c:98
const char * title_end
Definition civmanual.c:97
const char * subitem_end
Definition civmanual.c:105
const char * image_begin
Definition civmanual.c:100
enum universals_n kind
Definition fc_types.h:758
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
FILE * fc_fopen(const char *filename, const char *opentype)
Definition support.c:506
int fc_break_lines(char *str, size_t desired_len)
Definition support.c:1144
bool is_reg_file_for_access(const char *name, bool write_access)
Definition support.c:1129
char * fc_strrep_resize(char *str, size_t *len, const char *search, const char *replace)
Definition support.c:693
#define sz_strlcpy(dest, src)
Definition support.h:167
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:152
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:290
#define advance_iterate(_start, _p)
Definition tech.h:264
#define A_FIRST
Definition tech.h:44
#define advance_iterate_end
Definition tech.h:270
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:226
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:235
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
Definition terrain.c:682
#define terrain_type_iterate(_p)
Definition terrain.h:358
#define terrain_type_iterate_end
Definition terrain.h:364
void fc_interface_init_tool(void)
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1520
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1612
#define unit_type_iterate(_p)
Definition unittype.h:841
#define unit_type_iterate_end
Definition unittype.h:848
#define U_NOT_OBSOLETED
Definition unittype.h:509
const char * freeciv_name_version(void)
Definition version.c:35
const char * freeciv_datafile_version(void)
Definition version.c:186