summaryrefslogtreecommitdiffabout
path: root/src/idop.c
authorSergey Poznyakoff <gray@gnu.org>2017-01-30 20:35:35 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2017-01-30 20:35:35 (GMT)
commit6494fe85e087bad327859dd3103133569ac2ec5b (patch) (unidiff)
tree8daa2bef423a0b62e67fdaf3a177647d796acd7e /src/idop.c
parentcb959f75e36fbc08105fdc311fddd50516c5f1d8 (diff)
downloadidest-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.
Diffstat (limited to 'src/idop.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/idop.c59
1 files changed, 40 insertions, 19 deletions
diff --git a/src/idop.c b/src/idop.c
index 063ff78..c3a3ce2 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -190,6 +190,27 @@ safe_id3_file_update_and_close(struct id3_file *file)
190 190
191static int
192frame_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
204static int
205frame_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
191char * 212char *
192idest_ucs4_cvt(id3_ucs4_t const *ucs4) 213idest_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);
@@ -207,3 +228,4 @@ idest_ucs4_cvt(id3_ucs4_t const *ucs4)
207static void 228static void
208add_stringlist(gl_list_t list, union id3_field *field, int isgenre, 229add_stringlist(gl_list_t list, union id3_field *field,
230 struct id3_frame const *frame,
209 size_t *psize) 231 size_t *psize)
@@ -220,5 +242,5 @@ add_stringlist(gl_list_t list, union id3_field *field, int isgenre,
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);
@@ -286,3 +308,3 @@ field_binary_from_string(union id3_field *field, const char *str)
286char * 308char *
287field_to_string(union id3_field *field, int isgenre) 309field_to_string(union id3_field *field, struct id3_frame const *frame)
288{ 310{
@@ -314,4 +336,4 @@ field_to_string(union id3_field *field, int isgenre)
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;
@@ -320,3 +342,3 @@ field_to_string(union id3_field *field, int isgenre)
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;
@@ -330,3 +352,3 @@ field_to_string(union id3_field *field, int isgenre)
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);
@@ -530,3 +552,3 @@ update_frames(struct id3_tag *tag)
530static void 552static void
531collect_text_frames(struct id3_tag *tag) 553fixup_charset(struct id3_tag *tag)
532{ 554{
@@ -535,2 +557,5 @@ collect_text_frames(struct id3_tag *tag)
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++) {
@@ -539,2 +564,3 @@ collect_text_frames(struct id3_tag *tag)
539 idest_frame_lookup(frame->id); 564 idest_frame_lookup(frame->id);
565
540 if (!ft) { 566 if (!ft) {
@@ -547,2 +573,5 @@ collect_text_frames(struct id3_tag *tag)
547 573
574 if (!frame_encoding_is_8bit(frame))
575 continue;
576
548 ed_item_zero(&itm); 577 ed_item_zero(&itm);
@@ -562,10 +591,2 @@ collect_text_frames(struct id3_tag *tag)
562 591
563static void
564fixup_charset(struct id3_tag *tag)
565{
566 if (!broken_8bit_charset)
567 return;
568 collect_text_frames(tag);
569}
570
571void 592void

Return to:

Send suggestions and report system problems to the System administrator.