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
46#include "ruledit.h"
47
48static int re_parse_cmdline(int argc, char *argv[]);
49
51
52static int fatal_assertions = -1;
53
54/**********************************************************************/
57int main(int argc, char **argv)
58{
59 int ui_options;
61
63
64 /* Initialize the fc_interface functions needed to understand rules.
65 * fc_interface_init_tool() includes low level support like
66 * guaranteeing that fc_vsnprintf() will work after it,
67 * so this need to be early. */
69
70#ifdef ENABLE_NLS
71 (void) bindtextdomain("freeciv-ruledit", get_locale_dir());
72#endif
73
75#ifdef ENABLE_NLS
77#endif
78
80
81 // Initialize command line arguments.
82 reargs.ruleset = nullptr;
83
85
86 if (ui_options != -1) {
88
90
91 // Reset aifill to zero
92 game.info.aifill = 0;
93
95
96 i_am_tool();
97
98 if (comments_load()) {
100
102 } else {
103 /* TRANS: 'Failed to load comments-x.y.txt' where x.y is
104 * freeciv version */
105 log_error(R__("Failed to load %s."), COMMENTS_FILE_NAME);
106
108 }
109 }
110
112 log_close();
114
115 // Clean up command line arguments.
117
118 return exit_status;
119}
120
121/**********************************************************************/
124static int re_parse_cmdline(int argc, char *argv[])
125{
126 enum log_level loglevel = LOG_NORMAL;
127 int i = 1;
128 bool ui_separator = FALSE;
129 int ui_options = 0;
130
131 while (i < argc) {
132 char *option;
133
134 if (ui_separator) {
135 argv[1 + ui_options] = argv[i];
136 ui_options++;
137 } else if (is_option("--help", argv[i])) {
138 struct cmdhelp *help = cmdhelp_new(argv[0]);
139
140 cmdhelp_add(help, "h", "help",
141 R__("Print a summary of the options"));
142#ifdef FREECIV_DEBUG
143 cmdhelp_add(help, "d",
144 // TRANS: "debug" is exactly what user must type, do not translate.
145 R__("debug LEVEL"),
146 R__("Set debug log level (one of f,e,w,n,v,d, or "
147 "d:file1,min,max:...)"));
148#else /* FREECIV_DEBUG */
149 cmdhelp_add(help, "d",
150 // TRANS: "debug" is exactly what user must type, do not translate.
151 R__("debug LEVEL"),
152 R__("Set debug log level (one of f,e,w,n,v)"));
153#endif /* FREECIV_DEBUG */
154 cmdhelp_add(help, "v", "version",
155 R__("Print the version number"));
156 cmdhelp_add(help, "r",
157 // TRANS: argument (don't translate) VALUE (translate)
158 R__("ruleset RULESET"),
159 R__("Ruleset to use as the starting point."));
160#ifndef FREECIV_NDEBUG
161 cmdhelp_add(help, "F",
162 // TRANS: "Fatal" is exactly what user must type, do not translate.
163 R__("Fatal [SIGNAL]"),
164 R__("Raise a signal on failed assertion"));
165#endif // FREECIV_NDEBUG
166 /* The function below prints a header and footer for the options.
167 * Furthermore, the options are sorted. */
168 cmdhelp_display(help, TRUE, TRUE, TRUE);
169 cmdhelp_destroy(help);
170
172 } else if (is_option("--version", argv[i])) {
174
176 } else if ((option = get_option_malloc("--ruleset", argv, &i, argc, true))) {
177 if (reargs.ruleset) {
178 fc_fprintf(stderr, R__("Can only edit one ruleset at a time.\n"));
179 } else {
181 }
182 } else if ((option = get_option_malloc("--debug", argv, &i, argc, FALSE))) {
183 if (!log_parse_level_str(option, &loglevel)) {
185 R__("Invalid debug level \"%s\" specified with --debug "
186 "option.\n"), option);
187 fc_fprintf(stderr, R__("Try using --help.\n"));
189 }
190 free(option);
191#ifndef FREECIV_NDEBUG
192 } else if (is_option("--Fatal", argv[i])) {
193 if (i + 1 >= argc || '-' == argv[i + 1][0]) {
195 } else if (str_to_int(argv[i + 1], &fatal_assertions)) {
196 i++;
197 } else {
198 fc_fprintf(stderr, R__("Invalid signal number \"%s\".\n"),
199 argv[i + 1]);
200 fc_fprintf(stderr, R__("Try using --help.\n"));
202 }
203#endif // FREECIV_NDEBUG
204 } else if (is_option("--", argv[i])) {
206 } else {
207 fc_fprintf(stderr, R__("Unrecognized option: \"%s\"\n"), argv[i]);
209 }
210
211 i++;
212 }
213
214 log_init(nullptr, loglevel, nullptr, nullptr, fatal_assertions);
215
216 return ui_options;
217}
void comments_free(void)
Definition comments.c:278
bool comments_load(void)
Definition comments.c:110
char * incite_cost
Definition comments.c:77
#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:445
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: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:50
int main(int argc, char **argv)
Definition ruledit.cpp:57
static int re_parse_cmdline(int argc, char *argv[])
Definition ruledit.cpp:124
static int fatal_assertions
Definition ruledit.cpp:52
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