2 * Copyright 2004 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 struct keyval
*comments_dup(const struct keyval
*comments
)
31 for (i
= 0; comments
[i
].key
; i
++)
33 c
= xnew(struct keyval
, i
+ 1);
34 for (i
= 0; comments
[i
].key
; i
++) {
35 c
[i
].key
= xstrdup(comments
[i
].key
);
36 c
[i
].val
= xstrdup(comments
[i
].val
);
43 void comments_free(struct keyval
*comments
)
47 for (i
= 0; comments
[i
].key
; i
++) {
48 free(comments
[i
].key
);
49 free(comments
[i
].val
);
54 const char *comments_get_val(const struct keyval
*comments
, const char *key
)
58 for (i
= 0; comments
[i
].key
; i
++) {
59 if (strcasecmp(comments
[i
].key
, key
) == 0)
60 return comments
[i
].val
;
65 int comments_get_int(const struct keyval
*comments
, const char *key
)
70 val
= comments_get_val(comments
, key
);
73 if (str_to_int(val
, &ival
) == -1)
78 static const char *interesting
[] = {
79 "artist", "album", "title", "tracknumber", "discnumber", "genre",
80 "date", "compilation", "albumartist", NULL
83 int is_interesting_key(const char *key
)
87 for (i
= 0; interesting
[i
]; i
++) {
88 if (strcasecmp(key
, interesting
[i
]) == 0)
94 void fix_track_or_disc(char *str
)
96 char *slash
= strchr(str
, '/');