# HG changeset patch # User Eugene Zagidullin # Date 1196294953 -10800 # Node ID dfa3c3aa2dc7ed94d25594d9f375b44f1e77e4ea # Parent 9773d2c69857914a8e33d2998b162fe5293d619e switched to mowgli_dictionary from GHashTable diff -r 9773d2c69857 -r dfa3c3aa2dc7 src/demac/Makefile --- a/src/demac/Makefile Wed Nov 28 18:15:40 2007 +0100 +++ b/src/demac/Makefile Thu Nov 29 03:09:13 2007 +0300 @@ -12,4 +12,4 @@ CFLAGS += ${PLUGIN_CFLAGS} CPPFLAGS += ${PLUGIN_CPPFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} ${ARCH_DEFINES} -I../../intl -I../.. -LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} +LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${MOWGLI_LIBS} diff -r 9773d2c69857 -r dfa3c3aa2dc7 src/demac/apev2.c --- a/src/demac/apev2.c Wed Nov 28 18:15:40 2007 +0100 +++ b/src/demac/apev2.c Thu Nov 29 03:09:13 2007 +0300 @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -36,22 +37,7 @@ #define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -static gboolean strcase_equal (gconstpointer v1, gconstpointer v2) { - return (g_ascii_strcasecmp((gchar *)v1, (gchar *)v2) == 0); -} - -static guint strcase_hash (gconstpointer v) { - gchar *tmp; - gchar buf[TMP_BUFSIZE+1]; - gchar *p = buf; - - for(tmp=(gchar*)v; (*tmp && (p < buf+TMP_BUFSIZE)); tmp++) - *(p++) = g_ascii_toupper(*tmp); - *p = '\0'; - return g_str_hash((gconstpointer)buf); -} - -GHashTable* parse_apev2_tag(VFSFile *vfd) { +mowgli_dictionary_t* parse_apev2_tag(VFSFile *vfd) { unsigned char tmp[TMP_BUFSIZE+1]; unsigned char tmp2[TMP_BUFSIZE+1]; guint64 signature; @@ -59,7 +45,7 @@ guint32 tag_size, item_size, item_flags; guint32 tag_items; guint32 tag_flags; - GHashTable *hash; + mowgli_dictionary_t *dict; aud_vfs_fseek(vfd, -32, SEEK_END); signature = get_le64(vfd); @@ -84,7 +70,7 @@ return NULL; } - hash = g_hash_table_new_full(strcase_hash, strcase_equal, g_free, g_free); /* string-keyed table with dynamically allocated keys and items */ + dict = mowgli_dictionary_create(g_ascii_strcasecmp); aud_vfs_fseek(vfd, -tag_size, SEEK_END); int i; @@ -109,8 +95,8 @@ /* APEv2 stores all items in utf-8 */ gchar *item = ((tag_version == 1000 ) ? aud_str_to_utf8((gchar*)tmp2) : g_strdup((gchar*)tmp2)); - g_hash_table_insert (hash, g_strdup((gchar*)tmp), item); + mowgli_dictionary_add(dict, (char*)tmp, item); } - return hash; + return dict; } diff -r 9773d2c69857 -r dfa3c3aa2dc7 src/demac/apev2.h --- a/src/demac/apev2.h Wed Nov 28 18:15:40 2007 +0100 +++ b/src/demac/apev2.h Thu Nov 29 03:09:13 2007 +0300 @@ -1,9 +1,9 @@ #ifndef APEV2_H #define APEV2_H -#include +#include #include -GHashTable* parse_apev2_tag(VFSFile *vfd); +mowgli_dictionary_t* parse_apev2_tag(VFSFile *vfd); #endif diff -r 9773d2c69857 -r dfa3c3aa2dc7 src/demac/plugin.c --- a/src/demac/plugin.c Wed Nov 28 18:15:40 2007 +0100 +++ b/src/demac/plugin.c Thu Nov 29 03:09:13 2007 +0300 @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -293,6 +294,10 @@ pb->output->pause(paused); } +static void destroy_cb(mowgli_dictionary_elem_t *delem, void *privdata) { + g_free(delem->data); +} + Tuple *demac_probe_for_tuple (gchar *uri, VFSFile *vfd) { #ifdef DEBUG fprintf(stderr, "** demac: plugin.c: demac_probe_for_tuple()\n"); @@ -300,16 +305,16 @@ Tuple *tpl = aud_tuple_new_from_filename(uri); gchar codec_string[32]; - GHashTable *tag = NULL; + mowgli_dictionary_t *tag = NULL; gchar *item; if ((tag = parse_apev2_tag(vfd)) != NULL) { - if((item = g_hash_table_lookup (tag, "Artist")) != NULL) aud_tuple_associate_string(tpl, FIELD_ARTIST, NULL, item); - if((item = g_hash_table_lookup (tag, "Title")) != NULL) aud_tuple_associate_string(tpl, FIELD_TITLE, NULL, item); - if((item = g_hash_table_lookup (tag, "Album")) != NULL) aud_tuple_associate_string(tpl, FIELD_ALBUM, NULL, item); - if((item = g_hash_table_lookup (tag, "Comment")) != NULL) aud_tuple_associate_string(tpl, FIELD_COMMENT, NULL, item); - if((item = g_hash_table_lookup (tag, "Genre")) != NULL) aud_tuple_associate_string(tpl, FIELD_GENRE, NULL, item); - if((item = g_hash_table_lookup (tag, "Track")) != NULL) aud_tuple_associate_int(tpl, FIELD_TRACK_NUMBER, NULL, atoi(item)); - if((item = g_hash_table_lookup (tag, "Year")) != NULL) aud_tuple_associate_int(tpl, FIELD_YEAR, NULL, atoi(item)); + if((item = mowgli_dictionary_retrieve(tag, "Artist")) != NULL) aud_tuple_associate_string(tpl, FIELD_ARTIST, NULL, item); + if((item = mowgli_dictionary_retrieve(tag, "Title")) != NULL) aud_tuple_associate_string(tpl, FIELD_TITLE, NULL, item); + if((item = mowgli_dictionary_retrieve(tag, "Album")) != NULL) aud_tuple_associate_string(tpl, FIELD_ALBUM, NULL, item); + if((item = mowgli_dictionary_retrieve(tag, "Comment")) != NULL) aud_tuple_associate_string(tpl, FIELD_COMMENT, NULL, item); + if((item = mowgli_dictionary_retrieve(tag, "Genre")) != NULL) aud_tuple_associate_string(tpl, FIELD_GENRE, NULL, item); + if((item = mowgli_dictionary_retrieve(tag, "Track")) != NULL) aud_tuple_associate_int(tpl, FIELD_TRACK_NUMBER, NULL, atoi(item)); + if((item = mowgli_dictionary_retrieve(tag, "Year")) != NULL) aud_tuple_associate_int(tpl, FIELD_YEAR, NULL, atoi(item)); } APEContext *ctx = calloc(sizeof(APEContext), 1); @@ -319,7 +324,7 @@ ape_read_close(ctx); free(ctx); - if (tag) g_hash_table_remove_all(tag); + if (tag) mowgli_dictionary_destroy(tag, destroy_cb, NULL); g_sprintf(codec_string, "Monkey's Audio v%4.2f", (float)ctx->fileversion/1000.0); #ifdef DEBUG