Freeciv-3.1: /fast/freeciv/nightly/S3_1/tools/fcmp/mpcli.c Source File

Freeciv-3.1

Loading...
Searching...
No Matches
mpcli.c
Go to the documentation of this file.
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.
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 <stdlib.h>
19
20/* utility */
21#include "fc_cmdline.h"
22#include "fciconv.h"
23#include "fcintl.h"
24#include "log.h"
25#include "mem.h"
26
27/* common */
28#include "version.h"
29
30/* modinst */
31#include "download.h"
32#include "mpcmdline.h"
33#include "mpdb.h"
34
35#include "modinst.h"
36
37 struct fcmp_params fcmp = {
38 .list_url = MODPACK_LIST_URL,
39 .inst_prefix = NULL,
40 .autoinstall = NULL
41};
42
43/**********************************************************************/
46 static void msg_callback(const char *msg)
47{
48 log_normal("%s", msg);
49}
50
51/**********************************************************************/
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)
58{
59 const char *type_str;
60 const char *lic_str;
61 const char *inst_str;
62
63 if (modpack_type_is_valid(type)) {
64 type_str = _(modpack_type_name(type));
65 } else {
66 /* TRANS: Unknown modpack type */
67 type_str = _("?");
68 }
69
70 if (license != NULL) {
71 lic_str = license;
72 } else {
73 /* TRANS: License of modpack is not known */
74 lic_str = Q_("?license:Unknown");
75 }
76
77 inst_str = mpdb_installed_version(name, type);
78 if (inst_str == NULL) {
79 inst_str = _("Not installed");
80 }
81
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);
91 }
92}
93
94/**********************************************************************/
97 int main(int argc, char *argv[])
98{
99 int ui_options;
100
101 fcmp_init();
102
103 /* This modifies argv! */
104 ui_options = fcmp_parse_cmdline(argc, argv);
105
106 if (ui_options != -1) {
107 int i;
108
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"));
113
114 /* TRANS: No full stop after the URL, could cause confusion. */
115 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
116
117 ui_options = -1;
118 } else {
119 log_error(_("Unknown option '--' '%s'"), argv[i]);
120 ui_options = -1;
121 }
122 }
123 }
124
125 if (ui_options != -1) {
126 const char *rev_ver;
127
128 load_install_info_lists(&fcmp);
129
130 log_normal(_("Freeciv modpack installer (command line version)"));
131
132 log_normal("%s%s", word_version(), VERSION_STRING);
133
134 rev_ver = fc_git_revision();
135 if (rev_ver != NULL) {
136 log_normal(_("commit: %s"), rev_ver);
137 }
138
139 log_normal("%s", "");
140
141 if (fcmp.autoinstall == NULL) {
142 download_modpack_list(&fcmp, setup_modpack_list, msg_callback);
143 } else {
144 const char *errmsg;
145
146 errmsg = download_modpack(fcmp.autoinstall, &fcmp, msg_callback, NULL);
147
148 if (errmsg == NULL) {
149 log_normal(_("Modpack installed successfully"));
150 } else {
151 log_error(_("Modpack install failed: %s"), errmsg);
152 }
153 }
154
155 close_mpdbs();
156 }
157
158 fcmp_deinit();
159 cmdline_option_values_free();
160
161 return EXIT_SUCCESS;
162}
download_modpack
const char * download_modpack(const char *URL, const struct fcmp_params *fcmp, dl_msg_callback mcb, dl_pb_callback pbcb)
Definition download.c:66
download_modpack_list
const char * download_modpack_list(const struct fcmp_params *fcmp, modpack_list_setup_cb cb, dl_msg_callback mcb)
Definition download.c:403
download.h
is_option
bool is_option(const char *option_name, char *option)
Definition fc_cmdline.c:112
cmdline_option_values_free
void cmdline_option_values_free(void)
Definition fc_cmdline.c:97
fc_cmdline.h
fciconv.h
fc_fprintf
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
_
#define _(String)
Definition fcintl.h:67
type
GType type
Definition repodlgs.c:1312
name
const char * name
Definition inputfile.c:127
log.h
log_normal
#define log_normal(message,...)
Definition log.h:107
log_error
#define log_error(message,...)
Definition log.h:103
mem.h
load_install_info_lists
void load_install_info_lists(struct fcmp_params *fcmp)
Definition modinst.c:44
fcmp_deinit
void fcmp_deinit(void)
Definition modinst.c:98
fcmp_init
void fcmp_init(void)
Definition modinst.c:82
modinst.h
MODPACK_LIST_URL
#define MODPACK_LIST_URL
Definition modinst.h:30
main
int main(int argc, char *argv[])
Definition mpcli.c:97
fcmp
struct fcmp_params fcmp
Definition mpcli.c:37
setup_modpack_list
static void setup_modpack_list(const char *name, const char *URL, const char *version, const char *license, enum modpack_type type, const char *subtype, const char *notes)
Definition mpcli.c:54
msg_callback
static void msg_callback(const char *msg)
Definition mpcli.c:46
fcmp_parse_cmdline
int fcmp_parse_cmdline(int argc, char *argv[])
Definition mpcmdline.c:45
mpcmdline.h
mpdb_installed_version
const char * mpdb_installed_version(const char *name, enum modpack_type type)
Definition mpdb.c:253
close_mpdbs
void close_mpdbs(void)
Definition mpdb.c:202
mpdb.h
fcmp_params
Definition modinst.h:17
fcmp_params::list_url
const char * list_url
Definition modinst.h:18
fcmp_params::autoinstall
const char * autoinstall
Definition modinst.h:20
fc_git_revision
const char * fc_git_revision(void)
Definition version.c:75
word_version
const char * word_version(void)
Definition version.c:62
version.h