bygfoot/src/main.c

112 lines
2.5 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>
/*d*/
#include "file.h"
#include "free.h"
2004-12-23 13:58:39 +01:00
#include "main.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
{
ligs = cps = NULL;
country.name = country.symbol = country.sid = NULL;
transfer_list = NULL;
player_names = NULL;
2005-01-09 21:21:22 +01:00
my_team = NULL;
2004-12-23 13:58:39 +01:00
font_name = g_string_new("0");
2005-01-09 21:21:22 +01:00
debug = FALSE;
live_game.units = g_array_new(FALSE, FALSE, sizeof(LiveGameUnit));
live_game.window = NULL;
live_game_temp.units = g_array_new(FALSE, FALSE, sizeof(LiveGameUnit));
live_game_temp.window = NULL;
popups_active = 0;
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 */
srandom((unsigned)time(NULL));
file_add_support_directory_recursive(PACKAGE_DATA_DIR "/" PACKAGE "/support_files");
2004-12-23 13:58:39 +01:00
sprintf(buf, "%s/support_files", pwd);
g_free(pwd);
file_add_support_directory_recursive(buf);
2004-12-23 13:58:39 +01:00
sprintf(buf, "%s/.bygfoot", g_get_home_dir());
file_add_support_directory_recursive(buf);
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);
2004-12-23 13:58:39 +01:00
window_show_startup();
gtk_main ();
2005-01-09 21:21:22 +01:00
main_exit_program(EXIT_OK, NULL);
2004-12-23 13:58:39 +01:00
return 0;
}
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);
}