Freeciv-3.1: /fast/freeciv/nightly/S3_1/tools/ruledit/ruledit.cpp Source File

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
56 struct ruledit_arguments reargs;
57
58 static int fatal_assertions = -1;
59
60/**********************************************************************/
63 int 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. */
84 fc_interface_init_tool();
85
86#ifdef ENABLE_NLS
87 (void) bindtextdomain("freeciv-ruledit", get_locale_dir());
88#endif
89
90 init_character_encodings(FC_DEFAULT_DATA_ENCODING, FALSE);
91#ifdef ENABLE_NLS
92 bind_textdomain_codeset("freeciv-ruledit", get_internal_encoding());
93#endif
94
95 registry_module_init();
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) {
105 init_connections();
106
107 settings_init(FALSE);
108
109 /* Reset aifill to zero */
110 game.info.aifill = 0;
111
112 game_init(FALSE);
113
114 i_am_tool();
115
116 if (comments_load()) {
117 ruledit_qt_run(ui_options, argv);
118
119 comments_free();
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
129 registry_module_close();
130 log_close();
131 libfreeciv_free();
132
133 /* Clean up command line arguments. */
134 cmdline_option_values_free();
135
136 return exit_status;
137}
138
139/**********************************************************************/
142 static 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 {
185 reargs.ruleset = option;
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/**********************************************************************/
216 void show_experimental(QWidget *wdg)
217{
218#ifdef RULEDIT_EXPERIMENTAL
219 wdg->show();
220#else
221 wdg->hide();
222#endif
223}
comments_free
void comments_free(void)
Definition comments.c:142
comments_load
bool comments_load(void)
Definition comments.c:61
comments.h
COMMENTS_FILE_NAME
#define COMMENTS_FILE_NAME
Definition comments.h:20
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
cmdline_option_values_free
void cmdline_option_values_free(void)
Definition fc_cmdline.c:97
fc_cmdline.h
libfreeciv_free
void libfreeciv_free(void)
Definition fc_interface.c:103
fc_interface.h
i_am_tool
static void i_am_tool(void)
Definition fc_interface.h:80
fc_prehdrs.h
get_internal_encoding
const char * get_internal_encoding(void)
Definition fciconv.c:182
init_character_encodings
static char void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Definition fciconv.c:70
fciconv.h
FC_DEFAULT_DATA_ENCODING
#define FC_DEFAULT_DATA_ENCODING
Definition fciconv.h:89
fc_fprintf
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
get_locale_dir
const char * get_locale_dir(void)
Definition fcintl.c:111
fcintl.h
bindtextdomain
#define bindtextdomain(Package, Directory)
Definition fcintl.h:82
R__
#define R__(String)
Definition fcintl.h:75
game
struct civ_game game
Definition game.c:57
game_init
void game_init(bool keep_ruleset_value)
Definition game.c:429
log_close
void log_close(void)
Definition log.c:270
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.h
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
registry_module_init
void registry_module_init(void)
Definition registry.c:30
registry_module_close
void registry_module_close(void)
Definition registry.c:40
registry.h
reargs
struct ruledit_arguments reargs
Definition ruledit.cpp:56
main
int main(int argc, char **argv)
Definition ruledit.cpp:63
re_parse_cmdline
static int re_parse_cmdline(int argc, char *argv[])
Definition ruledit.cpp:142
show_experimental
void show_experimental(QWidget *wdg)
Definition ruledit.cpp:216
fatal_assertions
static int fatal_assertions
Definition ruledit.cpp:58
ruledit.h
ruledit_qt_run
int ruledit_qt_run(int argc, char **argv)
Definition ruledit_qt.cpp:70
ruledit_qt.h
init_connections
void init_connections(void)
Definition sernet.c:1355
sernet.h
settings_init
void settings_init(bool act)
Definition settings.c:4952
settings.h
str_to_int
bool str_to_int(const char *str, int *pint)
Definition shared.c:512
civ_game::info
struct packet_game_info info
Definition game.h:89
cmdhelp
Definition fc_cmdhelp.c:43
option
Definition options.c:454
packet_game_info::aifill
int aifill
Definition packets_gen.h:121
ruledit_arguments
Definition ruledit.h:18
ruledit_arguments::ruleset
char * ruleset
Definition ruledit.h:20
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
fc_interface_init_tool
void fc_interface_init_tool(void)
Definition tools_fc_interface.c:60
tools_fc_interface.h
freeciv_name_version
const char * freeciv_name_version(void)
Definition version.c:35
version.h