bygfoot/src/free.c

1106 lines
23 KiB
C
Raw Normal View History

2005-10-20 17:45:00 +02:00
/*
2005-11-26 17:52:51 +01:00
free.c
2005-10-20 17:45:00 +02:00
Bygfoot Football Manager -- a small and simple GTK2-based
football management game.
http://bygfoot.sourceforge.net
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
2005-10-27 23:10:15 +02:00
#include "bet_struct.h"
2004-12-23 13:58:39 +01:00
#include "free.h"
2005-07-01 22:51:46 +02:00
#include "lg_commentary_struct.h"
2008-11-27 14:24:18 +01:00
#include "news_struct.h"
2005-10-24 22:50:48 +02:00
#include "strategy_struct.h"
2005-06-05 12:39:29 +02:00
#include "transfer.h"
#include "user.h"
#include "variables.h"
2004-12-23 13:58:39 +01:00
/**
Free all memory allocated by the program.
2005-10-09 11:35:44 +02:00
This mainly means we have to free a lot of strings
2004-12-23 13:58:39 +01:00
and GArrays. */
void
free_memory(void)
{
#ifdef DEBUG
printf("free_memory\n");
#endif
free_variables();
free_names(FALSE);
2005-05-16 09:09:53 +02:00
free_transfer_list();
2005-10-24 22:50:48 +02:00
free_strategies();
free_country(&country, FALSE);
2005-04-04 12:36:04 +02:00
free_users(FALSE);
2005-10-27 23:10:15 +02:00
free_bets(FALSE);
2005-07-01 22:51:46 +02:00
free_lg_commentary(FALSE);
2008-11-27 14:24:18 +01:00
free_news(FALSE);
2008-11-28 15:09:08 +01:00
free_newspaper(FALSE);
2005-04-04 12:36:04 +02:00
free_support_dirs();
free_jobs(FALSE);
2008-12-01 21:39:16 +01:00
free_g_array(&live_games);
2005-01-09 21:21:22 +01:00
}
2005-05-16 09:09:53 +02:00
/** Free the transfer list. */
void
free_transfer_list(void)
{
#ifdef DEBUG
printf("free_transfer_list\n");
#endif
2005-05-17 08:15:05 +02:00
gint i;
2005-05-16 09:09:53 +02:00
for(i=0;i<transfer_list->len;i++)
g_array_free(g_array_index(transfer_list, Transfer, i).offers, TRUE);
free_g_array(&transfer_list);
}
2005-05-01 12:16:14 +02:00
/** Free the memory occupied by the season stats. */
void
2005-05-02 16:39:30 +02:00
free_season_stats(gboolean reset)
2005-05-01 12:16:14 +02:00
{
#ifdef DEBUG
printf("free_season_stats\n");
#endif
2005-05-01 12:16:14 +02:00
gint i, j;
2005-05-02 16:39:30 +02:00
if(season_stats == NULL)
{
if(reset)
season_stats = g_array_new(FALSE, FALSE, sizeof(SeasonStat));
return;
}
2005-05-01 12:16:14 +02:00
for(i=0;i<season_stats->len;i++)
{
for(j=0;j<g_array_index(season_stats, SeasonStat, i).league_stats->len;j++)
free_league_stats(
&g_array_index(g_array_index(season_stats, SeasonStat, i).league_stats,
LeagueStat, j));
for(j=0;j<g_array_index(season_stats, SeasonStat, i).league_champs->len;j++)
{
2005-10-09 11:35:44 +02:00
free_gchar_ptr(
2005-05-01 12:16:14 +02:00
g_array_index(
g_array_index(season_stats, SeasonStat, i).league_champs,
ChampStat, j).cl_name);
2005-10-09 11:35:44 +02:00
free_gchar_ptr(
2005-05-01 12:16:14 +02:00
g_array_index(
g_array_index(season_stats, SeasonStat, i).league_champs,
ChampStat, j).team_name);
2005-05-01 12:16:14 +02:00
}
for(j=0;j<g_array_index(season_stats, SeasonStat, i).cup_champs->len;j++)
{
2005-10-09 11:35:44 +02:00
free_gchar_ptr(
2005-05-01 12:16:14 +02:00
g_array_index(
g_array_index(season_stats, SeasonStat, i).cup_champs,
ChampStat, j).cl_name);
2005-10-09 11:35:44 +02:00
free_gchar_ptr(
2005-05-01 12:16:14 +02:00
g_array_index(
g_array_index(season_stats, SeasonStat, i).cup_champs,
ChampStat, j).team_name);
2005-05-01 12:16:14 +02:00
}
2005-05-16 09:09:53 +02:00
g_array_free(g_array_index(season_stats, SeasonStat, i).cup_champs, TRUE);
g_array_free(g_array_index(season_stats, SeasonStat, i).league_champs, TRUE);
2005-05-01 12:16:14 +02:00
}
2005-05-02 16:39:30 +02:00
free_g_array(&season_stats);
if(reset)
season_stats = g_array_new(FALSE, FALSE, sizeof(SeasonStat));
2005-05-01 12:16:14 +02:00
}
/** Free the users array. */
void
2005-04-04 12:36:04 +02:00
free_users(gboolean reset)
{
#ifdef DEBUG
printf("free_users\n");
#endif
gint i;
if(users == NULL)
2005-04-04 12:36:04 +02:00
{
if(reset)
users = g_array_new(FALSE, FALSE, sizeof(User));
return;
2005-04-04 12:36:04 +02:00
}
for(i=0;i<users->len;i++)
free_user(&usr(i));
free_g_array(&users);
2005-04-04 12:36:04 +02:00
if(reset)
users = g_array_new(FALSE, FALSE, sizeof(User));
}
/** Free the memory the user occupies.
@param user The user we free. */
void
free_user(User *user)
{
#ifdef DEBUG
printf("free_user\n");
#endif
gint i, j;
2005-03-18 23:03:23 +01:00
2005-10-09 11:35:44 +02:00
free_gchar_ptr(user->name);
2005-06-20 14:46:57 +02:00
free_g_string(&user->sponsor.name);
2005-10-09 11:35:44 +02:00
free_gchar_ptr(user->mmatches_file);
free_live_game(&user->live_game);
2005-03-24 08:42:24 +01:00
free_option_list(&user->options, FALSE);
2005-03-18 23:03:23 +01:00
for(i=0;i<user->events->len;i++)
free_event(&g_array_index(user->events, Event, i));
free_g_array(&user->events);
2005-04-16 09:46:04 +02:00
for(i=0;i<user->history->len;i++)
{
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(user->history,
UserHistory, i).team_name);
for(j=0;j<3;j++)
free_gchar_ptr(g_array_index(user->history,
UserHistory, i).string[j]);
}
2005-04-16 09:46:04 +02:00
free_g_array(&user->history);
2005-07-08 11:26:00 +02:00
2005-08-21 21:58:51 +02:00
free_mmatches(&user->mmatches, FALSE);
2005-08-20 21:39:36 +02:00
2005-07-08 11:26:00 +02:00
free_player_array(&user->youth_academy.players);
2005-10-27 23:10:15 +02:00
free_g_array(&user->bets[0]);
free_g_array(&user->bets[1]);
g_array_free(user->default_team, TRUE);
2005-03-18 23:03:23 +01:00
}
2005-08-20 21:39:36 +02:00
/** Free the memorable matches array of the user and the memorable matches
file name . */
void
2005-08-21 21:58:51 +02:00
free_mmatches(GArray **mmatches, gboolean reset)
2005-08-20 21:39:36 +02:00
{
#ifdef DEBUG
printf("free_mmatches\n");
#endif
2005-08-20 21:39:36 +02:00
gint i;
2005-08-21 21:58:51 +02:00
if(*mmatches == NULL)
2005-08-20 21:39:36 +02:00
{
if(reset)
2005-08-21 21:58:51 +02:00
*mmatches = g_array_new(FALSE, FALSE, sizeof(MemMatch));
2005-08-20 21:39:36 +02:00
return;
}
2005-08-21 21:58:51 +02:00
for(i=0;i<(*mmatches)->len;i++)
2005-08-20 21:39:36 +02:00
{
2005-08-21 21:58:51 +02:00
free_g_string(&g_array_index(*mmatches, MemMatch, i).competition_name);
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(*mmatches, MemMatch, i).country_name);
2005-08-21 21:58:51 +02:00
free_live_game(&g_array_index(*mmatches, MemMatch, i).lg);
2005-08-20 21:39:36 +02:00
}
2005-08-21 21:58:51 +02:00
free_g_array(mmatches);
2005-08-20 21:39:36 +02:00
if(reset)
2005-08-21 21:58:51 +02:00
*mmatches = g_array_new(FALSE, FALSE, sizeof(MemMatch));
2005-08-20 21:39:36 +02:00
}
2005-03-18 23:03:23 +01:00
/** Free a user event. */
void
free_event(Event *event)
{
#ifdef DEBUG
printf("free_event\n");
#endif
2005-10-09 11:35:44 +02:00
free_gchar_ptr(event->value_string);
}
/** Free an array of options.
@param array The array we free.
@param reset Whether to create the array anew (empty).
@see #Option */
void
2005-03-24 08:42:24 +01:00
free_option_list(OptionList *optionlist, gboolean reset)
{
#ifdef DEBUG
printf("free_option_list\n");
#endif
gint i;
2005-03-24 08:42:24 +01:00
if(optionlist->list == NULL)
{
if(reset)
2005-03-24 08:42:24 +01:00
{
optionlist->list = g_array_new(FALSE, FALSE, sizeof(Option));
g_datalist_init(&optionlist->datalist);
}
return;
}
2005-03-24 08:42:24 +01:00
for(i=0;i<optionlist->list->len;i++)
{
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(optionlist->list, Option, i).name);
free_gchar_ptr(g_array_index(optionlist->list, Option, i).string_value);
}
2005-03-24 08:42:24 +01:00
free_g_array(&optionlist->list);
if(reset)
2005-03-24 08:42:24 +01:00
{
optionlist->list = g_array_new(FALSE, FALSE, sizeof(Option));
g_datalist_init(&optionlist->datalist);
}
}
2005-01-09 21:21:22 +01:00
/** Free a live game variable. */
void
free_live_game(LiveGame *match)
{
#ifdef DEBUG
printf("free_live_game\n");
#endif
2005-03-10 21:59:39 +01:00
gint i, j, k;
2005-01-09 21:21:22 +01:00
2005-08-20 21:39:36 +02:00
if(match->units == NULL || match->started_game == -1)
2005-01-09 21:21:22 +01:00
return;
for(i=0;i<match->units->len;i++)
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(match->units, LiveGameUnit, i).event.commentary);
2005-03-10 21:59:39 +01:00
for(i=0;i<2;i++)
{
2005-10-27 23:10:15 +02:00
free_g_array(&match->action_ids[i]);
2005-10-09 11:35:44 +02:00
free_gchar_ptr(match->team_names[i]);
2005-03-10 21:59:39 +01:00
for(j=0;j<LIVE_GAME_STAT_ARRAY_END;j++)
{
2005-03-11 13:17:48 +01:00
for(k=0;k<match->stats.players[i][j]->len;k++)
2005-10-09 11:35:44 +02:00
g_free(g_ptr_array_index(match->stats.players[i][j], k));
2005-03-10 21:59:39 +01:00
2005-03-11 13:17:48 +01:00
free_g_ptr_array(&match->stats.players[i][j]);
2005-03-10 21:59:39 +01:00
}
}
2005-01-09 21:21:22 +01:00
free_g_array(&match->units);
2004-12-23 13:58:39 +01:00
}
/**
Free a country variable.
2004-12-23 13:58:39 +01:00
*/
void
free_country(Country *cntry, gboolean reset)
2004-12-23 13:58:39 +01:00
{
#ifdef DEBUG
printf("free_country\n");
#endif
free_gchar_ptr(cntry->name);
free_gchar_ptr(cntry->symbol);
free_gchar_ptr(cntry->sid);
2004-12-23 13:58:39 +01:00
free_leagues_array(&cntry->leagues, reset);
free_cups_array(&cntry->cups, reset);
free_g_ptr_array(&cntry->allcups);
2005-05-16 09:09:53 +02:00
2005-05-06 18:35:19 +02:00
if(reset)
{
cntry->allcups = g_ptr_array_new();
cntry->sid = g_strdup("NONAME");
}
}
/**
Free the memory occupied by a leagues array.
@param leagues The pointer to the array we free.
*/
void
2005-04-04 12:36:04 +02:00
free_leagues_array(GArray **leagues, gboolean reset)
{
#ifdef DEBUG
printf("free_leagues_array\n");
#endif
gint i;
if(*leagues == NULL)
2005-04-04 12:36:04 +02:00
{
if(reset)
*leagues = g_array_new(FALSE, FALSE, sizeof(League));
return;
2005-04-04 12:36:04 +02:00
}
for(i=0;i<(*leagues)->len;i++)
free_league(&g_array_index(*leagues, League, i));
free_g_array(leagues);
2005-04-04 12:36:04 +02:00
if(reset)
*leagues = g_array_new(FALSE, FALSE, sizeof(League));
2004-12-23 13:58:39 +01:00
}
/**
Free the memory occupied by a league.
@param league The pointer to the league we free.
*/
void
free_league(League *league)
{
#ifdef DEBUG
printf("free_league\n");
#endif
2005-10-09 11:35:44 +02:00
free_gchar_ptr(league->name);
free_gchar_ptr(league->short_name);
free_gchar_ptr(league->symbol);
free_gchar_ptr(league->sid);
2009-01-08 23:20:26 +01:00
free_gchar_array(&league->skip_weeks_with);
2004-12-23 13:58:39 +01:00
if(league->teams != NULL)
2005-04-10 18:34:27 +02:00
free_teams_array(&league->teams, FALSE);
2004-12-23 13:58:39 +01:00
free_joined_leagues(&league->joined_leagues);
free_prom_rel(&league->prom_rel);
2005-10-09 11:35:44 +02:00
free_g_array(&league->teams);
2008-11-21 18:00:47 +01:00
free_tables(&league->tables);
free_new_tables(&league->new_tables);
2005-04-13 15:01:59 +02:00
free_g_array(&league->fixtures);
free_g_array(&league->rr_breaks);
2008-12-26 16:59:46 +01:00
free_g_array(&league->week_breaks);
2005-04-14 21:07:25 +02:00
2007-02-17 13:06:30 +01:00
free_g_array(&league->two_match_weeks[0]);
free_g_array(&league->two_match_weeks[1]);
2005-04-29 21:48:02 +02:00
free_league_stats(&league->stats);
2005-04-13 15:01:59 +02:00
}
/** Free the promotion/relegation struct of a league. */
void
free_prom_rel(PromRel *prom_rel)
{
gint i;
for(i = 0; i < prom_rel->elements->len; i++)
g_free(g_array_index(prom_rel->elements, PromRelElement, i).dest_sid);
free_g_array(&prom_rel->elements);
for(i = 0; i < prom_rel->prom_games->len; i++)
{
g_free(g_array_index(prom_rel->prom_games, PromGames, i).dest_sid);
g_free(g_array_index(prom_rel->prom_games, PromGames, i).loser_sid);
g_free(g_array_index(prom_rel->prom_games, PromGames, i).cup_sid);
}
free_g_array(&prom_rel->prom_games);
}
/** Free the data in the joined leagues array. */
void
free_joined_leagues(GArray **joined_leagues)
{
#ifdef DEBUG
printf("free_joined_leagues\n");
#endif
gint i;
for(i = 0; i < (*joined_leagues)->len; i++)
free_gchar_ptr(g_array_index(*joined_leagues, JoinedLeague, i).sid);
free_g_array(joined_leagues);
}
2005-04-29 21:48:02 +02:00
/** Free the league stats. */
void
free_league_stats(LeagueStat *stats)
{
#ifdef DEBUG
printf("free_league_stats\n");
#endif
2005-04-29 21:48:02 +02:00
gint i;
free_gchar_ptr(stats->league_name);
free_gchar_ptr(stats->league_symbol);
2005-04-29 21:48:02 +02:00
for(i=0;i<stats->teams_off->len;i++)
{
free_gchar_ptr(g_array_index(stats->teams_off, Stat, i).team_name);
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(stats->teams_off, Stat, i).value_string);
}
2005-04-29 21:48:02 +02:00
free_g_array(&stats->teams_off);
for(i=0;i<stats->teams_def->len;i++)
{
free_gchar_ptr(g_array_index(stats->teams_def, Stat, i).team_name);
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(stats->teams_def, Stat, i).value_string);
}
2005-04-29 21:48:02 +02:00
free_g_array(&stats->teams_def);
for(i=0;i<stats->player_scorers->len;i++)
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(stats->player_scorers, Stat, i).value_string);
2005-04-29 21:48:02 +02:00
free_g_array(&stats->player_scorers);
for(i=0;i<stats->player_goalies->len;i++)
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(stats->player_goalies, Stat, i).value_string);
2005-04-29 21:48:02 +02:00
free_g_array(&stats->player_goalies);
}
2008-11-21 18:00:47 +01:00
/** Free a tables array. */
2005-04-13 15:01:59 +02:00
void
2008-11-21 18:00:47 +01:00
free_tables(GArray **tables)
2005-04-13 15:01:59 +02:00
{
#ifdef DEBUG
printf("free_tables\n");
#endif
2008-11-21 18:00:47 +01:00
gint i;
for(i = 0; i < (*tables)->len; i++)
{
free_gchar_ptr(g_array_index(*tables, Table, i).name);
free_g_array(&g_array_index(*tables, Table, i).elements);
}
2005-04-13 15:01:59 +02:00
2008-11-21 18:00:47 +01:00
g_array_free(*tables, TRUE);
*tables = NULL;
}
/** Free a new_tables array. */
void
free_new_tables(GArray **new_tables)
{
#ifdef DEBUG
printf("free_new_tables\n");
#endif
gint i;
for(i = 0; i < (*new_tables)->len; i++)
free_gchar_ptr(g_array_index(*new_tables, NewTable, i).name);
g_array_free(*new_tables, TRUE);
*new_tables = NULL;
}
/** Free the memory occupied by a teams array.
@param teams The pointer to the array we free. */
void
2005-04-10 18:34:27 +02:00
free_teams_array(GArray **teams, gboolean reset)
{
#ifdef DEBUG
printf("free_teams_array\n");
#endif
gint i;
if(*teams == NULL)
2005-04-10 18:34:27 +02:00
{
if(reset)
*teams = g_array_new(FALSE, FALSE, sizeof(Team));
return;
2005-04-10 18:34:27 +02:00
}
for(i=0;i<(*teams)->len;i++)
free_team(&g_array_index(*teams, Team, i));
free_g_array(teams);
2005-04-10 18:34:27 +02:00
if(reset)
*teams = g_array_new(FALSE, FALSE, sizeof(Team));
2004-12-23 13:58:39 +01:00
}
/**
Free the memory occupied by a team.
@param tm The pointer to the team we free.
2004-12-23 13:58:39 +01:00
*/
void
free_team(Team *tm)
2004-12-23 13:58:39 +01:00
{
#ifdef DEBUG
printf("free_team\n");
#endif
2005-10-09 11:35:44 +02:00
free_gchar_ptr(tm->stadium.name);
free_gchar_ptr(tm->name);
free_gchar_ptr(tm->names_file);
free_gchar_ptr(tm->symbol);
free_gchar_ptr(tm->def_file);
2005-07-08 11:26:00 +02:00
free_player_array(&tm->players);
}
/** Free an array containing players. */
void
free_player_array(GArray **players)
{
#ifdef DEBUG
printf("free_player_array\n");
#endif
2005-07-08 11:26:00 +02:00
gint i;
if(*players != NULL)
2004-12-23 13:58:39 +01:00
{
2005-07-08 11:26:00 +02:00
for(i=0;i<(*players)->len;i++)
free_player(&g_array_index((*players), Player, i));
2005-07-08 11:26:00 +02:00
free_g_array(players);
2004-12-23 13:58:39 +01:00
}
}
/** Free the memory occupied by a player.
@param pl The pointer to the player we free. */
void
free_player(Player *pl)
{
#ifdef DEBUG
printf("free_player\n");
#endif
2005-10-09 11:35:44 +02:00
free_gchar_ptr(pl->name);
free_g_array(&pl->cards);
2005-06-21 15:33:16 +02:00
free_g_array(&pl->games_goals);
}
/**
Free the memory occupied by a cups array.
@param cups The pointer to the array we free.
*/
void
2005-04-04 12:36:04 +02:00
free_cups_array(GArray **cups, gboolean reset)
{
#ifdef DEBUG
printf("free_cups_array\n");
#endif
gint i;
if(*cups == NULL)
2005-04-04 12:36:04 +02:00
{
if(reset)
*cups = g_array_new(FALSE, FALSE, sizeof(Cup));
return;
2005-04-04 12:36:04 +02:00
}
for(i=0;i<(*cups)->len;i++)
2005-05-06 18:35:19 +02:00
free_cup(&g_array_index(*cups, Cup, i));
free_g_array(cups);
2005-04-04 12:36:04 +02:00
if(reset)
*cups = g_array_new(FALSE, FALSE, sizeof(Cup));
}
/**
Free the memory occupied by a cup.
@param cup The pointer to the cup we free.
*/
void
free_cup(Cup *cup)
{
#ifdef DEBUG
printf("free_cup\n");
#endif
gint i;
2005-10-09 11:35:44 +02:00
free_gchar_ptr(cup->name);
free_gchar_ptr(cup->short_name);
free_gchar_ptr(cup->symbol);
free_gchar_ptr(cup->sid);
2009-01-08 23:20:26 +01:00
free_gchar_array(&cup->skip_weeks_with);
for(i=0;i<cup->rounds->len;i++)
free_cup_round(&g_array_index(cup->rounds, CupRound, i));
2005-05-08 19:56:26 +02:00
free_g_array(&cup->rounds);
2008-12-28 16:44:12 +01:00
2005-04-13 15:01:59 +02:00
free_g_array(&cup->fixtures);
2008-12-26 16:59:46 +01:00
free_g_array(&cup->week_breaks);
2005-01-09 21:21:22 +01:00
free_g_ptr_array(&cup->bye);
2005-10-05 21:59:37 +02:00
free_gchar_array(&cup->team_names);
2005-05-08 19:56:26 +02:00
free_g_ptr_array(&cup->teams);
2005-10-05 21:59:37 +02:00
free_gchar_array(&cup->properties);
}
void
free_cup_round(CupRound *cup_round)
{
#ifdef DEBUG
printf("free_cup_round\n");
#endif
gint j;
2009-01-04 11:53:09 +01:00
g_free(cup_round->name);
free_g_array(&cup_round->two_match_weeks[0]);
free_g_array(&cup_round->two_match_weeks[1]);
2008-12-28 16:44:12 +01:00
for(j = 0; j < cup_round->waits->len; j++)
g_free(g_array_index(cup_round->waits, CupRoundWait, j).cup_sid);
free_g_array(&cup_round->waits);
if(cup_round->round_robin_number_of_groups > 0)
{
free_tables(&cup_round->tables);
for(j=0;j<cup_round->choose_teams->len;j++)
free_cup_choose_team(
&g_array_index(cup_round->choose_teams, CupChooseTeam, j));
free_g_array(&cup_round->choose_teams);
g_ptr_array_free(cup_round->team_ptrs, TRUE);
}
}
/**
Free the memory occupied by a CupChooseTeam.
@param cup_choose_team The pointer to the team we free.
*/
void
free_cup_choose_team(CupChooseTeam *cup_choose_team)
{
#ifdef DEBUG
printf("free_cup_choose_team\n");
#endif
2005-10-09 11:35:44 +02:00
free_gchar_ptr(cup_choose_team->sid);
}
/** Free some global variables (except for the country variable). */
void
free_variables(void)
{
#ifdef DEBUG
printf("free_variables\n");
#endif
2005-03-24 08:42:24 +01:00
free_option_list(&options, FALSE);
2005-06-26 13:42:01 +02:00
free_option_list(&settings, FALSE);
2005-03-24 08:42:24 +01:00
free_option_list(&constants, FALSE);
2005-05-06 18:35:19 +02:00
free_option_list(&constants_app, FALSE);
2005-10-24 22:50:48 +02:00
free_option_list(&tokens, FALSE);
2005-04-04 12:36:04 +02:00
2005-10-09 11:35:44 +02:00
free_gchar_ptr(save_file);
2005-05-02 16:39:30 +02:00
2005-05-16 09:09:53 +02:00
g_rand_free(rand_generator);
2005-05-02 16:39:30 +02:00
free_season_stats(FALSE);
}
2005-07-01 22:51:46 +02:00
/** Free the list with live game commentary text. */
void
free_lg_commentary(gboolean reset)
{
#ifdef DEBUG
printf("free_lg_commentary\n");
#endif
2005-07-01 22:51:46 +02:00
gint i, j;
for(i=0;i<LIVE_GAME_EVENT_END;i++)
if(lg_commentary[i] != NULL)
{
for(j=0;j<lg_commentary[i]->len;j++)
{
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_array_index(lg_commentary[i], LGCommentary, j).text);
free_gchar_ptr(g_array_index(lg_commentary[i], LGCommentary, j).condition);
2005-07-01 22:51:46 +02:00
}
free_g_array(&lg_commentary[i]);
}
if(reset)
for(i=0;i<LIVE_GAME_EVENT_END;i++)
lg_commentary[i] = g_array_new(FALSE, FALSE, sizeof(LGCommentary));
}
2008-11-28 15:09:08 +01:00
/** Free the news variables. */
2008-11-27 14:24:18 +01:00
void
free_news(gboolean reset)
{
#ifdef DEBUG
printf("free_news\n");
#endif
gint i, j, k;
for(i=0;i<NEWS_ARTICLE_TYPE_END;i++)
if(news[i] != NULL)
{
for(j=0;j<news[i]->len;j++)
{
g_free(g_array_index(news[i], NewsArticle, j).condition);
for(k = 0; k < g_array_index(news[i], NewsArticle, j).titles->len; k++)
2008-12-01 21:39:16 +01:00
{
2008-11-27 14:24:18 +01:00
g_free(g_array_index(g_array_index(news[i], NewsArticle, j).titles, NewsText, k).text);
2008-12-01 21:39:16 +01:00
g_free(g_array_index(g_array_index(news[i], NewsArticle, j).titles, NewsText, k).condition);
}
2008-11-27 14:24:18 +01:00
g_array_free(g_array_index(news[i], NewsArticle, j).titles, TRUE);
for(k = 0; k < g_array_index(news[i], NewsArticle, j).subtitles->len; k++)
2008-12-01 21:39:16 +01:00
{
2008-11-27 14:24:18 +01:00
g_free(g_array_index(g_array_index(news[i], NewsArticle, j).subtitles, NewsText, k).text);
2008-12-01 21:39:16 +01:00
g_free(g_array_index(g_array_index(news[i], NewsArticle, j).subtitles, NewsText, k).condition);
}
2008-11-27 14:24:18 +01:00
g_array_free(g_array_index(news[i], NewsArticle, j).subtitles, TRUE);
}
free_g_array(&news[i]);
}
if(reset)
for(i=0;i<NEWS_ARTICLE_TYPE_END;i++)
news[i] = g_array_new(FALSE, FALSE, sizeof(NewsArticle));
}
2008-11-28 15:09:08 +01:00
void
free_newspaper(gboolean reset)
{
gint i;
for(i = 0; i < newspaper.articles->len; i++)
2008-12-19 18:28:51 +01:00
free_newspaper_article(&g_array_index(newspaper.articles, NewsPaperArticle, i));
2008-11-28 15:09:08 +01:00
g_array_free(newspaper.articles, TRUE);
if(reset)
newspaper.articles = g_array_new(FALSE, FALSE, sizeof(NewsPaperArticle));
}
2008-12-19 18:28:51 +01:00
void
free_newspaper_article(NewsPaperArticle *article)
{
g_free(article->title_small);
g_free(article->title);
g_free(article->subtitle);
}
/**
2005-10-09 11:35:44 +02:00
Free a GPtrArray containing strings.
@param array The array to be freed.
*/
void
2005-10-05 21:59:37 +02:00
free_gchar_array(GPtrArray **array)
{
#ifdef DEBUG
printf("_array\n");
#endif
#ifdef DEBUG
printf("free_gchar_array\n");
#endif
gint i;
if(*array == NULL)
return;
for(i=0;i<(*array)->len;i++)
2005-10-09 11:35:44 +02:00
free_gchar_ptr(g_ptr_array_index(*array, i));
2005-01-09 21:21:22 +01:00
free_g_ptr_array(array);
2005-10-05 21:59:37 +02:00
*array = NULL;
2005-01-09 21:21:22 +01:00
}
/** Free a GString if it isn't NULL.
@param string The string to be freed. */
void
free_g_string(GString **string)
{
#ifdef DEBUG
printf("free_g_string\n");
#endif
2005-01-09 21:21:22 +01:00
if(*string == NULL)
return;
g_string_free(*string, TRUE);
*string = NULL;
}
/** Free a GArray if it isn't NULL.
@param array The array to be freed. */
void
free_g_array(GArray **array)
{
#ifdef DEBUG
printf("free_g_array\n");
#endif
2005-01-09 21:21:22 +01:00
if(*array == NULL)
return;
g_array_free(*array, TRUE);
*array = NULL;
}
/** Free a GPtrArray if it isn't NULL.
@param array The array to be freed. */
void
free_g_ptr_array(GPtrArray **array)
{
#ifdef DEBUG
printf("free_g_ptr_array\n");
#endif
2005-01-09 21:21:22 +01:00
if(*array == NULL)
return;
g_ptr_array_free(*array, TRUE);
*array = NULL;
}
2005-04-04 12:36:04 +02:00
/** Free the glist containing the support directories. */
void
free_support_dirs(void)
{
#ifdef DEBUG
printf("free_support_dirs\n");
#endif
2005-04-04 12:36:04 +02:00
GList *elem = support_directories;
if(elem == NULL)
return;
while(elem)
{
2005-10-09 11:35:44 +02:00
free_gchar_ptr(elem->data);
2005-04-04 12:36:04 +02:00
elem = elem->next;
}
g_list_free(support_directories);
support_directories = NULL;
}
/** Free a list of names. */
void
free_name_list(NameList *namelist, gboolean reset)
{
#ifdef DEBUG
printf("free_name_list\n");
#endif
2005-10-09 11:35:44 +02:00
gint i;
if(namelist->sid == NULL)
{
if(reset)
{
2005-10-09 11:35:44 +02:00
namelist->sid = NULL;
namelist->first_names = g_ptr_array_new();
namelist->last_names = g_ptr_array_new();
}
return;
}
2005-10-09 11:35:44 +02:00
free_gchar_ptr(namelist->sid);
for(i=0;i<namelist->first_names->len;i++)
free_gchar_ptr(g_ptr_array_index(namelist->first_names, i));
free_g_ptr_array(&namelist->first_names);
2005-10-09 11:35:44 +02:00
for(i=0;i<namelist->last_names->len;i++)
free_gchar_ptr(g_ptr_array_index(namelist->last_names, i));
free_g_ptr_array(&namelist->last_names);
if(reset)
{
2005-10-09 11:35:44 +02:00
namelist->sid = NULL;
namelist->first_names = g_ptr_array_new();
namelist->last_names = g_ptr_array_new();
}
}
/** Free the array with the name lists. */
void
free_names(gboolean reset)
{
#ifdef DEBUG
printf("free_names\n");
#endif
gint i;
if(name_lists == NULL)
{
if(reset)
name_lists = g_array_new(FALSE, FALSE, sizeof(NameList));
return;
}
for(i=0;i<name_lists->len;i++)
free_name_list(&g_array_index(name_lists, NameList, i), FALSE);
free_g_array(&name_lists);
if(reset)
name_lists = g_array_new(FALSE, FALSE, sizeof(NameList));
}
2005-10-24 22:50:48 +02:00
/** Free the array with the CPU strategies. */
void
free_strategies(void)
{
#ifdef DEBUG
printf("free_strategies\n");
#endif
2005-10-24 22:50:48 +02:00
gint i, j;
for(i=0;i<strategies->len;i++)
{
g_free(g_array_index(strategies, Strategy, i).sid);
g_free(g_array_index(strategies, Strategy, i).desc);
for(j=0;j<g_array_index(strategies, Strategy, i).prematch->len;j++)
{
g_free(
g_array_index(
g_array_index(
strategies, Strategy, i).prematch, StrategyPrematch, j).condition);
g_array_free(
g_array_index(
g_array_index(strategies, Strategy, i).prematch, StrategyPrematch, j).formations,
TRUE);
}
g_array_free(g_array_index(strategies, Strategy, i).prematch, TRUE);
for(j=0;j<g_array_index(strategies, Strategy, i).match_action->len;j++)
2005-10-27 23:10:15 +02:00
{
2005-10-24 22:50:48 +02:00
g_free(
g_array_index(
g_array_index(
strategies, Strategy, i).match_action, StrategyMatchAction, j).condition);
g_array_free(
g_array_index(
g_array_index(
strategies, Strategy, i).match_action, StrategyMatchAction, j).parsed_condition, TRUE);
2005-10-27 23:10:15 +02:00
g_free(
g_array_index(
g_array_index(
strategies, Strategy, i).match_action, StrategyMatchAction, j).sub_condition);
}
2005-10-24 22:50:48 +02:00
g_array_free(g_array_index(strategies, Strategy, i).match_action, TRUE);
}
g_array_free(strategies, TRUE);
}
2005-10-27 23:10:15 +02:00
/** Free the betting arrays. */
void
free_bets(gboolean reset)
{
#ifdef DEBUG
printf("free_bets\n");
#endif
2005-10-27 23:10:15 +02:00
free_g_array(&(bets[0]));
free_g_array(&(bets[1]));
if(reset)
{
bets[0] = g_array_new(FALSE, FALSE, sizeof(BetMatch));
bets[1] = g_array_new(FALSE, FALSE, sizeof(BetMatch));
}
}
/** Free a job struct.
@param free_team Whether to free the team associated
with the job if it's an international offer. */
void
free_job(Job *job, gboolean free_tm)
{
#ifdef DEBUG
printf("free_job\n");
#endif
gint i;
if(job->type == JOB_TYPE_INTERNATIONAL)
{
free_gchar_ptr(job->country_file);
free_gchar_ptr(job->country_name);
free_gchar_ptr(job->league_name);
}
}
/** Free the jobs and job_teams arrays. */
void
free_jobs(gboolean reset)
{
#ifdef DEBUG
printf("free_jobs\n");
#endif
gint i;
if(jobs == NULL)
{
if(reset)
{
jobs = g_array_new(FALSE, FALSE, sizeof(Job));
}
return;
}
for(i=0;i<jobs->len;i++)
free_job(&g_array_index(jobs, Job, i), TRUE);
free_g_array(&jobs);
if(reset)
{
jobs = g_array_new(FALSE, FALSE, sizeof(Job));
}
}