aboutsummaryrefslogtreecommitdiff
path: root/src/idop.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-29 14:33:27 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-07-29 14:33:27 +0300
commit8006a1de47d492a2fc15e314a3851fb40e6622bd (patch)
tree2d28aa3e671e5b5ccecc4ef0f2f60020d47e20e3 /src/idop.c
parent07e8fc8a6afe790f7e225601392cf6d17b6a3591 (diff)
downloadidest-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.c94
1 files changed, 60 insertions, 34 deletions
diff --git a/src/idop.c b/src/idop.c
index e549bcc..353bd46 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -39,20 +39,20 @@ parse_ed_items(gl_list_t *plist, const char *arg)
gl_list_t list;
if (!*plist)
*plist = ed_list_create();
list = *plist;
while (*arg) {
struct ed_item *itm;
- size_t len = strcspn(arg, " \t,");
+ size_t len = strcspn(arg, ",");
itm = ed_item_from_frame_spec(arg, len);
gl_list_add_last(list, itm);
arg += len;
if (!*arg)
break;
- arg += strspn(arg, " \t,");
+ arg += strspn(arg, ",");
}
}
void
parse_filter_items(const char *arg)
{
@@ -365,12 +365,54 @@ build_tag_options(struct id3_tag *tag, unsigned long location,
*(unsigned int*)data |= IDEST_ID3V_1;
else
*(unsigned int*)data |= IDEST_ID3V_2;
return 0;
}
+static void
+set_tag_options(struct id3_tag *tag, int vopt)
+{
+ int opts = 0;
+
+ if (vopt & IDEST_ID3V_1)
+ opts |= ID3_TAG_OPTION_ID3V1;
+ if (!(vopt & IDEST_ID3V_2))
+ opts |= ID3_TAG_OPTION_NO_ID3V2;
+ if (opts)
+ id3_tag_options(tag,
+ ID3_TAG_OPTION_ID3V1|ID3_TAG_OPTION_NO_ID3V2,
+ opts);
+}
+
+int
+guess_file_tag_options(struct id3_file *file, int *modified)
+{
+ int vopt = version_option;
+ int m = 0;
+
+ if (!modified)
+ modified = &m;
+ if (convert_version == 0) {
+ if (*modified && !vopt) {
+ if (id3_file_struct_ntags(file)) {
+ id3_file_struct_iterate(file,
+ build_tag_options,
+ &vopt);
+ } else
+ vopt = default_version_option;
+ }
+ } else if (id3_file_struct_ntags(file)) {
+ id3_file_struct_iterate(file, build_tag_options, &vopt);
+ if (vopt != convert_version) {
+ vopt = convert_version;
+ *modified |= 1;
+ }
+ }
+ return vopt;
+}
+
struct id3_frame *
find_matching_frame(struct id3_tag *tag, const struct ed_item *item,
idest_frame_cmp_t cmp)
{
struct id3_frame *frame;
@@ -449,17 +491,19 @@ copy_source_tags(struct id3_tag *tag)
void
set_tags(const char *name)
{
struct id3_file *file;
struct id3_tag *tag;
int modified = 0;
- int vopt = version_option;
-
+ int vopt;
+ int has_tags;
+
file = id3_file_open(name, ID3_FILE_MODE_READWRITE);
if (!file)
error(1, errno, "cannot open file %s", name);
+ has_tags = id3_file_struct_ntags(file);
tag = id3_file_tag(file);
if (!tag)
abort(); /* FIXME */
if (input_list) {
gl_list_iterator_t itr;
@@ -479,44 +523,20 @@ set_tags(const char *name)
}
modified |= copy_source_tags(tag);
/* FIXME */
modified |= guile_transform(name, tag);
-
- if (convert_version == 0) {
- if (modified && !vopt) {
- if (id3_file_struct_ntags(file)) {
- id3_file_struct_iterate(file,
- build_tag_options,
- &vopt);
- } else
- vopt = default_version_option;
- }
- } else if (id3_file_struct_ntags(file)) {
- id3_file_struct_iterate(file, build_tag_options, &vopt);
- if (vopt != convert_version) {
- vopt = convert_version;
- modified |= 1;
- }
- }
-
- if (modified && vopt) {
- int opts = 0;
- if (vopt & IDEST_ID3V_1)
- opts |= ID3_TAG_OPTION_ID3V1;
- if (!(vopt & IDEST_ID3V_2))
- opts |= ID3_TAG_OPTION_NO_ID3V2;
- id3_tag_options(tag,
- ID3_TAG_OPTION_ID3V1|ID3_TAG_OPTION_NO_ID3V2,
- opts);
- }
- if (modified)
+ vopt = (source_tag && !has_tags) ? source_vopt :
+ guess_file_tag_options(file, &modified);
+
+ if (modified) {
+ set_tag_options(tag, vopt);
safe_id3_file_update_and_close(file);
- else
+ } else
id3_file_close(file);
}
void
del_tags(const char *name)
{
@@ -529,23 +549,29 @@ del_tags(const char *name)
tag = id3_file_tag(file);
if (!tag)
abort(); /* FIXME */
if (filter_list) {
int i;
struct id3_frame *frame;
+ int modified = 0;
+ int vopt;
for (i = 0; (frame = id3_tag_findframe(tag, NULL, i)); ) {
const struct idest_frametab *ft =
idest_frame_lookup(frame->id);
if (ed_list_locate(filter_list,
frame, ft ? ft->cmp : NULL)) {
id3_tag_detachframe(tag, frame);
id3_frame_delete(frame);
+ modified = 1;
} else
i++;
}
+ vopt = guess_file_tag_options(file, &modified);
+ if (modified)
+ set_tag_options(tag, vopt);
} else
id3_tag_clearframes(tag);
safe_id3_file_update_and_close(file);
}
static void

Return to:

Send suggestions and report system problems to the System administrator.