Now with the format really changed

This commit is contained in:
gunnar_g 2010-04-02 10:49:15 +00:00
parent fb9ed5a65e
commit 6377338c61
1 changed files with 102 additions and 103 deletions

View File

@ -21,7 +21,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
/* /*
* Initial main.c file generated by Glade. Edit as required. * Initial main.c file generated by Glade. Edit as required.
@ -33,11 +33,10 @@
#include <glib.h> #include <glib.h>
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#include "bygfoot.h"
#include "bet_struct.h" #include "bet_struct.h"
#include "debug.h" #include "debug.h"
#include "file.h" #include "file.h"
@ -71,11 +70,11 @@
#endif #endif
/** Whether the last save gets loaded at startup /** Whether the last save gets loaded at startup
(cl switch -l). */ (cl switch -l). */
gboolean load_last_save; gboolean load_last_save;
/** Parse the command line arguments given by the user. */ /** Parse the command line arguments given by the user. */
void void
main_parse_cl_arguments(gint *argc, gchar ***argv) main_parse_cl_arguments(gint *argc, gchar ***argv)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -84,53 +83,53 @@ main_parse_cl_arguments(gint *argc, gchar ***argv)
gboolean testcom = FALSE, calodds = FALSE; gboolean testcom = FALSE, calodds = FALSE;
gchar *support_dir = NULL, *lang = NULL, gchar *support_dir = NULL, *lang = NULL,
*testcom_file = NULL, *token_file = NULL, *testcom_file = NULL, *token_file = NULL,
*event_name = NULL, *event_name = NULL,
*country_sid = NULL; *country_sid = NULL;
gint number_of_passes = 1, gint number_of_passes = 1,
num_matches = 100, skilldiffmax = 20; num_matches = 100, skilldiffmax = 20;
GError *error = NULL; GError *error = NULL;
GOptionContext *context = NULL; GOptionContext *context = NULL;
GOptionEntry entries[] = GOptionEntry entries[] =
{{ "last-save", 'l', 0, G_OPTION_ARG_NONE, &load_last_save, _("Load last savegame"), NULL }, {{ "last-save", 'l', 0, G_OPTION_ARG_NONE, &load_last_save, _("Load last savegame"), NULL },
{ "support-dir", 's', 0, G_OPTION_ARG_STRING, &support_dir, { "support-dir", 's', 0, G_OPTION_ARG_STRING, &support_dir,
_("Specify additional support directory (takes priority over default ones)"), "DIR" }, _("Specify additional support directory (takes priority over default ones)"), "DIR" },
{ "country", 'c', 0, G_OPTION_ARG_STRING, &country_sid, _("String id of the country to load"), "SID" }, { "country", 'c', 0, G_OPTION_ARG_STRING, &country_sid, _("String id of the country to load"), "SID" },
{ "lang", 'L', 0, G_OPTION_ARG_STRING, &lang, _("Language to use (a code like 'de')"), "CODE" }, { "lang", 'L', 0, G_OPTION_ARG_STRING, &lang, _("Language to use (a code like 'de')"), "CODE" },
{ "testcom", 't', 0, G_OPTION_ARG_NONE, &testcom, _("Test an XML commentary file"), NULL }, { "testcom", 't', 0, G_OPTION_ARG_NONE, &testcom, _("Test an XML commentary file"), NULL },
{ "commentary-file", 'C', 0, G_OPTION_ARG_STRING, &testcom_file, { "commentary-file", 'C', 0, G_OPTION_ARG_STRING, &testcom_file,
_("Commentary file name (may be in a support dir)"), "FILE" }, _("Commentary file name (may be in a support dir)"), "FILE" },
{ "token-file", 'T', 0, G_OPTION_ARG_STRING, &token_file, { "token-file", 'T', 0, G_OPTION_ARG_STRING, &token_file,
/* Live game tokens are strings like _AT_ in live game commentary files /* 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 which will be filled in by the program during runtime; e.g. _AT_ becomes
the attendace for the match. */ the attendace for the match. */
_("File containing live game tokens (may be in a support dir)"), "FILE" }, _("File containing live game tokens (may be in a support dir)"), "FILE" },
{ "event-name", 'e', 0, G_OPTION_ARG_STRING, &event_name, { "event-name", 'e', 0, G_OPTION_ARG_STRING, &event_name,
_("Commentary event to test; leave out to test all commentaries"), "EVENTNAME" }, _("Commentary event to test; leave out to test all commentaries"), "EVENTNAME" },
{ "num-passes", 'n', 0, G_OPTION_ARG_INT, &number_of_passes, { "num-passes", 'n', 0, G_OPTION_ARG_INT, &number_of_passes,
_("How many commentaries to generate per event"), "N" }, _("How many commentaries to generate per event"), "N" },
{ "calodds", 'O', 0, G_OPTION_ARG_NONE, &calodds, { "calodds", 'O', 0, G_OPTION_ARG_NONE, &calodds,
"[developer] Calibrate the betting odds by simulating a lot of matches", NULL }, "[developer] Calibrate the betting odds by simulating a lot of matches", NULL },
{ "num-matches", 'm', 0, G_OPTION_ARG_INT, &num_matches, { "num-matches", 'm', 0, G_OPTION_ARG_INT, &num_matches,
"[developer] How many matches to simulate per skill diff step", "N" }, "[developer] How many matches to simulate per skill diff step", "N" },
{ "num-skilldiff", 'S', 0, G_OPTION_ARG_INT, &skilldiffmax, { "num-skilldiff", 'S', 0, G_OPTION_ARG_INT, &skilldiffmax,
"[developer] How many skill diff steps to take", "N" }, "[developer] How many skill diff steps to take", "N" },
{NULL}}; {NULL}};
if(argc == NULL || argv == NULL) if(argc == NULL || argv == NULL)
return; return;
context = g_option_context_new(_("- a simple and addictive GTK2 football manager")); context = g_option_context_new(_("- a simple and addictive GTK2 football manager"));
g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
@ -146,31 +145,31 @@ main_parse_cl_arguments(gint *argc, gchar ***argv)
if(calodds) if(calodds)
{ {
option_add(&options, "int_opt_calodds", 1, NULL); option_add(&options, "int_opt_calodds", 1, NULL);
option_add(&options, "int_opt_calodds_skilldiffmax", skilldiffmax, NULL); option_add(&options, "int_opt_calodds_skilldiffmax", skilldiffmax, NULL);
option_add(&options, "int_opt_calodds_matches", num_matches, NULL); option_add(&options, "int_opt_calodds_matches", num_matches, NULL);
} }
if(testcom) if(testcom)
{ {
lg_commentary_test(testcom_file, token_file, event_name, number_of_passes); lg_commentary_test(testcom_file, token_file, event_name, number_of_passes);
main_exit_program(EXIT_OK, NULL); main_exit_program(EXIT_OK, NULL);
} }
if(support_dir != NULL) if(support_dir != NULL)
{ {
gchar *fullpath = (support_dir[strlen(support_dir)] == G_DIR_SEPARATOR) ? gchar *fullpath = (support_dir[strlen(support_dir)] == G_DIR_SEPARATOR) ?
g_path_get_dirname(support_dir) : g_path_get_dirname(support_dir) :
g_strdup_printf("%s%s", support_dir, G_DIR_SEPARATOR_S); g_strdup_printf("%s%s", support_dir, G_DIR_SEPARATOR_S);
file_add_support_directory_recursive(fullpath); file_add_support_directory_recursive(fullpath);
g_free(fullpath); g_free(fullpath);
g_free(support_dir); g_free(support_dir);
} }
if(lang != NULL) if(lang != NULL)
{ {
language_set(language_get_code_index(lang) + 1); language_set(language_get_code_index(lang) + 1);
file_load_hints_file(); file_load_hints_file();
g_free(lang); g_free(lang);
} }
@ -182,7 +181,7 @@ main_parse_cl_arguments(gint *argc, gchar ***argv)
} }
/** Parse the command line arguments given by the user. */ /** Parse the command line arguments given by the user. */
void void
main_parse_debug_cl_arguments(gint *argc, gchar ***argv) main_parse_debug_cl_arguments(gint *argc, gchar ***argv)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -190,22 +189,22 @@ main_parse_debug_cl_arguments(gint *argc, gchar ***argv)
#endif #endif
gint deb_level = -1, gint deb_level = -1,
deb_output = -1; deb_output = -1;
gchar *debug_text = NULL; gchar *debug_text = NULL;
GError *error = NULL; GError *error = NULL;
GOptionContext *context = NULL; GOptionContext *context = NULL;
GOptionEntry entries[] = GOptionEntry entries[] =
{{ "debug-level", 'd', 0, G_OPTION_ARG_INT, &deb_level, "[developer] Debug level to use", "N" }, {{ "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" }, { "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, { "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" }, "[developer] A debug command like 'deb100 to set the debug level'; see the debug window and debug.c", "STRING" },
{NULL}}; {NULL}};
debug_level = DEBUG_LEVEL_DEFAULT; debug_level = DEBUG_LEVEL_DEFAULT;
debug_output = DEBUG_OUTPUT_DEFAULT; debug_output = DEBUG_OUTPUT_DEFAULT;
if(argc == NULL || argv == NULL) if(argc == NULL || argv == NULL)
return; return;
context = g_option_context_new(_("- a simple and addictive GTK2 football manager")); context = g_option_context_new(_("- a simple and addictive GTK2 football manager"));
g_option_context_set_ignore_unknown_options(context, TRUE); g_option_context_set_ignore_unknown_options(context, TRUE);
@ -227,16 +226,16 @@ main_parse_debug_cl_arguments(gint *argc, gchar ***argv)
} }
if(deb_output != -1) if(deb_output != -1)
debug_output = deb_output; debug_output = deb_output;
if(debug_text != NULL) if(debug_text != NULL)
statp = debug_text; statp = debug_text;
} }
/** /**
Initialize some global variables. Most of them get nullified. Initialize some global variables. Most of them get nullified.
*/ */
void void
main_init_variables(void) main_init_variables(void)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -255,20 +254,20 @@ main_init_variables(void)
season = week = week_round = 1; season = week = week_round = 1;
for(i=0;i<COUNT_END;i++) for(i=0;i<COUNT_END;i++)
counters[i] = 0; counters[i] = 0;
counters[COUNT_LEAGUE_ID] = ID_LEAGUE_START; counters[COUNT_LEAGUE_ID] = ID_LEAGUE_START;
counters[COUNT_CUP_ID] = ID_CUP_START; counters[COUNT_CUP_ID] = ID_CUP_START;
counters[COUNT_HINT_NUMBER] = -1; counters[COUNT_HINT_NUMBER] = -1;
window.main = window.startup = window.main = window.startup =
window.live = window.warning = window.progress = window.digits = window.live = window.warning = window.progress = window.digits =
window.stadium = window.job_offer = window.yesno = window.stadium = window.job_offer = window.yesno =
window.options = window.font_sel = window.options = window.font_sel =
window.file_chooser = window.contract = window.file_chooser = window.contract =
window.menu_player = window.user_management = window.menu_player = window.user_management =
window.mmatches = window.bets = window.splash = window.mmatches = window.bets = window.splash =
window.training_camp = NULL; window.training_camp = NULL;
users = g_array_new(FALSE, FALSE, sizeof(User)); users = g_array_new(FALSE, FALSE, sizeof(User));
transfer_list = g_array_new(FALSE, FALSE, sizeof(Transfer)); transfer_list = g_array_new(FALSE, FALSE, sizeof(Transfer));
@ -283,21 +282,21 @@ main_init_variables(void)
save_file = NULL; save_file = NULL;
constants_app.list = settings.list = constants_app.list = settings.list =
constants.list = options.list = tokens.list = constants.list = options.list = tokens.list =
hints.list = NULL; hints.list = NULL;
constants_app.datalist = settings.datalist = constants_app.datalist = settings.datalist =
constants.datalist = options.datalist = constants.datalist = options.datalist =
tokens.datalist = hints.datalist = NULL; tokens.datalist = hints.datalist = NULL;
selected_row = -1; selected_row = -1;
timeout_id = -1; timeout_id = -1;
for(i=0;i<LIVE_GAME_EVENT_END;i++) for(i=0;i<LIVE_GAME_EVENT_END;i++)
lg_commentary[i] = g_array_new(FALSE, FALSE, sizeof(LGCommentary)); lg_commentary[i] = g_array_new(FALSE, FALSE, sizeof(LGCommentary));
for(i=0;i<NEWS_ARTICLE_TYPE_END;i++) for(i=0;i<NEWS_ARTICLE_TYPE_END;i++)
news[i] = g_array_new(FALSE, FALSE, sizeof(NewsArticle)); news[i] = g_array_new(FALSE, FALSE, sizeof(NewsArticle));
newspaper.articles = g_array_new(FALSE, FALSE, sizeof(NewsPaperArticle)); newspaper.articles = g_array_new(FALSE, FALSE, sizeof(NewsPaperArticle));
@ -305,15 +304,15 @@ main_init_variables(void)
xml_strategy_load_strategies(); xml_strategy_load_strategies();
current_interest = rint(math_rnd(const_float("float_finance_interest_lower"), current_interest = rint(math_rnd(const_float("float_finance_interest_lower"),
const_float("float_finance_interest_upper")) / const_float("float_finance_interest_upper")) /
const_float("float_finance_interest_step")) * const_float("float_finance_interest_step"); const_float("float_finance_interest_step")) * const_float("float_finance_interest_step");
language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1); language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);
option_add(&options, "int_opt_calodds", 0, NULL); option_add(&options, "int_opt_calodds", 0, NULL);
/** Some of these (or all) are disabled (set to 1) in supernational /** Some of these (or all) are disabled (set to 1) in supernational
country defs. */ country defs. */
option_add(&settings, "int_opt_goto_mode", 0, NULL); option_add(&settings, "int_opt_goto_mode", 0, NULL);
option_add(&settings, "int_opt_disable_finances", 0, NULL); option_add(&settings, "int_opt_disable_finances", 0, NULL);
option_add(&settings, "int_opt_disable_transfers", 0, NULL); option_add(&settings, "int_opt_disable_transfers", 0, NULL);
@ -325,13 +324,13 @@ main_init_variables(void)
} }
/** /**
Process the command line arguments and do some things Process the command line arguments and do some things
that have to be done at the beginning (like initializing the that have to be done at the beginning (like initializing the
random number generator). random number generator).
@param argc Number of command line arguments. @param argc Number of command line arguments.
@param argv Command line arguments array. @param argv Command line arguments array.
*/ */
void void
main_init(gint *argc, gchar ***argv) main_init(gint *argc, gchar ***argv)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -377,12 +376,12 @@ main_init(gint *argc, gchar ***argv)
} }
/** /**
Initialize the GTK stuff and the gettext stuff. Initialize the GTK stuff and the gettext stuff.
Start the game. Start the game.
@param argc Number of command line arguments. @param argc Number of command line arguments.
@param argv Command line arguments array. @param argv Command line arguments array.
*/ */
gint gint
main (gint argc, gchar *argv[]) main (gint argc, gchar *argv[])
{ {
#ifdef DEBUG #ifdef DEBUG
@ -405,8 +404,8 @@ main (gint argc, gchar *argv[])
main_init(&argc, &argv); main_init(&argc, &argv);
if((load_last_save && !load_game_from_command_line("last_save")) || if((load_last_save && !load_game_from_command_line("last_save")) ||
(!load_last_save && (argc == 1 || (!load_last_save && (argc == 1 ||
(argc > 1 && !load_game_from_command_line(argv[1]))))) (argc > 1 && !load_game_from_command_line(argv[1])))))
{ {
if(country.sid == NULL) if(country.sid == NULL)
{ {
@ -431,11 +430,11 @@ main (gint argc, gchar *argv[])
} }
/** Exit the program with the given exit code and message. Try to /** Exit the program with the given exit code and message. Try to
destroy all widgets and free all memory first. destroy all widgets and free all memory first.
@param exit_code The number we return to the shell. @param exit_code The number we return to the shell.
@param exit_message The message we print. @param exit_message The message we print.
@return The exit code of the program. */ @return The exit code of the program. */
void void
main_exit_program(gint exit_code, gchar *format, ...) main_exit_program(gint exit_code, gchar *format, ...)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -447,21 +446,21 @@ main_exit_program(gint exit_code, gchar *format, ...)
if(format != NULL) if(format != NULL)
{ {
va_start (args, format); va_start (args, format);
g_vsprintf(text, format, args); g_vsprintf(text, format, args);
va_end (args); va_end (args);
debug_print_message(text, NULL); debug_print_message(text, NULL);
} }
if(gtk_main_level() > 0) if(gtk_main_level() > 0)
gtk_main_quit(); gtk_main_quit();
free_memory(); free_memory();
if(!os_is_unix && exit_code != EXIT_OK) if(!os_is_unix && exit_code != EXIT_OK)
{ {
debug_print_message("Press RETURN. Program will exit."); debug_print_message("Press RETURN. Program will exit.");
getchar(); getchar();
} }
exit(exit_code); exit(exit_code);