aboutsummaryrefslogtreecommitdiff
path: root/src/idop.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-11 11:45:17 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-07-11 11:45:17 +0300
commitc3052454045484d22ba4d94722016162c222fb17 (patch)
treeaf70ba549577d8a508afff53e565c47d479b06a0 /src/idop.c
parent3eca38aa7fa33362df0acc9c17493ad027809437 (diff)
downloadidest-c3052454045484d22ba4d94722016162c222fb17.tar.gz
idest-c3052454045484d22ba4d94722016162c222fb17.tar.bz2
Include comment classes (short descriptions) to the output.
* src/idest.h (ed_item): New members lang & class. (field_to_string): New proto. (ed_list_add_item): Change signature. * src/idop.c (add_stringlist): Change signature. Optionally return the total length of strings added to the list. All uses changed. (field_to_string): New function. (ed_item_set_comment_fields): New function. * src/main.c (ed_list_add_item): Add comment classes.
Diffstat (limited to 'src/idop.c')
-rw-r--r--src/idop.c106
1 files changed, 100 insertions, 6 deletions
diff --git a/src/idop.c b/src/idop.c
index 7310aad..5eb2609 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -51,13 +51,13 @@ set_frame_value(struct id3_frame *frame, const char *value)
case item_comment:
/* Field 0: Encoding */
field = id3_frame_field(frame, 0);
id3_field_settextencoding(field, encoding);
/* FIXME: Field 1: Language */
- /* FIXME: Field 2: String */
+ /* FIXME: Field 2: Short descr */
/* Field 3: Comment */
field = id3_frame_field(frame, 3);
if (latin1_option)
ucs4 = id3_latin1_ucs4duplicate(
(const id3_latin1_t *) value);
else
@@ -199,28 +199,103 @@ idest_ucs4_cvt(id3_ucs4_t const *ucs4)
return (char*)id3_ucs4_latin1duplicate(ucs4);
else
return (char*)id3_ucs4_utf8duplicate(ucs4);
}
static void
-add_stringlist(gl_list_t list, struct id3_frame *frame,
- union id3_field *field)
+add_stringlist(gl_list_t list, union id3_field *field, int isgenre,
+ size_t *psize)
{
unsigned i, nstrings = id3_field_getnstrings(field);
+ size_t size = 0;
+
for (i = 0; i < nstrings; i++) {
id3_ucs4_t const *ucs4;
char *str;
ucs4 = id3_field_getstrings(field, i);
if (!ucs4)
continue;
- if (strcmp(frame->id, ID3_FRAME_GENRE) == 0)
+ if (isgenre)
ucs4 = id3_genre_name(ucs4);
str = idest_ucs4_cvt(ucs4);
+ size += strlen(str);
gl_list_add_last(list, str);
}
+ if (psize)
+ *psize = size;
+}
+
+char *
+field_to_string(union id3_field *field, int isgenre)
+{
+ id3_ucs4_t const *ucs4;
+ char *ret = NULL;
+ char buf[128];
+
+ switch (id3_field_type(field)) {
+ case ID3_FIELD_TYPE_TEXTENCODING:
+ case ID3_FIELD_TYPE_INT8:
+ case ID3_FIELD_TYPE_INT16:
+ case ID3_FIELD_TYPE_INT24:
+ case ID3_FIELD_TYPE_INT32:
+ case ID3_FIELD_TYPE_INT32PLUS:
+ snprintf(buf, sizeof(buf), "%ld", field->number.value);
+ ret = xstrdup(buf);
+ break;
+
+ case ID3_FIELD_TYPE_LATIN1:
+ case ID3_FIELD_TYPE_LATIN1FULL:
+ /* FIXME */
+ ret = xstrdup(id3_field_getlatin1(field));
+ break;
+
+ case ID3_FIELD_TYPE_LATIN1LIST:
+ /* FIXME */
+ break;
+
+ case ID3_FIELD_TYPE_STRING:
+ ucs4 = id3_field_getstring(field);;
+ if (ucs4)
+ ret = idest_ucs4_cvt(ucs4);
+ break;
+
+ case ID3_FIELD_TYPE_STRINGFULL:
+ ucs4 = id3_field_getfullstring(field);
+ ret = idest_ucs4_cvt(ucs4);
+ break;
+
+ case ID3_FIELD_TYPE_STRINGLIST: {
+ gl_list_t list;
+ size_t sz;
+ gl_list_iterator_t itr;
+ const void *p;
+
+ list = new_string_list(true);
+ add_stringlist(list, field, isgenre, &sz);
+ ret = xmalloc(sz + 1);
+ ret[0] = 0;
+ itr = gl_list_iterator(list);
+ while (gl_list_iterator_next(&itr, &p, NULL))
+ strcat(ret, p);
+ gl_list_iterator_free(&itr);
+ gl_list_free(list);
+ break;
+ }
+
+ case ID3_FIELD_TYPE_LANGUAGE:
+ case ID3_FIELD_TYPE_FRAMEID:
+ case ID3_FIELD_TYPE_DATE:
+ ret = xstrdup(field->immediate.value);
+ break;
+
+ case ID3_FIELD_TYPE_BINARYDATA:
+ /* FIXME */
+ break;
+ }
+ return ret;
}
static void
add_field(gl_list_t list, struct id3_frame *frame, union id3_field *field)
{
id3_ucs4_t const *ucs4;
@@ -238,13 +313,15 @@ add_field(gl_list_t list, struct id3_frame *frame, union id3_field *field)
case ID3_FIELD_TYPE_STRINGFULL:
ucs4 = id3_field_getfullstring(field);
str = idest_ucs4_cvt(ucs4);
gl_list_add_last(list, str);
break;
case ID3_FIELD_TYPE_STRINGLIST:
- add_stringlist(list, frame, field);
+ add_stringlist(list, field,
+ strcmp(frame->id, ID3_FRAME_GENRE) == 0,
+ NULL);
break;
case ID3_FIELD_TYPE_LANGUAGE:
case ID3_FIELD_TYPE_FRAMEID:
case ID3_FIELD_TYPE_DATE:
case ID3_FIELD_TYPE_INT8:
case ID3_FIELD_TYPE_INT16:
@@ -252,12 +329,29 @@ add_field(gl_list_t list, struct id3_frame *frame, union id3_field *field)
case ID3_FIELD_TYPE_INT32:
case ID3_FIELD_TYPE_INT32PLUS:
case ID3_FIELD_TYPE_BINARYDATA:;
}
}
+void
+ed_item_set_comment_fields(struct ed_item *itm, struct id3_frame *frame)
+{
+ union id3_field *field;
+
+ if (strcmp(frame->id, ID3_FRAME_COMMENT) == 0) {
+ field = id3_frame_field(frame, 1);
+ if (!field)
+ return;
+ itm->lang = field_to_string(field, 0);
+ field = id3_frame_field(frame, 2);
+ if (!field)
+ return;
+ itm->class = field_to_string(field, 0);
+ }
+}
+
static gl_list_t
frame_to_list(struct id3_frame *frame)
{
gl_list_t list;
unsigned i;
union id3_field *field;
@@ -274,13 +368,13 @@ show_tags(struct id3_tag *tag)
struct id3_frame *frame;
unsigned i;
for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) {
gl_list_t list = frame_to_list(frame);
if (gl_list_size(list) > 0)
- ed_list_add_item(frame->id, list);
+ ed_list_add_item(frame, list);
else
gl_list_free(list);
}
ed_list_print();
ed_list_clear();
}

Return to:

Send suggestions and report system problems to the System administrator.