Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #657117 ยป 0034-freeciv-manual-Make-output-format-selection-runtime-.patch

Marko Lindqvist, 2018-10-07 11:29 AM

View differences:

configure.ac
AM_CONDITIONAL([CLIENT], [test "x$client" = "xyes"])
AC_ARG_ENABLE([freeciv-manual],
AS_HELP_STRING([--enable-freeciv-manual=no/yes/wiki/html], [build freeciv-manual [wiki]]),
AS_HELP_STRING([--enable-freeciv-manual], [build freeciv-manual]),
[case "${enableval}" in
yes|wiki) fcmanual=wiki ;;
no) fcmanual=no ;;
html) fcmanual=html ;;
yes) fcmanual=yes ;;
no) fcmanual=no ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-freeciv-manual]) ;;
esac], [fcmanual=wiki])
esac], [fcmanual=yes])
AM_CONDITIONAL([FCMANUAL], [test "x$fcmanual" != "xno"])
if test x$fcmanual = xhtml ; then
AC_DEFINE([MANUAL_USE_HTML], [1], [Build freeciv-manual with html formatting])
fi
dnl freeciv-modpack checks
AC_ARG_ENABLE([fcmp],
AS_HELP_STRING([--enable-fcmp=no/yes/gtk3/gtk3x/qt/cli/all/auto], [build freeciv-modpack-program [auto]]),
scripts/travis-build.sh
apt-get -y install ${dependencies}
# Configure and build Freeciv
./autogen.sh CFLAGS="-O3" --enable-client=gtk3,qt,sdl2,stub --enable-fcmp=cli,gtk3,qt --enable-freeciv-manual=html --enable-ai-static=classic,threaded,tex --prefix=${HOME}/freeciv/ && make -s -j$(nproc)
./autogen.sh CFLAGS="-O3" --enable-client=gtk3,qt,sdl2,stub --enable-fcmp=cli,gtk3,qt --enable-freeciv-manual --enable-ai-static=classic,threaded,tex --prefix=${HOME}/freeciv/ && make -s -j$(nproc)
sudo -u travis make install
echo "Freeciv build successful!"
tools/civmanual.c
MANUAL_COUNT
};
/* This formats the manual for an HTML wiki. */
#ifdef MANUAL_USE_HTML
#define FILE_EXT "html"
#define HEADER "<html><head><link rel=\"stylesheet\" type=\"text/css\" "\
"href=\"manual.css\"/><meta http-equiv=\"Content-Type\" "\
"content=\"text/html; charset=UTF-8\"/></head><body>\n\n"
#define TITLE_BEGIN "<h1>"
#define TITLE_END "</h1>"
#define SECTION_TITLE_BEGIN "<h3 class='section'>"
#define SECTION_TITLE_END "</h3>"
#define IMAGE_BEGIN "<img src=\""
#define IMAGE_END ".png\">"
#define ITEM_BEGIN "<div class='item' id='%s%d'>\n"
#define ITEM_END "</div>\n"
#define SUBITEM_BEGIN "<pre class='%s'>"
#define SUBITEM_END "</pre>\n"
#define TAIL "</body></html>"
#else /* MANUAL_USE_HTML */
#define FILE_EXT "mediawiki"
#define HEADER " "
#define TITLE_BEGIN "="
#define TITLE_END "="
#define SECTION_TITLE_BEGIN "==="
#define SECTION_TITLE_END "==="
#define IMAGE_BEGIN "[[Image:"
#define IMAGE_END ".png]]"
#define ITEM_BEGIN "----\n<!-- %s %d -->\n"
#define ITEM_END "\n"
#define SUBITEM_BEGIN "<!-- %s -->\n"
#define SUBITEM_END "\n"
#define TAIL " "
#endif /* MANUAL_USE_HTML */
struct tag_types {
const char *file_ext;
const char *header;
const char *title_begin;
const char *title_end;
const char *sect_title_begin;
const char *sect_title_end;
const char *image_begin;
const char *image_end;
const char *item_begin;
const char *item_end;
const char *subitem_begin;
const char *subitem_end;
const char *tail;
};
struct tag_types html_tags = {
/* file extension */
"html",
/* header */
"<html><head><link rel=\"stylesheet\" type=\"text/css\" "
"href=\"manual.css\"/><meta http-equiv=\"Content-Type\" "
"content=\"text/html; charset=UTF-8\"/></head><body>\n\n",
/* title begin */
"<h1>",
/* title end */
"</h1>",
/* section title begin */
"<h3 class='section'>",
/* section title end */
"</h3>",
/* image begin */
"<img src=\"",
/* image end */
".png\">",
/* item begin */
"<div class='item' id='%s%d'>\n",
/* item end */
"</div>\n",
/* subitem begin */
"<pre class='%s'>",
/* subitem end */
"</pre>\n",
/* tail */
"</body></html>"
};
struct tag_types wiki_tags = {
/* file extension */
"mediawiki",
/* header */
" ",
/* title begin */
"=",
/* title end */
"=",
/* section title begin */
"===",
/* section title end */
"===",
/* image begin */
"[[Image:",
/* image end */
".png]]",
/* item begin */
"----\n<!-- %s %d -->\n",
/* item end */
"\n",
/* subitem begin */
"<!-- %s -->\n",
/* subitem end */
"\n",
/* tail */
" "
};
void insert_client_build_info(char *outbuf, size_t outlen);
......
}
/**********************************************************************//**
Write a server manual in the format chosen at build time, then quit.
Write a server manual, then quit.
**************************************************************************/
static bool manual_command(void)
static bool manual_command(struct tag_types *tag_info)
{
FILE *doc;
char filename[40];
......
int ri;
fc_snprintf(filename, sizeof(filename), "%s%d.%s",
game.server.rulesetdir, manuals + 1, FILE_EXT);
game.server.rulesetdir, manuals + 1, tag_info->file_ext);
if (!is_reg_file_for_access(filename, TRUE)
|| !(doc = fc_fopen(filename, "w"))) {
......
return FALSE;
}
fprintf(doc, HEADER);
fprintf(doc, "%s", tag_info->header);
fprintf(doc, "<!-- Generated by freeciv-manual version %s -->\n\n",
freeciv_datafile_version());
switch (manuals) {
case MANUAL_SETTINGS:
/* TRANS: markup ... Freeciv version ... ruleset name ... markup */
fprintf(doc, _("%sFreeciv %s server options (%s)%s\n\n"), TITLE_BEGIN,
VERSION_STRING, game.control.name, TITLE_END);
fprintf(doc, _("%sFreeciv %s server options (%s)%s\n\n"), tag_info->title_begin,
VERSION_STRING, game.control.name, tag_info->title_end);
settings_iterate(SSET_ALL, pset) {
char buf[256];
const char *sethelp;
fprintf(doc, ITEM_BEGIN, "setting", setting_number(pset));
fprintf(doc, "%s%s - %s%s\n\n", SECTION_TITLE_BEGIN,
fprintf(doc, tag_info->item_begin, "setting", setting_number(pset));
fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin,
setting_name(pset), _(setting_short_help(pset)),
SECTION_TITLE_END);
tag_info->sect_title_end);
sethelp = _(setting_extra_help(pset, TRUE));
if (strlen(sethelp) > 0) {
char *help = fc_strdup(sethelp);
......
setting_value_name(pset, TRUE, buf, sizeof(buf)));
}
fprintf(doc, ITEM_END);
fprintf(doc, "%s", tag_info->item_end);
} settings_iterate_end;
break;
case MANUAL_COMMANDS:
/* TRANS: markup ... Freeciv version ... markup */
fprintf(doc, _("%sFreeciv %s server commands%s\n\n"), TITLE_BEGIN,
VERSION_STRING, TITLE_END);
fprintf(doc, _("%sFreeciv %s server commands%s\n\n"), tag_info->title_begin,
VERSION_STRING, tag_info->title_end);
for (i = 0; i < CMD_NUM; i++) {
const struct command *cmd = command_by_number(i);
fprintf(doc, ITEM_BEGIN, "cmd", i);
fprintf(doc, "%s%s - %s%s\n\n", SECTION_TITLE_BEGIN,
fprintf(doc, tag_info->item_begin, "cmd", i);
fprintf(doc, "%s%s - %s%s\n\n", tag_info->sect_title_begin,
command_name(cmd), command_short_help(cmd),
SECTION_TITLE_END);
tag_info->sect_title_end);
if (command_synopsis(cmd)) {
char *cmdstr = fc_strdup(command_synopsis(cmd));
size_t cmdstr_len = strlen(cmdstr) + 1;
......
}
}
fprintf(doc, ITEM_END);
fprintf(doc, "%s", tag_info->item_end);
}
break;
case MANUAL_TERRAIN:
/* TRANS: markup ... Freeciv version ... ruleset name ... markup */
fprintf(doc, _("%sFreeciv %s terrain help (%s)%s\n\n"), TITLE_BEGIN,
VERSION_STRING, game.control.name, TITLE_END);
fprintf(doc, _("%sFreeciv %s terrain help (%s)%s\n\n"), tag_info->title_begin,
VERSION_STRING, game.control.name, tag_info->title_end);
fprintf(doc, "<table><tr bgcolor=#9bc3d1><th colspan=2>%s</th>", _("Terrain"));
fprintf(doc, "<th>F/P/T</th><th>%s</th>", _("Resources"));
fprintf(doc, "<th>%s<br/>%s</th>", _("Move cost"), _("Defense bonus"));
......
continue;
}
fprintf(doc, "<tr><td>" IMAGE_BEGIN "%s" IMAGE_END "</td><td>%s</td>",
pterrain->graphic_str, terrain_name_translation(pterrain));
fprintf(doc, "<tr><td>%s%s%s</td><td>%s</td>",
tag_info->image_begin, pterrain->graphic_str, tag_info->image_end,
terrain_name_translation(pterrain));
fprintf(doc, "<td>%d/%d/%d</td>\n",
pterrain->output[O_FOOD], pterrain->output[O_SHIELD],
pterrain->output[O_TRADE]);
fprintf(doc, "<td><table width=\"100%%\">\n");
for (r = pterrain->resources; *r; r++) {
fprintf(doc, "<tr><td>" IMAGE_BEGIN "%s" IMAGE_END "</td><td>%s</td>"
fprintf(doc, "<tr><td>%s%s%s</td><td>%s</td>"
"<td align=\"right\">%d/%d/%d</td></tr>\n",
(*r)->graphic_str,
tag_info->image_begin, (*r)->graphic_str, tag_info->image_end,
extra_name_translation(*r),
(*r)->data.resource->output[O_FOOD],
(*r)->data.resource->output[O_SHIELD],
......
case MANUAL_WONDERS:
if (manuals == MANUAL_BUILDINGS) {
/* TRANS: markup ... Freeciv version ... ruleset name ... markup */
fprintf(doc, _("%sFreeciv %s buildings help (%s)%s\n\n"), TITLE_BEGIN,
VERSION_STRING, game.control.name, TITLE_END);
fprintf(doc, _("%sFreeciv %s buildings help (%s)%s\n\n"), tag_info->title_begin,
VERSION_STRING, game.control.name, tag_info->title_end);
} else {
/* TRANS: markup ... Freeciv version ... ruleset name ... markup */
fprintf(doc, _("%sFreeciv %s wonders help (%s)%s\n\n"), TITLE_BEGIN,
VERSION_STRING, game.control.name, TITLE_END);
fprintf(doc, _("%sFreeciv %s wonders help (%s)%s\n\n"), tag_info->title_begin,
VERSION_STRING, game.control.name, tag_info->title_end);
}
fprintf(doc, "<table>\n<tr bgcolor=#9bc3d1><th colspan=2>%s</th>"
......
struct advance *obs_tech = NULL;
if (!valid_improvement(pimprove)
|| is_great_wonder(pimprove) == (manuals == MANUAL_BUILDINGS)) {
|| is_great_wonder(pimprove) == (manuals == MANUAL_BUILDINGS)) {
continue;
}
helptext_building(buf, sizeof(buf), NULL, NULL, pimprove);
fprintf(doc, "<tr><td>" IMAGE_BEGIN "%s" IMAGE_END "</td><td>%s</td>\n"
fprintf(doc, "<tr><td>%s%s%s</td><td>%s</td>\n"
"<td align=\"center\"><b>%d</b><br/>%d</td>\n<td>",
pimprove->graphic_str,
tag_info->image_begin, pimprove->graphic_str, tag_info->image_end,
improvement_name_translation(pimprove),
pimprove->build_cost,
pimprove->upkeep);
......
* manual pages. */
/* FIXME: this doesn't resemble the wiki manual at all. */
/* TRANS: markup ... Freeciv version ... ruleset name ... markup */
fprintf(doc, _("%sFreeciv %s governments help (%s)%s\n\n"), TITLE_BEGIN,
VERSION_STRING, game.control.name, TITLE_END);
fprintf(doc, _("%sFreeciv %s governments help (%s)%s\n\n"), tag_info->title_begin,
VERSION_STRING, game.control.name, tag_info->title_end);
governments_iterate(pgov) {
char buf[64000];
fprintf(doc, ITEM_BEGIN, "gov", pgov->item_number);
fprintf(doc, "%s%s%s\n\n", SECTION_TITLE_BEGIN,
government_name_translation(pgov), SECTION_TITLE_END);
fprintf(doc, SUBITEM_BEGIN, "helptext");
fprintf(doc, tag_info->item_begin, "gov", pgov->item_number);
fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin,
government_name_translation(pgov), tag_info->sect_title_end);
fprintf(doc, tag_info->subitem_begin, "helptext");
helptext_government(buf, sizeof(buf), NULL, NULL, pgov);
fprintf(doc, "%s\n\n", buf);
fprintf(doc, SUBITEM_END);
fprintf(doc, ITEM_END);
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, "%s", tag_info->item_end);
} governments_iterate_end;
break;
......
/* FIXME: this doesn't resemble the wiki manual at all. */
/* TRANS: markup ... Freeciv version ... ruleset name ... markup */
fprintf(doc, _("%sFreeciv %s unit types help (%s)%s\n\n"),
TITLE_BEGIN, VERSION_STRING, game.control.name, TITLE_END);
tag_info->title_begin, VERSION_STRING, game.control.name,
tag_info->title_end);
unit_type_iterate(putype) {
char buf[64000];
fprintf(doc, ITEM_BEGIN, "utype", putype->item_number);
fprintf(doc, "%s%s%s\n\n", SECTION_TITLE_BEGIN,
utype_name_translation(putype), SECTION_TITLE_END);
fprintf(doc, SUBITEM_BEGIN, "cost");
fprintf(doc, tag_info->item_begin, "utype", putype->item_number);
fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin,
utype_name_translation(putype), tag_info->sect_title_end);
fprintf(doc, tag_info->subitem_begin, "cost");
fprintf(doc,
PL_("Cost: %d shield",
"Cost: %d shields",
utype_build_shield_cost_base(putype)),
utype_build_shield_cost_base(putype));
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "upkeep");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "upkeep");
fprintf(doc, _("Upkeep: %s"),
helptext_unit_upkeep_str(putype));
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "moves");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "moves");
fprintf(doc, _("Moves: %s"),
move_points_text(putype->move_rate, TRUE));
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "vision");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "vision");
fprintf(doc, _("Vision: %d"),
(int)sqrt((double)putype->vision_radius_sq));
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "attack");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "attack");
fprintf(doc, _("Attack: %d"),
putype->attack_strength);
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "defense");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "defense");
fprintf(doc, _("Defense: %d"),
putype->defense_strength);
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "firepower");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "firepower");
fprintf(doc, _("Firepower: %d"),
putype->firepower);
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "hitpoints");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "hitpoints");
fprintf(doc, _("Hitpoints: %d"),
putype->hp);
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "obsolete");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "obsolete");
fprintf(doc, _("Obsolete by: %s"),
U_NOT_OBSOLETED == putype->obsoleted_by ?
Q_("?utype:None") :
utype_name_translation(putype->obsoleted_by));
fprintf(doc, SUBITEM_END);
fprintf(doc, SUBITEM_BEGIN, "helptext");
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, tag_info->subitem_begin, "helptext");
helptext_unit(buf, sizeof(buf), NULL, "", putype);
fprintf(doc, "%s", buf);
fprintf(doc, SUBITEM_END);
fprintf(doc, ITEM_END);
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, "%s", tag_info->item_end);
} unit_type_iterate_end;
break;
......
/* FIXME: this doesn't resemble the wiki manual at all. */
/* TRANS: markup ... Freeciv version ... ruleset name ... markup */
fprintf(doc, _("%sFreeciv %s tech help (%s)%s\n\n"),
TITLE_BEGIN, VERSION_STRING, game.control.name, TITLE_END);
tag_info->title_begin, VERSION_STRING, game.control.name,
tag_info->title_end);
advance_iterate(A_FIRST, ptech) {
if (valid_advance(ptech)) {
char buf[64000];
fprintf(doc, ITEM_BEGIN, "tech", ptech->item_number);
fprintf(doc, "%s%s%s\n\n", SECTION_TITLE_BEGIN,
advance_name_translation(ptech), SECTION_TITLE_END);
fprintf(doc, tag_info->item_begin, "tech", ptech->item_number);
fprintf(doc, "%s%s%s\n\n", tag_info->sect_title_begin,
advance_name_translation(ptech), tag_info->sect_title_end);
fprintf(doc, SUBITEM_BEGIN, "helptext");
fprintf(doc, tag_info->subitem_begin, "helptext");
helptext_advance(buf, sizeof(buf), NULL, "", ptech->item_number);
fprintf(doc, "%s", buf);
fprintf(doc, SUBITEM_END);
fprintf(doc, "%s", tag_info->subitem_end);
fprintf(doc, ITEM_END);
fprintf(doc, "%s", tag_info->item_end);
}
} advance_iterate_end;
break;
......
} /* switch */
fprintf(doc, TAIL);
fprintf(doc, "%s", tag_info->tail);
fclose(doc);
log_normal(_("Manual file %s successfully written."), filename);
} /* manuals */
......
bool showvers = FALSE;
char *option = NULL;
int retval = EXIT_SUCCESS;
struct tag_types *tag_info = &html_tags;
init_nls();
registry_module_init();
......
showvers = TRUE;
} else if ((option = get_option_malloc("--log", argv, &inx, argc, TRUE))) {
srvarg.log_filename = option;
} else if (is_option("--wiki", argv[inx])) {
tag_info = &wiki_tags;
#ifndef FREECIV_NDEBUG
} else if (is_option("--Fatal", argv[inx])) {
if (inx + 1 >= argc || '-' == argv[inx + 1][0]) {
......
_("Make manual for RULESET"));
cmdhelp_add(help, "v", "version",
_("Print the version number"));
cmdhelp_add(help, "w", "wiki",
_("Write manual in wiki format"));
/* The function below prints a header and footer for the options.
* Furthermore, the options are sorted. */
......
exit(EXIT_SUCCESS);
}
if (!manual_command()) {
if (!manual_command(tag_info)) {
retval = EXIT_FAILURE;
}
    (1-1/1)