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