From df4df46065ca8f1cf2adc6b8809fbcf8b556e86f Mon Sep 17 00:00:00 2001 From: gyboth Date: Wed, 20 Apr 2005 17:56:31 +0000 Subject: [PATCH] Restructured definition directory. --- src/bygfoot.h | 1 + src/cup.c | 28 +++++++------- src/file.c | 78 ++++++++++++++++++++++++++------------ src/file.h | 3 ++ src/fixture.c | 2 +- support_files/bygfoot.conf | 2 +- 6 files changed, 75 insertions(+), 39 deletions(-) diff --git a/src/bygfoot.h b/src/bygfoot.h index 058a1de5..01eefa60 100644 --- a/src/bygfoot.h +++ b/src/bygfoot.h @@ -87,6 +87,7 @@ enum ExitCodes EXIT_FIXTURE_WRITE_ERROR, /** There was an error writing the fixtures. */ EXIT_USER_FIRED, EXIT_CUP_LAST_ROUND, + EXIT_FIRST_WEEK_ERROR, EXIT_END }; diff --git a/src/cup.c b/src/cup.c index e1325dd5..64ae1539 100644 --- a/src/cup.c +++ b/src/cup.c @@ -548,6 +548,12 @@ cup_get_first_week_of_cup_round(const Cup *cup, gint cup_round) week_number = cup_get_first_week_of_cup_round(cup, cup_round + 1) - cup_get_matchdays_in_cup_round(cup, cup_round) * cup->week_gap; + if(week_number <= 0) + { + g_warning("cup_get_first_week_of_cup_round: first week of cup %s cup round %d is not positive (%d).\nPlease lower the week gap or set a later last week.\n", cup->name->str, cup_round, week_number); + main_exit_program(EXIT_FIRST_WEEK_ERROR, NULL); + } + return week_number; } @@ -668,19 +674,15 @@ cup_round_name(const Fixture *fix, gchar *buf) cup_get_round_name(cup, fix->round, buf); - if(cup_round->round_robin_number_of_groups == 0) - strcpy(buf, "Round robin"); - { - if(cup_round->home_away) - { - if(fix->second_leg) - strcat(buf, " -- Second leg"); - else - strcat(buf, " -- First leg"); - } - else if(fix->replay_number > 0) - strcat(buf, " -- Replay match"); - } + if(cup_round->home_away) + { + if(fix->second_leg) + strcat(buf, " -- Second leg"); + else + strcat(buf, " -- First leg"); + } + else if(fix->replay_number > 0) + strcat(buf, " -- Replay match"); } /** Return the cup round given by the number. */ diff --git a/src/file.c b/src/file.c index 4ecfae76..5e23668b 100644 --- a/src/file.c +++ b/src/file.c @@ -68,13 +68,14 @@ file_find_support_file (const gchar *filename, gboolea { gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data, G_DIR_SEPARATOR_S, filename); - if (g_file_test (pathname, G_FILE_TEST_EXISTS)) + if (g_file_test (pathname, G_FILE_TEST_EXISTS) && + !g_file_test(pathname, G_FILE_TEST_IS_DIR)) return pathname; - + g_free (pathname); elem = elem->next; } - + if(warning) g_warning("file_find_support_file: file '%s' not found.", filename); @@ -181,35 +182,64 @@ file_check_home_dir_copy_conf_files(void) /** Copy the xml definition files into the home dir. */ void -file_check_home_dir_copy_definition_files(void) +file_check_home_dir_copy_definition_dir(const gchar *dirname, const gchar *basename) { gint i; - gchar buf[SMALL]; + gchar buf[SMALL], buf2[SMALL]; const gchar *home = g_get_home_dir(); - GPtrArray *dir_contents = NULL; + GPtrArray *dir_contents = NULL; + + sprintf(buf, "%s/%s/%s", home, HOMEDIRNAME, basename); + + if(!g_file_test(buf, G_FILE_TEST_EXISTS)) + { + sprintf(buf2, "mkdir -v %s", buf); + file_my_system(buf2); + } + + dir_contents = file_dir_get_contents(dirname, "", ""); + + for(i=0;ilen;i++) + { + sprintf(buf, "%s/%s/%s/%s", home, HOMEDIRNAME, basename, + ((GString*)g_ptr_array_index(dir_contents, i))->str); + + if(g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, ".xml") && + !g_file_test(buf, G_FILE_TEST_EXISTS)) + { + + sprintf(buf2, "cp -v %s/%s %s", dirname, + ((GString*)g_ptr_array_index(dir_contents, i))->str, + buf); + file_my_system(buf2); + + } + else + { + sprintf(buf, "%s/%s", dirname, ((GString*)g_ptr_array_index(dir_contents, i))->str); + + if(g_file_test(buf, G_FILE_TEST_IS_DIR)) + { + sprintf(buf2, "%s/%s", basename, + ((GString*)g_ptr_array_index(dir_contents, i))->str); + file_check_home_dir_copy_definition_dir(buf, buf2); + } + } + } + + free_g_string_array(&dir_contents); +} + +/** Copy the xml definition files into the home dir. */ +void +file_check_home_dir_copy_definition_files(void) +{ GList *elem = support_directories; while(elem != NULL) { if(g_str_has_suffix((gchar*)elem->data, "definitions")) - { - dir_contents = file_dir_get_contents((gchar*)elem->data, "", ".xml"); - - for(i=0;ilen;i++) - { - sprintf(buf, "%s/%s/definitions/%s", home, HOMEDIRNAME, - ((GString*)g_ptr_array_index(dir_contents, i))->str); - if(!g_file_test(buf, G_FILE_TEST_EXISTS)) - { - sprintf(buf, "cp -v %s/%s %s/%s/definitions/%s", (gchar*)elem->data, - ((GString*)g_ptr_array_index(dir_contents, i))->str, - home, HOMEDIRNAME, ((GString*)g_ptr_array_index(dir_contents, i))->str); - file_my_system(buf); - } - } - - free_g_string_array(&dir_contents); - } + file_check_home_dir_copy_definition_dir((const gchar*)elem->data, "definitions"); elem = elem->next; } diff --git a/src/file.h b/src/file.h index d7d54ff7..33bfaf21 100644 --- a/src/file.h +++ b/src/file.h @@ -47,6 +47,9 @@ file_check_home_dir_copy_conf_files(void); void file_check_home_dir_copy_definition_files(void); +void +file_check_home_dir_copy_definition_dir(const gchar *dirname, const gchar *basename); + gboolean file_my_system(const gchar *command); diff --git a/src/fixture.c b/src/fixture.c index 1a4610ea..ce15f076 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -373,7 +373,7 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, GPtrArray *teams) if(first_week < 1) { - g_warning("fixture_write_round_robin: first week is not positive: %d\n", first_week); + g_warning("fixture_write_round_robin: first week of %s is not positive (%d).\nPlease lower the week gap or set a later last week.\n", league_cup_get_name_string(clid), first_week); main_exit_program(EXIT_FIXTURE_WRITE_ERROR, NULL); } diff --git a/support_files/bygfoot.conf b/support_files/bygfoot.conf index ace4118f..4313e887 100644 --- a/support_files/bygfoot.conf +++ b/support_files/bygfoot.conf @@ -21,7 +21,7 @@ int_opt_player_precision 0 int_opt_live_game_player_list_refresh 48 # whether some debugging info's shown (in the console) -int_opt_debug 0 +int_opt_debug 60 string_opt_player_names_file player_names.xml string_opt_constants_file bygfoot_constants