Freeciv-3.1
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 enum log_level loglevel = LOG_NORMAL;
66 int ui_options;
67 int exit_status = EXIT_SUCCESS;
68
69 // Load Windows post-crash debugger
70#ifdef FREECIV_MSWINDOWS
71# ifndef FREECIV_NDEBUG
72 if (LoadLibrary("exchndl.dll") == NULL) {
73# ifdef FREECIV_DEBUG
74 fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n");
75# endif /* FREECIV_DEBUG */
76 }
77# endif /* FREECIV_NDEBUG */
78#endif /* FREECIV_MSWINDOWS */
79
80 /* Initialize the fc_interface functions needed to understand rules.
81 * fc_interface_init_tool() includes low level support like
82 * guaranteeing that fc_vsnprintf() will work after it,
83 * so this need to be early. */
85
86#ifdef ENABLE_NLS
87 (void) bindtextdomain("freeciv-ruledit", get_locale_dir());
88#endif
89
91#ifdef ENABLE_NLS
92 bind_textdomain_codeset("freeciv-ruledit", get_internal_encoding());
93#endif
94
96
97 log_init(NULL, loglevel, NULL, NULL, fatal_assertions);
98
99 /* Initialize command line arguments. */
100 reargs.ruleset = NULL;
101
102 ui_options = re_parse_cmdline(argc, argv);
103
104 if (ui_options != -1) {
106
108
109 /* Reset aifill to zero */
110 game.info.aifill = 0;
111
113
114 i_am_tool();
115
116 if (comments_load()) {
117 ruledit_qt_run(ui_options, argv);
118
120 } else {
121 /* TRANS: 'Failed to load comments-x.y.txt' where x.y is
122 * freeciv version */
123 log_error(R__("Failed to load %s."), COMMENTS_FILE_NAME);
124
125 exit_status = EXIT_FAILURE;
126 }
127 }
128
130 log_close();
132
133 /* Clean up command line arguments. */
135
136 return exit_status;
137}
138
139/**********************************************************************/
142static int re_parse_cmdline(int argc, char *argv[])
143{
144 int i = 1;
145 bool ui_separator = FALSE;
146 int ui_options = 0;
147
148 while (i < argc) {
149 char *option;
150
151 if (ui_separator) {
152 argv[1 + ui_options] = argv[i];
153 ui_options++;
154 } else if (is_option("--help", argv[i])) {
155 struct cmdhelp *help = cmdhelp_new(argv[0]);
156
157 cmdhelp_add(help, "h", "help",
158 R__("Print a summary of the options"));
159 cmdhelp_add(help, "v", "version",
160 R__("Print the version number"));
161 cmdhelp_add(help, "r",
162 /* TRANS: argument (don't translate) VALUE (translate) */
163 R__("ruleset RULESET"),
164 R__("Ruleset to use as the starting point."));
165#ifndef FREECIV_NDEBUG
166 cmdhelp_add(help, "F",
167 /* TRANS: "Fatal" is exactly what user must type, do not translate. */
168 R__("Fatal [SIGNAL]"),
169 R__("Raise a signal on failed assertion"));
170#endif /* FREECIV_NDEBUG */
171 /* The function below prints a header and footer for the options.
172 * Furthermore, the options are sorted. */
173 cmdhelp_display(help, TRUE, TRUE, TRUE);
174 cmdhelp_destroy(help);
175
176 exit(EXIT_SUCCESS);
177 } else if (is_option("--version", argv[i])) {
178 fc_fprintf(stderr, "%s \n", freeciv_name_version());
179
180 exit(EXIT_SUCCESS);
181 } else if ((option = get_option_malloc("--ruleset", argv, &i, argc, true))) {
182 if (reargs.ruleset) {
183 fc_fprintf(stderr, R__("Can only edit one ruleset at a time.\n"));
184 } else {
186 }
187#ifndef FREECIV_NDEBUG
188 } else if (is_option("--Fatal", argv[i])) {
189 if (i + 1 >= argc || '-' == argv[i + 1][0]) {
190 fatal_assertions = SIGABRT;
191 } else if (str_to_int(argv[i + 1], &fatal_assertions)) {
192 i++;
193 } else {
194 fc_fprintf(stderr, R__("Invalid signal number \"%s\".\n"),
195 argv[i + 1]);
196 fc_fprintf(stderr, R__("Try using --help.\n"));
197 exit(EXIT_FAILURE);
198 }
199#endif /* FREECIV_NDEBUG */
200 } else if (is_option("--", argv[i])) {
201 ui_separator = TRUE;
202 } else {
203 fc_fprintf(stderr, R__("Unrecognized option: \"%s\"\n"), argv[i]);
204 exit(EXIT_FAILURE);
205 }
206
207 i++;
208 }
209
210 return ui_options;
211}
212
213/**********************************************************************/
216void show_experimental(QWidget *wdg)
217{
218#ifdef RULEDIT_EXPERIMENTAL
219 wdg->show();
220#else
221 wdg->hide();
222#endif
223}
void comments_free(void)
Definition comments.c:143
bool comments_load(void)
Definition comments.c:62
#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:57
void game_init(bool keep_ruleset_value)
Definition game.c:429
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
log_level
Definition log.h:28
@ LOG_NORMAL
Definition log.h:32
#define log_error(message,...)
Definition log.h:103
void registry_module_init(void)
Definition registry.c:30
void registry_module_close(void)
Definition registry.c:40
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:142
void show_experimental(QWidget *wdg)
Definition ruledit.cpp:216
static int fatal_assertions
Definition ruledit.cpp:58
int ruledit_qt_run(int argc, char **argv)
void init_connections(void)
Definition sernet.c:1355
void settings_init(bool act)
Definition settings.c:4952
bool str_to_int(const char *str, int *pint)
Definition shared.c:512
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