X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmetaflac%2Foperations_shorthand_cuesheet.c;h=f59bc8993fec0f12e1818d18167c2375a59bfcb9;hb=3c84f9e86b40b64bb42af6dff8c61521c5439ecd;hp=a4d11a08220fac1f3c11029f7172ca45bf8efca1;hpb=4a839537f259a82fb9988671ef9ef7c5488b5dc6;p=platform%2Fupstream%2Fflac.git diff --git a/src/metaflac/operations_shorthand_cuesheet.c b/src/metaflac/operations_shorthand_cuesheet.c index a4d11a0..f59bc89 100644 --- a/src/metaflac/operations_shorthand_cuesheet.c +++ b/src/metaflac/operations_shorthand_cuesheet.c @@ -1,5 +1,5 @@ /* metaflac - Command-line FLAC metadata editor - * Copyright (C) 2001,2002,2003,2004,2005,2006 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 @@ -11,18 +11,25 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#if HAVE_CONFIG_H +# include +#endif + +#include +#include #include "options.h" #include "utils.h" #include "FLAC/assert.h" #include "share/grabbag.h" -#include +#include "share/compat.h" +#include "operations_shorthand.h" -static FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet, const char *cs_filename, FLAC__bool *needs_write, FLAC__uint64 lead_out_offset, FLAC__bool is_cdda, Argument_AddSeekpoint *add_seekpoint_link); +static FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet, const char *cs_filename, FLAC__bool *needs_write, FLAC__uint64 lead_out_offset, unsigned sample_rate, FLAC__bool is_cdda, Argument_AddSeekpoint *add_seekpoint_link); static FLAC__bool export_cs_to(const char *filename, const FLAC__StreamMetadata *cuesheet, const char *cs_filename); FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write) @@ -32,6 +39,7 @@ FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); FLAC__uint64 lead_out_offset = 0; FLAC__bool is_cdda = false; + unsigned sample_rate = 0; if(0 == iterator) die("out of memory allocating iterator"); @@ -47,7 +55,8 @@ FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata FLAC__metadata_iterator_delete(iterator); return false; } - is_cdda = (block->data.stream_info.channels == 1 || block->data.stream_info.channels == 2) && (block->data.stream_info.bits_per_sample == 16) && (block->data.stream_info.sample_rate == 44100); + sample_rate = block->data.stream_info.sample_rate; + is_cdda = (block->data.stream_info.channels == 1 || block->data.stream_info.channels == 2) && (block->data.stream_info.bits_per_sample == 16) && (sample_rate == 44100); } else if(block->type == FLAC__METADATA_TYPE_CUESHEET) cuesheet = block; @@ -66,7 +75,7 @@ FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata ok = false; } else { - ok = import_cs_from(filename, &cuesheet, operation->argument.import_cuesheet_from.filename, needs_write, lead_out_offset, is_cdda, operation->argument.import_cuesheet_from.add_seekpoint_link); + ok = import_cs_from(filename, &cuesheet, operation->argument.import_cuesheet_from.filename, needs_write, lead_out_offset, sample_rate, is_cdda, operation->argument.import_cuesheet_from.add_seekpoint_link); if(ok) { /* append CUESHEET block */ while(FLAC__metadata_iterator_next(iterator)) @@ -101,7 +110,7 @@ FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata * local routines */ -FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet, const char *cs_filename, FLAC__bool *needs_write, FLAC__uint64 lead_out_offset, FLAC__bool is_cdda, Argument_AddSeekpoint *add_seekpoint_link) +FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet, const char *cs_filename, FLAC__bool *needs_write, FLAC__uint64 lead_out_offset, unsigned sample_rate, FLAC__bool is_cdda, Argument_AddSeekpoint *add_seekpoint_link) { FILE *f; const char *error_message; @@ -118,11 +127,11 @@ FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet, f = fopen(cs_filename, "r"); if(0 == f) { - fprintf(stderr, "%s: ERROR: can't open import file %s\n", filename, cs_filename); + fprintf(stderr, "%s: ERROR: can't open import file %s: %s\n", filename, cs_filename, strerror(errno)); return false; } - *cuesheet = grabbag__cuesheet_parse(f, &error_message, &last_line_read, is_cdda, lead_out_offset); + *cuesheet = grabbag__cuesheet_parse(f, &error_message, &last_line_read, sample_rate, is_cdda, lead_out_offset); if(f != stdin) fclose(f); @@ -153,11 +162,7 @@ FLAC__bool import_cs_from(const char *filename, FLAC__StreamMetadata **cuesheet, for(track = 0; track < cs->num_tracks; track++) { const FLAC__StreamMetadata_CueSheet_Track *tr = cs->tracks+track; for(index = 0; index < tr->num_indices; index++) { -#ifdef _MSC_VER - sprintf(spec, "%I64u;", tr->offset + tr->indices[index].offset); -#else - sprintf(spec, "%llu;", tr->offset + tr->indices[index].offset); -#endif + flac_snprintf(spec, sizeof (spec), "%" PRIu64 ";", (tr->offset + tr->indices[index].offset)); local_strcat(seekpoint_specification, spec); } } @@ -183,17 +188,19 @@ FLAC__bool export_cs_to(const char *filename, const FLAC__StreamMetadata *cueshe f = fopen(cs_filename, "w"); if(0 == f) { - fprintf(stderr, "%s: ERROR: can't open export file %s\n", filename, cs_filename); + fprintf(stderr, "%s: ERROR: can't open export file %s: %s\n", filename, cs_filename, strerror(errno)); return false; } reflen = strlen(filename) + 7 + 1; if(0 == (ref = malloc(reflen))) { fprintf(stderr, "%s: ERROR: allocating memory\n", filename); + if(f != stdout) + fclose(f); return false; } - snprintf(ref, reflen, "\"%s\" FLAC", filename); + flac_snprintf(ref, reflen, "\"%s\" FLAC", filename); grabbag__cuesheet_emit(f, cuesheet, ref);