diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-11 12:42:16 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-11 13:00:48 +0300 |
commit | 892d9b1f21b131c2d7fad21c441e4aa47e8e15d6 (patch) | |
tree | a40926451727b0ef64bf5a8bfd67663a64b56667 /src/idop.c | |
parent | c3052454045484d22ba4d94722016162c222fb17 (diff) | |
download | idest-892d9b1f21b131c2d7fad21c441e4aa47e8e15d6.tar.gz idest-892d9b1f21b131c2d7fad21c441e4aa47e8e15d6.tar.bz2 |
Accept language and class specs when setting comment fields.
* src/idest.h (set_frame_value): Change signature.
* src/idop.c (set_frame_value): Change signature.
Set lang and class for comment fields, if supplied.
(update_frame): New function. Introduces special handling
for comment fields.
(set_tags): Call update_frame.
* src/main.c (ed_list_add_assignment): Accept language and class
specs for comment fields (--set comment:lang:class=value).
* NEWS: Update.
Diffstat (limited to 'src/idop.c')
-rw-r--r-- | src/idop.c | 74 |
1 files changed, 55 insertions, 19 deletions
@@ -21,4 +21,5 @@ void -set_frame_value(struct id3_frame *frame, const char *value) +set_frame_value(struct id3_frame *frame, const struct ed_item *item) { + const char *value = item->v.value; union id3_field *field; @@ -28,2 +29,3 @@ set_frame_value(struct id3_frame *frame, const char *value) id3_ucs4_t *ucs4; + const char *class; @@ -55,4 +57,15 @@ set_frame_value(struct id3_frame *frame, const char *value) id3_field_settextencoding(field, encoding); - /* FIXME: Field 1: Language */ - /* FIXME: Field 2: Short descr */ + /* Field 1: Language */ + field = id3_frame_field(frame, 1); + id3_field_setlanguage(field, item->lang ? item->lang : "eng"); + /* Field 2: Short descr */ + field = id3_frame_field(frame, 2); + class = item->class ? item->class : ""; + if (latin1_option) + ucs4 = id3_latin1_ucs4duplicate( + (const id3_latin1_t *)class); + else + ucs4 = id3_utf8_ucs4duplicate( + (const id3_utf8_t *)class); + id3_field_setstring(field, ucs4); /* Field 3: Comment */ @@ -89,2 +102,40 @@ safe_id3_file_update_and_close(struct id3_file *file) +static void +update_frame(struct id3_tag *tag, const struct ed_item *item) +{ + struct id3_frame *frame = id3_tag_findframe(tag, item->id, 0); + if (!frame) { + frame = id3_frame_new(item->id); + if (id3_tag_attachframe(tag, frame)) + error(1, 0, "cannot attach new frame"); + } else if (strcmp(item->id, ID3_FRAME_COMMENT) == 0 + && item->class) { + /* Special handling for comments */ + int i = 0; + union id3_field *field; + + do { + union id3_field *field = id3_frame_field(frame, 2); + char *s; + + if (field && (s = field_to_string(field, 0)) + && strcmp(s, item->class) == 0) + break; + } while (frame = id3_tag_findframe(tag, item->id, ++i)); + if (!frame) { + frame = id3_frame_new(item->id); + if (id3_tag_attachframe(tag, frame)) + error(1, 0, "cannot attach new frame"); + } + } else { + struct id3_frame *fp; + + while (fp = id3_tag_findframe(tag, item->id, 1)) { + id3_tag_detachframe(tag, fp); + id3_frame_delete(fp); + } + } + set_frame_value(frame, item); +} + void @@ -110,18 +161,3 @@ set_tags(const char *name) const struct ed_item *item = p; - struct id3_frame *frame - = id3_tag_findframe(tag, item->id, 0); - if (!frame) { - frame = id3_frame_new(item->id); - if (id3_tag_attachframe(tag, frame)) - error(1, 0, "cannot attach new frame"); - } else { - struct id3_frame *fp; - - while (fp = id3_tag_findframe(tag, item->id, - 1)) { - id3_tag_detachframe(tag, fp); - id3_frame_delete(fp); - } - } - set_frame_value(frame, item->v.value); + update_frame(tag, item); modified |= 1; |