bygfoot/src/main.c

152 lines
3.6 KiB
C
Raw Normal View History

2004-12-23 13:58:39 +01:00
/*
* Initial main.c file generated by Glade. Edit as required.
* Glade will not overwrite this file.
*/
#include <time.h>
#include "file.h"
#include "free.h"
2005-06-14 17:27:44 +02:00
#include "language.h"
2005-04-04 12:36:04 +02:00
#include "live_game.h"
2004-12-23 13:58:39 +01:00
#include "main.h"
2005-06-14 17:27:44 +02:00
#include "misc_callbacks.h"
#include "name_struct.h"
2005-06-14 17:27:44 +02:00
#include "option.h"
2005-05-01 12:16:14 +02:00
#include "stat_struct.h"
2005-06-05 12:39:29 +02:00
#include "transfer_struct.h"
#include "variables.h"
#include "window.h"
2004-12-23 13:58:39 +01:00
/**
Initialize some global variables. Most of them get nullified.
*/
void
main_init_variables(void)
2004-12-23 13:58:39 +01:00
{
2005-04-13 15:01:59 +02:00
gint i;
2005-05-06 18:35:19 +02:00
ligs = cps = NULL;
2005-04-14 21:07:25 +02:00
acps = NULL;
country.name = country.symbol = country.sid = NULL;
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++)
counters[i] = 0;
2005-04-14 21:07:25 +02:00
counters[COUNT_LEAGUE_ID] = ID_LEAGUE_START;
counters[COUNT_CUP_ID] = ID_CUP_START;
2005-03-27 19:59:57 +02:00
window.main = window.startup =
window.live = window.warning = window.progress = window.digits =
window.stadium = window.job_offer = window.yesno =
2005-04-04 12:36:04 +02:00
window.options = window.font_sel = window.file_sel = window.contract =
2005-03-27 19:59:57 +02:00
window.menu_player = window.user_management = NULL;
2004-12-23 13:58:39 +01:00
2005-04-04 12:36:04 +02:00
live_game_reset(&live_game_temp, NULL, FALSE);
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-01-09 21:21:22 +01:00
2005-04-04 12:36:04 +02:00
save_file = g_string_new("");
2005-05-06 18:35:19 +02:00
constants_app.list =
constants.list = options.list = NULL;
constants_app.datalist =
constants.datalist = options.datalist = NULL;
2005-03-24 08:42:24 +01:00
2005-01-09 21:21:22 +01:00
popups_active = 0;
selected_row[0] = selected_row[1] = -1;
2005-03-17 21:26:01 +01:00
timeout_id = -1;
file_load_conf_files();
2005-06-14 17:27:44 +02:00
language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);
2004-12-23 13:58:39 +01: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[])
2004-12-23 13:58:39 +01:00
{
gchar buf[SMALL];
gchar *pwd = g_get_current_dir();
/* initialize the random nr generator */
2005-04-04 12:36:04 +02:00
rand_generator = g_rand_new();
support_directories = NULL;
2004-12-23 13:58:39 +01:00
2005-05-18 18:00:49 +02:00
file_add_support_directory_recursive(PACKAGE_DATA_DIR "/" PACKAGE "/support_files");
2005-04-04 12:36:04 +02:00
sprintf(buf, "%s/%s", g_get_home_dir(), HOMEDIRNAME);
2005-01-10 16:24:15 +01:00
file_add_support_directory_recursive(buf);
2005-04-04 12:36:04 +02:00
2004-12-23 13:58:39 +01:00
sprintf(buf, "%s/support_files", pwd);
g_free(pwd);
file_add_support_directory_recursive(buf);
2005-04-04 12:36:04 +02:00
file_check_home_dir();
2004-12-23 13:58:39 +01:00
main_init_variables();
2004-12-23 13:58:39 +01: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
main (gint argc, gchar *argv[])
{
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif
gtk_set_locale ();
gtk_init (&argc, &argv);
main_init(argc, argv);
window_show_startup();
2005-03-08 09:25:46 +01:00
stat0 = STATUS_TEAM_SELECTION;
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
destroy all widgets and free all memory first.
@param exit_code The number we return to the shell.
2005-01-09 21:21:22 +01:00
@param exit_message The message we print.
@return The exit code of the program. */
void
2005-01-09 21:21:22 +01:00
main_exit_program(gint exit_code, gchar *exit_message)
{
if(gtk_main_level() > 0)
gtk_main_quit();
free_memory();
2005-01-09 21:21:22 +01:00
if(exit_message != NULL)
g_warning(exit_message);
exit(exit_code);
}