bitmath: Finish up optimizations
[platform/upstream/flac.git] / src / metaflac / operations.c
index 204d2a4..62d5701 100644 (file)
@@ -1,5 +1,5 @@
 /* metaflac - Command-line FLAC metadata editor
- * Copyright (C) 2001,2002,2003,2004,2005,2006,2007  Josh Coalson
+ * Copyright (C) 2001,2002,2003,2004,2005,2006,2007,2008,2009  Josh Coalson
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -25,7 +25,9 @@
 #include "utils.h"
 #include "FLAC/assert.h"
 #include "FLAC/metadata.h"
+#include "share/alloc.h"
 #include "share/grabbag.h"
+#include "share/compat.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -117,7 +119,7 @@ FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOpt
                die("out of memory allocating chain");
 
        /*@@@@ lame way of guessing the file type */
-       if(strlen(filename) >= 4 && 0 == strcmp(filename+strlen(filename)-4, ".ogg"))
+       if(strlen(filename) >= 4 && (0 == strcmp(filename+strlen(filename)-4, ".oga") || 0 == strcmp(filename+strlen(filename)-4, ".ogg")))
                is_ogg = true;
 
        if(! (is_ogg? FLAC__metadata_chain_read_ogg(chain, filename) : FLAC__metadata_chain_read(chain, filename)) ) {
@@ -446,8 +448,8 @@ FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned nu
        }
 
        if(
-               0 == (title_gains = (float*)malloc(sizeof(float) * num_files)) ||
-               0 == (title_peaks = (float*)malloc(sizeof(float) * num_files))
+               0 == (title_gains = safe_malloc_mul_2op_(sizeof(float), /*times*/num_files)) ||
+               0 == (title_peaks = safe_malloc_mul_2op_(sizeof(float), /*times*/num_files))
        )
                die("out of memory allocating space for title gains/peaks");
 
@@ -564,11 +566,7 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
                        PPR; printf("  sample_rate: %u Hz\n", block->data.stream_info.sample_rate);
                        PPR; printf("  channels: %u\n", block->data.stream_info.channels);
                        PPR; printf("  bits-per-sample: %u\n", block->data.stream_info.bits_per_sample);
-#ifdef _MSC_VER
-                       PPR; printf("  total samples: %I64u\n", block->data.stream_info.total_samples);
-#else
-                       PPR; printf("  total samples: %llu\n", (unsigned long long)block->data.stream_info.total_samples);
-#endif
+                       PPR; printf("  total samples: %" PRIu64 "\n", block->data.stream_info.total_samples);
                        PPR; printf("  MD5 signature: ");
                        for(i = 0; i < 16; i++) {
                                printf("%02x", (unsigned)block->data.stream_info.md5sum[i]);
@@ -595,11 +593,7 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
                        PPR; printf("  seek points: %u\n", block->data.seek_table.num_points);
                        for(i = 0; i < block->data.seek_table.num_points; i++) {
                                if(block->data.seek_table.points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
-#ifdef _MSC_VER
-                                       PPR; printf("    point %u: sample_number=%I64u, stream_offset=%I64u, 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 %u: sample_number=%llu, stream_offset=%llu, frame_samples=%u\n", i, (unsigned long long)block->data.seek_table.points[i].sample_number, (unsigned long long)block->data.seek_table.points[i].stream_offset, block->data.seek_table.points[i].frame_samples);
-#endif
+                                       PPR; printf("    point %u: sample_number=%" PRIu64 ", stream_offset=%" PRIu64 ", 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 %u: PLACEHOLDER\n", i);
@@ -617,11 +611,7 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
                        break;
                case FLAC__METADATA_TYPE_CUESHEET:
                        PPR; printf("  media catalog number: %s\n", block->data.cue_sheet.media_catalog_number);
-#ifdef _MSC_VER
-                       PPR; printf("  lead-in: %I64u\n", block->data.cue_sheet.lead_in);
-#else
-                       PPR; printf("  lead-in: %llu\n", (unsigned long long)block->data.cue_sheet.lead_in);
-#endif
+                       PPR; printf("  lead-in: %" PRIu64 "\n", block->data.cue_sheet.lead_in);
                        PPR; printf("  is CD: %s\n", block->data.cue_sheet.is_cd? "true":"false");
                        PPR; printf("  number of tracks: %u\n", block->data.cue_sheet.num_tracks);
                        for(i = 0; i < block->data.cue_sheet.num_tracks; i++) {
@@ -629,11 +619,7 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
                                const FLAC__bool is_last = (i == block->data.cue_sheet.num_tracks-1);
                                const FLAC__bool is_leadout = is_last && track->num_indices == 0;
                                PPR; printf("    track[%u]\n", i);
-#ifdef _MSC_VER
-                               PPR; printf("      offset: %I64u\n", track->offset);
-#else
-                               PPR; printf("      offset: %llu\n", (unsigned long long)track->offset);
-#endif
+                               PPR; printf("      offset: %" PRIu64 "\n", track->offset);
                                if(is_last) {
                                        PPR; printf("      number: %u (%s)\n", (unsigned)track->number, is_leadout? "LEAD-OUT" : "INVALID");
                                }
@@ -648,11 +634,7 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
                                        for(j = 0; j < track->num_indices; j++) {
                                                const FLAC__StreamMetadata_CueSheet_Index *index = track->indices+j;
                                                PPR; printf("        index[%u]\n", j);
-#ifdef _MSC_VER
-                                               PPR; printf("          offset: %I64u\n", index->offset);
-#else
-                                               PPR; printf("          offset: %llu\n", (unsigned long long)index->offset);
-#endif
+                                               PPR; printf("          offset: %" PRIu64 "\n", index->offset);
                                                PPR; printf("          number: %u\n", (unsigned)index->number);
                                        }
                                }