diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2017-01-30 22:35:35 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2017-01-30 22:35:35 +0200 |
commit | 6494fe85e087bad327859dd3103133569ac2ec5b (patch) | |
tree | 8daa2bef423a0b62e67fdaf3a177647d796acd7e | |
parent | cb959f75e36fbc08105fdc311fddd50516c5f1d8 (diff) | |
download | idest-6494fe85e087bad327859dd3103133569ac2ec5b.tar.gz idest-6494fe85e087bad327859dd3103133569ac2ec5b.tar.bz2 |
Apply --broken-8bit-charset only to frames in 8-bit encoding.
* src/frametab.gperf (decode_qv): Passe frame as the 2nd argument
to field_to_string.
(text_decode): Likewise.
* src/idest.h (idest_ucs4_cvt): Remove.
(field_to_string): Change the type of the 2nd argument.
* src/idop.c (frame_encoding_is_8bit)
(frame_is_genre): New auxiliary functions.
(idest_ucs4_cvt): Take frame as the 2nd argument. Do recoding
only if the frame's encoding in 8-bit.
(add_stringlist): Take frame instead of the isgenre boolean; pass
it to idest_ucs4_cvt. All uses changed.
(field_to_string): Take frame as the 2nd argument. All uses changed.
(fixup_charset): Merge with collect_text_frames.
-rw-r--r-- | src/frametab.gperf | 5 | ||||
-rw-r--r-- | src/idest.h | 3 | ||||
-rw-r--r-- | src/idop.c | 57 |
3 files changed, 42 insertions, 23 deletions
diff --git a/src/frametab.gperf b/src/frametab.gperf index 7863d08..c02b771 100644 --- a/src/frametab.gperf +++ b/src/frametab.gperf | |||
@@ -42,7 +42,7 @@ decode_qv(struct ed_item *item, struct id3_frame const *frame, | |||
42 | field = id3_frame_field(frame, n + i); | 42 | field = id3_frame_field(frame, n + i); |
43 | if (!field) | 43 | if (!field) |
44 | break; | 44 | break; |
45 | item->qv[i] = field_to_string(field, 0); | 45 | item->qv[i] = field_to_string(field, frame); |
46 | } | 46 | } |
47 | return 0; | 47 | return 0; |
48 | } | 48 | } |
@@ -346,7 +346,6 @@ text_encode(struct id3_frame *frame, struct ed_item const *item) | |||
346 | static int | 346 | static int |
347 | text_decode(struct ed_item *item, struct id3_frame const *frame) | 347 | text_decode(struct ed_item *item, struct id3_frame const *frame) |
348 | { | 348 | { |
349 | int isgenre = strcmp(frame->id, ID3_FRAME_GENRE) == 0; | ||
350 | union id3_field *field; | 349 | union id3_field *field; |
351 | char *str; | 350 | char *str; |
352 | int rc; | 351 | int rc; |
@@ -354,7 +353,7 @@ text_decode(struct ed_item *item, struct id3_frame const *frame) | |||
354 | field = id3_frame_field(frame, 1); | 353 | field = id3_frame_field(frame, 1); |
355 | if (!field) | 354 | if (!field) |
356 | return IDEST_ERR_NOFIELD; | 355 | return IDEST_ERR_NOFIELD; |
357 | str = field_to_string(field, isgenre); | 356 | str = field_to_string(field, frame); |
358 | rc = utf8_convert(idest_conv_decode, str, &item->value); | 357 | rc = utf8_convert(idest_conv_decode, str, &item->value); |
359 | free(str); | 358 | free(str); |
360 | if (rc) | 359 | if (rc) |
diff --git a/src/idest.h b/src/idest.h index 2c10077..787cdad 100644 --- a/src/idest.h +++ b/src/idest.h | |||
@@ -92,11 +92,10 @@ int guess_file_tag_options(struct id3_file *file, int *modified); | |||
92 | int set_frame_value(struct id3_frame *frame, const struct ed_item *item); | 92 | int set_frame_value(struct id3_frame *frame, const struct ed_item *item); |
93 | void set_tags(const char *name); | 93 | void set_tags(const char *name); |
94 | void del_tags(const char *name); | 94 | void del_tags(const char *name); |
95 | char *idest_ucs4_cvt(id3_ucs4_t const *ucs4); | ||
96 | void query_tags(const char *name); | 95 | void query_tags(const char *name); |
97 | void info_id3(const char *name); | 96 | void info_id3(const char *name); |
98 | 97 | ||
99 | char *field_to_string(union id3_field *field, int isgenre); | 98 | char *field_to_string(union id3_field *field, struct id3_frame const *frame); |
100 | int field_binary_from_string(union id3_field *field, const char *str); | 99 | int field_binary_from_string(union id3_field *field, const char *str); |
101 | char *field_binary_to_string(union id3_field *field); | 100 | char *field_binary_to_string(union id3_field *field); |
102 | 101 | ||
@@ -188,10 +188,31 @@ safe_id3_file_update_and_close(struct id3_file *file) | |||
188 | sigprocmask(SIG_SETMASK, &oldset, NULL); | 188 | sigprocmask(SIG_SETMASK, &oldset, NULL); |
189 | } | 189 | } |
190 | 190 | ||
191 | static int | ||
192 | frame_encoding_is_8bit(struct id3_frame const *frame) | ||
193 | { | ||
194 | union id3_field const *field; | ||
195 | |||
196 | if (!frame) | ||
197 | return 0; | ||
198 | field = id3_frame_field(frame, 0); | ||
199 | if (!field) | ||
200 | return 0; | ||
201 | return id3_field_gettextencoding(field) == ID3_FIELD_TEXTENCODING_ISO_8859_1; | ||
202 | } | ||
203 | |||
204 | static int | ||
205 | frame_is_genre(struct id3_frame const *frame) | ||
206 | { | ||
207 | if (!frame) | ||
208 | return 0; | ||
209 | return strcmp(frame->id, ID3_FRAME_GENRE) == 0; | ||
210 | } | ||
211 | |||
191 | char * | 212 | char * |
192 | idest_ucs4_cvt(id3_ucs4_t const *ucs4) | 213 | idest_ucs4_cvt(id3_ucs4_t const *ucs4, struct id3_frame const *frame) |
193 | { | 214 | { |
194 | if (broken_8bit_charset) { | 215 | if (broken_8bit_charset && frame_encoding_is_8bit(frame)) { |
195 | char *tempval = (char*)id3_ucs4_latin1duplicate(ucs4); | 216 | char *tempval = (char*)id3_ucs4_latin1duplicate(ucs4); |
196 | char *output; | 217 | char *output; |
197 | int rc = utf8_convert(idest_conv_recode, tempval, &output); | 218 | int rc = utf8_convert(idest_conv_recode, tempval, &output); |
@@ -205,7 +226,8 @@ idest_ucs4_cvt(id3_ucs4_t const *ucs4) | |||
205 | } | 226 | } |
206 | 227 | ||
207 | static void | 228 | static void |
208 | add_stringlist(gl_list_t list, union id3_field *field, int isgenre, | 229 | add_stringlist(gl_list_t list, union id3_field *field, |
230 | struct id3_frame const *frame, | ||
209 | size_t *psize) | 231 | size_t *psize) |
210 | { | 232 | { |
211 | unsigned i, nstrings = id3_field_getnstrings(field); | 233 | unsigned i, nstrings = id3_field_getnstrings(field); |
@@ -218,9 +240,9 @@ add_stringlist(gl_list_t list, union id3_field *field, int isgenre, | |||
218 | ucs4 = id3_field_getstrings(field, i); | 240 | ucs4 = id3_field_getstrings(field, i); |
219 | if (!ucs4) | 241 | if (!ucs4) |
220 | continue; | 242 | continue; |
221 | if (isgenre) | 243 | if (frame_is_genre(frame)) |
222 | ucs4 = id3_genre_name(ucs4); | 244 | ucs4 = id3_genre_name(ucs4); |
223 | str = idest_ucs4_cvt(ucs4); | 245 | str = idest_ucs4_cvt(ucs4, frame); |
224 | size += strlen(str); | 246 | size += strlen(str); |
225 | gl_list_add_last(list, str); | 247 | gl_list_add_last(list, str); |
226 | } | 248 | } |
@@ -284,7 +306,7 @@ field_binary_from_string(union id3_field *field, const char *str) | |||
284 | } | 306 | } |
285 | 307 | ||
286 | char * | 308 | char * |
287 | field_to_string(union id3_field *field, int isgenre) | 309 | field_to_string(union id3_field *field, struct id3_frame const *frame) |
288 | { | 310 | { |
289 | id3_ucs4_t const *ucs4; | 311 | id3_ucs4_t const *ucs4; |
290 | char *ret = NULL; | 312 | char *ret = NULL; |
@@ -313,12 +335,12 @@ field_to_string(union id3_field *field, int isgenre) | |||
313 | case ID3_FIELD_TYPE_STRING: | 335 | case ID3_FIELD_TYPE_STRING: |
314 | ucs4 = id3_field_getstring(field);; | 336 | ucs4 = id3_field_getstring(field);; |
315 | if (ucs4) | 337 | if (ucs4) |
316 | ret = idest_ucs4_cvt(ucs4); | 338 | ret = idest_ucs4_cvt(ucs4, frame); |
317 | break; | 339 | break; |
318 | 340 | ||
319 | case ID3_FIELD_TYPE_STRINGFULL: | 341 | case ID3_FIELD_TYPE_STRINGFULL: |
320 | ucs4 = id3_field_getfullstring(field); | 342 | ucs4 = id3_field_getfullstring(field); |
321 | ret = idest_ucs4_cvt(ucs4); | 343 | ret = idest_ucs4_cvt(ucs4, frame); |
322 | break; | 344 | break; |
323 | 345 | ||
324 | case ID3_FIELD_TYPE_STRINGLIST: { | 346 | case ID3_FIELD_TYPE_STRINGLIST: { |
@@ -328,7 +350,7 @@ field_to_string(union id3_field *field, int isgenre) | |||
328 | const void *p; | 350 | const void *p; |
329 | 351 | ||
330 | list = new_string_list(true); | 352 | list = new_string_list(true); |
331 | add_stringlist(list, field, isgenre, &sz); | 353 | add_stringlist(list, field, frame, &sz); |
332 | ret = xmalloc(sz + 1); | 354 | ret = xmalloc(sz + 1); |
333 | ret[0] = 0; | 355 | ret[0] = 0; |
334 | itr = gl_list_iterator(list); | 356 | itr = gl_list_iterator(list); |
@@ -528,15 +550,19 @@ update_frames(struct id3_tag *tag) | |||
528 | } | 550 | } |
529 | 551 | ||
530 | static void | 552 | static void |
531 | collect_text_frames(struct id3_tag *tag) | 553 | fixup_charset(struct id3_tag *tag) |
532 | { | 554 | { |
533 | struct id3_frame *frame; | 555 | struct id3_frame *frame; |
534 | unsigned i; | 556 | unsigned i; |
535 | 557 | ||
558 | if (!broken_8bit_charset) | ||
559 | return; | ||
560 | |||
536 | for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) { | 561 | for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); i++) { |
537 | struct ed_item itm; | 562 | struct ed_item itm; |
538 | const struct idest_frametab *ft = | 563 | const struct idest_frametab *ft = |
539 | idest_frame_lookup(frame->id); | 564 | idest_frame_lookup(frame->id); |
565 | |||
540 | if (!ft) { | 566 | if (!ft) { |
541 | if (verbose_option) | 567 | if (verbose_option) |
542 | error(0, 0, | 568 | error(0, 0, |
@@ -545,6 +571,9 @@ collect_text_frames(struct id3_tag *tag) | |||
545 | continue; | 571 | continue; |
546 | } | 572 | } |
547 | 573 | ||
574 | if (!frame_encoding_is_8bit(frame)) | ||
575 | continue; | ||
576 | |||
548 | ed_item_zero(&itm); | 577 | ed_item_zero(&itm); |
549 | itm.name = xstrdup(frame->id); | 578 | itm.name = xstrdup(frame->id); |
550 | memcpy(itm.id, frame->id, 4); | 579 | memcpy(itm.id, frame->id, 4); |
@@ -560,14 +589,6 @@ collect_text_frames(struct id3_tag *tag) | |||
560 | } | 589 | } |
561 | } | 590 | } |
562 | 591 | ||
563 | static void | ||
564 | fixup_charset(struct id3_tag *tag) | ||
565 | { | ||
566 | if (!broken_8bit_charset) | ||
567 | return; | ||
568 | collect_text_frames(tag); | ||
569 | } | ||
570 | |||
571 | void | 592 | void |
572 | set_tags(const char *name) | 593 | set_tags(const char *name) |
573 | { | 594 | { |