summaryrefslogtreecommitdiffabout
path: root/src/idop.c
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-11 08:45:17 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-07-11 08:45:17 (GMT)
commitc3052454045484d22ba4d94722016162c222fb17 (patch) (side-by-side diff)
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') (more/less context) (ignore whitespace changes)
-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
@@ -54,7 +54,7 @@ set_frame_value(struct id3_frame *frame, const char *value)
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)
@@ -202,10 +202,12 @@ idest_ucs4_cvt(id3_ucs4_t const *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;
@@ -213,11 +215,84 @@ add_stringlist(gl_list_t list, struct id3_frame *frame,
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
@@ -241,7 +316,9 @@ add_field(gl_list_t list, struct id3_frame *frame, union id3_field *field)
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:
@@ -255,6 +332,23 @@ add_field(gl_list_t list, struct id3_frame *frame, union id3_field *field)
}
}
+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)
{
@@ -277,7 +371,7 @@ show_tags(struct id3_tag *tag)
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);
}

Return to:

Send suggestions and report system problems to the System administrator.