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)
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 ***********************************************************************/
15 #include <fc_config.h>
18 #ifdef FREECIV_MSWINDOWS
23 #include "fc_cmdline.h"
26 #include "string_vector.h"
29 #include "fc_cmdhelp.h"
30 #include "fc_interface.h"
38 #include "tools_fc_interface.h"
44 static char *rs_selected
= NULL
;
45 static char *od_selected
= NULL
;
47 /**************************************************************************
48 Parse freeciv-ruleup commandline parameters.
49 **************************************************************************/
50 static void rup_parse_cmdline(int argc
, char *argv
[])
57 if (is_option("--help", argv
[i
])) {
58 struct cmdhelp
*help
= cmdhelp_new(argv
[0]);
60 cmdhelp_add(help
, "h", "help",
61 _("Print a summary of the options"));
62 cmdhelp_add(help
, "r",
63 /* TRANS: "ruleset" is exactly what user must type, do not translate. */
66 cmdhelp_add(help
, "o",
67 /* TRANS: "output" is exactly what user must type, do not translate. */
68 _("output DIRECTORY"),
69 _("Create directory DIRECTORY for output"));
71 /* The function below prints a header and footer for the options.
72 * Furthermore, the options are sorted. */
73 cmdhelp_display(help
, TRUE
, FALSE
, TRUE
);
74 cmdhelp_destroy(help
);
76 cmdline_option_values_free();
79 } else if ((option
= get_option_malloc("--ruleset", argv
, &i
, argc
, TRUE
))) {
80 if (rs_selected
!= NULL
) {
82 _("Multiple rulesets requested. Only one ruleset at time supported.\n"));
86 } else if ((option
= get_option_malloc("--output", argv
, &i
, argc
, TRUE
))) {
87 if (od_selected
!= NULL
) {
89 _("Multiple output directories given.\n"));
94 fc_fprintf(stderr
, _("Unrecognized option: \"%s\"\n"), argv
[i
]);
95 cmdline_option_values_free();
103 /**************************************************************************
104 Main entry point for freeciv-ruleup
105 **************************************************************************/
106 int main(int argc
, char **argv
)
108 enum log_level loglevel
= LOG_NORMAL
;
110 /* Load win32 post-crash debugger */
111 #ifdef FREECIV_MSWINDOWS
112 # ifndef FREECIV_NDEBUG
113 if (LoadLibrary("exchndl.dll") == NULL
) {
114 # ifdef FREECIV_DEBUG
115 fprintf(stderr
, "exchndl.dll could not be loaded, no crash debugger\n");
116 # endif /* FREECIV_DEBUG */
118 # endif /* FREECIV_NDEBUG */
119 #endif /* FREECIV_MSWINDOWS */
123 registry_module_init();
124 init_character_encodings(FC_DEFAULT_DATA_ENCODING
, FALSE
);
126 log_init(NULL
, loglevel
, NULL
, NULL
, -1);
130 settings_init(FALSE
);
135 /* Initialize the fc_interface functions needed to understand rules. */
136 fc_interface_init_tool();
138 rup_parse_cmdline(argc
, argv
);
140 /* Set ruleset user requested to use */
141 if (rs_selected
== NULL
) {
142 rs_selected
= GAME_DEFAULT_RULESETDIR
;
144 sz_strlcpy(game
.server
.rulesetdir
, rs_selected
);
146 /* Reset aifill to zero */
147 game
.info
.aifill
= 0;
149 if (load_rulesets(NULL
, TRUE
, FALSE
, TRUE
)) {
150 struct rule_data data
;
153 data
.nationlist
= game
.server
.ruledit
.nationlist
;
155 if (od_selected
!= NULL
) {
156 fc_strlcpy(tgt_dir
, od_selected
, sizeof(tgt_dir
));
158 fc_snprintf(tgt_dir
, sizeof(tgt_dir
), "%s.ruleup", rs_selected
);
162 save_ruleset(tgt_dir
, rs_selected
, &data
);
163 log_normal("Saved %s", tgt_dir
);
166 log_error(_("Can't load ruleset %s"), rs_selected
);
169 registry_module_close();
173 cmdline_option_values_free();