fix bug in MD5 sum printing
[flac.git] / src / metaflac / main.c
index 2b5c420..4f3b56a 100644 (file)
@@ -33,17 +33,19 @@ more powerful operations yet to add:
 #include <stdlib.h>
 #include <string.h>
 
-#if HAVE_GETOPT_LONG
+#if 0
+/*[JEC] was:#if HAVE_GETOPT_LONG*/
+/*[JEC] see flac/include/share/getopt.h as to why the change */
 #  include <getopt.h>
 #else
 #  include "share/getopt.h"
 #endif
 
 /*
-   getopt format struct; note we don't use short options so we just
+   FLAC__share__getopt format struct; note we don't use short options so we just
    set the 'val' field to 0 everywhere to indicate a valid option.
 */
-static struct option long_options_[] = {
+static struct FLAC__share__option long_options_[] = {
        /* global options */
     { "preserve-modtime", 0, 0, 0 },
     { "with-filename", 0, 0, 0 },
@@ -135,7 +137,7 @@ typedef struct {
 } Argument_BlockNumber;
 
 typedef struct {
-       FLAC__MetaDataType type;
+       FLAC__MetadataType type;
        char application_id[4]; /* only relevant if type == FLAC__STREAM_METADATA_TYPE_APPLICATION */
        FLAC__bool filter_application_by_id;
 } Argument_BlockTypeEntry;
@@ -201,7 +203,7 @@ typedef struct {
                unsigned capacity;
        } args;
        unsigned num_files;
-       const char **filenames;
+       char **filenames;
 } CommandLineOptions;
 
 static void die(const char *message);
@@ -226,25 +228,25 @@ static FLAC__bool parse_application_data_format(const char *in, FLAC__bool *out)
 static FLAC__bool do_operations(const CommandLineOptions *options);
 static FLAC__bool do_major_operation(const CommandLineOptions *options);
 static FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOptions *options);
-static FLAC__bool do_major_operation__list(const char *filename, FLAC__MetaData_Chain *chain, const CommandLineOptions *options);
-static FLAC__bool do_major_operation__append(FLAC__MetaData_Chain *chain, const CommandLineOptions *options);
-static FLAC__bool do_major_operation__remove(FLAC__MetaData_Chain *chain, const CommandLineOptions *options);
-static FLAC__bool do_major_operation__remove_all(FLAC__MetaData_Chain *chain, const CommandLineOptions *options);
+static FLAC__bool do_major_operation__list(const char *filename, FLAC__Metadata_Chain *chain, const CommandLineOptions *options);
+static FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const CommandLineOptions *options);
+static FLAC__bool do_major_operation__remove(FLAC__Metadata_Chain *chain, const CommandLineOptions *options);
+static FLAC__bool do_major_operation__remove_all(FLAC__Metadata_Chain *chain, const CommandLineOptions *options);
 static FLAC__bool do_shorthand_operations(const CommandLineOptions *options);
 static FLAC__bool do_shorthand_operations_on_file(const char *fielname, const CommandLineOptions *options);
