comparison src/demac/apev2.c @ 2196:dfa3c3aa2dc7

switched to mowgli_dictionary from GHashTable
author Eugene Zagidullin <e.asphyx@gmail.com>
date Thu, 29 Nov 2007 03:09:13 +0300
parents 80d7ab8f2ec5
children c8d558dab2a7
comparison
equal deleted inserted replaced
2195:9773d2c69857 2196:dfa3c3aa2dc7
23 #include <stdlib.h> 23 #include <stdlib.h>
24 #include <errno.h> 24 #include <errno.h>
25 #include <string.h> 25 #include <string.h>
26 26
27 #include <glib.h> 27 #include <glib.h>
28 #include <mowgli.h>
28 #include <audacious/vfs.h> 29 #include <audacious/vfs.h>
29 #include <audacious/plugin.h> 30 #include <audacious/plugin.h>
30 31
31 #include "ape.h" 32 #include "ape.h"
32 #include "apev2.h" 33 #include "apev2.h"
34 #define TMP_BUFSIZE 256 35 #define TMP_BUFSIZE 256
35 #ifndef MIN 36 #ifndef MIN
36 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 37 #define MIN(a,b) ((a) < (b) ? (a) : (b))
37 #endif 38 #endif
38 39
39 static gboolean strcase_equal (gconstpointer v1, gconstpointer v2) { 40 mowgli_dictionary_t* parse_apev2_tag(VFSFile *vfd) {
40 return (g_ascii_strcasecmp((gchar *)v1, (gchar *)v2) == 0);
41 }
42
43 static guint strcase_hash (gconstpointer v) {
44 gchar *tmp;
45 gchar buf[TMP_BUFSIZE+1];
46 gchar *p = buf;
47
48 for(tmp=(gchar*)v; (*tmp && (p < buf+TMP_BUFSIZE)); tmp++)
49 *(p++) = g_ascii_toupper(*tmp);
50 *p = '\0';
51 return g_str_hash((gconstpointer)buf);
52 }
53
54 GHashTable* parse_apev2_tag(VFSFile *vfd) {
55 unsigned char tmp[TMP_BUFSIZE+1]; 41 unsigned char tmp[TMP_BUFSIZE+1];
56 unsigned char tmp2[TMP_BUFSIZE+1]; 42 unsigned char tmp2[TMP_BUFSIZE+1];
57 guint64 signature; 43 guint64 signature;
58 guint32 tag_version; 44 guint32 tag_version;
59 guint32 tag_size, item_size, item_flags; 45 guint32 tag_size, item_size, item_flags;
60 guint32 tag_items; 46 guint32 tag_items;
61 guint32 tag_flags; 47 guint32 tag_flags;
62 GHashTable *hash; 48 mowgli_dictionary_t *dict;
63 49
64 aud_vfs_fseek(vfd, -32, SEEK_END); 50 aud_vfs_fseek(vfd, -32, SEEK_END);
65 signature = get_le64(vfd); 51 signature = get_le64(vfd);
66 if (signature != MKTAG64('A', 'P', 'E', 'T', 'A', 'G', 'E', 'X')) { 52 if (signature != MKTAG64('A', 'P', 'E', 'T', 'A', 'G', 'E', 'X')) {
67 #ifdef DEBUG 53 #ifdef DEBUG
82 fprintf(stderr, "** demac: apev2.c: found empty tag\n"); 68 fprintf(stderr, "** demac: apev2.c: found empty tag\n");
83 #endif 69 #endif
84 return NULL; 70 return NULL;
85 } 71 }
86 72
87 hash = g_hash_table_new_full(strcase_hash, strcase_equal, g_free, g_free); /* string-keyed table with dynamically allocated keys and items */ 73 dict = mowgli_dictionary_create(g_ascii_strcasecmp);
88 74
89 aud_vfs_fseek(vfd, -tag_size, SEEK_END); 75 aud_vfs_fseek(vfd, -tag_size, SEEK_END);
90 int i; 76 int i;
91 unsigned char *p; 77 unsigned char *p;
92 for(i=0; i<tag_items; i++) { 78 for(i=0; i<tag_items; i++) {
107 fprintf(stderr, "%s: \"%s\", f:%08x\n", tmp, tmp2, item_flags); 93 fprintf(stderr, "%s: \"%s\", f:%08x\n", tmp, tmp2, item_flags);
108 #endif 94 #endif
109 /* APEv2 stores all items in utf-8 */ 95 /* APEv2 stores all items in utf-8 */
110 gchar *item = ((tag_version == 1000 ) ? aud_str_to_utf8((gchar*)tmp2) : g_strdup((gchar*)tmp2)); 96 gchar *item = ((tag_version == 1000 ) ? aud_str_to_utf8((gchar*)tmp2) : g_strdup((gchar*)tmp2));
111 97
112 g_hash_table_insert (hash, g_strdup((gchar*)tmp), item); 98 mowgli_dictionary_add(dict, (char*)tmp, item);
113 } 99 }
114 100
115 return hash; 101 return dict;
116 } 102 }