Freeciv-3.2: /fast/freeciv/nightly/S3_2/tools/fcmp/mpcmdline.c Source File

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/**********************************************************************/
45 int 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. */
90 cmdhelp_display(help, TRUE, TRUE, TRUE);
91 cmdhelp_destroy(help);
92
93 exit(EXIT_SUCCESS);
94 } else if ((option = get_option_malloc("--List", argv, &i, argc, TRUE))) {
95 fcmp.list_url = option;
96 } else if ((option = get_option_malloc("--prefix", argv, &i, argc, TRUE))) {
97 fcmp.inst_prefix = option;
98 } else if ((option = get_option_malloc("--install", argv, &i, argc, TRUE))) {
99 fcmp.autoinstall = option;
100 } else if ((option = get_option_malloc("--debug", argv, &i, argc, FALSE))) {
101 if (!log_parse_level_str(option, &loglevel)) {
102 fc_fprintf(stderr,
103 _("Invalid debug level \"%s\" specified with --debug "
104 "option.\n"), option);
105 fc_fprintf(stderr, _("Try using --help.\n"));
106 exit(EXIT_FAILURE);
107 }
108 free(option);
109 } else if (is_option("--version", argv[i])) {
110 fc_fprintf(stderr, "%s \n", freeciv_name_version());
111
112 exit(EXIT_SUCCESS);
113 } else if (is_option("--", argv[i])) {
114 ui_separator = TRUE;
115 } else {
116 fc_fprintf(stderr, _("Unrecognized option: \"%s\"\n"), argv[i]);
117 exit(EXIT_FAILURE);
118 }
119
120 i++;
121 }
122
123 log_init(NULL, loglevel, NULL, NULL, -1);
124
125 if (fcmp.inst_prefix == NULL) {
126 fcmp.inst_prefix = freeciv_storage_dir();
127
128 if (fcmp.inst_prefix == NULL) {
129 log_error("Cannot determine freeciv storage directory");
130 }
131 }
132
133 return ui_options;
134}
incite_cost
char * incite_cost
Definition comments.c:74
cmdhelp_destroy
void cmdhelp_destroy(struct cmdhelp *pcmdhelp)
Definition fc_cmdhelp.c:70
cmdhelp_display
void cmdhelp_display(struct cmdhelp *pcmdhelp, bool sort, bool gui_options, bool report_bugs)
Definition fc_cmdhelp.c:104
cmdhelp_new
struct cmdhelp * cmdhelp_new(const char *cmdname)
Definition fc_cmdhelp.c:57
cmdhelp_add
void cmdhelp_add(struct cmdhelp *pcmdhelp, const char *shortarg, const char *longarg, const char *helpstr,...)
Definition fc_cmdhelp.c:86
fc_cmdhelp.h
is_option
bool is_option(const char *option_name, char *option)
Definition fc_cmdline.c:112
get_option_malloc
char * get_option_malloc(const char *option_name, char **argv, int *i, int argc, bool gc)
Definition fc_cmdline.c:50
fc_cmdline.h
fciconv.h
fc_fprintf
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
fcintl.h
_
#define _(String)
Definition fcintl.h:67
log_init
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
log_parse_level_str
bool log_parse_level_str(const char *level_str, enum log_level *ret_level)
Definition log.c:86
log_level
log_level
Definition log.h:28
LOG_NORMAL
@ LOG_NORMAL
Definition log.h:32
log_error
#define log_error(message,...)
Definition log.h:103
modinst.h
fcmp_parse_cmdline
int fcmp_parse_cmdline(int argc, char *argv[])
Definition mpcmdline.c:45
fcmp
struct fcmp_params fcmp
Definition mpcli.c:37
mpcmdline.h
freeciv_storage_dir
char * freeciv_storage_dir(void)
Definition shared.c:678
cmdhelp
Definition fc_cmdhelp.c:43
fcmp_params
Definition modinst.h:17
fcmp_params::inst_prefix
const char * inst_prefix
Definition modinst.h:19
fcmp_params::list_url
const char * list_url
Definition modinst.h:18
fcmp_params::autoinstall
const char * autoinstall
Definition modinst.h:20
option
Definition options.c:478
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
freeciv_name_version
const char * freeciv_name_version(void)
Definition version.c:35
version.h