-static FLAC__bool do_shorthand_operation(const char *filename, FLAC__MetaData_Chain *chain, const Operation *operation, FLAC__bool *needs_write);
-static FLAC__bool do_shorthand_operation__add_padding(FLAC__MetaData_Chain *chain, unsigned length, FLAC__bool *needs_write);
-static FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__MetaData_Chain *chain, OperationType op);
-static FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__MetaData_Chain *chain, const Operation *operation, FLAC__bool *needs_write);
-static FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetaData *block, unsigned block_number);
-static void write_metadata(const char *filename, FLAC__StreamMetaData *block, unsigned block_number, FLAC__bool hexdump_application);
-static void write_vc_field(const char *filename, const FLAC__StreamMetaData_VorbisComment_Entry *entry);
-static void write_vc_fields(const char *filename, const char *field_name, const FLAC__StreamMetaData_VorbisComment_Entry entry[], unsigned num_entries);
-static FLAC__bool remove_vc_all(FLAC__StreamMetaData *block, FLAC__bool *needs_write);
-static FLAC__bool remove_vc_field(FLAC__StreamMetaData *block, const char *field_name, FLAC__bool *needs_write);
-static FLAC__bool remove_vc_firstfield(FLAC__StreamMetaData *block, const char *field_name, FLAC__bool *needs_write);
-static FLAC__bool set_vc_field(FLAC__StreamMetaData *block, const Argument_VcField *field, FLAC__bool *needs_write);
-static FLAC__bool field_name_matches_entry(const char *field_name, unsigned field_name_length, const FLAC__StreamMetaData_VorbisComment_Entry *entry);
+static FLAC__bool do_shorthand_operation(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write);
+static FLAC__bool do_shorthand_operation__add_padding(FLAC__Metadata_Chain *chain, unsigned length, FLAC__bool *needs_write);
+static FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__Metadata_Chain *chain, OperationType op);
+static FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write);
+static FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetadata *block, unsigned block_number);
+static void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned block_number, FLAC__bool hexdump_application);
+static void write_vc_field(const char *filename, const FLAC__StreamMetadata_VorbisComment_Entry *entry);
+static void write_vc_fields(const char *filename, const char *field_name, const FLAC__StreamMetadata_VorbisComment_Entry entry[], unsigned num_entries);
+static FLAC__bool remove_vc_all(FLAC__StreamMetadata *block, FLAC__bool *needs_write);
+static FLAC__bool remove_vc_field(FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write);
+static FLAC__bool remove_vc_firstfield(FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write);
+static FLAC__bool set_vc_field(FLAC__StreamMetadata *block, const Argument_VcField *field, FLAC__bool *needs_write);
+static FLAC__bool field_name_matches_entry(const char *field_name, unsigned field_name_length, const FLAC__StreamMetadata_VorbisComment_Entry *entry);
 static void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const char *indent);
 
 int main(int argc, char *argv[])
@@ -304,10 +306,10 @@ FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options)
     int option_index = 1;
        FLAC__bool had_error = false;
 
