webperimental: killstack decides stack protects.
[freeciv.git] / tools / ruledit / ruledit.cpp
blob330c19e8c45000adbb54945a56d44c6a0e471e75
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include "fc_prehdrs.h"
20 /* ANSI */
21 #include <stdlib.h>
23 #ifdef FREECIV_MSWINDOWS
24 #include <windows.h>
25 #endif
27 /* utility */
28 #include "fc_cmdline.h"
29 #include "fciconv.h"
30 #include "fcintl.h"
31 #include "log.h"
32 #include "registry.h"
34 /* common */
35 #include "fc_cmdhelp.h"
36 #include "fc_interface.h"
37 #include "version.h"
39 /* server */
40 #include "sernet.h"
41 #include "settings.h"
43 /* tools/shared */
44 #include "tools_fc_interface.h"
46 /* ruledit */
47 #include "comments.h"
48 #include "ruledit_qt.h"
50 #include "ruledit.h"
52 static int re_parse_cmdline(int argc, char *argv[]);
54 struct ruledit_arguments reargs;
56 /**************************************************************************
57 Main entry point for freeciv-ruledit
58 **************************************************************************/
59 int main(int argc, char **argv)
61 enum log_level loglevel = LOG_NORMAL;
62 int ui_options;
64 /* Load win32 post-crash debugger */
65 #ifdef FREECIV_MSWINDOWS
66 # ifndef FREECIV_NDEBUG
67 if (LoadLibrary("exchndl.dll") == NULL) {
68 # ifdef FREECIV_DEBUG
69 fprintf(stderr, "exchndl.dll could not be loaded, no crash debugger\n");
70 # endif /* FREECIV_DEBUG */
72 # endif /* FREECIV_NDEBUG */
73 #endif /* FREECIV_MSWINDOWS */
75 init_nls();
77 #ifdef ENABLE_NLS
78 (void) bindtextdomain("freeciv-ruledit", get_locale_dir());
79 #endif
81 init_character_encodings(FC_DEFAULT_DATA_ENCODING, FALSE);
82 #ifdef ENABLE_NLS
83 bind_textdomain_codeset("freeciv-ruledit", get_internal_encoding());
84 #endif
86 registry_module_init();
88 log_init(NULL, loglevel, NULL, NULL, -1);
90 /* Initialize command line arguments. */
91 reargs.ruleset = NULL;
93 ui_options = re_parse_cmdline(argc, argv);
95 if (ui_options != -1) {
96 init_connections();
98 settings_init(FALSE);
100 /* Reset aifill to zero */
101 game.info.aifill = 0;
103 game_init(FALSE);
104 i_am_tool();
106 /* Initialize the fc_interface functions needed to understand rules. */
107 fc_interface_init_tool();
109 if (comments_load()) {
110 ruledit_qt_run(ui_options, argv);
112 comments_free();
113 } else {
114 log_error(R__("Failed to load comments.txt"));
118 registry_module_close();
119 log_close();
120 free_libfreeciv();
121 free_nls();
123 /* Clean up command line arguments. */
124 cmdline_option_values_free();
126 return EXIT_SUCCESS;
129 /**************************************************************************
130 Parse freeciv-ruledit commandline.
131 **************************************************************************/
132 static int re_parse_cmdline(int argc, char *argv[])
134 int i = 1;
135 bool ui_separator = FALSE;
136 int ui_options = 0;
138 while (i < argc) {
139 char *option;
141 if (ui_separator) {
142 argv[1 + ui_options] = argv[i];
143 ui_options++;
144 } else if (is_option("--help", argv[i])) {
145 struct cmdhelp *help = cmdhelp_new(argv[0]);
147 cmdhelp_add(help, "h", "help",
148 R__("Print a summary of the options"));
149 cmdhelp_add(help, "v", "version",
150 R__("Print the version number"));
151 cmdhelp_add(help, "r",
152 /* TRANS: argument (don't translate) VALUE (translate) */
153 R__("ruleset RULESET"),
154 R__("Ruleset to use as the starting point."));
155 /* The function below prints a header and footer for the options.
156 * Furthermore, the options are sorted. */
157 cmdhelp_display(help, TRUE, TRUE, TRUE);
158 cmdhelp_destroy(help);
160 exit(EXIT_SUCCESS);
161 } else if (is_option("--version", argv[i])) {
162 fc_fprintf(stderr, "%s \n", freeciv_name_version());
164 exit(EXIT_SUCCESS);
165 } else if ((option = get_option_malloc("--ruleset", argv, &i, argc, true))) {
166 if (reargs.ruleset) {
167 fc_fprintf(stderr, R__("Can only edit one ruleset at a time.\n"));
168 } else {
169 reargs.ruleset = option;
171 } else if (is_option("--", argv[i])) {
172 ui_separator = TRUE;
173 } else {
174 fc_fprintf(stderr, R__("Unrecognized option: \"%s\"\n"), argv[i]);
175 exit(EXIT_FAILURE);
178 i++;
181 return ui_options;
184 /**************************************************************************
185 Show widget if experimental features enabled, hide otherwise
186 **************************************************************************/
187 void show_experimental(QWidget *wdg)
189 #ifdef RULEDIT_EXPERIMENTAL
190 wdg->show();
191 #else
192 wdg->hide();
193 #endif