mirror of
https://github.com/tstellar/bygfoot.git
synced 2025-02-28 17:27:57 +01:00
Corrected pointer warnings.
This commit is contained in:
parent
f70f2d54e6
commit
50d4794c87
23
src/league.c
23
src/league.c
@ -1028,3 +1028,26 @@ league_add_table(League *league)
|
|||||||
|
|
||||||
g_array_append_val(league->tables, new_table);
|
g_array_append_val(league->tables, new_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
query_league_cup_has_property(gint clid, const gchar *property)
|
||||||
|
{
|
||||||
|
const GPtrArray *properties = league_cup_get_properties(clid);
|
||||||
|
return query_misc_string_in_array(property, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPtrArray*
|
||||||
|
league_cup_get_teams(gint clid)
|
||||||
|
{
|
||||||
|
return (clid < ID_CUP_START) ?
|
||||||
|
(GPtrArray*)league_from_clid(clid)->teams :
|
||||||
|
cup_from_clid(clid)->teams;
|
||||||
|
}
|
||||||
|
|
||||||
|
GPtrArray*
|
||||||
|
league_cup_get_properties(gint clid)
|
||||||
|
{
|
||||||
|
return (clid < ID_CUP_START) ?
|
||||||
|
league_from_clid(clid)->properties :
|
||||||
|
cup_from_clid(clid)->properties;
|
||||||
|
}
|
||||||
|
13
src/league.h
13
src/league.h
@ -31,14 +31,10 @@
|
|||||||
#include "league_struct.h"
|
#include "league_struct.h"
|
||||||
#include "fixture_struct.h"
|
#include "fixture_struct.h"
|
||||||
|
|
||||||
#define league_cup_get_teams(clid) (clid < ID_CUP_START) ? ((gpointer)(league_from_clid(clid)->teams)) : ((gpointer)(cup_from_clid(clid)->teams))
|
|
||||||
#define league_cup_get_fixtures(clid) (clid < ID_CUP_START) ? (league_from_clid(clid)->fixtures) : (cup_from_clid(clid)->fixtures)
|
#define league_cup_get_fixtures(clid) (clid < ID_CUP_START) ? (league_from_clid(clid)->fixtures) : (cup_from_clid(clid)->fixtures)
|
||||||
#define league_cup_get_name_string(clid) (clid < ID_CUP_START) ? league_from_clid(clid)->name : cup_from_clid(clid)->name
|
#define league_cup_get_name_string(clid) (clid < ID_CUP_START) ? league_from_clid(clid)->name : cup_from_clid(clid)->name
|
||||||
#define league_cup_get_yellow_red(clid) (clid < ID_CUP_START) ? (league_from_clid(clid)->yellow_red) : (cup_from_clid(clid)->yellow_red)
|
#define league_cup_get_yellow_red(clid) (clid < ID_CUP_START) ? (league_from_clid(clid)->yellow_red) : (cup_from_clid(clid)->yellow_red)
|
||||||
|
|
||||||
#define league_cup_get_properties(clid) (clid < ID_CUP_START) ? ((gpointer)(league_from_clid(clid)->properties)) : ((gpointer)(cup_from_clid(clid)->properties))
|
|
||||||
#define query_league_cup_has_property(clid, string) query_misc_string_in_array(string, (GArray*)league_cup_get_properties(clid))
|
|
||||||
|
|
||||||
#define league_table_cumul(league) (&g_array_index((league)->tables, Table, 0))
|
#define league_table_cumul(league) (&g_array_index((league)->tables, Table, 0))
|
||||||
#define league_table(league) (&g_array_index((league)->tables, Table, league->tables->len - 1))
|
#define league_table(league) (&g_array_index((league)->tables, Table, league->tables->len - 1))
|
||||||
|
|
||||||
@ -149,4 +145,13 @@ league_check_new_tables(League *league);
|
|||||||
void
|
void
|
||||||
league_add_table(League *league);
|
league_add_table(League *league);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
query_league_cup_has_property(gint clid, const gchar *property);
|
||||||
|
|
||||||
|
GPtrArray*
|
||||||
|
league_cup_get_teams(gint clid);
|
||||||
|
|
||||||
|
GPtrArray*
|
||||||
|
league_cup_get_properties(gint clid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -300,7 +300,7 @@ misc_float_compare(gfloat first, gfloat second)
|
|||||||
|
|
||||||
/** Check whether the string is in the string array. */
|
/** Check whether the string is in the string array. */
|
||||||
gboolean
|
gboolean
|
||||||
query_misc_string_in_array(const gchar *string, GPtrArray *array)
|
query_misc_string_in_array(const gchar *string, const GPtrArray *array)
|
||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ gint
|
|||||||
misc_float_compare(gfloat first, gfloat second);
|
misc_float_compare(gfloat first, gfloat second);
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
query_misc_string_in_array(const gchar *string, GPtrArray *array);
|
query_misc_string_in_array(const gchar *string, const GPtrArray *array);
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
query_misc_integer_is_in_g_array(gint item, GArray *array);
|
query_misc_integer_is_in_g_array(gint item, GArray *array);
|
||||||
|
52
src/news.c
52
src/news.c
@ -105,7 +105,7 @@ news_select(const GArray *news_array, gchar *title, gchar *subtitle,
|
|||||||
const NewsArticle *article;
|
const NewsArticle *article;
|
||||||
gint order_articles[news_array->len];
|
gint order_articles[news_array->len];
|
||||||
|
|
||||||
math_generate_permutation(order_articles, 0, news_array->len - 1);
|
news_articles_get_order(news_array, order_articles);
|
||||||
|
|
||||||
*title_id = *subtitle_id = -1;
|
*title_id = *subtitle_id = -1;
|
||||||
|
|
||||||
@ -192,8 +192,8 @@ news_check_for_repetition(gint id, gboolean is_title)
|
|||||||
|
|
||||||
|
|
||||||
/** Write a random order of indices into the integer array
|
/** Write a random order of indices into the integer array
|
||||||
(only depending on the priority values of the commentaries).
|
(only depending on the priority values of the news titles).
|
||||||
I don't like this implementation of ordering the commentaries
|
I don't like this implementation of ordering the titles
|
||||||
according to their priority :-P can't think of a better one, though. */
|
according to their priority :-P can't think of a better one, though. */
|
||||||
void
|
void
|
||||||
news_titles_get_order(const GArray *titles, gint *order)
|
news_titles_get_order(const GArray *titles, gint *order)
|
||||||
@ -237,6 +237,52 @@ news_titles_get_order(const GArray *titles, gint *order)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Write a random order of indices into the integer array
|
||||||
|
(only depending on the priority values of the news articles).
|
||||||
|
I don't like this implementation of ordering the articles
|
||||||
|
according to their priority :-P can't think of a better one, though. */
|
||||||
|
void
|
||||||
|
news_articles_get_order(const GArray *articles, gint *order)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
printf("news_articles_get_order\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gint i, j, order_idx = 0;
|
||||||
|
gint priority_sum = 0, bounds[articles->len + 1];
|
||||||
|
|
||||||
|
bounds[0] = 0;
|
||||||
|
|
||||||
|
for(i=0;i<articles->len;i++)
|
||||||
|
{
|
||||||
|
priority_sum += g_array_index(articles, NewsArticle, i).priority;
|
||||||
|
bounds[i + 1] = priority_sum;
|
||||||
|
order[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gint permutation[priority_sum];
|
||||||
|
|
||||||
|
math_generate_permutation(permutation, 1, priority_sum);
|
||||||
|
|
||||||
|
for(i=0;i<priority_sum;i++)
|
||||||
|
{
|
||||||
|
if(order_idx == articles->len)
|
||||||
|
break;
|
||||||
|
|
||||||
|
for(j=0;j<articles->len;j++)
|
||||||
|
if(bounds[j] < permutation[i] && permutation[i] <= bounds[j + 1])
|
||||||
|
{
|
||||||
|
if(!query_integer_is_in_array(j, order, articles->len))
|
||||||
|
{
|
||||||
|
order[order_idx] = j;
|
||||||
|
order_idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Set match-related tokens for the news. */
|
/** Set match-related tokens for the news. */
|
||||||
void
|
void
|
||||||
news_set_match_tokens(const LiveGame *live_game)
|
news_set_match_tokens(const LiveGame *live_game)
|
||||||
|
@ -73,4 +73,7 @@ news_set_fixture_tokens(const Fixture *fix);
|
|||||||
void
|
void
|
||||||
news_set_rank_tokens(const Fixture *fix);
|
news_set_rank_tokens(const Fixture *fix);
|
||||||
|
|
||||||
|
void
|
||||||
|
news_articles_get_order(const GArray *articles, gint *order);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -66,6 +66,8 @@ typedef struct
|
|||||||
/** A condition (if not fulfilled, the article doesn't get
|
/** A condition (if not fulfilled, the article doesn't get
|
||||||
shown). */
|
shown). */
|
||||||
gchar *condition;
|
gchar *condition;
|
||||||
|
/** Priority of the article. */
|
||||||
|
gint priority;
|
||||||
|
|
||||||
} NewsArticle;
|
} NewsArticle;
|
||||||
|
|
||||||
|
@ -943,7 +943,7 @@ team_get_index(const Team *tm)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
gint i;
|
gint i;
|
||||||
gpointer *teams = league_cup_get_teams(tm->clid);
|
gpointer *teams = (gpointer*)league_cup_get_teams(tm->clid);
|
||||||
|
|
||||||
if(tm->clid < ID_CUP_START)
|
if(tm->clid < ID_CUP_START)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#define TAG_ARTICLE "news_article"
|
#define TAG_ARTICLE "news_article"
|
||||||
#define TAG_ARTICLE_TYPE "type"
|
#define TAG_ARTICLE_TYPE "type"
|
||||||
#define TAG_ARTICLE_CONDITION "condition"
|
#define TAG_ARTICLE_CONDITION "condition"
|
||||||
|
#define TAG_ARTICLE_PRIORITY "priority"
|
||||||
#define TAG_ARTICLE_TITLE "title"
|
#define TAG_ARTICLE_TITLE "title"
|
||||||
#define TAG_ARTICLE_SUBTITLE "subtitle"
|
#define TAG_ARTICLE_SUBTITLE "subtitle"
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ enum XmlNewsStates
|
|||||||
STATE_ARTICLE,
|
STATE_ARTICLE,
|
||||||
STATE_ARTICLE_TYPE,
|
STATE_ARTICLE_TYPE,
|
||||||
STATE_ARTICLE_CONDITION,
|
STATE_ARTICLE_CONDITION,
|
||||||
|
STATE_ARTICLE_PRIORITY,
|
||||||
STATE_ARTICLE_TITLE,
|
STATE_ARTICLE_TITLE,
|
||||||
STATE_ARTICLE_SUBTITLE,
|
STATE_ARTICLE_SUBTITLE,
|
||||||
STATE_END
|
STATE_END
|
||||||
@ -124,11 +126,14 @@ xml_news_read_start_element (GMarkupParseContext *context,
|
|||||||
new_article.titles = g_array_new(FALSE, FALSE, sizeof(NewsText));
|
new_article.titles = g_array_new(FALSE, FALSE, sizeof(NewsText));
|
||||||
new_article.subtitles = g_array_new(FALSE, FALSE, sizeof(NewsText));
|
new_article.subtitles = g_array_new(FALSE, FALSE, sizeof(NewsText));
|
||||||
new_article.condition = g_strdup("0");
|
new_article.condition = g_strdup("0");
|
||||||
|
new_article.priority = 1;
|
||||||
}
|
}
|
||||||
else if(strcmp(element_name, TAG_ARTICLE_TYPE) == 0)
|
else if(strcmp(element_name, TAG_ARTICLE_TYPE) == 0)
|
||||||
state = STATE_ARTICLE_TYPE;
|
state = STATE_ARTICLE_TYPE;
|
||||||
else if(strcmp(element_name, TAG_ARTICLE_CONDITION) == 0)
|
else if(strcmp(element_name, TAG_ARTICLE_CONDITION) == 0)
|
||||||
state = STATE_ARTICLE_CONDITION;
|
state = STATE_ARTICLE_CONDITION;
|
||||||
|
else if(strcmp(element_name, TAG_ARTICLE_PRIORITY) == 0)
|
||||||
|
state = STATE_ARTICLE_PRIORITY;
|
||||||
else if(strcmp(element_name, TAG_ARTICLE_TITLE) == 0)
|
else if(strcmp(element_name, TAG_ARTICLE_TITLE) == 0)
|
||||||
{
|
{
|
||||||
state = STATE_ARTICLE_TITLE;
|
state = STATE_ARTICLE_TITLE;
|
||||||
@ -190,6 +195,7 @@ xml_news_read_end_element (GMarkupParseContext *context,
|
|||||||
state = STATE_NEWS;
|
state = STATE_NEWS;
|
||||||
else if(strcmp(element_name, TAG_ARTICLE_TYPE) == 0 ||
|
else if(strcmp(element_name, TAG_ARTICLE_TYPE) == 0 ||
|
||||||
strcmp(element_name, TAG_ARTICLE_CONDITION) == 0 ||
|
strcmp(element_name, TAG_ARTICLE_CONDITION) == 0 ||
|
||||||
|
strcmp(element_name, TAG_ARTICLE_PRIORITY) == 0 ||
|
||||||
strcmp(element_name, TAG_ARTICLE_TITLE) == 0 ||
|
strcmp(element_name, TAG_ARTICLE_TITLE) == 0 ||
|
||||||
strcmp(element_name, TAG_ARTICLE_SUBTITLE) == 0)
|
strcmp(element_name, TAG_ARTICLE_SUBTITLE) == 0)
|
||||||
state = STATE_ARTICLE;
|
state = STATE_ARTICLE;
|
||||||
@ -216,16 +222,21 @@ xml_news_read_text (GMarkupParseContext *context,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
gchar buf[text_len + 1];
|
gchar buf[text_len + 1];
|
||||||
|
gint int_value;
|
||||||
|
|
||||||
strncpy(buf, text, text_len);
|
strncpy(buf, text, text_len);
|
||||||
buf[text_len] = '\0';
|
buf[text_len] = '\0';
|
||||||
|
|
||||||
|
int_value = (gint)g_ascii_strtod(buf, NULL);
|
||||||
|
|
||||||
if(state == STATE_PAPER_NAME)
|
if(state == STATE_PAPER_NAME)
|
||||||
g_ptr_array_add(newspaper.names, g_strdup(buf));
|
g_ptr_array_add(newspaper.names, g_strdup(buf));
|
||||||
else if(state == STATE_ARTICLE_TYPE)
|
else if(state == STATE_ARTICLE_TYPE)
|
||||||
article_idx = xml_news_article_type_to_int(buf);
|
article_idx = xml_news_article_type_to_int(buf);
|
||||||
else if(state == STATE_ARTICLE_CONDITION)
|
else if(state == STATE_ARTICLE_CONDITION)
|
||||||
misc_string_assign(&new_article.condition, buf);
|
misc_string_assign(&new_article.condition, buf);
|
||||||
|
else if(state == STATE_ARTICLE_PRIORITY)
|
||||||
|
new_article.priority = int_value;
|
||||||
else if(state == STATE_ARTICLE_TITLE)
|
else if(state == STATE_ARTICLE_TITLE)
|
||||||
{
|
{
|
||||||
new_title.text = g_strdup(buf);
|
new_title.text = g_strdup(buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user