diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-04-17 07:16:25 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-04-17 07:19:37 +0200 |
commit | 44c28f00d65ace6ea6ef340de03139f98648ebe5 (patch) | |
tree | 8da8fba54c6229ba4232ccc55ddd86a1ad8ca89a | |
parent | cce2b6ba51addf1b28088174708a3c09a7f81329 (diff) | |
download | fiv-44c28f00d65ace6ea6ef340de03139f98648ebe5.tar.gz fiv-44c28f00d65ace6ea6ef340de03139f98648ebe5.tar.xz fiv-44c28f00d65ace6ea6ef340de03139f98648ebe5.zip |
Make supported media type listing output unique
-rw-r--r-- | fiv-io.c | 11 | ||||
-rw-r--r-- | fiv.c | 6 |
2 files changed, 12 insertions, 5 deletions
@@ -121,23 +121,28 @@ const char *fiv_io_supported_media_types[] = { gchar ** 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(); for (const char **p = fiv_io_supported_media_types; *p; p++) - g_ptr_array_add(types, g_strdup(*p)); + if (g_hash_table_insert(unique, g_strdup(*p), NULL)) + g_ptr_array_add(types, g_strdup(*p)); #ifdef HAVE_GDKPIXBUF GSList *formats = gdk_pixbuf_get_formats(); for (GSList *iter = formats; iter; iter = iter->next) { gchar **subtypes = gdk_pixbuf_format_get_mime_types(iter->data); 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_slist_free(formats); #endif // HAVE_GDKPIXBUF + g_hash_table_unref(unique); g_ptr_array_add(types, NULL); - return (char **) g_ptr_array_free(types, FALSE); + return (gchar **) g_ptr_array_free(types, FALSE); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2204,8 +2204,10 @@ main(int argc, char *argv[]) return 0; } if (show_supported_media_types) { - for (char **types = fiv_io_all_supported_media_types(); *types; ) - g_print("%s\n", *types++); + char **types = fiv_io_all_supported_media_types(); + for (char **p = types; *p; p++) + g_print("%s\n", *p); + g_strfreev(types); return 0; } if (invalidate_cache) { |