Freeciv-3.2
Loading...
Searching...
No Matches
mpcmdline.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/* utility */
19#include "fc_cmdline.h"
20#include "fciconv.h"
21#include "fcintl.h"
22#include "support.h"
23
24/* common */
25#include "fc_cmdhelp.h"
26#include "version.h"
27
28/* modinst */
29#include "modinst.h"
30
31#include "mpcmdline.h"
32
33extern struct fcmp_params fcmp;
34
35/**********************************************************************/
45int fcmp_parse_cmdline(int argc, char *argv[])
46{
47 int i = 1;
48 bool ui_separator = FALSE;
49 int ui_options = 0;
50 char *option = NULL;
51 enum log_level loglevel = LOG_NORMAL;
52
53 while (i < argc) {
54 if (ui_separator) {
55 argv[1 + ui_options] = argv[i];
56 ui_options++;
57 } else if (is_option("--help", argv[i])) {
58 struct cmdhelp *help = cmdhelp_new(argv[0]);
59
60 cmdhelp_add(help, "h", "help",
61 _("Print a summary of the options"));
62 cmdhelp_add(help, "L",
63 /* TRANS: "List" is exactly what user must type, do not translate. */
64 _("List URL"),
65 _("Load modpack list from given URL"));
66 cmdhelp_add(help, "p",
67 /* TRANS: "prefix" is exactly what user must type, do not translate. */
68 _("prefix DIR"),
69 _("Install modpacks to given directory hierarchy"));
70 cmdhelp_add(help, "i",
71 /* TRANS: "install" is exactly what user must type, do not translate. */
72 _("install URL"),
73 _("Automatically install modpack from a given URL"));
74#ifdef FREECIV_DEBUG
75 cmdhelp_add(help, "d",
76 /* TRANS: "debug" is exactly what user must type, do not translate. */
77 _("debug LEVEL"),
78 _("Set debug log level (one of f,e,w,n,v,d, or "
79 "d:file1,min,max:...)"));
80#else /* FREECIV_DEBUG */
81 cmdhelp_add(help, "d",
82 /* TRANS: "debug" is exactly what user must type, do not translate. */
83 _("debug LEVEL"),
84 _("Set debug log level (one of f,e,w,n,v)"));
85#endif /* FREECIV_DEBUG */
86 cmdhelp_add(help, "v", "version",
87 _("Print the version number"));
88 /* The function below prints a header and footer for the options.
89 * Furthermore, the options are sorted. */
91 cmdhelp_destroy(help);
92
94 } else if ((option = get_option_malloc("--List", argv, &i, argc, TRUE))) {
96 } else if ((option = get_option_malloc("--prefix", argv, &i, argc, TRUE))) {
98 } else if ((option = get_option_malloc("--install", argv, &i, argc, TRUE))) {
100 } else if ((option = get_option_malloc("--debug", argv, &i, argc, FALSE))) {
101 if (!log_parse_level_str(option, &loglevel)) {
103 _("Invalid debug level \"%s\" specified with --debug "
104 "option.\n"), option);
105 fc_fprintf(stderr, _("Try using --help.\n"));
107 }
108 free(option);
109 } else if (is_option("--version", argv[i])) {
111
113 } else if (is_option("--", argv[i])) {
115 } else {
116 fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]);
118 }
119
120 i++;
121 }
122
123 log_init(NULL, loglevel, NULL, NULL, -1);
124
125 if (fcmp.inst_prefix == NULL) {
127
128 if (fcmp.inst_prefix == NULL) {
129 log_error("Cannot determine freeciv storage directory");
130 }
131 }
132
133 return ui_options;
134}
char * incite_cost
Definition comments.c:75
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 fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
#define _(String)
Definition fcintl.h:67
void log_init(const char *filename, enum log_level initial_level, log_callback_fn callback, log_prefix_fn prefix, int fatal_assertions)
Definition log.c:245
bool log_parse_level_str(const char *level_str, enum log_level *ret_level)
Definition log.c:86
log_level
Definition log.h:28
@ LOG_NORMAL
Definition log.h:32
#define log_error(message,...)
Definition log.h:103
int fcmp_parse_cmdline(int argc, char *argv[])
Definition mpcmdline.c:45
struct fcmp_params fcmp
Definition mpcli.c:37
char * freeciv_storage_dir(void)
Definition shared.c:678
const char * inst_prefix
Definition modinst.h:19
const char * list_url
Definition modinst.h:18
const char * autoinstall
Definition modinst.h:20
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char * freeciv_name_version(void)
Definition version.c:35