Remove hard limitation that AI wonder cities never build settlers
[freeciv.git] / tools / mpcli.c
blobef32b9524c6e1d2300333c79b02cdb4d6624bff0
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include <stdlib.h>
20 /* utility */
21 #include "fc_cmdline.h"
22 #include "fciconv.h"
23 #include "fcintl.h"
24 #include "log.h"
25 #include "mem.h"
27 /* common */
28 #include "version.h"
30 /* modinst */
31 #include "download.h"
32 #include "mpcmdline.h"
33 #include "mpdb.h"
35 #include "modinst.h"
37 struct fcmp_params fcmp = {
38 .list_url = MODPACK_LIST_URL,
39 .inst_prefix = NULL,
40 .autoinstall = NULL
43 /**************************************************************************
44 Progress indications from downloader
45 **************************************************************************/
46 static void msg_callback(const char *msg)
48 log_normal("%s", msg);
51 /**************************************************************************
52 Build main modpack list view
53 **************************************************************************/
54 static void setup_modpack_list(const char *name, const char *URL,
55 const char *version, const char *license,
56 enum modpack_type type, const char *subtype,
57 const char *notes)
59 const char *type_str;
60 const char *lic_str;
61 const char *inst_str;
63 if (modpack_type_is_valid(type)) {
64 type_str = _(modpack_type_name(type));
65 } else {
66 /* TRANS: Unknown modpack type */
67 type_str = _("?");
70 if (license != NULL) {
71 lic_str = license;
72 } else {
73 /* TRANS: License of modpack is not known */
74 lic_str = Q_("?license:Unknown");
77 inst_str = get_installed_version(name, type);
78 if (inst_str == NULL) {
79 inst_str = _("Not installed");
82 log_normal("%s", "");
83 log_normal(_("Name=\"%s\""), name);
84 log_normal(_("Version=\"%s\""), version);
85 log_normal(_("Installed=\"%s\""), inst_str);
86 log_normal(_("Type=\"%s\" / \"%s\""), type_str, subtype);
87 log_normal(_("License=\"%s\""), lic_str);
88 log_normal(_("URL=\"%s\""), URL);
89 if (notes != NULL) {
90 log_normal(_("Comment=\"%s\""), notes);
94 /**************************************************************************
95 Entry point of the freeciv-modpack program
96 **************************************************************************/
97 int main(int argc, char *argv[])
99 int ui_options;
101 fcmp_init();
103 /* This modifies argv! */
104 ui_options = fcmp_parse_cmdline(argc, argv);
106 if (ui_options != -1) {
107 int i;
109 for (i = 1; i <= ui_options; i++) {
110 if (is_option("--help", argv[i])) {
111 fc_fprintf(stderr,
112 _("This modpack installer does not support any specific options\n\n"));
114 /* TRANS: No full stop after the URL, could cause confusion. */
115 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
117 ui_options = -1;
118 } else {
119 log_error(_("Unknown option '--' '%s'"), argv[i]);
120 ui_options = -1;
125 if (ui_options != -1) {
126 const char *rev_ver = fc_svn_revision();
128 load_install_info_lists(&fcmp);
130 log_normal(_("Freeciv modpack installer (command line version)"));
132 if (rev_ver == NULL) {
133 log_normal("%s%s", word_version(), VERSION_STRING);
135 rev_ver = fc_git_revision();
136 if (rev_ver != NULL) {
137 log_normal(_("commit: %s"), rev_ver);
139 } else {
140 log_normal("%s%s (%s)", word_version(), VERSION_STRING, rev_ver);
143 log_normal("%s", "");
145 if (fcmp.autoinstall == NULL) {
146 download_modpack_list(&fcmp, setup_modpack_list, msg_callback);
147 } else {
148 const char *errmsg;
150 errmsg = download_modpack(fcmp.autoinstall, &fcmp, msg_callback, NULL);
152 if (errmsg == NULL) {
153 log_normal(_("Modpack installed successfully"));
154 } else {
155 log_error(_("Modpack install failed: %s"), errmsg);
159 save_install_info_lists(&fcmp);
162 fcmp_deinit();
163 cmdline_option_values_free();
165 return EXIT_SUCCESS;