Freeciv-3.3
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#include "fc_prehdrs.h"
19
20// ANSI
21#include <stdlib.h>
22
23#include <signal.h>
24
25#ifdef FREECIV_MSWINDOWS
26#include <windows.h>
27#endif
28
29// utility
30#include "fc_cmdline.h"
31#include "fciconv.h"
32#include "fcintl.h"
33#include "log.h"
34#include "registry.h"
35
36// common
37#include "fc_cmdhelp.h"
38#include "fc_interface.h"
39#include "version.h"
40
41// server
42#include "sernet.h"
43#include "settings.h"
44
45// tools/shared
46#include "tools_fc_interface.h"
47
48// ruledit
49#include "comments.h"
50#include "ruledit_qt.h"
51
52#include "ruledit.h"
53
54static int re_parse_cmdline(int argc, char *argv[]);
55
57
58static int fatal_assertions = -1;
59
60/**********************************************************************/
63int main(int argc, char **argv)
64{
65 int ui_options;
67
68 // Load Windows post-crash debugger
69#ifdef FREECIV_MSWINDOWS
70# ifndef FREECIV_NDEBUG
71 if (LoadLibrary("exchndl.dll") == nullptr) {
72# ifdef FREECIV_DEBUG
73 fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n");
74# endif // FREECIV_DEBUG
75 }
76# endif // FREECIV_NDEBUG
77#endif // FREECIV_MSWINDOWS
78
79 /* Initialize the fc_interface functions needed to understand rules.
80 * fc_interface_init_tool() includes low level support like
81 * guaranteeing that fc_vsnprintf() will work after it,
82 * so this need to be early. */
84
85#ifdef ENABLE_NLS
86 (void) bindtextdomain("freeciv-ruledit", get_locale_dir());
87#endif
88
90#ifdef ENABLE_NLS
92#endif
93
95
96 // Initialize command line arguments.
97 reargs.ruleset = nullptr;
98
100
101 if (ui_options != -1) {
103
105
106 // Reset aifill to zero
107 game.info.aifill = 0;
108
110
111 i_am_tool();
112
113 if (comments_load()) {
115
117 } else {
118 /* TRANS: 'Failed to load comments-x.y.txt' where x.y is
119 * freeciv version */
120 log_error(R__("Failed to load %s."), COMMENTS_FILE_NAME);
121
123 }
124 }
125
127 log_close();
129
130 // Clean up command line arguments.
132
133 return exit_status;
134}
135
136/**********************************************************************/
139static int re_parse_cmdline(int argc, char *argv[])
140{
141 enum log_level loglevel = LOG_NORMAL;
142 int i = 1;
143 bool ui_separator = FALSE;
144 int ui_options = 0;
145
146 while (i < argc) {
147 char *option;
148
149 if (ui_separator) {
150 argv[1 + ui_options] = argv[i];
151 ui_options++;
152 } else if (is_option("--help", argv[i])) {
153 struct cmdhelp *help = cmdhelp_new(argv[0]);
154
155 cmdhelp_add(help, "h", "help",
156 R__("Print a summary of the options"));
157#ifdef FREECIV_DEBUG
158 cmdhelp_add(help, "d",
159 // TRANS: "debug" is exactly what user must type, do not translate.
160 R__("debug LEVEL"),
161 R__("Set debug log level (one of f,e,w,n,v,d, or "
162 "d:file1,min,max:...)"));
163#else /* FREECIV_DEBUG */
164 cmdhelp_add(help, "d",
165 // TRANS: "debug" is exactly what user must type, do not translate.
166 R__("debug LEVEL"),
167 R__("Set debug log level (one of f,e,w,n,v)"));
168#endif /* FREECIV_DEBUG */
169 cmdhelp_add(help, "v", "version",
170 R__("Print the version number"));
171 cmdhelp_add(help, "r",
172 // TRANS: argument (don't translate) VALUE (translate)
173 R__("ruleset RULESET"),
174 R__("Ruleset to use as the starting point."));
175#ifndef FREECIV_NDEBUG
176 cmdhelp_add(help, "F",
177 // TRANS: "Fatal" is exactly what user must type, do not translate.
178 R__("Fatal [SIGNAL]"),
179 R__("Raise a signal on failed assertion"));
180#endif // FREECIV_NDEBUG
181 /* The function below prints a header and footer for the options.
182 * Furthermore, the options are sorted. */
183 cmdhelp_display(help, TRUE, TRUE, TRUE);
184 cmdhelp_destroy(help);
185
187 } else if (is_option("--version", argv[i])) {
189
191 } else if ((option = get_option_malloc("--ruleset", argv, &i, argc, true))) {
192 if (reargs.ruleset) {
193 fc_fprintf(stderr, R__("Can only edit one ruleset at a time.\n"));
194 } else {
196 }
197 } else if ((option = get_option_malloc("--debug", argv, &i, argc, FALSE))) {
198 if (!log_parse_level_str(option, &loglevel)) {
200 R__("Invalid debug level \"%s\" specified with --debug "
201 "option.\n"), option);
202 fc_fprintf(stderr, R__("Try using --help.\n"));
204 }
205 free(option);
206#ifndef FREECIV_NDEBUG
207 } else if (is_option("--Fatal", argv[i])) {
208 if (i + 1 >= argc || '-' == argv[i + 1][0]) {
210 } else if (str_to_int(argv[i + 1], &fatal_assertions)) {
211 i++;
212 } else {
213 fc_fprintf(stderr, R__("Invalid signal number \"%s\".\n"),
214 argv[i + 1]);
215 fc_fprintf(stderr, R__("Try using --help.\n"));
217 }
218#endif // FREECIV_NDEBUG
219 } else if (is_option("--", argv[i])) {
221 } else {
222 fc_fprintf(stderr, R__("Unrecognized option: \"%s\"\n"), argv[i]);
224 }
225
226 i++;
227 }
228
229 log_init(nullptr, loglevel, nullptr, nullptr, fatal_assertions);
230
231 return ui_options;
232}
233
234/**********************************************************************/
237void show_experimental(QWidget *wdg)
238{
239#ifdef RULEDIT_EXPERIMENTAL
240 wdg->show();
241#else
242 wdg->hide();
243#endif
244}
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 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:61
void game_init(bool keep_ruleset_value)
Definition game.c:445
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:56
int main(int argc, char **argv)
Definition ruledit.cpp:63
static int re_parse_cmdline(int argc, char *argv[])
Definition ruledit.cpp:139
void show_experimental(QWidget *wdg)
Definition ruledit.cpp:237
static int fatal_assertions
Definition ruledit.cpp:58
int ruledit_qt_run(int argc, char **argv)
void init_connections(void)
Definition sernet.c:1362
void settings_init(bool act)
Definition settings.c:5212
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