Freeciv-3.4
Loading...
Searching...
No Matches
ruledit.cpp
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// ANSI
19#include <stdlib.h>
20
21#include <signal.h>
22
23// utility
24#include "executable.h"
25#include "fc_cmdline.h"
26#include "fciconv.h"
27#include "fcintl.h"
28#include "log.h"
29#include "registry.h"
30
31// common
32#include "fc_cmdhelp.h"
33#include "fc_interface.h"
34#include "version.h"
35
36// server
37#include "sernet.h"
38#include "settings.h"
39
40// tools/shared
41#include "tools_fc_interface.h"
42
43// ruledit
44#include "comments.h"
45#include "ruledit_qt.h"
46
47#include "ruledit.h"
48
49static int re_parse_cmdline(int argc, char *argv[]);
50
52
53static int fatal_assertions = -1;
54
55/**********************************************************************/
58int main(int argc, char **argv)
59{
60 int ui_options;
62
64
65 /* Initialize the fc_interface functions needed to understand rules.
66 * fc_interface_init_tool() includes low level support like
67 * guaranteeing that fc_vsnprintf() will work after it,
68 * so this need to be early. */
70
71#ifdef ENABLE_NLS
72 (void) bindtextdomain("freeciv-ruledit", get_locale_dir());
73#endif
74
76#ifdef ENABLE_NLS
78#endif
79
81
82 // Initialize command line arguments.
83 reargs.ruleset = nullptr;
84
86
87 if (ui_options != -1) {
89
91
92 // Reset aifill to zero
93 game.info.aifill = 0;
94
96
97 i_am_tool();
98
99 if (comments_load()) {
101
103 } else {
104 /* TRANS: 'Failed to load comments-x.y.txt' where x.y is
105 * freeciv version */
106 log_error(R__("Failed to load %s."), COMMENTS_FILE_NAME);
107
109 }
110 }
111
113 log_close();
115
116 // Clean up command line arguments.
118
119 return exit_status;
120}
121
122/**********************************************************************/
125static int re_parse_cmdline(int argc, char *argv[])
126{
127 enum log_level loglevel = LOG_NORMAL;
128 int i = 1;
129 bool ui_separator = FALSE;
130 int ui_options = 0;
131
132 while (i < argc) {
133 char *option;
134
135 if (ui_separator) {
136 argv[1 + ui_options] = argv[i];
137 ui_options++;
138 } else if (is_option("--help", argv[i])) {
139 struct cmdhelp *help = cmdhelp_new(argv[0]);
140
141 cmdhelp_add(help, "h", "help",
142 R__("Print a summary of the options"));
143#ifdef FREECIV_DEBUG
144 cmdhelp_add(help, "d",
145 // TRANS: "debug" is exactly what user must type, do not translate.
146 R__("debug LEVEL"),
147 R__("Set debug log level (one of f,e,w,n,v,d, or "
148 "d:file1,min,max:...)"));
149#else /* FREECIV_DEBUG */
150 cmdhelp_add(help, "d",
151 // TRANS: "debug" is exactly what user must type, do not translate.
152 R__("debug LEVEL"),
153 R__("Set debug log level (one of f,e,w,n,v)"));
154#endif /* FREECIV_DEBUG */
155 cmdhelp_add(help, "v", "version",
156 R__("Print the version number"));
157 cmdhelp_add(help, "r",
158 // TRANS: argument (don't translate) VALUE (translate)
159 R__("ruleset RULESET"),
160 R__("Ruleset to use as the starting point."));
161#ifndef FREECIV_NDEBUG
162 cmdhelp_add(help, "F",
163 // TRANS: "Fatal" is exactly what user must type, do not translate.
164 R__("Fatal [SIGNAL]"),
165 R__("Raise a signal on failed assertion"));
166#endif // FREECIV_NDEBUG
167 /* The function below prints a header and footer for the options.
168 * Furthermore, the options are sorted. */
169 cmdhelp_display(help, TRUE, TRUE, TRUE);
170 cmdhelp_destroy(help);
171
173 } else if (is_option("--version", argv[i])) {
175
177 } else if ((option = get_option_malloc("--ruleset", argv, &i, argc, true))) {
178 if (reargs.ruleset) {
179 fc_fprintf(stderr, R__("Can only edit one ruleset at a time.\n"));
180 } else {
182 }
183 } else if ((option = get_option_malloc("--debug", argv, &i, argc, FALSE))) {
184 if (!log_parse_level_str(option, &loglevel)) {
186 R__("Invalid debug level \"%s\" specified with --debug "
187 "option.\n"), option);
188 fc_fprintf(stderr, R__("Try using --help.\n"));
190 }
191 free(option);
192#ifndef FREECIV_NDEBUG
193 } else if (is_option("--Fatal", argv[i])) {
194 if (i + 1 >= argc || '-' == argv[i + 1][0]) {
196 } else if (str_to_int(argv[i + 1], &fatal_assertions)) {
197 i++;
198 } else {
199 fc_fprintf(stderr, R__("Invalid signal number \"%s\".\n"),
200 argv[i + 1]);
201 fc_fprintf(stderr, R__("Try using --help.\n"));
203 }
204#endif // FREECIV_NDEBUG
205 } else if (is_option("--", argv[i])) {
207 } else {
208 fc_fprintf(stderr, R__("Unrecognized option: \"%s\"\n"), argv[i]);
210 }
211
212 i++;
213 }
214
215 log_init(nullptr, loglevel, nullptr, nullptr, fatal_assertions);
216
217 return ui_options;
218}
219
220/**********************************************************************/
223void show_experimental(QWidget *wdg)
224{
225#ifdef RULEDIT_EXPERIMENTAL
226 wdg->show();
227#else
228 wdg->hide();
229#endif
230}
void comments_free(void)
Definition comments.c:276
bool comments_load(void)
Definition comments.c:109
char * incite_cost
Definition comments.c:76
#define COMMENTS_FILE_NAME
Definition comments.h:20
void executable_init(void)
Definition executable.c:34
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 cmdline_option_values_free(void)
Definition fc_cmdline.c:97
void libfreeciv_free(void)
static void i_am_tool(void)
const char * get_internal_encoding(void)
Definition fciconv.c:182
static char void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Definition fciconv.c:70
#define FC_DEFAULT_DATA_ENCODING
Definition fciconv.h:89
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
const char * get_locale_dir(void)
Definition fcintl.c:111
#define bindtextdomain(Package, Directory)
Definition fcintl.h:82
#define R__(String)
Definition fcintl.h:75
struct civ_game game
Definition game.c:62
void game_init(bool keep_ruleset_value)
Definition game.c:446
void log_close(void)
Definition log.c:270
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:29
@ LOG_NORMAL
Definition log.h:33
#define log_error(message,...)
Definition log.h:104
void registry_module_init(void)
Definition registry.c:31
void registry_module_close(void)
Definition registry.c:41
struct ruledit_arguments reargs
Definition ruledit.cpp:51
int main(int argc, char **argv)
Definition ruledit.cpp:58
static int re_parse_cmdline(int argc, char *argv[])
Definition ruledit.cpp:125
void show_experimental(QWidget *wdg)
Definition ruledit.cpp:223
static int fatal_assertions
Definition ruledit.cpp:53
int ruledit_qt_run(int argc, char **argv)
void init_connections(void)
Definition sernet.c:1362
void settings_init(bool act)
Definition settings.c:5257
bool str_to_int(const char *str, int *pint)
Definition shared.c:515
struct packet_game_info info
Definition game.h:89
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
void fc_interface_init_tool(void)
const char * freeciv_name_version(void)
Definition version.c:35