fix bug in MD5 sum printing
[flac.git] / src / metaflac / main.c
index 44951a2..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 },
@@ -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) {
@@ -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);
@@ -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);
 
@@ -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,7 +1508,12 @@ 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:
@@ -1547,13 +1560,13 @@ FLAC__bool remove_vc_all(FLAC__StreamMetadata *block, FLAC__bool *needs_write)
        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;