-    while ((ret = getopt_long(argc, argv, "", long_options_, &option_index)) != -1) {
+    while ((ret = FLAC__share__getopt_long(argc, argv, "", long_options_, &option_index)) != -1) {
         switch (ret) {
             case 0:
-                               had_error |= !parse_option(option_index, optarg, options);
+                               had_error |= !parse_option(option_index, FLAC__share__optarg, options);
                 break;
                        case '?':
                        case ':':
@@ -320,22 +322,22 @@ FLAC__bool parse_options(int argc, char *argv[], CommandLineOptions *options)
     }
 
        if(options->prefix_with_filename == 2)
-               options->prefix_with_filename = (argc - optind > 1);
+               options->prefix_with_filename = (argc - FLAC__share__optind > 1);
 
-       if(optind >= argc && !options->show_long_help) {
+       if(FLAC__share__optind >= argc && !options->show_long_help) {
                fprintf(stderr,"ERROR: you must specify at least one FLAC file;\n");
                fprintf(stderr,"       metaflac cannot be used as a pipe\n");
                had_error = true;
        }
 
-       options->num_files = argc - optind;
+       options->num_files = argc - FLAC__share__optind;
 
        if(options->num_files > 0) {
                unsigned i = 0;
                if(0 == (options->filenames = malloc(sizeof(char *) * options->num_files)))
                        die("out of memory allocating space for file names list");
-               while(optind < argc)
-                       options->filenames[i++] = local_strdup(argv[optind++]);
+               while(FLAC__share__optind < argc)
+                       options->filenames[i++] = local_strdup(argv[FLAC__share__optind++]);
        }
 
        if(options->args.checks.num_major_ops > 0) {
@@ -1056,13 +1058,13 @@ FLAC__bool do_major_operation(const CommandLineOptions *options)
 FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOptions *options)
 {
        FLAC__bool ok = true, needs_write = false;
-       FLAC__MetaData_Chain *chain = FLAC__metadata_chain_new();
+       FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new();
 
        if(0 == chain)
                die("out of memory allocating chain");
 
        if(!FLAC__metadata_chain_read(chain, filename)) {
-               fprintf(stderr, "ERROR: reading metadata, status = \"%s\"\n", FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]);
+               fprintf(stderr, "ERROR: reading metadata, status = \"%s\"\n", FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
                return false;
        }
 
@@ -1100,7 +1102,7 @@ FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOpt
                        FLAC__metadata_chain_sort_padding(chain);
                ok = FLAC__metadata_chain_write(chain, options->use_padding, options->preserve_modtime);
                if(!ok)
-                       fprintf(stderr, "ERROR: writing FLAC file %s, error = %s\n", filename, FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]);
+                       fprintf(stderr, "ERROR: writing FLAC file %s, error = %s\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
        }
 
        FLAC__metadata_chain_delete(chain);
@@ -1108,10 +1110,10 @@ FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOpt
        return ok;
 }
 
-FLAC__bool do_major_operation__list(const char *filename, FLAC__MetaData_Chain *chain, const CommandLineOptions *options)
+FLAC__bool do_major_operation__list(const char *filename, FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
 {
-       FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new();
-       FLAC__StreamMetaData *block;
+       FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
+       FLAC__StreamMetadata *block;
        FLAC__bool ok = true;
        unsigned block_number;
 
@@ -1136,16 +1138,16 @@ FLAC__bool do_major_operation__list(const char *filename, FLAC__MetaData_Chain *
        return ok;
 }
 
-FLAC__bool do_major_operation__append(FLAC__MetaData_Chain *chain, const CommandLineOptions *options)
+FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
 {
        (void) chain, (void) options;
        fprintf(stderr, "ERROR: --append not implemented yet\n"); /*@@@*/
        return false;
 }
 
-FLAC__bool do_major_operation__remove(FLAC__MetaData_Chain *chain, const CommandLineOptions *options)
+FLAC__bool do_major_operation__remove(FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
 {
-       FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new();
+       FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
        FLAC__bool ok = true;
        unsigned block_number;
 
@@ -1157,8 +1159,11 @@ FLAC__bool do_major_operation__remove(FLAC__MetaData_Chain *chain, const Command
        block_number = 0;
        while(ok && FLAC__metadata_iterator_next(iterator)) {
                block_number++;
-               if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number))
+               if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number)) {
                        ok &= FLAC__metadata_iterator_delete_block(iterator, options->use_padding);
+                       if(options->use_padding)
+                               ok &= FLAC__metadata_iterator_next(iterator);
+               }
        }
 
        FLAC__metadata_iterator_delete(iterator);
@@ -1166,9 +1171,9 @@ FLAC__bool do_major_operation__remove(FLAC__MetaData_Chain *chain, const Command
        return ok;
 }
 
-FLAC__bool do_major_operation__remove_all(FLAC__MetaData_Chain *chain, const CommandLineOptions *options)
+FLAC__bool do_major_operation__remove_all(FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
 {
-       FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new();
+       FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
        FLAC__bool ok = true;
 
        if(0 == iterator)
@@ -1176,8 +1181,11 @@ FLAC__bool do_major_operation__remove_all(FLAC__MetaData_Chain *chain, const Com
 
        FLAC__metadata_iterator_init(iterator, chain);
 
-       while(ok && FLAC__metadata_iterator_next(iterator))
+       while(ok && FLAC__metadata_iterator_next(iterator)) {
                ok &= FLAC__metadata_iterator_delete_block(iterator, options->use_padding);
+               if(options->use_padding)
+                       ok &= FLAC__metadata_iterator_next(iterator);
+       }
 
        FLAC__metadata_iterator_delete(iterator);
 
@@ -1200,13 +1208,13 @@ FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLi
 {
        unsigned i;
        FLAC__bool ok = true, needs_write = false;
-       FLAC__MetaData_Chain *chain = FLAC__metadata_chain_new();
+       FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new();
 
        if(0 == chain)
                die("out of memory allocating chain");
 
        if(!FLAC__metadata_chain_read(chain, filename)) {
-               fprintf(stderr, "ERROR: reading metadata, status = \"%s\"\n", FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]);
+               fprintf(stderr, "ERROR: reading metadata, status = \"%s\"\n", FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
                return false;
        }
 
@@ -1218,7 +1226,7 @@ FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLi
                        FLAC__metadata_chain_sort_padding(chain);
                ok = FLAC__metadata_chain_write(chain, options->use_padding, options->preserve_modtime);
                if(!ok)
-                       fprintf(stderr, "ERROR: writing FLAC file %s, error = %s\n", filename, FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]);
+                       fprintf(stderr, "ERROR: writing FLAC file %s, error = %s\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
        }
 
        FLAC__metadata_chain_delete(chain);
@@ -1226,7 +1234,7 @@ FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLi
        return ok;
 }
 
-FLAC__bool do_shorthand_operation(const char *filename, FLAC__MetaData_Chain *chain, const Operation *operation, FLAC__bool *needs_write)
+FLAC__bool do_shorthand_operation(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write)
 {
        FLAC__bool ok = true;
 
@@ -1262,10 +1270,10 @@ FLAC__bool do_shorthand_operation(const char *filename, FLAC__MetaData_Chain *ch
        return ok;
 }
 
-FLAC__bool do_shorthand_operation__add_padding(FLAC__MetaData_Chain *chain, unsigned length, FLAC__bool *needs_write)
+FLAC__bool do_shorthand_operation__add_padding(FLAC__Metadata_Chain *chain, unsigned length, FLAC__bool *needs_write)
 {
-       FLAC__StreamMetaData *padding = 0;
-       FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new();
+       FLAC__StreamMetadata *padding = 0;
+       FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
 
        if(0 == iterator)
                die("out of memory allocating iterator");
@@ -1282,7 +1290,7 @@ FLAC__bool do_shorthand_operation__add_padding(FLAC__MetaData_Chain *chain, unsi
        padding->length = length;
 
        if(!FLAC__metadata_iterator_insert_block_after(iterator, padding)) {
-               fprintf(stderr, "ERROR: adding new PADDING block to metadata, status =\"%s\"\n", FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]);
+               fprintf(stderr, "ERROR: adding new PADDING block to metadata, status =\"%s\"\n", FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
                FLAC__metadata_object_delete(padding);
                return false;
        }
@@ -1291,12 +1299,12 @@ FLAC__bool do_shorthand_operation__add_padding(FLAC__MetaData_Chain *chain, unsi
        return true;
 }
 
-FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__MetaData_Chain *chain, OperationType op)
+FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__Metadata_Chain *chain, OperationType op)
 {
        unsigned i;
        FLAC__bool ok = true;
-       FLAC__StreamMetaData *block;
-       FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new();
+       FLAC__StreamMetadata *block;
+       FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
 
        if(0 == iterator)
                die("out of memory allocating iterator");
@@ -1352,11 +1360,11 @@ FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__MetaDa
        return ok;
 }
 
-FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__MetaData_Chain *chain, const Operation *operation, FLAC__bool *needs_write)
+FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write)
 {
        FLAC__bool ok = true, found_vc_block = false;
-       FLAC__StreamMetaData *block = 0;
-       FLAC__MetaData_Iterator *iterator = FLAC__metadata_iterator_new();
+       FLAC__StreamMetadata *block = 0;
+       FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
 
        if(0 == iterator)
                die("out of memory allocating iterator");
@@ -1377,7 +1385,7 @@ FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__Me
                while(FLAC__metadata_iterator_next(iterator))
                        ;
                if(!FLAC__metadata_iterator_insert_block_after(iterator, block)) {
-                       fprintf(stderr, "ERROR: adding new VORBIS_COMMENT block to metadata, status =\"%s\"\n", FLAC__MetaData_ChainStatusString[FLAC__metadata_chain_status(chain)]);
+                       fprintf(stderr, "ERROR: adding new VORBIS_COMMENT block to metadata, status =\"%s\"\n", FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
                        return false;
                }
                /* iterator is left pointing to new block */
@@ -1415,7 +1423,7 @@ FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__Me
        return ok;
 }
 
-FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetaData *block, unsigned block_number)
+FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetadata *block, unsigned block_number)
 {
        unsigned i, j;
        FLAC__bool matches_number = false, matches_type = false;
@@ -1453,14 +1461,14 @@ FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMe
        return matches_number && matches_type;
 }
 
-void write_metadata(const char *filename, FLAC__StreamMetaData *block, unsigned block_number, FLAC__bool hexdump_application)
+void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned block_number, FLAC__bool hexdump_application)
 {
        unsigned i;
 
 /*@@@ yuck, should do this with a varargs function or something: */
 #define PPR if(filename)printf("%s:",filename);
        PPR; printf("METADATA block #%u\n", block_number);
-       PPR; printf("  type: %u (%s)\n", (unsigned)block->type, block->type<=FLAC__METADATA_TYPE_VORBIS_COMMENT? FLAC__MetaDataTypeString[block->type] : "UNKNOWN");
+       PPR; printf("  type: %u (%s)\n", (unsigned)block->type, block->type<=FLAC__METADATA_TYPE_VORBIS_COMMENT? FLAC__MetadataTypeString[block->type] : "UNKNOWN");
        PPR; printf("  is last: %s\n", block->is_last? "true":"false");
        PPR; printf("  length: %u\n", block->length);
 
@@ -1476,9 +1484,9 @@ void write_metadata(const char *filename, FLAC__StreamMetaData *block, unsigned
                        PPR; printf("  total samples: %llu\n", block->data.stream_info.total_samples);
                        PPR; printf("  MD5 signature: ");
                        for(i = 0; i < 16; i++) {
-                               PPR; printf("%02x", block->data.stream_info.md5sum[i]);
+                               printf("%02x", (unsigned)block->data.stream_info.md5sum[i]);
                        }
-                       PPR; printf("\n");
+                       printf("\n");
                        break;
                case FLAC__METADATA_TYPE_PADDING:
                        /* nothing to print */
@@ -1500,10 +1508,24 @@ void write_metadata(const char *filename, FLAC__StreamMetaData *block, unsigned
                case FLAC__METADATA_TYPE_SEEKTABLE:
                        PPR; printf("  seek points: %u\n", block->data.seek_table.num_points);
                        for(i = 0; i < block->data.seek_table.num_points; i++) {
-                               PPR; printf("    point %d: sample_number=%llu, stream_offset=%llu, frame_samples=%u\n", i, block->data.seek_table.points[i].sample_number, block->data.seek_table.points[i].stream_offset, block->data.seek_table.points[i].frame_samples);
+                               if(block->data.seek_table.points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
+                                       PPR; printf("    point %d: sample_number=%llu, stream_offset=%llu, frame_samples=%u\n", i, block->data.seek_table.points[i].sample_number, block->data.seek_table.points[i].stream_offset, block->data.seek_table.points[i].frame_samples);
+                               }
+                               else {
+                                       PPR; printf("    point %d: PLACEHOLDER\n", i);
+                               }
                        }
                        break;
                case FLAC__METADATA_TYPE_VORBIS_COMMENT:
+                       PPR; printf("  vendor string: ");
+                       fwrite(block->data.vorbis_comment.vendor_string.entry, 1, block->data.vorbis_comment.vendor_string.length, stdout);
+                       printf("\n");
+                       PPR; printf("  comments: %u\n", block->data.vorbis_comment.num_comments);
+                       for(i = 0; i < block->data.vorbis_comment.num_comments; i++) {
+                               PPR; printf("    comment[%u]: ", i);
+                               fwrite(block->data.vorbis_comment.comments[i].entry, 1, block->data.vorbis_comment.comments[i].length, stdout);
+                               printf("\n");
+                       }
                        break;
                default:
                        PPR; printf("SKIPPING block of unknown type\n");
@@ -1512,7 +1534,7 @@ void write_metadata(const char *filename, FLAC__StreamMetaData *block, unsigned
 #undef PPR
 }
 
-void write_vc_field(const char *filename, const FLAC__StreamMetaData_VorbisComment_Entry *entry)
+void write_vc_field(const char *filename, const FLAC__StreamMetadata_VorbisComment_Entry *entry)
 {
        if(filename)
                printf("%s:", filename);
@@ -1520,7 +1542,7 @@ void write_vc_field(const char *filename, const FLAC__StreamMetaData_VorbisComme
        printf("\n");
 }
 
-void write_vc_fields(const char *filename, const char *field_name, const FLAC__StreamMetaData_VorbisComment_Entry entry[], unsigned num_entries)
+void write_vc_fields(const char *filename, const char *field_name, const FLAC__StreamMetadata_VorbisComment_Entry entry[], unsigned num_entries)
 {
        unsigned i;
        const unsigned field_name_length = strlen(field_name);
@@ -1531,26 +1553,26 @@ void write_vc_fields(const char *filename, const char *field_name, const FLAC__S
        }
 }
 
-FLAC__bool remove_vc_all(FLAC__StreamMetaData *block, FLAC__bool *needs_write)
+FLAC__bool remove_vc_all(FLAC__StreamMetadata *block, FLAC__bool *needs_write)
 {
        FLAC__ASSERT(0 != block);
        FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
        FLAC__ASSERT(0 != needs_write);
 
        if(0 != block->data.vorbis_comment.comments) {
-               FLAC__ASSERT(block->data.vorbis_comment.num_comments == 0);
+               FLAC__ASSERT(block->data.vorbis_comment.num_comments > 0);
                if(!FLAC__metadata_object_vorbiscomment_resize_comments(block, 0))
                        return false;
                *needs_write = true;
        }
        else {
-               FLAC__ASSERT(block->data.vorbis_comment.num_comments > 0);
+               FLAC__ASSERT(block->data.vorbis_comment.num_comments == 0);
        }
 
        return true;
 }
 
-FLAC__bool remove_vc_field(FLAC__StreamMetaData *block, const char *field_name, FLAC__bool *needs_write)
+FLAC__bool remove_vc_field(FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write)
 {
        FLAC__bool ok = true;
        const unsigned field_name_length = strlen(field_name);
@@ -1572,7 +1594,7 @@ FLAC__bool remove_vc_field(FLAC__StreamMetaData *block, const char *field_name,
        return ok;
 }
 
-FLAC__bool remove_vc_firstfield(FLAC__StreamMetaData *block, const char *field_name, FLAC__bool *needs_write)
+FLAC__bool remove_vc_firstfield(FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write)
 {
        const unsigned field_name_length = strlen(field_name);
        unsigned i;
@@ -1594,9 +1616,9 @@ FLAC__bool remove_vc_firstfield(FLAC__StreamMetaData *block, const char *field_n
        return true;
 }
 
-FLAC__bool set_vc_field(FLAC__StreamMetaData *block, const Argument_VcField *field, FLAC__bool *needs_write)
+FLAC__bool set_vc_field(FLAC__StreamMetadata *block, const Argument_VcField *field, FLAC__bool *needs_write)
 {
-       FLAC__StreamMetaData_VorbisComment_Entry entry;
+       FLAC__StreamMetadata_VorbisComment_Entry entry;
        FLAC__ASSERT(0 != block);
        FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
        FLAC__ASSERT(0 != field);
@@ -1614,7 +1636,7 @@ FLAC__bool set_vc_field(FLAC__StreamMetaData *block, const Argument_VcField *fie
        }
 }
 
-FLAC__bool field_name_matches_entry(const char *field_name, unsigned field_name_length, const FLAC__StreamMetaData_VorbisComment_Entry *entry)
+FLAC__bool field_name_matches_entry(const char *field_name, unsigned field_name_length, const FLAC__StreamMetadata_VorbisComment_Entry *entry)
 {
        return (0 != memchr(entry->entry, '=', entry->length) && 0 == strncmp(field_name, entry->entry, field_name_length));
 }