diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-29 14:33:27 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-29 14:33:27 +0300 |
commit | 8006a1de47d492a2fc15e314a3851fb40e6622bd (patch) | |
tree | 2d28aa3e671e5b5ccecc4ef0f2f60020d47e20e3 /src/idop.c | |
parent | 07e8fc8a6afe790f7e225601392cf6d17b6a3591 (diff) | |
download | idest-8006a1de47d492a2fc15e314a3851fb40e6622bd.tar.gz idest-8006a1de47d492a2fc15e314a3851fb40e6622bd.tar.bz2 |
Add more tests.
* src/idest.h (source_vopt): New extern.
(guess_file_tag_options): New proto.
* src/idop.c (parse_ed_items): Use only commas as
separators.
(set_tag_options,guess_file_tag_options): New function.
(find_matching_frame): Use the above functions.
(del_tags): make sure tag version remains unchanged,
unless requested so on the command line.
* src/main.c (source_vopt): New variable.
(main): Set source_vopt.
* tests/Makefile.am: Add new testcases.
* tests/testsuite.at: Add new testcases.
* tests/copy-v1-00.at: New testcase.
* tests/copy-v12-00.at: New testcase.
* tests/copy-v2-00.at: New testcase.
* tests/del-all-v1.at: New testcase.
* tests/del-all-v12.at: New testcase.
* tests/del-all-v2.at: New testcase.
* tests/del-frame-v1.at: New testcase.
* tests/del-frame-v2.at: New testcase.
* tests/set-v1-01.at: New testcase.
* tests/set-v2-01.at: New testcase.
Diffstat (limited to 'src/idop.c')
-rw-r--r-- | src/idop.c | 94 |
1 files changed, 60 insertions, 34 deletions
@@ -42,14 +42,14 @@ parse_ed_items(gl_list_t *plist, const char *arg) | |||
42 | list = *plist; | 42 | list = *plist; |
43 | while (*arg) { | 43 | while (*arg) { |
44 | struct ed_item *itm; | 44 | struct ed_item *itm; |
45 | size_t len = strcspn(arg, " \t,"); | 45 | size_t len = strcspn(arg, ","); |
46 | 46 | ||
47 | itm = ed_item_from_frame_spec(arg, len); | 47 | itm = ed_item_from_frame_spec(arg, len); |
48 | gl_list_add_last(list, itm); | 48 | gl_list_add_last(list, itm); |
49 | arg += len; | 49 | arg += len; |
50 | if (!*arg) | 50 | if (!*arg) |
51 | break; | 51 | break; |
52 | arg += strspn(arg, " \t,"); | 52 | arg += strspn(arg, ","); |
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
@@ -368,6 +368,48 @@ build_tag_options(struct id3_tag *tag, unsigned long location, | |||
368 | return 0; | 368 | return 0; |
369 | } | 369 | } |
370 | 370 | ||
371 | static void | ||
372 | set_tag_options(struct id3_tag *tag, int vopt) | ||
373 | { | ||
374 | int opts = 0; | ||
375 | |||
376 | if (vopt & IDEST_ID3V_1) | ||
377 | opts |= ID3_TAG_OPTION_ID3V1; | ||
378 | if (!(vopt & IDEST_ID3V_2)) | ||
379 | opts |= ID3_TAG_OPTION_NO_ID3V2; | ||
380 | if (opts) | ||
381 | id3_tag_options(tag, | ||
382 | ID3_TAG_OPTION_ID3V1|ID3_TAG_OPTION_NO_ID3V2, | ||
383 | opts); | ||
384 | } | ||
385 | |||
386 | int | ||
387 | guess_file_tag_options(struct id3_file *file, int *modified) | ||
388 | { | ||
389 | int vopt = version_option; | ||
390 | int m = 0; | ||
391 | |||
392 | if (!modified) | ||
393 | modified = &m; | ||
394 | if (convert_version == 0) { | ||
395 | if (*modified && !vopt) { | ||
396 | if (id3_file_struct_ntags(file)) { | ||
397 | id3_file_struct_iterate(file, | ||
398 | build_tag_options, | ||
399 | &vopt); | ||
400 | } else | ||
401 | vopt = default_version_option; | ||
402 | } | ||
403 | } else if (id3_file_struct_ntags(file)) { | ||
404 | id3_file_struct_iterate(file, build_tag_options, &vopt); | ||
405 | if (vopt != convert_version) { | ||
406 | vopt = convert_version; | ||
407 | *modified |= 1; | ||
408 | } | ||
409 | } | ||
410 | return vopt; | ||
411 | } | ||
412 | |||
371 | struct id3_frame * | 413 | struct id3_frame * |
372 | find_matching_frame(struct id3_tag *tag, const struct ed_item *item, | 414 | find_matching_frame(struct id3_tag *tag, const struct ed_item *item, |
373 | idest_frame_cmp_t cmp) | 415 | idest_frame_cmp_t cmp) |
@@ -452,11 +494,13 @@ set_tags(const char *name) | |||
452 | struct id3_file *file; | 494 | struct id3_file *file; |
453 | struct id3_tag *tag; | 495 | struct id3_tag *tag; |
454 | int modified = 0; | 496 | int modified = 0; |
455 | int vopt = version_option; | 497 | int vopt; |
456 | 498 | int has_tags; | |
499 | |||
457 | file = id3_file_open(name, ID3_FILE_MODE_READWRITE); | 500 | file = id3_file_open(name, ID3_FILE_MODE_READWRITE); |
458 | if (!file) | 501 | if (!file) |
459 | error(1, errno, "cannot open file %s", name); | 502 | error(1, errno, "cannot open file %s", name); |
503 | has_tags = id3_file_struct_ntags(file); | ||
460 | tag = id3_file_tag(file); | 504 | tag = id3_file_tag(file); |
461 | if (!tag) | 505 | if (!tag) |
462 | abort(); /* FIXME */ | 506 | abort(); /* FIXME */ |
@@ -482,38 +526,14 @@ set_tags(const char *name) | |||
482 | 526 | ||
483 | /* FIXME */ | 527 | /* FIXME */ |
484 | modified |= guile_transform(name, tag); | 528 | modified |= guile_transform(name, tag); |
485 | |||
486 | if (convert_version == 0) { | ||
487 | if (modified && !vopt) { | ||
488 | if (id3_file_struct_ntags(file)) { | ||
489 | id3_file_struct_iterate(file, | ||
490 | build_tag_options, | ||
491 | &vopt); | ||
492 | } else | ||
493 | vopt = default_version_option; | ||
494 | } | ||
495 | } else if (id3_file_struct_ntags(file)) { | ||
496 | id3_file_struct_iterate(file, build_tag_options, &vopt); | ||
497 | if (vopt != convert_version) { | ||
498 | vopt = convert_version; | ||
499 | modified |= 1; | ||
500 | } | ||
501 | } | ||
502 | |||
503 | if (modified && vopt) { | ||
504 | int opts = 0; | ||
505 | 529 | ||
506 | if (vopt & IDEST_ID3V_1) | 530 | vopt = (source_tag && !has_tags) ? source_vopt : |
507 | opts |= ID3_TAG_OPTION_ID3V1; | 531 | guess_file_tag_options(file, &modified); |
508 | if (!(vopt & IDEST_ID3V_2)) | 532 | |
509 | opts |= ID3_TAG_OPTION_NO_ID3V2; | 533 | if (modified) { |
510 | id3_tag_options(tag, | 534 | set_tag_options(tag, vopt); |
511 | ID3_TAG_OPTION_ID3V1|ID3_TAG_OPTION_NO_ID3V2, | ||
512 | opts); | ||
513 | } | ||
514 | if (modified) | ||
515 | safe_id3_file_update_and_close(file); | 535 | safe_id3_file_update_and_close(file); |
516 | else | 536 | } else |
517 | id3_file_close(file); | 537 | id3_file_close(file); |
518 | } | 538 | } |
519 | 539 | ||
@@ -532,6 +552,8 @@ del_tags(const char *name) | |||
532 | if (filter_list) { | 552 | if (filter_list) { |
533 | int i; | 553 | int i; |
534 | struct id3_frame *frame; | 554 | struct id3_frame *frame; |
555 | int modified = 0; | ||
556 | int vopt; | ||
535 | 557 | ||
536 | for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); ) { | 558 | for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); ) { |
537 | const struct idest_frametab *ft = | 559 | const struct idest_frametab *ft = |
@@ -540,9 +562,13 @@ del_tags(const char *name) | |||
540 | frame, ft ? ft->cmp : NULL)) { | 562 | frame, ft ? ft->cmp : NULL)) { |
541 | id3_tag_detachframe(tag, frame); | 563 | id3_tag_detachframe(tag, frame); |
542 | id3_frame_delete(frame); | 564 | id3_frame_delete(frame); |
565 | modified = 1; | ||
543 | } else | 566 | } else |
544 | i++; | 567 | i++; |
545 | } | 568 | } |
569 | vopt = guess_file_tag_options(file, &modified); | ||
570 | if (modified) | ||
571 | set_tag_options(tag, vopt); | ||
546 | } else | 572 | } else |
547 | id3_tag_clearframes(tag); | 573 | id3_tag_clearframes(tag); |
548 | safe_id3_file_update_and_close(file); | 574 | safe_id3_file_update_and_close(file); |