From 25f29868150a992fa0d11e6944d720c9daadb530 Mon Sep 17 00:00:00 2001 From: rbuj Date: Tue, 2 Feb 2021 16:04:02 +0100 Subject: Remove warning -Wbad-function-cast --- libmate-desktop/mate-languages.c | 62 ++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 25 deletions(-) (limited to 'libmate-desktop/mate-languages.c') diff --git a/libmate-desktop/mate-languages.c b/libmate-desktop/mate-languages.c index 57ce6ab..c0b00c1 100644 --- a/libmate-desktop/mate-languages.c +++ b/libmate-desktop/mate-languages.c @@ -555,6 +555,24 @@ collect_locales_from_localebin (void) return found_locales; } +static void +fill_count_map (GHashTable *count_map, + const char *code) +{ + int count; + gpointer pointer; + + if (code == NULL) + return; + + if ((pointer = g_hash_table_lookup (count_map, code)) != NULL) + count = GPOINTER_TO_INT (pointer) + 1; + else + count = 1; + + g_hash_table_insert (count_map, g_strdup (code), GINT_TO_POINTER (count)); +} + static void count_languages_and_territories (void) { @@ -566,25 +584,9 @@ count_languages_and_territories (void) g_hash_table_iter_init (&iter, mate_available_locales_map); while (g_hash_table_iter_next (&iter, NULL, &value)) { - MateLocale *locale; - - locale = (MateLocale *) value; - - if (locale->language_code != NULL) { - int count; - - count = GPOINTER_TO_INT (g_hash_table_lookup (mate_language_count_map, locale->language_code)); - count++; - g_hash_table_insert (mate_language_count_map, g_strdup (locale->language_code), GINT_TO_POINTER (count)); - } - - if (locale->territory_code != NULL) { - int count; - - count = GPOINTER_TO_INT (g_hash_table_lookup (mate_territory_count_map, locale->territory_code)); - count++; - g_hash_table_insert (mate_territory_count_map, g_strdup (locale->territory_code), GINT_TO_POINTER (count)); - } + MateLocale *locale = (MateLocale *) value; + fill_count_map (mate_language_count_map, locale->language_code); + fill_count_map (mate_territory_count_map, locale->territory_code); } } @@ -614,11 +616,16 @@ collect_locales (void) static gint get_language_count (const char *language) { - if (mate_language_count_map == NULL) { + gint count = 0; + gpointer pointer; + + if (mate_language_count_map == NULL) collect_locales (); - } - return GPOINTER_TO_INT (g_hash_table_lookup (mate_language_count_map, language)); + if ((pointer = g_hash_table_lookup (mate_language_count_map, language)) != NULL) + count = GPOINTER_TO_INT (pointer); + + return count; } static gboolean @@ -630,11 +637,16 @@ is_unique_language (const char *language) static gint get_territory_count (const char *territory) { - if (mate_territory_count_map == NULL) { + gint count = 0; + gpointer pointer; + + if (mate_territory_count_map == NULL) collect_locales (); - } - return GPOINTER_TO_INT (g_hash_table_lookup (mate_territory_count_map, territory)); + if ((pointer = g_hash_table_lookup (mate_territory_count_map, territory)) != NULL) + count = GPOINTER_TO_INT (pointer); + + return count; } static gboolean -- cgit v1.2.1