Make supported media type listing output unique

This commit is contained in:
Přemysl Eric Janouch 2023-04-17 07:16:25 +02:00
parent cce2b6ba51
commit 44c28f00d6
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 12 additions and 5 deletions

View File

@ -121,8 +121,11 @@ const char *fiv_io_supported_media_types[] = {
gchar ** gchar **
fiv_io_all_supported_media_types(void) fiv_io_all_supported_media_types(void)
{ {
GHashTable *unique =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
GPtrArray *types = g_ptr_array_new(); GPtrArray *types = g_ptr_array_new();
for (const char **p = fiv_io_supported_media_types; *p; p++) for (const char **p = fiv_io_supported_media_types; *p; p++)
if (g_hash_table_insert(unique, g_strdup(*p), NULL))
g_ptr_array_add(types, g_strdup(*p)); g_ptr_array_add(types, g_strdup(*p));
#ifdef HAVE_GDKPIXBUF #ifdef HAVE_GDKPIXBUF
@ -130,14 +133,16 @@ fiv_io_all_supported_media_types(void)
for (GSList *iter = formats; iter; iter = iter->next) { for (GSList *iter = formats; iter; iter = iter->next) {
gchar **subtypes = gdk_pixbuf_format_get_mime_types(iter->data); gchar **subtypes = gdk_pixbuf_format_get_mime_types(iter->data);
for (gchar **p = subtypes; *p; p++) for (gchar **p = subtypes; *p; p++)
g_ptr_array_add(types, *p); if (g_hash_table_insert(unique, *p, NULL))
g_ptr_array_add(types, g_strdup(*p));
g_free(subtypes); g_free(subtypes);
} }
g_slist_free(formats); g_slist_free(formats);
#endif // HAVE_GDKPIXBUF #endif // HAVE_GDKPIXBUF
g_hash_table_unref(unique);
g_ptr_array_add(types, NULL); g_ptr_array_add(types, NULL);
return (char **) g_ptr_array_free(types, FALSE); return (gchar **) g_ptr_array_free(types, FALSE);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

6
fiv.c
View File

@ -2204,8 +2204,10 @@ main(int argc, char *argv[])
return 0; return 0;
} }
if (show_supported_media_types) { if (show_supported_media_types) {
for (char **types = fiv_io_all_supported_media_types(); *types; ) char **types = fiv_io_all_supported_media_types();
g_print("%s\n", *types++); for (char **p = types; *p; p++)
g_print("%s\n", *p);
g_strfreev(types);
return 0; return 0;
} }
if (invalidate_cache) { if (invalidate_cache) {