bygfoot/src/main.c

551 lines
17 KiB
C
Raw Normal View History

2005-10-20 17:45:00 +02:00
/*
2005-11-26 17:52:51 +01:00
main.c
2005-10-20 17:45:00 +02:00
Bygfoot Football Manager -- a small and simple GTK2-based
football management game.
http://bygfoot.sourceforge.net
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2010-04-02 12:49:15 +02:00
*/
2005-10-20 17:45:00 +02:00
#include <time.h>
2005-10-24 22:50:48 +02:00
#include <glib/gprintf.h>
#include <glib.h>
#ifdef G_OS_WIN32
2010-04-02 12:49:15 +02:00
#include <io.h>
#include <fcntl.h>
#endif
2005-10-27 23:10:15 +02:00
#include "bet_struct.h"
#include "bygfoot_struct.h"
2005-10-27 23:10:15 +02:00
#include "debug.h"
#include "file.h"
#include "free.h"
#include "job_struct.h"
#ifdef ENABLE_JSON
#include "json_interface.h"
#endif
2005-06-14 17:27:44 +02:00
#include "language.h"
2005-10-25 17:26:53 +02:00
#include "lg_commentary.h"
2005-04-04 12:36:04 +02:00
#include "live_game.h"
2005-09-29 15:41:16 +02:00
#include "load_save.h"
2004-12-23 13:58:39 +01:00
#include "main.h"
2008-11-06 09:03:09 +01:00
#include "maths.h"
2005-09-29 15:41:16 +02:00
#include "misc.h"
2005-06-14 17:27:44 +02:00
#include "misc_callbacks.h"
#include "name_struct.h"
2008-11-27 14:24:18 +01:00
#include "news_struct.h"
2005-06-14 17:27:44 +02:00
#include "option.h"
2005-10-27 23:10:15 +02:00
#include "start_end.h"
2005-05-01 12:16:14 +02:00
#include "stat_struct.h"
2005-10-24 22:50:48 +02:00
#include "strategy_struct.h"
2005-06-05 12:39:29 +02:00
#include "transfer_struct.h"
#include "variables.h"
#include "window.h"
#include "xml_country.h"
2005-10-24 22:50:48 +02:00
#include "xml_strategy.h"
2009-05-01 14:19:16 +02:00
#define DEBUG_LEVEL_DEFAULT 0
#if defined(MAC_BUILD) || defined(G_OS_WIN32)
#define DEBUG_OUTPUT_DEFAULT 2
#else
#define DEBUG_OUTPUT_DEFAULT 0
#endif
2005-10-03 20:08:26 +02:00
/** Whether the last save gets loaded at startup
2010-04-02 12:49:15 +02:00
(cl switch -l). */
2005-10-03 20:08:26 +02:00
gboolean load_last_save;
2005-09-29 15:41:16 +02:00
/** Parse command line options used for selecting the frontend or backend to
* use with bygfoot.
*/
static void
main_parse_frontend_backend_cl_arguments(gint *argc, gchar ***argv, CommandLineArgs *args)
{
GError *error = NULL;
GOptionContext *context = NULL;
GOptionEntry entries[] = {
{ "json", 0, 0, G_OPTION_ARG_FILENAME, &args->json_filename,
"JSON file containing commands to run. bygfoot will run the "
"commands in this file and then exit", "FILE"},
{NULL}
};
if(argc == NULL || argv == NULL)
return;
context = g_option_context_new(_("- a simple and addictive GTK2 football manager"));
g_option_context_set_ignore_unknown_options(context, TRUE);
g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
g_option_context_add_group(context, gtk_get_option_group (FALSE));
g_option_context_parse(context, argc, argv, &error);
g_option_context_free(context);
if(error != NULL)
{
misc_print_error(&error, FALSE);
return;
}
}
2005-09-29 15:41:16 +02:00
/** Parse the command line arguments given by the user. */
2010-04-02 12:49:15 +02:00
void
main_parse_cl_arguments(gint *argc, gchar ***argv, Bygfoot *bygfoot)
2005-09-29 15:41:16 +02:00
{
#ifdef DEBUG
printf("main_parse_cl_arguments\n");
#endif
2005-10-27 23:10:15 +02:00
gboolean testcom = FALSE, calodds = FALSE;
2005-10-25 17:26:53 +02:00
gchar *support_dir = NULL, *lang = NULL,
2010-04-02 12:49:15 +02:00
*testcom_file = NULL, *token_file = NULL,
*event_name = NULL,
*country_sid = NULL;
2009-04-29 19:18:54 +02:00
gint number_of_passes = 1,
2010-04-02 12:49:15 +02:00
num_matches = 100, skilldiffmax = 20;
guint32 random_seed = 0;
2005-09-29 15:41:16 +02:00
GError *error = NULL;
GOptionContext *context = NULL;
GOptionEntry entries[] =
2010-04-02 12:49:15 +02:00
{{ "last-save", 'l', 0, G_OPTION_ARG_NONE, &load_last_save, _("Load last savegame"), NULL },
2008-12-17 16:31:07 +01:00
2010-04-02 12:49:15 +02:00
{ "support-dir", 's', 0, G_OPTION_ARG_STRING, &support_dir,
_("Specify additional support directory (takes priority over default ones)"), "DIR" },
2010-04-02 12:45:33 +02:00
2010-04-02 12:49:15 +02:00
{ "country", 'c', 0, G_OPTION_ARG_STRING, &country_sid, _("String id of the country to load"), "SID" },
2008-12-17 16:31:07 +01:00
2010-04-02 12:49:15 +02:00
{ "lang", 'L', 0, G_OPTION_ARG_STRING, &lang, _("Language to use (a code like 'de')"), "CODE" },
2005-09-29 15:41:16 +02:00
2010-04-02 12:49:15 +02:00
{ "testcom", 't', 0, G_OPTION_ARG_NONE, &testcom, _("Test an XML commentary file"), NULL },
2005-10-25 17:26:53 +02:00
2010-04-02 12:49:15 +02:00
{ "commentary-file", 'C', 0, G_OPTION_ARG_STRING, &testcom_file,
_("Commentary file name (may be in a support dir)"), "FILE" },
2005-10-25 17:26:53 +02:00
2010-04-02 12:49:15 +02:00
{ "token-file", 'T', 0, G_OPTION_ARG_STRING, &token_file,
/* Live game tokens are strings like _AT_ in live game commentary files
which will be filled in by the program during runtime; e.g. _AT_ becomes
the attendace for the match. */
_("File containing live game tokens (may be in a support dir)"), "FILE" },
2005-10-25 17:26:53 +02:00
2010-04-02 12:49:15 +02:00
{ "event-name", 'e', 0, G_OPTION_ARG_STRING, &event_name,
_("Commentary event to test; leave out to test all commentaries"), "EVENTNAME" },
2005-10-25 17:26:53 +02:00
2010-04-02 12:49:15 +02:00
{ "num-passes", 'n', 0, G_OPTION_ARG_INT, &number_of_passes,
_("How many commentaries to generate per event"), "N" },
2005-10-25 17:26:53 +02:00
2010-04-02 12:49:15 +02:00
{ "calodds", 'O', 0, G_OPTION_ARG_NONE, &calodds,
"[developer] Calibrate the betting odds by simulating a lot of matches", NULL },
2005-10-27 23:10:15 +02:00
2010-04-02 12:49:15 +02:00
{ "num-matches", 'm', 0, G_OPTION_ARG_INT, &num_matches,
"[developer] How many matches to simulate per skill diff step", "N" },
2005-10-27 23:10:15 +02:00
2010-04-02 12:49:15 +02:00
{ "num-skilldiff", 'S', 0, G_OPTION_ARG_INT, &skilldiffmax,
"[developer] How many skill diff steps to take", "N" },
2005-10-27 23:10:15 +02:00
{ "random-seed", 0, 0, G_OPTION_ARG_INT, &random_seed,
"Seed to initialize random number generator. Valid values are"
" 32-bit unsigned integers > 0", "N"},
2010-04-02 12:49:15 +02:00
{NULL}};
2005-09-29 15:41:16 +02:00
if(argc == NULL || argv == NULL)
2010-04-02 12:49:15 +02:00
return;
2005-09-29 15:41:16 +02:00
2005-10-01 10:12:06 +02:00
context = g_option_context_new(_("- a simple and addictive GTK2 football manager"));
2005-09-29 15:41:16 +02:00
g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
g_option_context_add_group(context, gtk_get_option_group (FALSE));
2005-09-29 15:41:16 +02:00
g_option_context_parse(context, argc, argv, &error);
g_option_context_free(context);
2009-05-01 14:19:16 +02:00
if(error != NULL)
{
misc_print_error(&error, FALSE);
return;
}
2005-09-29 15:41:16 +02:00
2005-10-27 23:10:15 +02:00
if(calodds)
{
2010-04-02 12:49:15 +02:00
option_add(&options, "int_opt_calodds", 1, NULL);
option_add(&options, "int_opt_calodds_skilldiffmax", skilldiffmax, NULL);
option_add(&options, "int_opt_calodds_matches", num_matches, NULL);
2005-10-27 23:10:15 +02:00
}
2005-10-25 17:26:53 +02:00
if(testcom)
{
2010-04-02 12:49:15 +02:00
lg_commentary_test(testcom_file, token_file, event_name, number_of_passes);
main_exit_program(EXIT_OK, NULL);
2005-10-25 17:26:53 +02:00
}
2005-09-29 15:41:16 +02:00
if(support_dir != NULL)
{
2010-04-02 12:49:15 +02:00
gchar *fullpath = (support_dir[strlen(support_dir)] == G_DIR_SEPARATOR) ?
2008-11-25 15:31:35 +01:00
g_path_get_dirname(support_dir) :
g_strdup_printf("%s%s", support_dir, G_DIR_SEPARATOR_S);
file_add_support_directory_recursive(bygfoot, fullpath);
2010-04-02 12:49:15 +02:00
g_free(fullpath);
g_free(support_dir);
2005-09-29 15:41:16 +02:00
}
if(lang != NULL)
2006-02-28 23:17:08 +01:00
{
2010-04-02 12:49:15 +02:00
language_set(language_get_code_index(lang) + 1);
file_load_hints_file();
2008-12-17 16:31:07 +01:00
g_free(lang);
2006-02-28 23:17:08 +01:00
}
2005-12-10 13:21:19 +01:00
2008-12-17 16:31:07 +01:00
if(country_sid != NULL)
{
country.sid = g_strdup(country_sid);
g_free(country_sid);
}
if (random_seed)
g_rand_set_seed(rand_generator, random_seed);
2005-09-29 15:41:16 +02:00
}
2009-04-29 19:18:54 +02:00
/** Parse the command line arguments given by the user. */
2010-04-02 12:49:15 +02:00
void
2009-04-29 19:18:54 +02:00
main_parse_debug_cl_arguments(gint *argc, gchar ***argv)
{
#ifdef DEBUG
printf("main_parse_debug_cl_arguments\n");
#endif
gint deb_level = -1,
2010-04-02 12:49:15 +02:00
deb_output = -1;
2009-04-29 19:18:54 +02:00
gchar *debug_text = NULL;
GError *error = NULL;
GOptionContext *context = NULL;
GOptionEntry entries[] =
2010-04-02 12:49:15 +02:00
{{ "debug-level", 'd', 0, G_OPTION_ARG_INT, &deb_level, "[developer] Debug level to use", "N" },
{ "debug-output", 'o', 0, G_OPTION_ARG_INT, &deb_output, "[developer] Debug output to use", "0, 1 or 2" },
{ "deb", 'D', 0, G_OPTION_ARG_STRING, &debug_text,
"[developer] A debug command like 'deb100 to set the debug level'; see the debug window and debug.c", "STRING" },
{NULL}};
2009-04-29 19:18:54 +02:00
2009-05-01 14:19:16 +02:00
debug_level = DEBUG_LEVEL_DEFAULT;
debug_output = DEBUG_OUTPUT_DEFAULT;
2009-04-29 19:18:54 +02:00
if(argc == NULL || argv == NULL)
2010-04-02 12:49:15 +02:00
return;
2009-04-29 19:18:54 +02:00
context = g_option_context_new(_("- a simple and addictive GTK2 football manager"));
g_option_context_set_ignore_unknown_options(context, TRUE);
g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
g_option_context_add_group(context, gtk_get_option_group (FALSE));
2009-04-29 19:18:54 +02:00
g_option_context_parse(context, argc, argv, &error);
g_option_context_free(context);
if(error != NULL)
{
2009-05-01 14:19:16 +02:00
misc_print_error(&error, FALSE);
2009-04-29 19:18:54 +02:00
return;
}
if(deb_level != -1)
{
debug_level = deb_level;
window_create(WINDOW_DEBUG);
}
if(deb_output != -1)
2010-04-02 12:49:15 +02:00
debug_output = deb_output;
2009-04-29 19:18:54 +02:00
if(debug_text != NULL)
2010-04-02 12:49:15 +02:00
statp = debug_text;
2009-04-29 19:18:54 +02:00
}
2004-12-23 13:58:39 +01:00
/**
2010-04-02 12:49:15 +02:00
Initialize some global variables. Most of them get nullified.
*/
void
main_init_variables(void)
2004-12-23 13:58:39 +01:00
{
#ifdef DEBUG
printf("main_init_variables\n");
#endif
2005-04-13 15:01:59 +02:00
gint i;
2005-09-29 15:41:16 +02:00
ligs = g_array_new(FALSE, FALSE, sizeof(League));
cps = g_array_new(FALSE, FALSE, sizeof(Cup));;
acps = g_ptr_array_new();
2005-10-09 11:35:44 +02:00
country.name = NULL;
country.symbol = NULL;
2008-12-17 16:31:07 +01:00
country.sid = NULL;
2005-10-31 17:19:14 +01:00
2005-04-16 09:46:04 +02:00
season = week = week_round = 1;
2005-04-13 15:01:59 +02:00
for(i=0;i<COUNT_END;i++)
2010-04-02 12:49:15 +02:00
counters[i] = 0;
2005-04-13 15:01:59 +02:00
2005-04-14 21:07:25 +02:00
counters[COUNT_LEAGUE_ID] = ID_LEAGUE_START;
counters[COUNT_CUP_ID] = ID_CUP_START;
2006-02-15 13:03:48 +01:00
counters[COUNT_HINT_NUMBER] = -1;
2005-04-14 21:07:25 +02:00
2005-03-27 19:59:57 +02:00
window.main = window.startup =
2010-04-02 12:49:15 +02:00
window.live = window.warning = window.progress = window.digits =
window.stadium = window.job_offer = window.yesno =
window.options = window.font_sel =
window.file_chooser = window.contract =
window.menu_player = window.user_management =
window.mmatches = window.bets = window.splash =
window.training_camp = NULL;
2010-04-02 12:45:33 +02:00
users = g_array_new(FALSE, FALSE, sizeof(User));
2005-03-19 21:04:08 +01:00
transfer_list = g_array_new(FALSE, FALSE, sizeof(Transfer));
2005-05-01 12:16:14 +02:00
season_stats = g_array_new(FALSE, FALSE, sizeof(SeasonStat));
name_lists = g_array_new(FALSE, FALSE, sizeof(NameList));
2005-10-24 22:50:48 +02:00
strategies = g_array_new(FALSE, FALSE, sizeof(Strategy));
2008-12-01 21:39:16 +01:00
live_games = g_array_new(FALSE, FALSE, sizeof(LiveGame));
2005-10-27 23:10:15 +02:00
bets[0] = g_array_new(FALSE, FALSE, sizeof(BetMatch));
bets[1] = g_array_new(FALSE, FALSE, sizeof(BetMatch));
jobs = g_array_new(FALSE, FALSE, sizeof(Job));
2005-10-09 11:35:44 +02:00
save_file = NULL;
2005-04-04 12:36:04 +02:00
2005-06-26 13:42:01 +02:00
constants_app.list = settings.list =
2010-04-02 12:49:15 +02:00
constants.list = options.list = tokens.list =
hints.list = NULL;
2005-06-26 13:42:01 +02:00
constants_app.datalist = settings.datalist =
2010-04-02 12:49:15 +02:00
constants.datalist = options.datalist =
tokens.datalist = hints.datalist = NULL;
2005-03-24 08:42:24 +01:00
2005-07-08 11:26:00 +02:00
selected_row = -1;
2005-03-17 21:26:01 +01:00
timeout_id = -1;
2005-06-26 13:42:01 +02:00
for(i=0;i<LIVE_GAME_EVENT_END;i++)
2010-04-02 12:49:15 +02:00
lg_commentary[i] = g_array_new(FALSE, FALSE, sizeof(LGCommentary));
2005-06-26 13:42:01 +02:00
2008-11-27 14:24:18 +01:00
for(i=0;i<NEWS_ARTICLE_TYPE_END;i++)
2010-04-02 12:49:15 +02:00
news[i] = g_array_new(FALSE, FALSE, sizeof(NewsArticle));
2008-11-27 14:24:18 +01:00
2008-11-28 15:09:08 +01:00
newspaper.articles = g_array_new(FALSE, FALSE, sizeof(NewsPaperArticle));
file_load_conf_files();
2005-10-24 22:50:48 +02:00
xml_strategy_load_strategies();
2010-04-02 12:45:33 +02:00
2005-06-14 17:27:44 +02:00
language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);
2005-06-23 23:53:57 +02:00
2005-10-31 17:19:14 +01:00
option_add(&options, "int_opt_calodds", 0, NULL);
2005-06-23 23:53:57 +02:00
/** Some of these (or all) are disabled (set to 1) in supernational
2010-04-02 12:49:15 +02:00
country defs. */
2009-01-09 15:32:34 +01:00
option_add(&settings, "int_opt_goto_mode", 0, NULL);
2005-06-26 13:42:01 +02:00
option_add(&settings, "int_opt_disable_finances", 0, NULL);
option_add(&settings, "int_opt_disable_transfers", 0, NULL);
option_add(&settings, "int_opt_disable_stadium", 0, NULL);
option_add(&settings, "int_opt_disable_contracts", 0, NULL);
option_add(&settings, "int_opt_disable_boost_on", 0, NULL);
2005-09-19 23:13:36 +02:00
option_add(&settings, "int_opt_disable_ya", 0, NULL);
2007-01-18 18:29:56 +01:00
option_add(&settings, "int_opt_disable_training_camp", 0, NULL);
2004-12-23 13:58:39 +01:00
}
/**
Callback to use with g_ptr_array_foreach() to validate country xml files.
*/
static void validate_country_file(gpointer country_file, gpointer user_data)
{
Country country;
memset(&country, 0, sizeof(country));
xml_country_read(country_file, &country);
}
static void validate_country_files()
{
GPtrArray *country_files = file_get_country_files();
if(country_files->len == 0)
main_exit_program(EXIT_NO_COUNTRY_FILES,
"Didn't find any country definition files in the support directories.");
g_ptr_array_foreach(country_files, validate_country_file, NULL);
}
2004-12-23 13:58:39 +01:00
/**
2010-04-02 12:49:15 +02:00
Process the command line arguments and do some things
that have to be done at the beginning (like initializing the
random number generator).
@param argc Number of command line arguments.
@param argv Command line arguments array.
*/
void
main_init(gint *argc, gchar ***argv, Bygfoot *bygfoot)
2004-12-23 13:58:39 +01:00
{
#ifdef DEBUG
printf("main_init\n");
#endif
2004-12-23 13:58:39 +01:00
gchar buf[SMALL];
2009-05-01 14:19:16 +02:00
gchar *dir;
GPtrArray *country_files = NULL;
2009-04-29 19:18:54 +02:00
support_directories = NULL;
rand_generator = g_rand_new();
main_parse_debug_cl_arguments(argc, argv);
2005-07-17 13:55:33 +02:00
#ifdef G_OS_WIN32
os_is_unix = FALSE;
#else
os_is_unix = TRUE;
#endif
2009-05-01 14:19:16 +02:00
#if defined(G_OS_UNIX) && !defined(MAC_BUILD)
file_add_support_directory_recursive(bygfoot, PACKAGE_DATA_DIR "/" PACKAGE "/support_files");
2005-07-17 13:55:33 +02:00
sprintf(buf, "%s%s%s", g_get_home_dir(), G_DIR_SEPARATOR_S, HOMEDIRNAME);
file_add_support_directory_recursive(bygfoot, buf);
2005-07-19 17:55:34 +02:00
#endif
2005-04-04 12:36:04 +02:00
2009-04-30 10:38:36 +02:00
#ifndef MAC_BUILD
2009-05-01 14:19:16 +02:00
dir = g_get_current_dir();
sprintf(buf, "%s%ssupport_files", dir, G_DIR_SEPARATOR_S);
file_add_support_directory_recursive(bygfoot, buf);
2009-05-01 14:19:16 +02:00
sprintf(buf, "%s%ssaves", dir, G_DIR_SEPARATOR_S);
file_add_support_directory_recursive(bygfoot, buf);
2009-05-01 14:19:16 +02:00
g_free(dir);
2010-04-02 12:45:33 +02:00
#else
dir = file_get_mac_resource_path("support_files");
file_add_support_directory_recursive(bygfoot, dir);
2009-04-30 10:38:36 +02:00
#endif
main_init_variables();
2005-07-17 13:55:33 +02:00
2005-10-03 20:08:26 +02:00
load_last_save = FALSE;
main_parse_cl_arguments(argc, argv, bygfoot);
/* main_parse_cl_arguments may set the seed for the random number
* generator, so generate the interest after the seed is set. This help
* keeps the value consistent when --seed is used.
*/
current_interest = rint(math_rnd(const_float("float_finance_interest_lower"),
const_float("float_finance_interest_upper")) /
const_float("float_finance_interest_step")) * const_float("float_finance_interest_step");
2004-12-23 13:58:39 +01:00
}
/**
2010-04-02 12:49:15 +02:00
Initialize the GTK stuff and the gettext stuff.
Start the game.
@param argc Number of command line arguments.
@param argv Command line arguments array.
*/
gint
2004-12-23 13:58:39 +01:00
main (gint argc, gchar *argv[])
{
Bygfoot bygfoot;
CommandLineArgs cl_args;
#ifdef DEBUG
printf("main\n");
#endif
2004-12-23 13:58:39 +01:00
2009-05-01 14:19:16 +02:00
#if defined(ENABLE_NLS) && !defined(MAC_BUILD)
2004-12-23 13:58:39 +01:00
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif
#ifdef G_OS_WIN32
int fd1 = open ("stdout.log", O_CREAT|O_WRONLY|O_TRUNC, 0666);
dup2 (fd1, 1);
int fd2 = open ("stderr.log", O_CREAT|O_WRONLY|O_TRUNC, 0666);
dup2 (fd2, 2);
#endif
memset(&cl_args, 0, sizeof(cl_args));
#ifdef ENABLE_JSON
main_parse_frontend_backend_cl_arguments(&argc, &argv, &cl_args);
if (cl_args.json_filename) {
bygfoot_init(&bygfoot, BYGFOOT_FRONTEND_CONSOLE);
main_init(&argc, &argv, &bygfoot);
file_check_home_dir_create_dirs();
validate_country_files();
return bygfoot_json_main(&bygfoot, &cl_args);
}
#endif
bygfoot_init(&bygfoot, BYGFOOT_FRONTEND_GTK2);
gtk_init (&argc, &argv);
2005-11-26 17:52:51 +01:00
main_init(&argc, &argv, &bygfoot);
2005-09-29 15:41:16 +02:00
validate_country_files();
if((load_last_save && !load_game_from_command_line(&bygfoot, "last_save")) ||
2010-04-02 12:49:15 +02:00
(!load_last_save && (argc == 1 ||
(argc > 1 && !load_game_from_command_line(&bygfoot, argv[1])))))
2005-09-29 15:41:16 +02:00
{
2008-12-17 16:31:07 +01:00
if(country.sid == NULL)
{
stat0 = STATUS_SPLASH;
window_show_splash(&bygfoot);
2010-04-02 12:45:33 +02:00
2008-12-17 16:31:07 +01:00
if(os_is_unix)
2010-04-02 12:45:33 +02:00
file_check_home_dir();
2008-12-17 16:31:07 +01:00
}
else
{
window_show_startup(&bygfoot);
2008-12-17 16:31:07 +01:00
stat0 = STATUS_TEAM_SELECTION;
}
2005-09-29 15:41:16 +02:00
}
2005-04-07 18:44:33 +02:00
gtk_main ();
2004-12-23 13:58:39 +01:00
main_exit_program(EXIT_OK, NULL);
return 0;
2004-12-23 13:58:39 +01:00
}
2005-01-09 21:21:22 +01:00
/** Exit the program with the given exit code and message. Try to
2010-04-02 12:49:15 +02:00
destroy all widgets and free all memory first.
@param exit_code The number we return to the shell.
@param exit_message The message we print.
@return The exit code of the program. */
void
2005-10-24 22:50:48 +02:00
main_exit_program(gint exit_code, gchar *format, ...)
{
#ifdef DEBUG
printf("main_exit_program\n");
#endif
2005-10-24 22:50:48 +02:00
gchar text[SMALL];
va_list args;
2010-04-02 12:45:33 +02:00
2005-10-24 22:50:48 +02:00
if(format != NULL)
{
2010-04-02 12:49:15 +02:00
va_start (args, format);
g_vsprintf(text, format, args);
va_end (args);
debug_print_message(text, NULL);
2005-10-24 22:50:48 +02:00
}
if(gtk_main_level() > 0)
2010-04-02 12:49:15 +02:00
gtk_main_quit();
free_memory();
2005-10-21 15:45:58 +02:00
2005-12-21 17:02:49 +01:00
if(!os_is_unix && exit_code != EXIT_OK)
2005-10-21 15:45:58 +02:00
{
2010-04-02 12:49:15 +02:00
debug_print_message("Press RETURN. Program will exit.");
getchar();
2005-10-21 15:45:58 +02:00
}
2010-04-02 12:45:33 +02:00
exit(exit_code);
}