2004-12-30 17:48:19 +01:00
|
|
|
#include "cup.h"
|
|
|
|
#include "file.h"
|
2005-04-13 15:01:59 +02:00
|
|
|
#include "main.h"
|
2004-12-30 17:48:19 +01:00
|
|
|
#include "misc.h"
|
2005-05-06 18:35:19 +02:00
|
|
|
#include "option.h"
|
2005-04-14 21:07:25 +02:00
|
|
|
#include "variables.h"
|
2004-12-23 13:58:39 +01:00
|
|
|
#include "xml_cup.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The tags used in the XML files defining cups.
|
|
|
|
*/
|
|
|
|
#define TAG_CUP "cup"
|
|
|
|
#define TAG_NAME "name"
|
|
|
|
#define TAG_SHORT_NAME "short_name"
|
|
|
|
#define TAG_SYMBOL "symbol"
|
2004-12-30 17:48:19 +01:00
|
|
|
#define TAG_SID "sid"
|
2005-05-06 18:35:19 +02:00
|
|
|
#define TAG_GROUP "group"
|
|
|
|
#define TAG_PROPERTY "property"
|
2004-12-23 13:58:39 +01:00
|
|
|
#define TAG_LAST_WEEK "last_week"
|
2005-05-06 18:35:19 +02:00
|
|
|
#define TAG_ADD_WEEK "add_week"
|
2004-12-23 13:58:39 +01:00
|
|
|
#define TAG_WEEK_GAP "week_gap"
|
|
|
|
#define TAG_YELLOW_RED "yellow_red"
|
2005-09-14 23:16:22 +02:00
|
|
|
#define TAG_TALENT_DIFF "talent_diff"
|
2004-12-23 13:58:39 +01:00
|
|
|
#define TAG_CUP_ROUNDS "cup_rounds"
|
|
|
|
#define TAG_CUP_ROUND "cup_round"
|
2005-05-08 19:56:26 +02:00
|
|
|
#define TAG_CUP_ROUND_NEW_TEAMS "new_teams"
|
2005-05-30 18:22:23 +02:00
|
|
|
#define TAG_CUP_ROUND_BYES "byes"
|
2004-12-23 13:58:39 +01:00
|
|
|
#define TAG_CUP_ROUND_HOME_AWAY "home_away"
|
|
|
|
#define TAG_CUP_ROUND_REPLAY "replay"
|
|
|
|
#define TAG_CUP_ROUND_NEUTRAL "neutral"
|
|
|
|
#define TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS "number_of_groups"
|
|
|
|
#define TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE "number_of_advance"
|
|
|
|
#define TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE "number_of_best_advance"
|
|
|
|
#define TAG_CHOOSE_TEAMS "choose_teams"
|
|
|
|
#define TAG_CHOOSE_TEAM "choose_team"
|
2004-12-30 17:48:19 +01:00
|
|
|
#define TAG_CHOOSE_TEAM_SID "choose_team_sid"
|
2004-12-23 13:58:39 +01:00
|
|
|
#define TAG_CHOOSE_TEAM_NUMBER_OF_TEAMS "number_of_teams"
|
|
|
|
#define TAG_CHOOSE_TEAM_START_IDX "start_idx"
|
|
|
|
#define TAG_CHOOSE_TEAM_END_IDX "end_idx"
|
|
|
|
#define TAG_CHOOSE_TEAM_RANDOMLY "randomly"
|
2005-05-06 18:35:19 +02:00
|
|
|
#define TAG_CHOOSE_TEAM_GENERATE "generate"
|
2004-12-23 13:58:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enum with the states used in the XML parser functions.
|
|
|
|
*/
|
|
|
|
enum XmlCupStates
|
|
|
|
{
|
|
|
|
STATE_CUP = 0,
|
2004-12-30 17:48:19 +01:00
|
|
|
STATE_NAME,
|
|
|
|
STATE_SHORT_NAME,
|
|
|
|
STATE_SYMBOL,
|
|
|
|
STATE_SID,
|
2005-05-06 18:35:19 +02:00
|
|
|
STATE_GROUP,
|
|
|
|
STATE_PROPERTY,
|
2004-12-30 17:48:19 +01:00
|
|
|
STATE_LAST_WEEK,
|
2005-05-06 18:35:19 +02:00
|
|
|
STATE_ADD_WEEK,
|
2004-12-30 17:48:19 +01:00
|
|
|
STATE_WEEK_GAP,
|
|
|
|
STATE_YELLOW_RED,
|
2005-09-14 23:16:22 +02:00
|
|
|
STATE_TALENT_DIFF,
|
2004-12-30 17:48:19 +01:00
|
|
|
STATE_CUP_ROUNDS,
|
|
|
|
STATE_CUP_ROUND,
|
2005-05-08 19:56:26 +02:00
|
|
|
STATE_CUP_ROUND_NEW_TEAMS,
|
2005-05-30 18:22:23 +02:00
|
|
|
STATE_CUP_ROUND_BYES,
|
2004-12-30 17:48:19 +01:00
|
|
|
STATE_CUP_ROUND_HOME_AWAY,
|
|
|
|
STATE_CUP_ROUND_REPLAY,
|
|
|
|
STATE_CUP_ROUND_NEUTRAL,
|
|
|
|
STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS,
|
|
|
|
STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE,
|
|
|
|
STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE,
|
|
|
|
STATE_CHOOSE_TEAMS,
|
|
|
|
STATE_CHOOSE_TEAM,
|
|
|
|
STATE_CHOOSE_TEAM_SID,
|
|
|
|
STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS,
|
|
|
|
STATE_CHOOSE_TEAM_START_IDX,
|
|
|
|
STATE_CHOOSE_TEAM_END_IDX,
|
|
|
|
STATE_CHOOSE_TEAM_RANDOMLY,
|
2005-05-06 18:35:19 +02:00
|
|
|
STATE_CHOOSE_TEAM_GENERATE,
|
2004-12-23 13:58:39 +01:00
|
|
|
STATE_END
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The state variable used in the XML parsing functions.
|
|
|
|
*/
|
|
|
|
gint state;
|
2004-12-30 17:48:19 +01:00
|
|
|
|
|
|
|
/** The variable we will fill and append to an array. */
|
|
|
|
Cup new_cup;
|
2005-05-08 19:56:26 +02:00
|
|
|
CupRound new_round;
|
|
|
|
CupChooseTeam new_choose_team;
|
2004-12-23 13:58:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The function called by the parser when an opening tag is read.
|
|
|
|
* The state variable is changed in this function and
|
|
|
|
* sometimes memory allocated for the information that's going to be read.
|
|
|
|
* @see The GLib manual (Simple XML parser).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xml_cup_read_start_element (GMarkupParseContext *context,
|
2004-12-30 17:48:19 +01:00
|
|
|
const gchar *element_name,
|
|
|
|
const gchar **attribute_names,
|
|
|
|
const gchar **attribute_values,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2004-12-23 13:58:39 +01:00
|
|
|
{
|
2004-12-30 17:48:19 +01:00
|
|
|
if(strcmp(element_name, TAG_CUP) == 0)
|
|
|
|
{
|
2005-04-14 21:07:25 +02:00
|
|
|
new_cup = cup_new(FALSE);
|
2004-12-30 17:48:19 +01:00
|
|
|
state = STATE_CUP;
|
|
|
|
}
|
|
|
|
else if(strcmp(element_name, TAG_NAME) == 0)
|
|
|
|
state = STATE_NAME;
|
|
|
|
else if(strcmp(element_name, TAG_SHORT_NAME) == 0)
|
|
|
|
state = STATE_SHORT_NAME;
|
|
|
|
else if(strcmp(element_name, TAG_SYMBOL) == 0)
|
|
|
|
state = STATE_SYMBOL;
|
|
|
|
else if(strcmp(element_name, TAG_SID) == 0)
|
|
|
|
state = STATE_SID;
|
2005-05-06 18:35:19 +02:00
|
|
|
else if(strcmp(element_name, TAG_GROUP) == 0)
|
|
|
|
state = STATE_GROUP;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(strcmp(element_name, TAG_LAST_WEEK) == 0)
|
|
|
|
state = STATE_LAST_WEEK;
|
2005-05-06 18:35:19 +02:00
|
|
|
else if(strcmp(element_name, TAG_PROPERTY) == 0)
|
|
|
|
state = STATE_PROPERTY;
|
|
|
|
else if(strcmp(element_name, TAG_ADD_WEEK) == 0)
|
|
|
|
state = STATE_ADD_WEEK;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(strcmp(element_name, TAG_WEEK_GAP) == 0)
|
|
|
|
state = STATE_WEEK_GAP;
|
|
|
|
else if(strcmp(element_name, TAG_YELLOW_RED) == 0)
|
|
|
|
state = STATE_YELLOW_RED;
|
2005-09-14 23:16:22 +02:00
|
|
|
else if(strcmp(element_name, TAG_TALENT_DIFF) == 0)
|
|
|
|
state = STATE_TALENT_DIFF;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUNDS) == 0)
|
|
|
|
state = STATE_CUP_ROUNDS;
|
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND) == 0)
|
|
|
|
{
|
2005-05-08 19:56:26 +02:00
|
|
|
new_round = cup_round_new();
|
2004-12-30 17:48:19 +01:00
|
|
|
state = STATE_CUP_ROUND;
|
|
|
|
}
|
2005-05-08 19:56:26 +02:00
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_NEW_TEAMS) == 0)
|
|
|
|
state = STATE_CUP_ROUND_NEW_TEAMS;
|
2005-05-30 18:22:23 +02:00
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_BYES) == 0)
|
|
|
|
state = STATE_CUP_ROUND_BYES;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_HOME_AWAY) == 0)
|
|
|
|
state = STATE_CUP_ROUND_HOME_AWAY;
|
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_REPLAY) == 0)
|
|
|
|
state = STATE_CUP_ROUND_REPLAY;
|
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_NEUTRAL) == 0)
|
|
|
|
state = STATE_CUP_ROUND_NEUTRAL;
|
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS) == 0)
|
|
|
|
state = STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS;
|
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE) == 0)
|
|
|
|
state = STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE;
|
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE) == 0)
|
|
|
|
state = STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE;
|
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAMS) == 0)
|
|
|
|
state = STATE_CHOOSE_TEAMS;
|
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM) == 0)
|
|
|
|
{
|
2005-05-08 19:56:26 +02:00
|
|
|
new_choose_team = cup_choose_team_new();
|
2004-12-30 17:48:19 +01:00
|
|
|
state = STATE_CHOOSE_TEAM;
|
|
|
|
}
|
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM_SID) == 0)
|
|
|
|
state = STATE_CHOOSE_TEAM_SID;
|
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM_NUMBER_OF_TEAMS) == 0)
|
|
|
|
state = STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS;
|
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM_START_IDX) == 0)
|
|
|
|
state = STATE_CHOOSE_TEAM_START_IDX;
|
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM_END_IDX) == 0)
|
|
|
|
state = STATE_CHOOSE_TEAM_END_IDX;
|
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM_RANDOMLY) == 0)
|
|
|
|
state = STATE_CHOOSE_TEAM_RANDOMLY;
|
2005-05-06 18:35:19 +02:00
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM_GENERATE) == 0)
|
|
|
|
state = STATE_CHOOSE_TEAM_GENERATE;
|
2004-12-30 17:48:19 +01:00
|
|
|
else
|
|
|
|
g_warning("xml_cup_read_start_element: unknown tag: %s; I'm in state %d\n",
|
|
|
|
element_name, state);
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The function called by the parser when a closing tag is read.
|
|
|
|
* The state variable is changed in this function.
|
|
|
|
* @see The GLib manual (Simple XML parser).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xml_cup_read_end_element (GMarkupParseContext *context,
|
2004-12-30 17:48:19 +01:00
|
|
|
const gchar *element_name,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2004-12-23 13:58:39 +01:00
|
|
|
{
|
2004-12-30 17:48:19 +01:00
|
|
|
if(strcmp(element_name, TAG_NAME) == 0 ||
|
|
|
|
strcmp(element_name, TAG_SHORT_NAME) == 0 ||
|
|
|
|
strcmp(element_name, TAG_SYMBOL) == 0 ||
|
|
|
|
strcmp(element_name, TAG_SID) == 0 ||
|
2005-05-06 18:35:19 +02:00
|
|
|
strcmp(element_name, TAG_GROUP) == 0 ||
|
2004-12-30 17:48:19 +01:00
|
|
|
strcmp(element_name, TAG_LAST_WEEK) == 0 ||
|
2005-05-06 18:35:19 +02:00
|
|
|
strcmp(element_name, TAG_PROPERTY) == 0 ||
|
|
|
|
strcmp(element_name, TAG_ADD_WEEK) == 0 ||
|
2004-12-30 17:48:19 +01:00
|
|
|
strcmp(element_name, TAG_WEEK_GAP) == 0 ||
|
|
|
|
strcmp(element_name, TAG_YELLOW_RED) == 0 ||
|
2005-09-14 23:16:22 +02:00
|
|
|
strcmp(element_name, TAG_TALENT_DIFF) == 0 ||
|
2005-05-08 19:56:26 +02:00
|
|
|
strcmp(element_name, TAG_CUP_ROUNDS) == 0)
|
2004-12-30 17:48:19 +01:00
|
|
|
state = STATE_CUP;
|
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND) == 0)
|
2005-05-08 19:56:26 +02:00
|
|
|
{
|
|
|
|
state = STATE_CUP_ROUNDS;
|
|
|
|
g_array_append_val(new_cup.rounds, new_round);
|
|
|
|
}
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(strcmp(element_name, TAG_CUP_ROUND_HOME_AWAY) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CUP_ROUND_REPLAY) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CUP_ROUND_NEUTRAL) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE) == 0 ||
|
2005-05-08 19:56:26 +02:00
|
|
|
strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CUP_ROUND_NEW_TEAMS) == 0 ||
|
2005-05-30 18:22:23 +02:00
|
|
|
strcmp(element_name, TAG_CUP_ROUND_BYES) == 0 ||
|
2005-05-08 19:56:26 +02:00
|
|
|
strcmp(element_name, TAG_CHOOSE_TEAMS) == 0)
|
2004-12-30 17:48:19 +01:00
|
|
|
state = STATE_CUP_ROUND;
|
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM) == 0)
|
2005-05-08 19:56:26 +02:00
|
|
|
{
|
2004-12-30 17:48:19 +01:00
|
|
|
state = STATE_CHOOSE_TEAMS;
|
2005-05-08 19:56:26 +02:00
|
|
|
g_array_append_val(new_round.choose_teams, new_choose_team);
|
|
|
|
}
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(strcmp(element_name, TAG_CHOOSE_TEAM_SID) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CHOOSE_TEAM_NUMBER_OF_TEAMS) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CHOOSE_TEAM_START_IDX) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CHOOSE_TEAM_END_IDX) == 0 ||
|
2005-05-06 18:35:19 +02:00
|
|
|
strcmp(element_name, TAG_CHOOSE_TEAM_RANDOMLY) == 0 ||
|
|
|
|
strcmp(element_name, TAG_CHOOSE_TEAM_GENERATE) == 0)
|
2004-12-30 17:48:19 +01:00
|
|
|
state = STATE_CHOOSE_TEAM;
|
|
|
|
else if(strcmp(element_name, TAG_CUP) != 0)
|
2005-05-06 18:35:19 +02:00
|
|
|
g_warning("xml_cup_read_end_element: unknown tag: %s; I'm in state %d\n",
|
2004-12-30 17:48:19 +01:00
|
|
|
element_name, state);
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The function called by the parser when the text between tags is read.
|
|
|
|
* This function is responsible for filling in the variables (e.g. team names)
|
|
|
|
* when a file gets loaded.
|
|
|
|
* @see The GLib manual (Simple XML parser).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xml_cup_read_text (GMarkupParseContext *context,
|
2004-12-30 17:48:19 +01:00
|
|
|
const gchar *text,
|
|
|
|
gsize text_len,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2004-12-23 13:58:39 +01:00
|
|
|
{
|
2004-12-30 17:48:19 +01:00
|
|
|
gchar buf[text_len + 1];
|
|
|
|
gint value;
|
2005-05-06 18:35:19 +02:00
|
|
|
GString *new_property = NULL;
|
2004-12-23 13:58:39 +01:00
|
|
|
|
2004-12-30 17:48:19 +01:00
|
|
|
strncpy(buf, text, text_len);
|
|
|
|
buf[text_len] = '\0';
|
|
|
|
|
|
|
|
value = (gint)g_ascii_strtod(buf, NULL);
|
|
|
|
|
|
|
|
if(state == STATE_NAME)
|
|
|
|
g_string_printf(new_cup.name, "%s", buf);
|
|
|
|
else if(state == STATE_SHORT_NAME)
|
|
|
|
g_string_printf(new_cup.short_name, "%s", buf);
|
|
|
|
else if(state == STATE_SYMBOL)
|
|
|
|
g_string_printf(new_cup.symbol, "%s", buf);
|
|
|
|
else if(state == STATE_SID)
|
|
|
|
g_string_printf(new_cup.sid, "%s", buf);
|
2005-05-06 18:35:19 +02:00
|
|
|
else if(state == STATE_GROUP)
|
|
|
|
new_cup.group = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_LAST_WEEK)
|
|
|
|
new_cup.last_week = value;
|
2005-05-06 18:35:19 +02:00
|
|
|
else if(state == STATE_PROPERTY)
|
|
|
|
{
|
|
|
|
new_property = g_string_new(buf);
|
|
|
|
g_ptr_array_add(new_cup.properties, new_property);
|
|
|
|
}
|
|
|
|
else if(state == STATE_ADD_WEEK)
|
|
|
|
new_cup.add_week = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_WEEK_GAP)
|
|
|
|
new_cup.week_gap = value;
|
|
|
|
else if(state == STATE_YELLOW_RED)
|
|
|
|
new_cup.yellow_red = value;
|
2005-09-14 23:16:22 +02:00
|
|
|
else if(state == STATE_TALENT_DIFF)
|
|
|
|
new_cup.talent_diff = value;
|
2005-05-08 19:56:26 +02:00
|
|
|
else if(state == STATE_CUP_ROUND_NEW_TEAMS)
|
|
|
|
new_round.new_teams = value;
|
2005-05-30 18:22:23 +02:00
|
|
|
else if(state == STATE_CUP_ROUND_BYES)
|
|
|
|
new_round.byes = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CUP_ROUND_HOME_AWAY)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_round.home_away = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CUP_ROUND_REPLAY)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_round.replay = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CUP_ROUND_NEUTRAL)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_round.neutral = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_round.round_robin_number_of_groups = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_round.round_robin_number_of_advance = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_round.round_robin_number_of_best_advance = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CHOOSE_TEAM_SID)
|
2005-05-08 19:56:26 +02:00
|
|
|
g_string_printf(new_choose_team.sid, "%s", buf);
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_choose_team.number_of_teams = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CHOOSE_TEAM_START_IDX)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_choose_team.start_idx = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CHOOSE_TEAM_END_IDX)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_choose_team.end_idx = value;
|
2004-12-30 17:48:19 +01:00
|
|
|
else if(state == STATE_CHOOSE_TEAM_RANDOMLY)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_choose_team.randomly = value;
|
2005-05-06 18:35:19 +02:00
|
|
|
else if(state == STATE_CHOOSE_TEAM_GENERATE)
|
2005-05-08 19:56:26 +02:00
|
|
|
new_choose_team.generate = value;
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-12-30 17:48:19 +01:00
|
|
|
* Function reading an XML file specifying a cup.
|
2004-12-23 13:58:39 +01:00
|
|
|
* @param cup_name name of the xml file (e.g. 'cup_england_fa.xml')
|
|
|
|
* to be read. Full path is not necessary, if the file is located in
|
|
|
|
* one of the suppport directories; neither are the prefix 'cup_'
|
|
|
|
* or the suffix '.xml'.
|
2004-12-30 17:48:19 +01:00
|
|
|
* @param cups The array we append the new cup to.
|
2004-12-23 13:58:39 +01:00
|
|
|
*/
|
|
|
|
void
|
2004-12-30 17:48:19 +01:00
|
|
|
xml_cup_read(const gchar *cup_name, GArray *cups)
|
2004-12-23 13:58:39 +01:00
|
|
|
{
|
2005-04-09 21:18:28 +02:00
|
|
|
gchar *file_name = file_find_support_file(cup_name, FALSE);
|
2004-12-23 13:58:39 +01:00
|
|
|
GMarkupParser parser = {xml_cup_read_start_element,
|
|
|
|
xml_cup_read_end_element,
|
|
|
|
xml_cup_read_text, NULL, NULL};
|
|
|
|
GMarkupParseContext *context;
|
|
|
|
gchar *file_contents;
|
|
|
|
gint length;
|
|
|
|
GError *error = NULL;
|
|
|
|
gchar buf[SMALL];
|
|
|
|
|
|
|
|
context =
|
|
|
|
g_markup_parse_context_new(&parser, 0, NULL, NULL);
|
|
|
|
|
|
|
|
if(file_name == NULL)
|
|
|
|
{
|
|
|
|
sprintf(buf, "cup_%s.xml", cup_name);
|
2005-04-09 21:18:28 +02:00
|
|
|
file_name = file_find_support_file(buf, TRUE);
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!g_file_get_contents(file_name, &file_contents, &length, &error))
|
|
|
|
{
|
|
|
|
g_warning("xml_cup_read: error reading file %s\n", file_name);
|
2005-01-09 21:21:22 +01:00
|
|
|
misc_print_error(&error, FALSE);
|
2004-12-23 13:58:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = STATE_CUP;
|
|
|
|
strcpy(buf, file_name);
|
|
|
|
g_free(file_name);
|
|
|
|
|
|
|
|
if(g_markup_parse_context_parse(context, file_contents, length, &error))
|
|
|
|
{
|
|
|
|
g_markup_parse_context_end_parse(context, NULL);
|
|
|
|
g_markup_parse_context_free(context);
|
|
|
|
g_free(file_contents);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_critical("xml_cup_read: error parsing file %s\n", buf);
|
2005-01-09 21:21:22 +01:00
|
|
|
misc_print_error(&error, TRUE);
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|
2005-04-13 15:01:59 +02:00
|
|
|
|
2005-05-06 18:35:19 +02:00
|
|
|
new_cup.id = cup_id_new;
|
2005-04-14 21:07:25 +02:00
|
|
|
g_array_append_val(cups, new_cup);
|
2004-12-23 13:58:39 +01:00
|
|
|
}
|