Freeciv-3.2
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
51#include "ruledit.h"
52
53static int re_parse_cmdline(int argc, char *argv[]);
54
56
57static int fatal_assertions = -1;
58
59/**********************************************************************/
62int main(int argc, char **argv)
63{
64 int ui_options;
66
67 // Load Windows post-crash debugger
68#ifdef FREECIV_MSWINDOWS
69# ifndef FREECIV_NDEBUG
70 if (LoadLibrary("exchndl.dll") == NULL) {
71# ifdef FREECIV_DEBUG
72 fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n");
73# endif // FREECIV_DEBUG
74 }
75# endif // FREECIV_NDEBUG
76#endif // FREECIV_MSWINDOWS
77
78 /* Initialize the fc_interface functions needed to understand rules.
79 * fc_interface_init_tool() includes low level support like
80 * guaranteeing that fc_vsnprintf() will work after it,
81 * so this need to be early. */
83
84#ifdef ENABLE_NLS
85 (void) bindtextdomain("freeciv-ruledit", get_locale_dir());
86#endif
87
89#ifdef ENABLE_NLS
91#endif
92
94
95 // Initialize command line arguments.
97
99
100 if (ui_options != -1) {
102
104
105 // Reset aifill to zero
106 game.info.aifill = 0;
107
109
110 i_am_tool();
111
112 if (comments_load()) {
114
116 } else {
117 /* TRANS: 'Failed to load comments-x.y.txt' where x.y is
118 * freeciv version */
119 log_error(R__("Failed to load %s."), COMMENTS_FILE_NAME);
120
122 }
123 }
124
126 log_close();
128
129 // Clean up command line arguments.
131
132 return exit_status;
133}
134
135/**********************************************************************/
138static int re_parse_cmdline(int argc, char *argv[])
139{
140 enum log_level loglevel = LOG_NORMAL;
141 int i = 1;
142 bool ui_separator = FALSE;
143 int ui_options = 0;
144
145 while (i < argc) {
146 char *option;
147
148 if (ui_separator) {
149 argv[1 + ui_options] = argv[i];
150 ui_options++;
151 } else if (is_option("--help", argv[i])) {
152 struct cmdhelp *help = cmdhelp_new(argv[0]);
153
154 cmdhelp_add(help, "h", "help",
155 R__("Print a summary of the options"));
156#ifdef FREECIV_DEBUG
157 cmdhelp_add(help, "d",
158 // TRANS: "debug" is exactly what user must type, do not translate.
159 R__("debug LEVEL"),
160 R__("Set debug log level (one of f,e,w,n,v,d, or "
161 "d:file1,min,max:...)"));
162#else /* FREECIV_DEBUG */
163 cmdhelp_add(help, "d",
164 // TRANS: "debug" is exactly what user must type, do not translate.
165 R__("debug LEVEL"),
166 R__("Set debug log level (one of f,e,w,n,v)"));
167#endif /* FREECIV_DEBUG */
168 cmdhelp_add(help, "v", "version",
169 R__("Print the version number"));
170 cmdhelp_add(help, "r",
171 // TRANS: argument (don't translate) VALUE (translate)
172 R__("ruleset RULESET"),
173 R__("Ruleset to use as the starting point."));
174#ifndef FREECIV_NDEBUG
175 cmdhelp_add(help, "F",
176 // TRANS: "Fatal" is exactly what user must type, do not translate.
177 R__("Fatal [SIGNAL]"),
178 R__("Raise a signal on failed assertion"));
179#endif // FREECIV_NDEBUG
180 /* The function below prints a header and footer for the options.
181 * Furthermore, the options are sorted. */
182 cmdhelp_display(help, TRUE, TRUE, TRUE);
183 cmdhelp_destroy(help);
184
186 } else if (is_option("--version", argv[i])) {
188
190 } else if ((option = get_option_malloc("--ruleset", argv, &i, argc, true))) {
191 if (reargs.ruleset) {
192 fc_fprintf(stderr, R__("Can only edit one ruleset at a time.\n"));
193 } else {
195 }
196 } else if ((option = get_option_malloc("--debug", argv, &i, argc, FALSE))) {
197 if (!log_parse_level_str(option, &loglevel)) {
199 R__("Invalid debug level \"%s\" specified with --debug "
200 "option.\n"), option);
201 fc_fprintf(stderr, R__("Try using --help.\n"));
203 }
204 free(option);
205#ifndef FREECIV_NDEBUG
206 } else if (is_option("--Fatal", argv[i])) {
207 if (i + 1 >= argc || '-' == argv[i + 1][0]) {
209 } else if (str_to_int(argv[i + 1], &fatal_assertions)) {
210 i++;
211 } else {
212 fc_fprintf(stderr, R__("Invalid signal number \"%s\".\n"),
213 argv[i + 1]);
214 fc_fprintf(stderr, R__("Try using --help.\n"));
216 }
217#endif // FREECIV_NDEBUG
218 } else if (is_option("--", argv[i])) {
220 } else {
221 fc_fprintf(stderr, R__("Unrecognized option: \"%s\"\n"), argv[i]);
223 }
224
225 i++;
226 }
227
228 log_init(NULL, loglevel, NULL, NULL, fatal_assertions);
229
230 return ui_options;
231}
void comments_free(void)
Definition comments.c:270
bool comments_load(void)
Definition comments.c:106
char * incite_cost
Definition comments.c:75
#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:62
void game_init(bool keep_ruleset_value)
Definition game.c:438
void log_close(void)
Definition log.c:278
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:253
bool log_parse_level_str(const char *level_str, enum log_level *ret_level)
Definition log.c:86
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:55
int main(int argc, char **argv)
Definition ruledit.cpp:62
static int re_parse_cmdline(int argc, char *argv[])
Definition ruledit.cpp:138
static int fatal_assertions
Definition ruledit.cpp:57
int ruledit_qt_run(int argc, char **argv)
void init_connections(void)
Definition sernet.c:1366
void settings_init(bool act)
Definition settings.c:5245
bool str_to_int(const char *str, int *pint)
Definition shared.c:517
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