diff --git a/src/cup.c b/src/cup.c index 9398adc1..6375fb11 100644 --- a/src/cup.c +++ b/src/cup.c @@ -237,7 +237,7 @@ cup_get_team_pointers(Cup *cup, gint round) if(debug > 70) for(i=0;ilen;i++) - printf("%d %s \n", i, ((Team*)g_ptr_array_index(teams, i))->name->str); + printf("cup_get_team_pointers: %d %s \n", i, ((Team*)g_ptr_array_index(teams, i))->name->str); } /** Get the pointers to the teams (already generated, in one of the leagues or cups) @@ -393,7 +393,7 @@ cup_load_choose_team(Cup *cup, GPtrArray *teams, const CupChooseTeam *ct) if(debug > 80) for(i=debug_num;ilen;i++) - printf("%d %s \n", i, ((Team*)g_ptr_array_index(teams, i))->name->str); + printf("cup_load_choose_team: %d %s \n", i, ((Team*)g_ptr_array_index(teams, i))->name->str); } /** Load the teams specified in the chooseteam from a non-country league. */ diff --git a/src/fixture.c b/src/fixture.c index dd1cd939..617244cd 100644 --- a/src/fixture.c +++ b/src/fixture.c @@ -47,10 +47,12 @@ fixture_write_cup_fixtures(Cup *cup) if(g_array_index(cup->rounds, CupRound, 0).round_robin_number_of_groups > 0) fixture_write_cup_round_robin(cup, 0, - g_array_index(cup->rounds, CupRound, 0).team_ptrs); + misc_copy_ptr_array( + g_array_index(cup->rounds, CupRound, 0).team_ptrs)); else fixture_write_knockout_round(cup, 0, - g_array_index(cup->rounds, CupRound, 0).team_ptrs); + misc_copy_ptr_array( + g_array_index(cup->rounds, CupRound, 0).team_ptrs)); } /** Update the fixtures for the given cup. diff --git a/src/misc.c b/src/misc.c index baeeecdb..64fdcf0f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -462,3 +462,21 @@ misc_parse(const gchar *s, gint *result) } return s; } + +/** Return a freshly allocated copy of the array. */ +GPtrArray* +misc_copy_ptr_array(const GPtrArray *array) +{ + gint i; + GPtrArray *copy = NULL; + + if(array != NULL) + copy = g_ptr_array_new(); + else + return NULL; + + for(i=0;ilen;i++) + g_ptr_array_add(copy, g_ptr_array_index(array, i)); + + return copy; +} diff --git a/src/misc.h b/src/misc.h index 6f57a06f..adfc936b 100644 --- a/src/misc.h +++ b/src/misc.h @@ -71,4 +71,7 @@ misc_parse_and(const gchar *s, gint *result); const gchar* misc_parse(const gchar *s, gint *result); +GPtrArray* +misc_copy_ptr_array(const GPtrArray *array); + #endif diff --git a/src/xml.c b/src/xml.c index 55cc2223..dc11f584 100644 --- a/src/xml.c +++ b/src/xml.c @@ -83,6 +83,9 @@ xml_load_league(const gchar *dirname, const gchar *basename, const GPtrArray *di gtk_progress_bar_get_fraction( GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar"))), buf); + if(debug > 80) + printf("%s\n", buf); + sprintf(buf, "%s/%s_teams.xml", dirname, prefix); xml_loadsave_teams_read(buf, lig(ligs->len - 1).teams); @@ -143,6 +146,9 @@ xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename, const GPtrAr gtk_progress_bar_get_fraction( GTK_PROGRESS_BAR(lookup_widget(window.progress, "progressbar"))), buf); + if(debug > 80) + printf("%s\n", buf); + sprintf(buf, "%s/%s_fixtures.xml", dirname, prefix); xml_loadsave_fixtures_read(buf, cup->fixtures); diff --git a/src/xml_loadsave_cup.c b/src/xml_loadsave_cup.c index 64505941..bb27c14b 100644 --- a/src/xml_loadsave_cup.c +++ b/src/xml_loadsave_cup.c @@ -28,6 +28,7 @@ enum TAG_CUP_ROUND_NEW_TEAMS, TAG_CUP_ROUND_BYES, TAG_CUP_ROUND_TEAMS_FILE, + TAG_CUP_ROUND_TEAM_PTR_ID, TAG_CUP_ROUND_TABLE_FILE, TAG_CUP_ROUND_HOME_AWAY, TAG_CUP_ROUND_REPLAY, @@ -128,6 +129,7 @@ xml_loadsave_cup_end_element (GMarkupParseContext *context, state = TAG_CUP_CHOOSE_TEAM; else if(tag == TAG_CUP_ROUND_HOME_AWAY || tag == TAG_CUP_ROUND_TEAMS_FILE || + tag == TAG_CUP_ROUND_TEAM_PTR_ID || tag == TAG_CUP_ROUND_TABLE_FILE || tag == TAG_CUP_ROUND_NEW_TEAMS || tag == TAG_CUP_ROUND_BYES || @@ -225,6 +227,8 @@ xml_loadsave_cup_text (GMarkupParseContext *context, g_ptr_array_add(new_cup->teams, &g_array_index(new_round.teams, Team, i)); } + else if(state == TAG_CUP_ROUND_TEAM_PTR_ID) + g_ptr_array_add(new_round.team_ptrs, team_of_id(int_value)); else if(state == TAG_CUP_ROUND_TABLE_FILE) { new_table = table_new(); @@ -388,6 +392,10 @@ xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gin xml_loadsave_cup_write_choose_team( fil, &g_array_index(cup_round->choose_teams, CupChooseTeam, i)); + for(i=0;iteam_ptrs->len;i++) + xml_write_int(fil, ((Team*)g_ptr_array_index(cup_round->team_ptrs, i))->id, + TAG_CUP_ROUND_TEAM_PTR_ID, I1); + fprintf(fil, "\n", TAG_CUP_ROUND); g_free(basename);