replace verbose/silent flags with a verbosity level
authorJosh Coalson <jcoalson@users.sourceforce.net>
Sun, 18 Jul 2004 01:23:52 +0000 (01:23 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Sun, 18 Jul 2004 01:23:52 +0000 (01:23 +0000)
src/flac/decode.c
src/flac/decode.h
src/flac/encode.c
src/flac/encode.h
src/flac/main.c
src/flac/utils.c
src/flac/utils.h

index 7a6d2ba..18b15c4 100644 (file)
@@ -43,8 +43,6 @@ typedef struct {
        FLAC__bool is_ogg;
 #endif
 
-       FLAC__bool verbose;
-       FLAC__bool silent;
        FLAC__bool is_aiff_out;
        FLAC__bool is_wave_out;
        FLAC__bool continue_through_decode_errors;
@@ -106,20 +104,20 @@ static FLAC__bool is_big_endian_host_;
 /*
  * local routines
  */
-static FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__bool verbose, FLAC__bool silent, FLAC__bool is_aiff_out, FLAC__bool is_wave_out, FLAC__bool continue_through_decode_errors, replaygain_synthesis_spec_t replaygain_synthesis_spec, FLAC__bool analysis_mode, analysis_options aopts, utils__SkipUntilSpecification *skip_specification, utils__SkipUntilSpecification *until_specification, utils__CueSpecification *cue_specification, const char *infilename, const char *outfilename);
+static FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__bool is_aiff_out, FLAC__bool is_wave_out, FLAC__bool continue_through_decode_errors, replaygain_synthesis_spec_t replaygain_synthesis_spec, FLAC__bool analysis_mode, analysis_options aopts, utils__SkipUntilSpecification *skip_specification, utils__SkipUntilSpecification *until_specification, utils__CueSpecification *cue_specification, const char *infilename, const char *outfilename);
 static void DecoderSession_destroy(DecoderSession *d, FLAC__bool error_occurred);
 static FLAC__bool DecoderSession_init_decoder(DecoderSession *d, decode_options_t decode_options, const char *infilename);
 static FLAC__bool DecoderSession_process(DecoderSession *d);
 static int DecoderSession_finish_ok(DecoderSession *d);
 static int DecoderSession_finish_error(DecoderSession *d);
-static FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input, FLAC__bool silent);
+static FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input);
 static FLAC__bool write_necessary_headers(DecoderSession *decoder_session);
 static FLAC__bool write_little_endian_uint16(FILE *f, FLAC__uint16 val);
 static FLAC__bool write_little_endian_uint32(FILE *f, FLAC__uint32 val);
 static FLAC__bool write_big_endian_uint16(FILE *f, FLAC__uint16 val);
 static FLAC__bool write_big_endian_uint32(FILE *f, FLAC__uint32 val);
 static FLAC__bool write_sane_extended(FILE *f, unsigned val);
-static FLAC__bool fixup_wave_chunk_size(const char *outfilename, FLAC__bool is_wave_out, unsigned riff_offset, unsigned data_offset, unsigned frames_offset, FLAC__uint32 total_samples, unsigned channels, unsigned bps, FLAC__bool silent);
+static FLAC__bool fixup_wave_chunk_size(const char *outfilename, FLAC__bool is_wave_out, unsigned riff_offset, unsigned data_offset, unsigned frames_offset, FLAC__uint32 total_samples, unsigned channels, unsigned bps);
 /*
  * We use 'void *' so that we can use the same callbacks for the
  * FLAC__StreamDecoder and FLAC__FileDecoder.  The 'decoder' argument is
@@ -147,8 +145,6 @@ int flac__decode_aiff(const char *infilename, const char *outfilename, FLAC__boo
 #else
                        /*is_ogg=*/false,
 #endif
-                       options.common.verbose,
-                       options.common.silent,
                        /*is_aiff_out=*/true,
                        /*is_wave_out=*/false,
                        options.common.continue_through_decode_errors,
@@ -185,8 +181,6 @@ int flac__decode_wav(const char *infilename, const char *outfilename, FLAC__bool
 #else
                        /*is_ogg=*/false,
 #endif
-                       options.common.verbose,
-                       options.common.silent,
                        /*is_aiff_out=*/false,
                        /*is_wave_out=*/true,
                        options.common.continue_through_decode_errors,
@@ -226,8 +220,6 @@ int flac__decode_raw(const char *infilename, const char *outfilename, FLAC__bool
 #else
                        /*is_ogg=*/false,
 #endif
-                       options.common.verbose,
-                       options.common.silent,
                        /*is_aiff_out=*/false,
                        /*is_wave_out=*/false,
                        options.common.continue_through_decode_errors,
@@ -252,7 +244,7 @@ int flac__decode_raw(const char *infilename, const char *outfilename, FLAC__bool
        return DecoderSession_finish_ok(&decoder_session);
 }
 
-FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__bool verbose, FLAC__bool silent, FLAC__bool is_aiff_out, FLAC__bool is_wave_out, FLAC__bool continue_through_decode_errors, replaygain_synthesis_spec_t replaygain_synthesis_spec, FLAC__bool analysis_mode, analysis_options aopts, utils__SkipUntilSpecification *skip_specification, utils__SkipUntilSpecification *until_specification, utils__CueSpecification *cue_specification, const char *infilename, const char *outfilename)
+FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__bool is_aiff_out, FLAC__bool is_wave_out, FLAC__bool continue_through_decode_errors, replaygain_synthesis_spec_t replaygain_synthesis_spec, FLAC__bool analysis_mode, analysis_options aopts, utils__SkipUntilSpecification *skip_specification, utils__SkipUntilSpecification *until_specification, utils__CueSpecification *cue_specification, const char *infilename, const char *outfilename)
 {
 #ifdef FLAC__HAS_OGG
        d->is_ogg = is_ogg;
@@ -260,8 +252,6 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__
        (void)is_ogg;
 #endif
 
-       d->verbose = verbose;
-       d->silent = silent;
        d->is_aiff_out = is_aiff_out;
        d->is_wave_out = is_wave_out;
        d->continue_through_decode_errors = continue_through_decode_errors;
@@ -301,7 +291,7 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__
                }
                else {
                        if(0 == (d->fout = fopen(outfilename, "wb"))) {
-                               if(!d->silent) fprintf(stderr, "%s: ERROR: can't open output file %s\n", d->inbasefilename, outfilename);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: can't open output file %s\n", d->inbasefilename, outfilename);
                                DecoderSession_destroy(d, /*error_occurred=*/true);
                                return false;
                        }
@@ -334,7 +324,7 @@ FLAC__bool DecoderSession_init_decoder(DecoderSession *decoder_session, decode_o
                decoder_session->decoder.ogg.file = OggFLAC__file_decoder_new();
 
                if(0 == decoder_session->decoder.ogg.file) {
-                       if(!decoder_session->silent) fprintf(stderr, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename);
                        return false;
                }
 
@@ -370,7 +360,7 @@ FLAC__bool DecoderSession_init_decoder(DecoderSession *decoder_session, decode_o
                decoder_session->decoder.flac.file = FLAC__file_decoder_new();
 
                if(0 == decoder_session->decoder.flac.file) {
-                       if(!decoder_session->silent) fprintf(stderr, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename);
                        return false;
                }
 
@@ -403,12 +393,12 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
 #ifdef FLAC__HAS_OGG
        if(d->is_ogg) {
                if(!OggFLAC__file_decoder_process_until_end_of_metadata(d->decoder.ogg.file)) {
-                       if(d->verbose) fprintf(stderr, "\n");
+                       flac__utils_printf(stderr, 2, "\n");
                        print_error_with_state(d, "ERROR while decoding metadata");
                        return false;
                }
                if(OggFLAC__file_decoder_get_state(d->decoder.ogg.file) != OggFLAC__FILE_DECODER_OK && OggFLAC__file_decoder_get_state(d->decoder.ogg.file) != OggFLAC__FILE_DECODER_END_OF_FILE) {
-                       if(d->verbose) fprintf(stderr, "\n");
+                       flac__utils_printf(stderr, 2, "\n");
                        print_error_with_state(d, "ERROR during metadata decoding");
                        return false;
                }
@@ -417,12 +407,12 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
 #endif
        {
                if(!FLAC__file_decoder_process_until_end_of_metadata(d->decoder.flac.file)) {
-                       if(d->verbose) fprintf(stderr, "\n");
+                       flac__utils_printf(stderr, 2, "\n");
                        print_error_with_state(d, "ERROR while decoding metadata");
                        return false;
                }
                if(FLAC__file_decoder_get_state(d->decoder.flac.file) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(d->decoder.flac.file) != FLAC__FILE_DECODER_END_OF_FILE) {
-                       if(d->verbose) fprintf(stderr, "\n");
+                       flac__utils_printf(stderr, 2, "\n");
                        print_error_with_state(d, "ERROR during metadata decoding");
                        return false;
                }
@@ -446,12 +436,12 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
                                return false;
                        }
                        if(!OggFLAC__file_decoder_process_until_end_of_file(d->decoder.ogg.file) && !d->aborting_due_to_until) {
-                               if(d->verbose) fprintf(stderr, "\n");
+                               flac__utils_printf(stderr, 2, "\n");
                                print_error_with_state(d, "ERROR while decoding frames");
                                return false;
                        }
                        if(OggFLAC__file_decoder_get_state(d->decoder.ogg.file) != OggFLAC__FILE_DECODER_OK && OggFLAC__file_decoder_get_state(d->decoder.ogg.file) != OggFLAC__FILE_DECODER_END_OF_FILE && !d->aborting_due_to_until) {
-                               if(d->verbose) fprintf(stderr, "\n");
+                               flac__utils_printf(stderr, 2, "\n");
                                print_error_with_state(d, "ERROR during decoding");
                                return false;
                        }
@@ -464,12 +454,12 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
                                return false;
                        }
                        if(!FLAC__file_decoder_process_until_end_of_file(d->decoder.flac.file) && !d->aborting_due_to_until) {
-                               if(d->verbose) fprintf(stderr, "\n");
+                               flac__utils_printf(stderr, 2, "\n");
                                print_error_with_state(d, "ERROR while decoding frames");
                                return false;
                        }
                        if(FLAC__file_decoder_get_state(d->decoder.flac.file) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(d->decoder.flac.file) != FLAC__FILE_DECODER_END_OF_FILE && !d->aborting_due_to_until) {
-                               if(d->verbose) fprintf(stderr, "\n");
+                               flac__utils_printf(stderr, 2, "\n");
                                print_error_with_state(d, "ERROR during decoding");
                                return false;
                        }
@@ -479,12 +469,12 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
 #ifdef FLAC__HAS_OGG
                if(d->is_ogg) {
                        if(!OggFLAC__file_decoder_process_until_end_of_file(d->decoder.ogg.file) && !d->aborting_due_to_until) {
-                               if(d->verbose) fprintf(stderr, "\n");
+                               flac__utils_printf(stderr, 2, "\n");
                                print_error_with_state(d, "ERROR while decoding data");
                                return false;
                        }
                        if(OggFLAC__file_decoder_get_state(d->decoder.ogg.file) != OggFLAC__FILE_DECODER_OK && OggFLAC__file_decoder_get_state(d->decoder.ogg.file) != OggFLAC__FILE_DECODER_END_OF_FILE && !d->aborting_due_to_until) {
-                               if(d->verbose) fprintf(stderr, "\n");
+                               flac__utils_printf(stderr, 2, "\n");
                                print_error_with_state(d, "ERROR during decoding");
                                return false;
                        }
@@ -493,12 +483,12 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
 #endif
                {
                        if(!FLAC__file_decoder_process_until_end_of_file(d->decoder.flac.file) && !d->aborting_due_to_until) {
-                               if(d->verbose) fprintf(stderr, "\n");
+                               flac__utils_printf(stderr, 2, "\n");
                                print_error_with_state(d, "ERROR while decoding data");
                                return false;
                        }
                        if(FLAC__file_decoder_get_state(d->decoder.flac.file) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(d->decoder.flac.file) != FLAC__FILE_DECODER_END_OF_FILE && !d->aborting_due_to_until) {
-                               if(d->verbose) fprintf(stderr, "\n");
+                               flac__utils_printf(stderr, 2, "\n");
                                print_error_with_state(d, "ERROR during decoding");
                                return false;
                        }
@@ -539,14 +529,14 @@ int DecoderSession_finish_ok(DecoderSession *d)
        if(d->analysis_mode)
                flac__analyze_finish(d->aopts);
        if(md5_failure) {
-               if(!d->silent) fprintf(stderr, "\r%s: WARNING, MD5 signature mismatch\n", d->inbasefilename);
+               flac__utils_printf(stderr, 1, "\r%s: WARNING, MD5 signature mismatch\n", d->inbasefilename);
        }
        else {
-               if(d->verbose) fprintf(stderr, "\r%s: %s         \n", d->inbasefilename, d->test_only? "ok           ":d->analysis_mode?"done           ":"done");
+               flac__utils_printf(stderr, 2, "\r%s: %s         \n", d->inbasefilename, d->test_only? "ok           ":d->analysis_mode?"done           ":"done");
        }
        DecoderSession_destroy(d, /*error_occurred=*/false);
        if((d->is_wave_out || d->is_aiff_out) && d->wave_chunk_size_fixup.needs_fixup)
-               if(!fixup_wave_chunk_size(d->outfilename, d->is_wave_out, d->wave_chunk_size_fixup.riff_offset, d->wave_chunk_size_fixup.data_offset, d->wave_chunk_size_fixup.frames_offset, (FLAC__uint32)d->samples_processed, d->channels, d->bps, d->silent))
+               if(!fixup_wave_chunk_size(d->outfilename, d->is_wave_out, d->wave_chunk_size_fixup.riff_offset, d->wave_chunk_size_fixup.data_offset, d->wave_chunk_size_fixup.frames_offset, (FLAC__uint32)d->samples_processed, d->channels, d->bps))
                        return 1;
        return 0;
 }
@@ -574,7 +564,7 @@ int DecoderSession_finish_error(DecoderSession *d)
        return 1;
 }
 
-FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input, FLAC__bool silent)
+FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input)
 {
        /* convert from mm:ss.sss to sample number if necessary */
        flac__utils_canonicalize_skip_until_specification(spec, sample_rate);
@@ -587,7 +577,7 @@ FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec,
 
        /* in any other case the total samples in the input must be known */
        if(total_samples_in_input == 0) {
-               if(!silent) fprintf(stderr, "%s: ERROR, cannot use --until when FLAC metadata has total sample count of 0\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR, cannot use --until when FLAC metadata has total sample count of 0\n", inbasefilename);
                return false;
        }
 
@@ -604,15 +594,15 @@ FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec,
 
        /* error check */
        if(spec->value.samples < 0) {
-               if(!silent) fprintf(stderr, "%s: ERROR, --until value is before beginning of input\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR, --until value is before beginning of input\n", inbasefilename);
                return false;
        }
        if((FLAC__uint64)spec->value.samples <= skip) {
-               if(!silent) fprintf(stderr, "%s: ERROR, --until value is before --skip point\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR, --until value is before --skip point\n", inbasefilename);
                return false;
        }
        if((FLAC__uint64)spec->value.samples > total_samples_in_input) {
-               if(!silent) fprintf(stderr, "%s: ERROR, --until value is after end of input\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR, --until value is after end of input\n", inbasefilename);
                return false;
        }
 
@@ -627,16 +617,16 @@ FLAC__bool write_necessary_headers(DecoderSession *decoder_session)
                FLAC__uint64 data_size = decoder_session->total_samples * decoder_session->channels * ((decoder_session->bps+7)/8);
                if(decoder_session->total_samples == 0) {
                        if(decoder_session->fout == stdout) {
-                               if(!decoder_session->silent) fprintf(stderr, "%s: WARNING, don't have accurate sample count available for %s header.\n", decoder_session->inbasefilename, fmt_desc);
-                               if(!decoder_session->silent) fprintf(stderr, "             Generated %s file will have a data chunk size of 0.  Try\n", fmt_desc);
-                               if(!decoder_session->silent) fprintf(stderr, "             decoding directly to a file instead.\n");
+                               flac__utils_printf(stderr, 1, "%s: WARNING, don't have accurate sample count available for %s header.\n", decoder_session->inbasefilename, fmt_desc);
+                               flac__utils_printf(stderr, 1, "             Generated %s file will have a data chunk size of 0.  Try\n", fmt_desc);
+                               flac__utils_printf(stderr, 1, "             decoding directly to a file instead.\n");
                        }
                        else {
                                decoder_session->wave_chunk_size_fixup.needs_fixup = true;
                        }
                }
                if(data_size >= 0xFFFFFFDC) {
-                       if(!decoder_session->silent) fprintf(stderr, "%s: ERROR: stream is too big to fit in a single %s file chunk\n", decoder_session->inbasefilename, fmt_desc);
+                       flac__utils_printf(stderr, 1, "%s: ERROR: stream is too big to fit in a single %s file chunk\n", decoder_session->inbasefilename, fmt_desc);
                        return false;
                }
                if(decoder_session->is_wave_out) {
@@ -808,7 +798,7 @@ FLAC__bool write_sane_extended(FILE *f, unsigned val)
        return true;
 }
 
-FLAC__bool fixup_wave_chunk_size(const char *outfilename, FLAC__bool is_wave_out, unsigned riff_offset, unsigned data_offset, unsigned frames_offset, FLAC__uint32 total_samples, unsigned channels, unsigned bps, FLAC__bool silent)
+FLAC__bool fixup_wave_chunk_size(const char *outfilename, FLAC__bool is_wave_out, unsigned riff_offset, unsigned data_offset, unsigned frames_offset, FLAC__uint32 total_samples, unsigned channels, unsigned bps)
 {
        const char *fmt_desc = (is_wave_out? "WAVE" : "AIFF");
        FLAC__bool (*write_it)(FILE *, FLAC__uint32) = (is_wave_out? write_little_endian_uint32 : write_big_endian_uint32);
@@ -816,7 +806,7 @@ FLAC__bool fixup_wave_chunk_size(const char *outfilename, FLAC__bool is_wave_out
        FLAC__uint32 data_size, aligned_data_size;
 
        if(0 == f) {
-               if(!silent) fprintf(stderr, "ERROR, couldn't open file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
+               flac__utils_printf(stderr, 1, "ERROR, couldn't open file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
                return false;
        }
 
@@ -825,34 +815,34 @@ FLAC__bool fixup_wave_chunk_size(const char *outfilename, FLAC__bool is_wave_out
                aligned_data_size++;
 
        if(fseek(f, riff_offset, SEEK_SET) < 0) {
-               if(!silent) fprintf(stderr, "ERROR, couldn't seek in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
+               flac__utils_printf(stderr, 1, "ERROR, couldn't seek in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
                fclose(f);
                return false;
        }
        if(!write_it(f, aligned_data_size + (is_wave_out? 36 : 46))) {
-               if(!silent) fprintf(stderr, "ERROR, couldn't write size in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
+               flac__utils_printf(stderr, 1, "ERROR, couldn't write size in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
                fclose(f);
                return false;
        }
        if(!is_wave_out) {
                if(fseek(f, frames_offset, SEEK_SET) < 0) {
-                       if(!silent) fprintf(stderr, "ERROR, couldn't seek in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
+                       flac__utils_printf(stderr, 1, "ERROR, couldn't seek in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
                        fclose(f);
                        return false;
                }
                if(!write_it(f, total_samples)) {
-                       if(!silent) fprintf(stderr, "ERROR, couldn't write size in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
+                       flac__utils_printf(stderr, 1, "ERROR, couldn't write size in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
                        fclose(f);
                        return false;
                }
        }
        if(fseek(f, data_offset, SEEK_SET) < 0) {
-               if(!silent) fprintf(stderr, "ERROR, couldn't seek in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
+               flac__utils_printf(stderr, 1, "ERROR, couldn't seek in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
                fclose(f);
                return false;
        }
        if(!write_it(f, data_size + (is_wave_out? 0 : 8))) {
-               if(!silent) fprintf(stderr, "ERROR, couldn't write size in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
+               flac__utils_printf(stderr, 1, "ERROR, couldn't write size in file %s while fixing up %s chunk size\n", outfilename, fmt_desc);
                fclose(f);
                return false;
        }
@@ -881,15 +871,15 @@ FLAC__StreamDecoderWriteStatus write_callback(const void *decoder, const FLAC__F
                return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
 
        if(bps != decoder_session->bps) {
-               if(!decoder_session->silent) fprintf(stderr, "%s: ERROR, bits-per-sample is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, bps, decoder_session->bps);
+               flac__utils_printf(stderr, 1, "%s: ERROR, bits-per-sample is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, bps, decoder_session->bps);
                return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
        }
        if(channels != decoder_session->channels) {
-               if(!decoder_session->silent) fprintf(stderr, "%s: ERROR, channels is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, channels, decoder_session->channels);
+               flac__utils_printf(stderr, 1, "%s: ERROR, channels is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, channels, decoder_session->channels);
                return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
        }
        if(frame->header.sample_rate != decoder_session->sample_rate) {
-               if(!decoder_session->silent) fprintf(stderr, "%s: ERROR, sample rate is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, frame->header.sample_rate, decoder_session->sample_rate);
+               flac__utils_printf(stderr, 1, "%s: ERROR, sample rate is %u in frame but %u in STREAMINFO\n", decoder_session->inbasefilename, frame->header.sample_rate, decoder_session->sample_rate);
                return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
        }
 
@@ -918,7 +908,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const void *decoder, const FLAC__F
                decoder_session->samples_processed += wide_samples;
                decoder_session->frame_counter++;
 
-               if(decoder_session->verbose && !(decoder_session->frame_counter & 0x3f))
+               if(!(decoder_session->frame_counter & 0x3f))
                        print_stats(decoder_session);
 
                if(decoder_session->analysis_mode) {
@@ -1050,12 +1040,12 @@ void metadata_callback(const void *decoder, const FLAC__StreamMetadata *metadata
 
                /* remember, metadata->data.stream_info.total_samples can be 0, meaning 'unknown' */
                if(metadata->data.stream_info.total_samples > 0 && skip >= metadata->data.stream_info.total_samples) {
-                       if(!decoder_session->silent) fprintf(stderr, "%s: ERROR trying to --skip more samples than in stream\n", decoder_session->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR trying to --skip more samples than in stream\n", decoder_session->inbasefilename);
                        decoder_session->abort_flag = true;
                        return;
                }
                else if(metadata->data.stream_info.total_samples == 0 && skip > 0) {
-                       if(!decoder_session->silent) fprintf(stderr, "%s: ERROR, can't --skip when FLAC metadata has total sample count of 0\n", decoder_session->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR, can't --skip when FLAC metadata has total sample count of 0\n", decoder_session->inbasefilename);
                        decoder_session->abort_flag = true;
                        return;
                }
@@ -1063,7 +1053,7 @@ void metadata_callback(const void *decoder, const FLAC__StreamMetadata *metadata
                decoder_session->total_samples = metadata->data.stream_info.total_samples - skip;
 
                /* note that we use metadata->data.stream_info.total_samples instead of decoder_session->total_samples */
-               if(!canonicalize_until_specification(decoder_session->until_specification, decoder_session->inbasefilename, decoder_session->sample_rate, skip, metadata->data.stream_info.total_samples, decoder_session->silent)) {
+               if(!canonicalize_until_specification(decoder_session->until_specification, decoder_session->inbasefilename, decoder_session->sample_rate, skip, metadata->data.stream_info.total_samples)) {
                        decoder_session->abort_flag = true;
                        return;
                }
@@ -1077,7 +1067,7 @@ void metadata_callback(const void *decoder, const FLAC__StreamMetadata *metadata
                }
 
                if(decoder_session->bps != 8 && decoder_session->bps != 16 && decoder_session->bps != 24) {
-                       if(!decoder_session->silent) fprintf(stderr, "%s: ERROR: bits per sample is not 8/16/24\n", decoder_session->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR: bits per sample is not 8/16/24\n", decoder_session->inbasefilename);
                        decoder_session->abort_flag = true;
                        return;
                }
@@ -1085,7 +1075,7 @@ void metadata_callback(const void *decoder, const FLAC__StreamMetadata *metadata
        else if(metadata->type == FLAC__METADATA_TYPE_CUESHEET) {
                /* remember, at this point, decoder_session->total_samples can be 0, meaning 'unknown' */
                if(decoder_session->total_samples == 0) {
-                       if(!decoder_session->silent) fprintf(stderr, "%s: ERROR can't use --cue when FLAC metadata has total sample count of 0\n", decoder_session->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR can't use --cue when FLAC metadata has total sample count of 0\n", decoder_session->inbasefilename);
                        decoder_session->abort_flag = true;
                        return;
                }
@@ -1109,7 +1099,7 @@ void metadata_callback(const void *decoder, const FLAC__StreamMetadata *metadata
                if (decoder_session->replaygain.spec.apply) {
                        double gain, peak;
                        if (!(decoder_session->replaygain.apply = grabbag__replaygain_load_from_vorbiscomment(metadata, decoder_session->replaygain.spec.use_album_gain, &gain, &peak))) {
-                               if(!decoder_session->silent) fprintf(stderr, "%s: WARNING: can't get %s ReplayGain tag\n", decoder_session->inbasefilename, decoder_session->replaygain.spec.use_album_gain? "album":"track");
+                               flac__utils_printf(stderr, 1, "%s: WARNING: can't get %s ReplayGain tag\n", decoder_session->inbasefilename, decoder_session->replaygain.spec.use_album_gain? "album":"track");
                        }
                        else {
                                const char *ls[] = { "no", "peak", "hard" };
@@ -1117,8 +1107,8 @@ void metadata_callback(const void *decoder, const FLAC__StreamMetadata *metadata
                                decoder_session->replaygain.scale = grabbag__replaygain_compute_scale_factor(peak, gain, decoder_session->replaygain.spec.preamp, decoder_session->replaygain.spec.limiter == RGSS_LIMIT__PEAK);
                                FLAC__ASSERT(decoder_session->bps > 0 && decoder_session->bps <= 32);
                                FLAC__replaygain_synthesis__init_dither_context(&decoder_session->replaygain.dither_context, decoder_session->bps, decoder_session->replaygain.spec.noise_shaping);
-                               if(!decoder_session->silent) fprintf(stderr, "%s: INFO: applying %s ReplayGain (gain=%0.2fdB+preamp=%0.1fdB, %s noise shaping, %s limiting) to output\n", decoder_session->inbasefilename, decoder_session->replaygain.spec.use_album_gain? "album":"track", gain, decoder_session->replaygain.spec.preamp, ns[decoder_session->replaygain.spec.noise_shaping], ls[decoder_session->replaygain.spec.limiter]);
-                               if(!decoder_session->silent) fprintf(stderr, "%s: WARNING: applying ReplayGain is not lossless\n", decoder_session->inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: INFO: applying %s ReplayGain (gain=%0.2fdB+preamp=%0.1fdB, %s noise shaping, %s limiting) to output\n", decoder_session->inbasefilename, decoder_session->replaygain.spec.use_album_gain? "album":"track", gain, decoder_session->replaygain.spec.preamp, ns[decoder_session->replaygain.spec.noise_shaping], ls[decoder_session->replaygain.spec.limiter]);
+                               flac__utils_printf(stderr, 1, "%s: WARNING: applying ReplayGain is not lossless\n", decoder_session->inbasefilename);
                        }
                }
        }
@@ -1128,7 +1118,7 @@ void error_callback(const void *decoder, FLAC__StreamDecoderErrorStatus status,
 {
        DecoderSession *decoder_session = (DecoderSession*)client_data;
        (void)decoder;
-       if(!decoder_session->silent) fprintf(stderr, "%s: *** Got error code %d:%s\n", decoder_session->inbasefilename, status, FLAC__StreamDecoderErrorStatusString[status]);
+       flac__utils_printf(stderr, 1, "%s: *** Got error code %d:%s\n", decoder_session->inbasefilename, status, FLAC__StreamDecoderErrorStatusString[status]);
        if(!decoder_session->continue_through_decode_errors)
                decoder_session->abort_flag = true;
 }
@@ -1137,30 +1127,27 @@ void print_error_with_state(const DecoderSession *d, const char *message)
 {
        const int ilen = strlen(d->inbasefilename) + 1;
 
-       if(d->silent)
-               return;
-
-       fprintf(stderr, "\n%s: %s\n", d->inbasefilename, message);
+       flac__utils_printf(stderr, 1, "\n%s: %s\n", d->inbasefilename, message);
 
 #ifdef FLAC__HAS_OGG
        if(d->is_ogg) {
                const OggFLAC__FileDecoderState ofd_state = OggFLAC__file_decoder_get_state(d->decoder.ogg.file);
                if(ofd_state != OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
-                       fprintf(stderr, "%*s state = %d:%s\n", ilen, "", (int)ofd_state, OggFLAC__FileDecoderStateString[ofd_state]);
+                       flac__utils_printf(stderr, 1, "%*s state = %d:%s\n", ilen, "", (int)ofd_state, OggFLAC__FileDecoderStateString[ofd_state]);
                }
                else {
                        const OggFLAC__SeekableStreamDecoderState ossd_state = OggFLAC__file_decoder_get_seekable_stream_decoder_state(d->decoder.ogg.file);
                        if(ossd_state != OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
-                               fprintf(stderr, "%*s state = %d:%s\n", ilen, "", (int)ossd_state, OggFLAC__SeekableStreamDecoderStateString[ossd_state]);
+                               flac__utils_printf(stderr, 1, "%*s state = %d:%s\n", ilen, "", (int)ossd_state, OggFLAC__SeekableStreamDecoderStateString[ossd_state]);
                        }
                        else {
                                const OggFLAC__StreamDecoderState osd_state = OggFLAC__file_decoder_get_state(d->decoder.ogg.file);
                                if(osd_state != OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
-                                       fprintf(stderr, "%*s state = %d:%s\n", ilen, "", (int)osd_state, OggFLAC__StreamDecoderStateString[osd_state]);
+                                       flac__utils_printf(stderr, 1, "%*s state = %d:%s\n", ilen, "", (int)osd_state, OggFLAC__StreamDecoderStateString[osd_state]);
                                }
                                else {
                                        const FLAC__StreamDecoderState fsd_state = OggFLAC__file_decoder_get_FLAC_stream_decoder_state(d->decoder.ogg.file);
-                                       fprintf(stderr, "%*s state = %d:%s\n", ilen, "", (int)fsd_state, FLAC__StreamDecoderStateString[fsd_state]);
+                                       flac__utils_printf(stderr, 1, "%*s state = %d:%s\n", ilen, "", (int)fsd_state, FLAC__StreamDecoderStateString[fsd_state]);
                                }
                        }
                }
@@ -1170,16 +1157,16 @@ void print_error_with_state(const DecoderSession *d, const char *message)
        {
                const FLAC__FileDecoderState ffd_state = FLAC__file_decoder_get_state(d->decoder.flac.file);
                if(ffd_state != FLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR) {
-                       fprintf(stderr, "%*s state = %d:%s\n", ilen, "", (int)ffd_state, FLAC__FileDecoderStateString[ffd_state]);
+                       flac__utils_printf(stderr, 1, "%*s state = %d:%s\n", ilen, "", (int)ffd_state, FLAC__FileDecoderStateString[ffd_state]);
                }
                else {
                        const FLAC__SeekableStreamDecoderState fssd_state = FLAC__file_decoder_get_seekable_stream_decoder_state(d->decoder.flac.file);
                        if(fssd_state != FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {
-                               fprintf(stderr, "%*s state = %d:%s\n", ilen, "", (int)fssd_state, FLAC__SeekableStreamDecoderStateString[fssd_state]);
+                               flac__utils_printf(stderr, 1, "%*s state = %d:%s\n", ilen, "", (int)fssd_state, FLAC__SeekableStreamDecoderStateString[fssd_state]);
                        }
                        else {
                                const FLAC__StreamDecoderState fsd_state = FLAC__file_decoder_get_stream_decoder_state(d->decoder.flac.file);
-                               fprintf(stderr, "%*s state = %d:%s\n", ilen, "", (int)fsd_state, FLAC__StreamDecoderStateString[fsd_state]);
+                               flac__utils_printf(stderr, 1, "%*s state = %d:%s\n", ilen, "", (int)fsd_state, FLAC__StreamDecoderStateString[fsd_state]);
                        }
                }
        }
@@ -1187,7 +1174,7 @@ void print_error_with_state(const DecoderSession *d, const char *message)
 
 void print_stats(const DecoderSession *decoder_session)
 {
-       if(decoder_session->verbose) {
+       if(flac__utils_verbosity_ >= 2) {
 #if defined _MSC_VER || defined __MINGW32__
                /* with VC++ you have to spoon feed it the casting */
                const double progress = (double)(FLAC__int64)decoder_session->samples_processed / (double)(FLAC__int64)decoder_session->total_samples * 100.0;
index 92bf012..58a616c 100644 (file)
@@ -36,8 +36,6 @@ typedef struct {
 } replaygain_synthesis_spec_t;
 
 typedef struct {
-       FLAC__bool verbose;
-       FLAC__bool silent;
        FLAC__bool continue_through_decode_errors;
        replaygain_synthesis_spec_t replaygain_synthesis_spec;
 #ifdef FLAC__HAS_OGG
index f511b29..8400435 100644 (file)
@@ -24,7 +24,6 @@
 #endif
 #include <limits.h> /* for LONG_MAX */
 #include <math.h> /* for floor() */
-#include <stdarg.h>
 #include <stdio.h> /* for FILE etc. */
 #include <stdlib.h> /* for malloc */
 #include <string.h> /* for strcmp() */
@@ -58,8 +57,6 @@ typedef struct {
        FLAC__bool use_ogg;
 #endif
        FLAC__bool verify;
-       FLAC__bool verbose;
-       FLAC__bool silent;
        FLAC__bool is_stdout;
        const char *inbasefilename;
        const char *outfilename;
@@ -132,14 +129,14 @@ extern FLAC__bool OggFLAC__file_encoder_disable_verbatim_subframes(OggFLAC__File
 /*
  * local routines
  */
-static FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC__bool verify, FLAC__bool verbose, FLAC__bool silent, FILE *infile, const char *infilename, const char *outfilename);
+static FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC__bool verify, FILE *infile, const char *infilename, const char *outfilename);
 static void EncoderSession_destroy(EncoderSession *e);
 static int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero);
 static int EncoderSession_finish_error(EncoderSession *e);
 static FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t options, unsigned channels, unsigned bps, unsigned sample_rate);
 static FLAC__bool EncoderSession_process(EncoderSession *e, const FLAC__int32 * const buffer[], unsigned samples);
 static FLAC__bool convert_to_seek_table_template(const char *requested_seek_points, int num_requested_seek_points, FLAC__StreamMetadata *cuesheet, EncoderSession *e);
-static FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input, FLAC__bool silent);
+static FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input);
 static void format_input(FLAC__int32 *dest[], unsigned wide_samples, FLAC__bool is_big_endian, FLAC__bool is_unsigned_samples, unsigned channels, unsigned bps);
 #ifdef FLAC__HAS_OGG
 static FLAC__StreamEncoderWriteStatus ogg_stream_encoder_write_callback(const OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
@@ -149,15 +146,15 @@ static void ogg_file_encoder_progress_callback(const OggFLAC__FileEncoder *encod
 static FLAC__StreamEncoderWriteStatus flac_stream_encoder_write_callback(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
 static void flac_stream_encoder_metadata_callback(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
 static void flac_file_encoder_progress_callback(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
-static FLAC__bool parse_cuesheet_(FLAC__StreamMetadata **cuesheet, const char *cuesheet_filename, const char *inbasefilename, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset, FLAC__bool silent);
+static FLAC__bool parse_cuesheet_(FLAC__StreamMetadata **cuesheet, const char *cuesheet_filename, const char *inbasefilename, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset);
 static void print_stats(const EncoderSession *encoder_session);
 static void print_error_with_state(const EncoderSession *e, const char *message);
 static void print_verify_error(EncoderSession *e);
-static FLAC__bool read_little_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent);
-static FLAC__bool read_little_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent);
-static FLAC__bool read_big_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent);
-static FLAC__bool read_big_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent);
-static FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent);
+static FLAC__bool read_little_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok, const char *fn);
+static FLAC__bool read_little_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn);
+static FLAC__bool read_big_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok, const char *fn);
+static FLAC__bool read_big_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn);
+static FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn);
 
 /*
  * public routines
@@ -186,8 +183,6 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                        /*use_ogg=*/false,
 #endif
                        options.common.verify,
-                       options.common.verbose,
-                       options.common.silent,
                        infile,
                        infilename,
                        outfilename
@@ -205,7 +200,7 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                if(feof(infile) || ((c= fread(chunk_id, 1U, 4U, infile)), c==0U && feof(infile)))
                        break;
                else if(c<4U || feof(infile)) {
-                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: incomplete chunk identifier\n", encoder_session.inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR: incomplete chunk identifier\n", encoder_session.inbasefilename);
                        return EncoderSession_finish_error(&encoder_session);
                }
 
@@ -213,57 +208,57 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                        unsigned long skip;
 
                        /* COMM chunk size */
-                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        else if(xx<18U) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: non-standard 'COMM' chunk has length = %u\n", encoder_session.inbasefilename, (unsigned int)xx);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: non-standard 'COMM' chunk has length = %u\n", encoder_session.inbasefilename, (unsigned int)xx);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else if(xx!=18U) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: non-standard 'COMM' chunk has length = %u\n", encoder_session.inbasefilename, (unsigned int)xx);
+                               flac__utils_printf(stderr, 1, "%s: WARNING: non-standard 'COMM' chunk has length = %u\n", encoder_session.inbasefilename, (unsigned int)xx);
                        }
                        skip= (xx-18U)+(xx & 1U);
 
                        /* number of channels */
-                       if(!read_big_endian_uint16(infile, &x, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_big_endian_uint16(infile, &x, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        else if(x==0U || x>FLAC__MAX_CHANNELS) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: unsupported number channels %u\n", encoder_session.inbasefilename, (unsigned int)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: unsupported number channels %u\n", encoder_session.inbasefilename, (unsigned int)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else if(options.common.sector_align && x!=2U) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: file has %u channels, must be 2 for --sector-align\n", encoder_session.inbasefilename, (unsigned int)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: file has %u channels, must be 2 for --sector-align\n", encoder_session.inbasefilename, (unsigned int)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        channels= x;
 
                        /* number of sample frames */
-                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        sample_frames= xx;
 
                        /* bits per sample */
-                       if(!read_big_endian_uint16(infile, &x, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_big_endian_uint16(infile, &x, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        else if(x!=8U && x!=16U && x!=24U) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: unsupported bits per sample %u\n", encoder_session.inbasefilename, (unsigned int)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: unsupported bits per sample %u\n", encoder_session.inbasefilename, (unsigned int)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else if(options.common.sector_align && x!=16U) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: file has %u bits per sample, must be 16 for --sector-align\n", encoder_session.inbasefilename, (unsigned int)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: file has %u bits per sample, must be 16 for --sector-align\n", encoder_session.inbasefilename, (unsigned int)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        bps= x;
 
                        /* sample rate */
-                       if(!read_sane_extended(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_sane_extended(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        else if(!FLAC__format_sample_rate_is_valid(xx)) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: unsupported sample rate %u\n", encoder_session.inbasefilename, (unsigned int)xx);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: unsupported sample rate %u\n", encoder_session.inbasefilename, (unsigned int)xx);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else if(options.common.sector_align && xx!=44100U) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: file's sample rate is %u, must be 44100 for --sector-align\n", encoder_session.inbasefilename, (unsigned int)xx);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: file's sample rate is %u, must be 44100 for --sector-align\n", encoder_session.inbasefilename, (unsigned int)xx);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        sample_rate= xx;
@@ -273,7 +268,7 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                        while(skip>0U && fseek(infile, skip, SEEK_CUR)<0) {
                                unsigned int need= min(skip, sizeof ucbuffer_);
                                if(fread(ucbuffer_, 1U, need, infile)<need) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read while skipping extra COMM data\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping extra COMM data\n", encoder_session.inbasefilename);
                                        return EncoderSession_finish_error(&encoder_session);
                                }
                                skip-= need;
@@ -297,15 +292,15 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                        FLAC__bool pad= false;
 
                        if(got_comm_chunk==false) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: got 'SSND' chunk before 'COMM' chunk\n", encoder_session.inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: got 'SSND' chunk before 'COMM' chunk\n", encoder_session.inbasefilename);
                                return EncoderSession_finish_error(&encoder_session);
                        }
 
                        /* SSND chunk size */
-                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        else if(xx!=(sample_frames*bytes_per_frame + 8U)) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: SSND chunk size inconsistent with sample frame count\n", encoder_session.inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: SSND chunk size inconsistent with sample frame count\n", encoder_session.inbasefilename);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        data_bytes= xx;
@@ -313,19 +308,19 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                        data_bytes-= 8U; /* discount the offset and block size fields */
 
                        /* offset */
-                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        else if(xx!=0U) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: offset is %u; must be 0\n", encoder_session.inbasefilename, (unsigned int)xx);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: offset is %u; must be 0\n", encoder_session.inbasefilename, (unsigned int)xx);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        offset= xx;
 
                        /* block size */
-                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        else if(xx!=0U) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: block size is %u; must be 0\n", encoder_session.inbasefilename, (unsigned int)xx);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: block size is %u; must be 0\n", encoder_session.inbasefilename, (unsigned int)xx);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        block_size= xx;
@@ -338,7 +333,7 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                         * now that we know the input size, canonicalize the
                         * --until string to an absolute sample number:
                         */
-                       if(!canonicalize_until_specification(&options.common.until_specification, encoder_session.inbasefilename, sample_rate, encoder_session.skip, total_samples_in_input, encoder_session.silent))
+                       if(!canonicalize_until_specification(&options.common.until_specification, encoder_session.inbasefilename, sample_rate, encoder_session.skip, total_samples_in_input))
                                return EncoderSession_finish_error(&encoder_session);
                        encoder_session.until = (FLAC__uint64)options.common.until_specification.value.samples;
                        FLAC__ASSERT(!options.common.sector_align || encoder_session.until == 0);
@@ -356,7 +351,7 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                                        while(skip>0 && fseek(infile, skip, SEEK_CUR)<0) {
                                                unsigned int need= min(skip, sizeof ucbuffer_);
                                                if(fread(ucbuffer_, 1U, need, infile)<need) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
+                                                       flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
                                                        return EncoderSession_finish_error(&encoder_session);
                                                }
                                                skip-= need;
@@ -414,17 +409,17 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
 
                                if(bytes_read==0U) {
                                        if(ferror(infile)) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                               flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                                return EncoderSession_finish_error(&encoder_session);
                                        }
                                        else if(feof(infile)) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: unexpected EOF; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned int)encoder_session.total_samples_to_encode, (unsigned int)encoder_session.samples_written);
+                                               flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned int)encoder_session.total_samples_to_encode, (unsigned int)encoder_session.samples_written);
                                                data_bytes= 0;
                                        }
                                }
                                else {
                                        if(bytes_read % bytes_per_frame != 0U) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename);
+                                               flac__utils_printf(stderr, 1, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename);
                                                return EncoderSession_finish_error(&encoder_session);
                                        }
                                        else {
@@ -456,7 +451,7 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                                        while(skip>0 && fseek(infile, skip, SEEK_CUR)<0) {
                                                unsigned int need= min(skip, sizeof ucbuffer_);
                                                if(fread(ucbuffer_, 1U, need, infile)<need) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
+                                                       flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
                                                        return EncoderSession_finish_error(&encoder_session);
                                                }
                                                skip-= need;
@@ -490,11 +485,11 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
 
                                                FLAC__ASSERT(CHUNK_OF_SAMPLES>=588U);
                                                if(bytes_read==0U && ferror(infile)) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                                       flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                                        return EncoderSession_finish_error(&encoder_session);
                                                }
                                                else if(bytes_read != (*options.common.align_reservoir_samples) * bytes_per_frame) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: unexpected EOF; read %u bytes; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned int)bytes_read, (unsigned int)encoder_session.total_samples_to_encode, (unsigned int)encoder_session.samples_written);
+                                                       flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; read %u bytes; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned int)bytes_read, (unsigned int)encoder_session.total_samples_to_encode, (unsigned int)encoder_session.samples_written);
                                                }
                                                else {
                                                        info_align_carry= *options.common.align_reservoir_samples;
@@ -508,7 +503,7 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                                unsigned char tmp;
 
                                if(fread(&tmp, 1U, 1U, infile)<1U) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read of SSND pad byte\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR during read of SSND pad byte\n", encoder_session.inbasefilename);
                                        return EncoderSession_finish_error(&encoder_session);
                                }
                        }
@@ -517,17 +512,17 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
                }
                else { /* other chunk */
                        if(!strncmp(chunk_id, "COMM", 4)) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: skipping extra 'COMM' chunk\n", encoder_session.inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: WARNING: skipping extra 'COMM' chunk\n", encoder_session.inbasefilename);
                        }
                        else if(!strncmp(chunk_id, "SSND", 4)) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: skipping extra 'SSND' chunk\n", encoder_session.inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: WARNING: skipping extra 'SSND' chunk\n", encoder_session.inbasefilename);
                        }
                        else {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: skipping unknown chunk '%s'\n", encoder_session.inbasefilename, chunk_id);
+                               flac__utils_printf(stderr, 1, "%s: WARNING: skipping unknown chunk '%s'\n", encoder_session.inbasefilename, chunk_id);
                        }
 
                        /* chunk size */
-                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_big_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        else {
                                unsigned long skip= xx+(xx & 1U);
@@ -546,7 +541,7 @@ flac__encode_aif(FILE *infile, long infilesize, const char *infilename, const ch
        }
 
        if(got_ssnd_chunk==false && sample_frames!=0U) {
-               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: missing SSND chunk\n", encoder_session.inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR: missing SSND chunk\n", encoder_session.inbasefilename);
                return EncoderSession_finish_error(&encoder_session);
        }
 
@@ -578,8 +573,6 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                        /*use_ogg=*/false,
 #endif
                        options.common.verify,
-                       options.common.verbose,
-                       options.common.silent,
                        infile,
                        infilename,
                        outfilename
@@ -591,7 +584,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
         * lookahead[] already has "RIFFxxxxWAVE", do sub-chunks
         */
        while(!feof(infile)) {
-               if(!read_little_endian_uint32(infile, &xx, true, encoder_session.inbasefilename, encoder_session.silent))
+               if(!read_little_endian_uint32(infile, &xx, true, encoder_session.inbasefilename))
                        return EncoderSession_finish_error(&encoder_session);
                if(feof(infile))
                        break;
@@ -599,68 +592,68 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                        unsigned block_align;
 
                        /* fmt sub-chunk size */
-                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        if(xx < 16) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: found non-standard 'fmt ' sub-chunk which has length = %u\n", encoder_session.inbasefilename, (unsigned)xx);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: found non-standard 'fmt ' sub-chunk which has length = %u\n", encoder_session.inbasefilename, (unsigned)xx);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else if(xx != 16 && xx != 18) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: found non-standard 'fmt ' sub-chunk which has length = %u\n", encoder_session.inbasefilename, (unsigned)xx);
+                               flac__utils_printf(stderr, 1, "%s: WARNING: found non-standard 'fmt ' sub-chunk which has length = %u\n", encoder_session.inbasefilename, (unsigned)xx);
                        }
                        data_bytes = xx;
                        /* compression code */
-                       if(!read_little_endian_uint16(infile, &x, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint16(infile, &x, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        if(x != 1) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: unsupported compression type %u\n", encoder_session.inbasefilename, (unsigned)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: unsupported compression type %u\n", encoder_session.inbasefilename, (unsigned)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        /* number of channels */
-                       if(!read_little_endian_uint16(infile, &x, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint16(infile, &x, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        if(x == 0 || x > FLAC__MAX_CHANNELS) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: unsupported number channels %u\n", encoder_session.inbasefilename, (unsigned)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: unsupported number channels %u\n", encoder_session.inbasefilename, (unsigned)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else if(options.common.sector_align && x != 2) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: file has %u channels, must be 2 for --sector-align\n", encoder_session.inbasefilename, (unsigned)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: file has %u channels, must be 2 for --sector-align\n", encoder_session.inbasefilename, (unsigned)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        channels = x;
                        /* sample rate */
-                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        if(!FLAC__format_sample_rate_is_valid(xx)) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: unsupported sample rate %u\n", encoder_session.inbasefilename, (unsigned)xx);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: unsupported sample rate %u\n", encoder_session.inbasefilename, (unsigned)xx);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else if(options.common.sector_align && xx != 44100) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: file's sample rate is %u, must be 44100 for --sector-align\n", encoder_session.inbasefilename, (unsigned)xx);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: file's sample rate is %u, must be 44100 for --sector-align\n", encoder_session.inbasefilename, (unsigned)xx);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        sample_rate = xx;
                        /* avg bytes per second (ignored) */
-                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        /* block align */
-                       if(!read_little_endian_uint16(infile, &x, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint16(infile, &x, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        block_align = x;
                        /* bits per sample */
-                       if(!read_little_endian_uint16(infile, &x, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint16(infile, &x, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        if(x != 8 && x != 16 && x != 24) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: unsupported bits-per-sample %u\n", encoder_session.inbasefilename, (unsigned)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: unsupported bits-per-sample %u\n", encoder_session.inbasefilename, (unsigned)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else if(options.common.sector_align && x != 16) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: file has %u bits per sample, must be 16 for --sector-align\n", encoder_session.inbasefilename, (unsigned)x);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: file has %u bits per sample, must be 16 for --sector-align\n", encoder_session.inbasefilename, (unsigned)x);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        bps = x;
                        if(bps * channels != block_align * 8) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: unsupported block alignment (%u), for bits-per-sample=%u, channels=%u\n", encoder_session.inbasefilename, block_align, bps, channels);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: unsupported block alignment (%u), for bits-per-sample=%u, channels=%u\n", encoder_session.inbasefilename, block_align, bps, channels);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        is_unsigned_samples = (x == 8);
@@ -672,7 +665,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                                for(left = data_bytes; left > 0; ) {
                                        need = min(left, CHUNK_OF_SAMPLES);
                                        if(fread(ucbuffer_, 1U, need, infile) < need) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
+                                               flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
                                                return EncoderSession_finish_error(&encoder_session);
                                        }
                                        left -= need;
@@ -694,7 +687,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                        FLAC__uint64 total_samples_in_input, trim = 0;
 
                        /* data size */
-                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        data_bytes = xx;
 
@@ -708,7 +701,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                         * now that we know the input size, canonicalize the
                         * --until string to an absolute sample number:
                         */
-                       if(!canonicalize_until_specification(&options.common.until_specification, encoder_session.inbasefilename, sample_rate, encoder_session.skip, total_samples_in_input, encoder_session.silent))
+                       if(!canonicalize_until_specification(&options.common.until_specification, encoder_session.inbasefilename, sample_rate, encoder_session.skip, total_samples_in_input))
                                return EncoderSession_finish_error(&encoder_session);
                        encoder_session.until = (FLAC__uint64)options.common.until_specification.value.samples;
                        FLAC__ASSERT(!options.common.sector_align || encoder_session.until == 0);
@@ -720,7 +713,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                                        for(left = (unsigned)encoder_session.skip; left > 0; ) { /*@@@ WATCHOUT: 4GB limit */
                                                need = min(left, CHUNK_OF_SAMPLES);
                                                if(fread(ucbuffer_, bytes_per_wide_sample, need, infile) < need) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
+                                                       flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
                                                        return EncoderSession_finish_error(&encoder_session);
                                                }
                                                left -= need;
@@ -781,17 +774,17 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                                bytes_read = fread(ucbuffer_, sizeof(unsigned char), min(data_bytes, CHUNK_OF_SAMPLES * bytes_per_wide_sample), infile);
                                if(bytes_read == 0) {
                                        if(ferror(infile)) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                               flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                                return EncoderSession_finish_error(&encoder_session);
                                        }
                                        else if(feof(infile)) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: unexpected EOF; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
+                                               flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
                                                data_bytes = 0;
                                        }
                                }
                                else {
                                        if(bytes_read % bytes_per_wide_sample != 0) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename);
+                                               flac__utils_printf(stderr, 1, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename);
                                                return EncoderSession_finish_error(&encoder_session);
                                        }
                                        else {
@@ -814,7 +807,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                                        for(left = (unsigned)trim; left > 0; ) { /*@@@ WATCHOUT: 4GB limit */
                                                need = min(left, CHUNK_OF_SAMPLES);
                                                if(fread(ucbuffer_, bytes_per_wide_sample, need, infile) < need) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
+                                                       flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
                                                        return EncoderSession_finish_error(&encoder_session);
                                                }
                                                left -= need;
@@ -847,11 +840,11 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                                                FLAC__ASSERT(CHUNK_OF_SAMPLES >= 588);
                                                bytes_read = fread(ucbuffer_, sizeof(unsigned char), (*options.common.align_reservoir_samples) * bytes_per_wide_sample, infile);
                                                if(bytes_read == 0 && ferror(infile)) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                                       flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                                        return EncoderSession_finish_error(&encoder_session);
                                                }
                                                else if(bytes_read != (*options.common.align_reservoir_samples) * bytes_per_wide_sample) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: unexpected EOF; read %u bytes; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)bytes_read, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
+                                                       flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; read %u bytes; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)bytes_read, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
                                                        data_bytes = 0;
                                                }
                                                else {
@@ -866,14 +859,14 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                }
                else {
                        if(xx == 0x20746d66 && got_fmt_chunk) { /* "fmt " */
-                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: skipping extra 'fmt ' sub-chunk\n", encoder_session.inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: WARNING: skipping extra 'fmt ' sub-chunk\n", encoder_session.inbasefilename);
                        }
                        else if(xx == 0x61746164) { /* "data" */
                                if(got_data_chunk) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: skipping extra 'data' sub-chunk\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: WARNING: skipping extra 'data' sub-chunk\n", encoder_session.inbasefilename);
                                }
                                else if(!got_fmt_chunk) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: got 'data' sub-chunk before 'fmt' sub-chunk\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR: got 'data' sub-chunk before 'fmt' sub-chunk\n", encoder_session.inbasefilename);
                                        return EncoderSession_finish_error(&encoder_session);
                                }
                                else {
@@ -881,10 +874,10 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                                }
                        }
                        else {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: skipping unknown sub-chunk '%c%c%c%c'\n", encoder_session.inbasefilename, (char)(xx&255), (char)((xx>>8)&255), (char)((xx>>16)&255), (char)(xx>>24));
+                               flac__utils_printf(stderr, 1, "%s: WARNING: skipping unknown sub-chunk '%c%c%c%c'\n", encoder_session.inbasefilename, (char)(xx&255), (char)((xx>>8)&255), (char)((xx>>16)&255), (char)(xx>>24));
                        }
                        /* sub-chunk size */
-                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename, encoder_session.silent))
+                       if(!read_little_endian_uint32(infile, &xx, false, encoder_session.inbasefilename))
                                return EncoderSession_finish_error(&encoder_session);
                        if(fseek(infile, xx, SEEK_CUR) < 0) {
                                /* can't seek input, read ahead manually... */
@@ -893,7 +886,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
                                for(left = xx; left > 0; ) {
                                        need = min(left, chunk);
                                        if(fread(ucbuffer_, 1, need, infile) < need) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read while skipping unsupported sub-chunk\n", encoder_session.inbasefilename);
+                                               flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping unsupported sub-chunk\n", encoder_session.inbasefilename);
                                                return EncoderSession_finish_error(&encoder_session);
                                        }
                                        left -= need;
@@ -930,8 +923,6 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
                        /*use_ogg=*/false,
 #endif
                        options.common.verify,
-                       options.common.verbose,
-                       options.common.silent,
                        infile,
                        infilename,
                        outfilename
@@ -960,7 +951,7 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
         * now that we know the input size, canonicalize the
         * --until strings to a number of samples:
         */
-       if(!canonicalize_until_specification(&options.common.until_specification, encoder_session.inbasefilename, options.sample_rate, encoder_session.skip, total_samples_in_input, encoder_session.silent))
+       if(!canonicalize_until_specification(&options.common.until_specification, encoder_session.inbasefilename, options.sample_rate, encoder_session.skip, total_samples_in_input))
                return EncoderSession_finish_error(&encoder_session);
        encoder_session.until = (FLAC__uint64)options.common.until_specification.value.samples;
        FLAC__ASSERT(!options.common.sector_align || encoder_session.until == 0);
@@ -982,8 +973,8 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
        }
        encoder_session.unencoded_size = encoder_session.total_samples_to_encode * bytes_per_wide_sample;
 
-       if(encoder_session.verbose && encoder_session.total_samples_to_encode <= 0)
-               fprintf(stderr, "(No runtime statistics possible; please wait for encoding to finish...)\n");
+       if(encoder_session.total_samples_to_encode <= 0)
+               flac__utils_printf(stderr, 2, "(No runtime statistics possible; please wait for encoding to finish...)\n");
 
        if(encoder_session.skip > 0) {
                unsigned skip_bytes = bytes_per_wide_sample * (unsigned)encoder_session.skip;
@@ -997,7 +988,7 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
                                for(left = skip_bytes; left > 0; ) {
                                        need = min(left, chunk);
                                        if(fread(ucbuffer_, 1, need, infile) < need) {
-                                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
+                                               flac__utils_printf(stderr, 1, "%s: ERROR during read while skipping samples\n", encoder_session.inbasefilename);
                                                return EncoderSession_finish_error(&encoder_session);
                                        }
                                        left -= need;
@@ -1048,7 +1039,7 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
                                memcpy(ucbuffer_, lookahead, lookahead_length);
                                bytes_read = fread(ucbuffer_+lookahead_length, sizeof(unsigned char), CHUNK_OF_SAMPLES * bytes_per_wide_sample - lookahead_length, infile) + lookahead_length;
                                if(ferror(infile)) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                        return EncoderSession_finish_error(&encoder_session);
                                }
                                lookahead_length = 0;
@@ -1058,12 +1049,12 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
 
                        if(bytes_read == 0) {
                                if(ferror(infile)) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                        return EncoderSession_finish_error(&encoder_session);
                                }
                        }
                        else if(bytes_read % bytes_per_wide_sample != 0) {
-                               if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename);
                                return EncoderSession_finish_error(&encoder_session);
                        }
                        else {
@@ -1093,7 +1084,7 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
                                        if(wanted > 0) {
                                                bytes_read += fread(ucbuffer_+lookahead_length, sizeof(unsigned char), wanted, infile);
                                                if(ferror(infile)) {
-                                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                                       flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                                        return EncoderSession_finish_error(&encoder_session);
                                                }
                                        }
@@ -1105,17 +1096,17 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
 
                        if(bytes_read == 0) {
                                if(ferror(infile)) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                        return EncoderSession_finish_error(&encoder_session);
                                }
                                else if(feof(infile)) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: unexpected EOF; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
+                                       flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
                                        total_input_bytes_read = max_input_bytes;
                                }
                        }
                        else {
                                if(bytes_read % bytes_per_wide_sample != 0) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR: got partial sample\n", encoder_session.inbasefilename);
                                        return EncoderSession_finish_error(&encoder_session);
                                }
                                else {
@@ -1157,11 +1148,11 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
                                FLAC__ASSERT(CHUNK_OF_SAMPLES >= 588);
                                bytes_read = fread(ucbuffer_, sizeof(unsigned char), (*options.common.align_reservoir_samples) * bytes_per_wide_sample, infile);
                                if(bytes_read == 0 && ferror(infile)) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: ERROR during read\n", encoder_session.inbasefilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR during read\n", encoder_session.inbasefilename);
                                        return EncoderSession_finish_error(&encoder_session);
                                }
                                else if(bytes_read != (*options.common.align_reservoir_samples) * bytes_per_wide_sample) {
-                                       if(!encoder_session.silent) fprintf(stderr, "%s: WARNING: unexpected EOF; read %u bytes; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)bytes_read, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
+                                       flac__utils_printf(stderr, 1, "%s: WARNING: unexpected EOF; read %u bytes; expected %u samples, got %u samples\n", encoder_session.inbasefilename, (unsigned)bytes_read, (unsigned)encoder_session.total_samples_to_encode, (unsigned)encoder_session.samples_written);
                                }
                                else {
                                        info_align_carry = *options.common.align_reservoir_samples;
@@ -1174,7 +1165,7 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
        return EncoderSession_finish_ok(&encoder_session, info_align_carry, info_align_zero);
 }
 
-FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC__bool verify, FLAC__bool verbose, FLAC__bool silent, FILE *infile, const char *infilename, const char *outfilename)
+FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC__bool verify, FILE *infile, const char *infilename, const char *outfilename)
 {
        unsigned i;
        FLAC__uint32 test = 1;
@@ -1199,8 +1190,6 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_
        (void)use_ogg;
 #endif
        e->verify = verify;
-       e->verbose = verbose;
-       e->silent = silent;
 
        e->is_stdout = (0 == strcmp(outfilename, "-"));
 
@@ -1231,7 +1220,7 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_
        }
 
        if(0 == (e->seek_table_template = FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE))) {
-               if(!e->silent) fprintf(stderr, "%s: ERROR allocating memory for seek table\n", e->inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for seek table\n", e->inbasefilename);
                return false;
        }
 
@@ -1240,7 +1229,7 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_
                if(e->is_stdout) {
                        e->encoder.ogg.stream = OggFLAC__stream_encoder_new();
                        if(0 == e->encoder.ogg.stream) {
-                               if(!e->silent) fprintf(stderr, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
                                EncoderSession_destroy(e);
                                return false;
                        }
@@ -1248,7 +1237,7 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_
                else {
                        e->encoder.ogg.file = OggFLAC__file_encoder_new();
                        if(0 == e->encoder.ogg.file) {
-                               if(!e->silent) fprintf(stderr, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
                                EncoderSession_destroy(e);
                                return false;
                        }
@@ -1259,7 +1248,7 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_
        if(e->is_stdout) {
                e->encoder.flac.stream = FLAC__stream_encoder_new();
                if(0 == e->encoder.flac.stream) {
-                       if(!e->silent) fprintf(stderr, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
                        EncoderSession_destroy(e);
                        return false;
                }
@@ -1267,7 +1256,7 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_
        else {
                e->encoder.flac.file = FLAC__file_encoder_new();
                if(0 == e->encoder.flac.file) {
-                       if(!e->silent) fprintf(stderr, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
                        EncoderSession_destroy(e);
                        return false;
                }
@@ -1354,9 +1343,9 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a
                }
        }
 
-       if(e->verbose && e->total_samples_to_encode > 0) {
+       if(e->total_samples_to_encode > 0) {
                print_stats(e);
-               fprintf(stderr, "\n");
+               flac__utils_printf(stderr, 2, "\n");
        }
 
        if(fse_state == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) {
@@ -1365,10 +1354,10 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a
        }
        else {
                if(info_align_carry >= 0) {
-                       if(!e->silent) fprintf(stderr, "%s: INFO: sector alignment causing %d samples to be carried over\n", e->inbasefilename, info_align_carry);
+                       flac__utils_printf(stderr, 1, "%s: INFO: sector alignment causing %d samples to be carried over\n", e->inbasefilename, info_align_carry);
                }
                if(info_align_zero >= 0) {
-                       if(!e->silent) fprintf(stderr, "%s: INFO: sector alignment causing %d zero samples to be appended\n", e->inbasefilename, info_align_zero);
+                       flac__utils_printf(stderr, 1, "%s: INFO: sector alignment causing %d zero samples to be appended\n", e->inbasefilename, info_align_zero);
                }
        }
 
@@ -1381,8 +1370,8 @@ int EncoderSession_finish_error(EncoderSession *e)
 {
        FLAC__StreamEncoderState fse_state;
 
-       if(e->verbose && e->total_samples_to_encode > 0)
-               fprintf(stderr, "\n");
+       if(e->total_samples_to_encode > 0)
+               flac__utils_printf(stderr, 2, "\n");
 
 #ifdef FLAC__HAS_OGG
        if(e->use_ogg) {
@@ -1426,16 +1415,16 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
 
        if(e->replay_gain) {
                if(channels != 1 && channels != 2) {
-                       if(!e->silent) fprintf(stderr, "%s: ERROR, number of channels (%u) must be 1 or 2 for --replay-gain\n", e->inbasefilename, channels);
+                       flac__utils_printf(stderr, 1, "%s: ERROR, number of channels (%u) must be 1 or 2 for --replay-gain\n", e->inbasefilename, channels);
                        return false;
                }
                if(!grabbag__replaygain_is_valid_sample_frequency(sample_rate)) {
-                       if(!e->silent) fprintf(stderr, "%s: ERROR, invalid sample rate (%u) for --replay-gain\n", e->inbasefilename, sample_rate);
+                       flac__utils_printf(stderr, 1, "%s: ERROR, invalid sample rate (%u) for --replay-gain\n", e->inbasefilename, sample_rate);
                        return false;
                }
                if(options.is_first_file) {
                        if(!grabbag__replaygain_init(sample_rate)) {
-                               if(!e->silent) fprintf(stderr, "%s: ERROR initializing ReplayGain stage\n", e->inbasefilename);
+                               flac__utils_printf(stderr, 1, "%s: ERROR initializing ReplayGain stage\n", e->inbasefilename);
                                return false;
                        }
                }
@@ -1444,11 +1433,11 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
        if(channels != 2)
                options.do_mid_side = options.loose_mid_side = false;
 
-       if(!parse_cuesheet_(&cuesheet, options.cuesheet_filename, e->inbasefilename, is_cdda, e->total_samples_to_encode, e->silent))
+       if(!parse_cuesheet_(&cuesheet, options.cuesheet_filename, e->inbasefilename, is_cdda, e->total_samples_to_encode))
                return false;
 
        if(!convert_to_seek_table_template(options.requested_seek_points, options.num_requested_seek_points, options.cued_seekpoints? cuesheet : 0, e)) {
-               if(!e->silent) fprintf(stderr, "%s: ERROR allocating memory for seek table\n", e->inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR allocating memory for seek table\n", e->inbasefilename);
                if(0 != cuesheet)
                        free(cuesheet);
                return false;
@@ -1626,7 +1615,7 @@ FLAC__bool EncoderSession_process(EncoderSession *e, const FLAC__int32 * const b
 {
        if(e->replay_gain) {
                if(!grabbag__replaygain_analyze(buffer, e->channels==2, e->bits_per_sample, samples)) {
-                       if(!e->silent) fprintf(stderr, "%s: WARNING, error while calculating ReplayGain\n", e->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: WARNING, error while calculating ReplayGain\n", e->inbasefilename);
                }
        }
 
@@ -1685,14 +1674,14 @@ FLAC__bool convert_to_seek_table_template(const char *requested_seek_points, int
 
        if(has_real_points) {
                if(e->is_stdout) {
-                       if(!e->silent) fprintf(stderr, "%s: WARNING, cannot write back seekpoints when encoding to stdout\n", e->inbasefilename);
+                       flac__utils_printf(stderr, 1, "%s: WARNING, cannot write back seekpoints when encoding to stdout\n", e->inbasefilename);
                }
        }
 
        return true;
 }
 
-FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input, FLAC__bool silent)
+FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input)
 {
        /* convert from mm:ss.sss to sample number if necessary */
        flac__utils_canonicalize_skip_until_specification(spec, sample_rate);
@@ -1705,7 +1694,7 @@ FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec,
 
        /* in any other case the total samples in the input must be known */
        if(total_samples_in_input == 0) {
-               if(!silent) fprintf(stderr, "%s: ERROR, cannot use --until when input length is unknown\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR, cannot use --until when input length is unknown\n", inbasefilename);
                return false;
        }
 
@@ -1722,15 +1711,15 @@ FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec,
 
        /* error check */
        if(spec->value.samples < 0) {
-               if(!silent) fprintf(stderr, "%s: ERROR, --until value is before beginning of input\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR, --until value is before beginning of input\n", inbasefilename);
                return false;
        }
        if((FLAC__uint64)spec->value.samples <= skip) {
-               if(!silent) fprintf(stderr, "%s: ERROR, --until value is before --skip point\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR, --until value is before --skip point\n", inbasefilename);
                return false;
        }
        if((FLAC__uint64)spec->value.samples > total_samples_in_input) {
-               if(!silent) fprintf(stderr, "%s: ERROR, --until value is after end of input\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR, --until value is after end of input\n", inbasefilename);
                return false;
        }
 
@@ -1824,7 +1813,7 @@ FLAC__StreamEncoderWriteStatus ogg_stream_encoder_write_callback(const OggFLAC__
        (void)samples;
        encoder_session->samples_written = (current_frame+1) * encoder_session->blocksize;
 
-       if(encoder_session->verbose && encoder_session->total_samples_to_encode > 0 && !(current_frame & encoder_session->stats_mask))
+       if(encoder_session->total_samples_to_encode > 0 && !(current_frame & encoder_session->stats_mask))
                print_stats(encoder_session);
 
        if(flac__utils_fwrite(buffer, sizeof(FLAC__byte), bytes, encoder_session->fout) == bytes)
@@ -1865,7 +1854,7 @@ FLAC__StreamEncoderWriteStatus flac_stream_encoder_write_callback(const FLAC__St
        encoder_session->bytes_written += bytes;
        encoder_session->samples_written += samples;
 
-       if(samples && encoder_session->verbose && encoder_session->total_samples_to_encode > 0 && !(current_frame & encoder_session->stats_mask))
+       if(samples && encoder_session->total_samples_to_encode > 0 && !(current_frame & encoder_session->stats_mask))
                print_stats(encoder_session);
 
        if(flac__utils_fwrite(buffer, sizeof(FLAC__byte), bytes, encoder_session->fout) == bytes)
@@ -1892,11 +1881,11 @@ void flac_file_encoder_progress_callback(const FLAC__FileEncoder *encoder, FLAC_
        encoder_session->bytes_written = bytes_written;
        encoder_session->samples_written = samples_written;
 
-       if(encoder_session->verbose && encoder_session->total_samples_to_encode > 0 && !((frames_written-1) & encoder_session->stats_mask))
+       if(encoder_session->total_samples_to_encode > 0 && !((frames_written-1) & encoder_session->stats_mask))
                print_stats(encoder_session);
 }
 
-FLAC__bool parse_cuesheet_(FLAC__StreamMetadata **cuesheet, const char *cuesheet_filename, const char *inbasefilename, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset, FLAC__bool silent)
+FLAC__bool parse_cuesheet_(FLAC__StreamMetadata **cuesheet, const char *cuesheet_filename, const char *inbasefilename, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset)
 {
        FILE *f;
        unsigned last_line_read;
@@ -1906,12 +1895,12 @@ FLAC__bool parse_cuesheet_(FLAC__StreamMetadata **cuesheet, const char *cuesheet
                return true;
 
        if(lead_out_offset == 0) {
-               if(!silent) fprintf(stderr, "%s: ERROR cannot import cuesheet when the number of input samples to encode is unknown\n", inbasefilename);
+               flac__utils_printf(stderr, 1, "%s: ERROR cannot import cuesheet when the number of input samples to encode is unknown\n", inbasefilename);
                return false;
        }
 
        if(0 == (f = fopen(cuesheet_filename, "r"))) {
-               if(!silent) fprintf(stderr, "%s: ERROR opening cuesheet \"%s\" for reading\n", inbasefilename, cuesheet_filename);
+               flac__utils_printf(stderr, 1, "%s: ERROR opening cuesheet \"%s\" for reading\n", inbasefilename, cuesheet_filename);
                return false;
        }
 
@@ -1920,7 +1909,7 @@ FLAC__bool parse_cuesheet_(FLAC__StreamMetadata **cuesheet, const char *cuesheet
        fclose(f);
 
        if(0 == *cuesheet) {
-               if(!silent) fprintf(stderr, "%s: ERROR parsing cuesheet \"%s\" on line %u: %s\n", inbasefilename, cuesheet_filename, last_line_read, error_message);
+               flac__utils_printf(stderr, 1, "%s: ERROR parsing cuesheet \"%s\" on line %u: %s\n", inbasefilename, cuesheet_filename, last_line_read, error_message);
                return false;
        }
 
@@ -1939,11 +1928,9 @@ void print_stats(const EncoderSession *encoder_session)
        const double ratio = (double)encoder_session->bytes_written / ((double)encoder_session->unencoded_size * min(1.0, progress));
 #endif
 
-       if(encoder_session->silent)
-               return;
 
        if(samples_written == encoder_session->total_samples_to_encode) {
-               fprintf(stderr, "\r%s:%s wrote %u bytes, ratio=%0.3f",
+               flac__utils_printf(stderr, 2, "\r%s:%s wrote %u bytes, ratio=%0.3f",
                        encoder_session->inbasefilename,
                        encoder_session->verify? " Verify OK," : "",
                        (unsigned)encoder_session->bytes_written,
@@ -1951,7 +1938,7 @@ void print_stats(const EncoderSession *encoder_session)
                );
        }
        else {
-               fprintf(stderr, "\r%s: %u%% complete, ratio=%0.3f", encoder_session->inbasefilename, (unsigned)floor(progress * 100.0 + 0.5), ratio);
+               flac__utils_printf(stderr, 2, "\r%s: %u%% complete, ratio=%0.3f", encoder_session->inbasefilename, (unsigned)floor(progress * 100.0 + 0.5), ratio);
        }
 }
 
@@ -1960,9 +1947,6 @@ void print_error_with_state(const EncoderSession *e, const char *message)
        const int ilen = strlen(e->inbasefilename) + 1;
        const char *state_string;
 
-       if(e->silent)
-               return;
-
        fprintf(stderr, "\n%s: %s\n", e->inbasefilename, message);
 
 #ifdef FLAC__HAS_OGG
@@ -1983,7 +1967,7 @@ void print_error_with_state(const EncoderSession *e, const char *message)
                state_string = FLAC__file_encoder_get_resolved_state_string(e->encoder.flac.file);
        }
 
-       fprintf(stderr, "%*s state = %s\n", ilen, "", state_string);
+       flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string);
 }
 
 void print_verify_error(EncoderSession *e)
@@ -1995,9 +1979,6 @@ void print_verify_error(EncoderSession *e)
        FLAC__int32 expected;
        FLAC__int32 got;
 
-       if(e->silent)
-               return;
-
 #ifdef FLAC__HAS_OGG
        if(e->use_ogg) {
                if(e->is_stdout) {
@@ -2016,29 +1997,29 @@ void print_verify_error(EncoderSession *e)
                FLAC__file_encoder_get_verify_decoder_error_stats(e->encoder.flac.file, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
        }
 
-       fprintf(stderr, "%s: ERROR: mismatch in decoded data, verify FAILED!\n", e->inbasefilename);
-       fprintf(stderr, "       Absolute sample=%u, frame=%u, channel=%u, sample=%u, expected %d, got %d\n", (unsigned)absolute_sample, frame_number, channel, sample, expected, got);
-       fprintf(stderr, "       Please submit a bug report to\n");
-       fprintf(stderr, "           http://sourceforge.net/bugs/?func=addbug&group_id=13478\n");
-       fprintf(stderr, "       Make sure to include an email contact in the comment and/or use the\n");
-       fprintf(stderr, "       \"Monitor\" feature to monitor the bug status.\n");
-       fprintf(stderr, "Verify FAILED!  Do not trust %s\n", e->outfilename);
+       flac__utils_printf(stderr, 1, "%s: ERROR: mismatch in decoded data, verify FAILED!\n", e->inbasefilename);
+       flac__utils_printf(stderr, 1, "       Absolute sample=%u, frame=%u, channel=%u, sample=%u, expected %d, got %d\n", (unsigned)absolute_sample, frame_number, channel, sample, expected, got);
+       flac__utils_printf(stderr, 1, "       Please submit a bug report to\n");
+       flac__utils_printf(stderr, 1, "           http://sourceforge.net/bugs/?func=addbug&group_id=13478\n");
+       flac__utils_printf(stderr, 1, "       Make sure to include an email contact in the comment and/or use the\n");
+       flac__utils_printf(stderr, 1, "       \"Monitor\" feature to monitor the bug status.\n");
+       flac__utils_printf(stderr, 1, "Verify FAILED!  Do not trust %s\n", e->outfilename);
 }
 
-FLAC__bool read_little_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent)
+FLAC__bool read_little_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok, const char *fn)
 {
        size_t bytes_read = fread(val, 1, 2, f);
 
        if(bytes_read == 0) {
                if(!eof_ok) {
-                       if(!silent) fprintf(stderr, "%s: ERROR: unexpected EOF\n", fn);
+                       flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn);
                        return false;
                }
                else
                        return true;
        }
        else if(bytes_read < 2) {
-               if(!silent) fprintf(stderr, "%s: ERROR: unexpected EOF\n", fn);
+               flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn);
                return false;
        }
        else {
@@ -2050,20 +2031,20 @@ FLAC__bool read_little_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_
        }
 }
 
-FLAC__bool read_little_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent)
+FLAC__bool read_little_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn)
 {
        size_t bytes_read = fread(val, 1, 4, f);
 
        if(bytes_read == 0) {
                if(!eof_ok) {
-                       if(!silent) fprintf(stderr, "%s: ERROR: unexpected EOF\n", fn);
+                       flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn);
                        return false;
                }
                else
                        return true;
        }
        else if(bytes_read < 4) {
-               if(!silent) fprintf(stderr, "%s: ERROR: unexpected EOF\n", fn);
+               flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn);
                return false;
        }
        else {
@@ -2076,7 +2057,7 @@ FLAC__bool read_little_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_
        }
 }
 
-FLAC__bool read_big_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent)
+FLAC__bool read_big_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok, const char *fn)
 {
        unsigned char buf[4];
        size_t bytes_read= fread(buf, 1, 2, f);
@@ -2084,7 +2065,7 @@ FLAC__bool read_big_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok,
        if(bytes_read==0U && eof_ok)
                return true;
        else if(bytes_read<2U) {
-               if(!silent) fprintf(stderr, "%s: ERROR: unexpected EOF\n", fn);
+               flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn);
                return false;
        }
 
@@ -2094,7 +2075,7 @@ FLAC__bool read_big_endian_uint16(FILE *f, FLAC__uint16 *val, FLAC__bool eof_ok,
        return true;
 }
 
-FLAC__bool read_big_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent)
+FLAC__bool read_big_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn)
 {
        unsigned char buf[4];
        size_t bytes_read= fread(buf, 1, 4, f);
@@ -2102,7 +2083,7 @@ FLAC__bool read_big_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok,
        if(bytes_read==0U && eof_ok)
                return true;
        else if(bytes_read<4U) {
-               if(!silent) fprintf(stderr, "%s: ERROR: unexpected EOF\n", fn);
+               flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn);
                return false;
        }
 
@@ -2113,7 +2094,7 @@ FLAC__bool read_big_endian_uint32(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok,
        return true;
 }
 
-FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn, FLAC__bool silent)
+FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, const char *fn)
        /* Read an IEEE 754 80-bit (aka SANE) extended floating point value from 'f',
         * convert it into an integral value and store in 'val'.  Return false if only
         * between 1 and 9 bytes remain in 'f', if 0 bytes remain in 'f' and 'eof_ok' is
@@ -2131,11 +2112,11 @@ FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, FLAC__bool eof_ok, con
        if(bytes_read==0U && eof_ok)
                return true;
        else if(bytes_read<10U) {
-               if(!silent) fprintf(stderr, "%s: ERROR: unexpected EOF\n", fn);
+               flac__utils_printf(stderr, 1, "%s: ERROR: unexpected EOF\n", fn);
                return false;
        }
        else if((buf[0]>>7)==1U || e<0 || e>63) {
-               if(!silent) fprintf(stderr, "%s: ERROR: invalid floating-point value\n", fn);
+               flac__utils_printf(stderr, 1, "%s: ERROR: invalid floating-point value\n", fn);
                return false;
        }
 
index 5a2f756..79976c6 100644 (file)
@@ -27,8 +27,6 @@
 #endif
 
 typedef struct {
-       FLAC__bool verbose;
-       FLAC__bool silent;
        utils__SkipUntilSpecification skip_specification;
        utils__SkipUntilSpecification until_specification;
        FLAC__bool verify;
index c1fb517..3eb432b 100644 (file)
@@ -203,8 +203,6 @@ static struct {
        FLAC__bool show_version;
        FLAC__bool mode_decode;
        FLAC__bool verify;
-       FLAC__bool verbose;
-       FLAC__bool silent;
        FLAC__bool force_file_overwrite;
        FLAC__bool continue_through_decode_errors;
        replaygain_synthesis_spec_t replaygain_synthesis_spec;
@@ -276,7 +274,7 @@ int main(int argc, char *argv[])
 
        setlocale(LC_ALL, "");
        if(!init_options()) {
-               if(!option_values.silent) fprintf(stderr, "ERROR: allocating memory\n");
+               flac__utils_printf(stderr, 1, "ERROR: allocating memory\n");
                retval = 1;
        }
        else {
@@ -307,7 +305,8 @@ int do_it()
        }
        else {
                if(option_values.num_files == 0) {
-                       if(!option_values.silent) short_usage();
+                       if(flac__utils_verbosity_ >= 1)
+                               short_usage();
                        return 0;
                }
 
@@ -420,7 +419,7 @@ int do_it()
                         * whole file.
                         */
                        if(option_values.padding < 0) {
-                               if(!option_values.silent) fprintf(stderr, "NOTE: --replay-gain may leave a small PADDING block even with --no-padding\n");
+                               flac__utils_printf(stderr, 1, "NOTE: --replay-gain may leave a small PADDING block even with --no-padding\n");
                                option_values.padding = GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED;
                        }
                        else {
@@ -437,37 +436,36 @@ int do_it()
                        return usage_error("ERROR: --cuesheet cannot be used when encoding multiple files\n");
                }
        }
-       if(option_values.verbose) {
-               fprintf(stderr, "\n");
-               fprintf(stderr, "flac %s, Copyright (C) 2000,2001,2002,2003,2004 Josh Coalson\n", FLAC__VERSION_STRING);
-               fprintf(stderr, "flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are\n");
-               fprintf(stderr, "welcome to redistribute it under certain conditions.  Type `flac' for details.\n\n");
 
-               if(!option_values.mode_decode) {
-                       char padopt[16];
-                       if(option_values.padding < 0)
-                               strcpy(padopt, "-");
-                       else
-                               sprintf(padopt, " %d", option_values.padding);
-                       fprintf(stderr,
-                               "options:%s%s%s%s -P%s -b %u%s -l %u%s%s%s -q %u -r %u,%u%s\n",
-                               option_values.delete_input?" --delete-input-file":"",
-                               option_values.sector_align?" --sector-align":"",
-                               option_values.use_ogg?" --ogg":"",
-                               option_values.lax?" --lax":"",
-                               padopt,
-                               (unsigned)option_values.blocksize,
-                               option_values.loose_mid_side?" -M":option_values.do_mid_side?" -m":"",
-                               option_values.max_lpc_order,
-                               option_values.do_exhaustive_model_search?" -e":"",
-                               option_values.do_escape_coding?" -E":"",
-                               option_values.do_qlp_coeff_prec_search?" -p":"",
-                               option_values.qlp_coeff_precision,
-                               (unsigned)option_values.min_residual_partition_order,
-                               (unsigned)option_values.max_residual_partition_order,
-                               option_values.verify? " -V":""
-                       );
-               }
+       flac__utils_printf(stderr, 2, "\n");
+       flac__utils_printf(stderr, 2, "flac %s, Copyright (C) 2000,2001,2002,2003,2004 Josh Coalson\n", FLAC__VERSION_STRING);
+       flac__utils_printf(stderr, 2, "flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are\n");
+       flac__utils_printf(stderr, 2, "welcome to redistribute it under certain conditions.  Type `flac' for details.\n\n");
+
+       if(!option_values.mode_decode) {
+               char padopt[16];
+               if(option_values.padding < 0)
+                       strcpy(padopt, "-");
+               else
+                       sprintf(padopt, " %d", option_values.padding);
+               flac__utils_printf(stderr, 2,
+                       "options:%s%s%s%s -P%s -b %u%s -l %u%s%s%s -q %u -r %u,%u%s\n",
+                       option_values.delete_input?" --delete-input-file":"",
+                       option_values.sector_align?" --sector-align":"",
+                       option_values.use_ogg?" --ogg":"",
+                       option_values.lax?" --lax":"",
+                       padopt,
+                       (unsigned)option_values.blocksize,
+                       option_values.loose_mid_side?" -M":option_values.do_mid_side?" -m":"",
+                       option_values.max_lpc_order,
+                       option_values.do_exhaustive_model_search?" -e":"",
+                       option_values.do_escape_coding?" -E":"",
+                       option_values.do_qlp_coeff_prec_search?" -p":"",
+                       option_values.qlp_coeff_precision,
+                       (unsigned)option_values.min_residual_partition_order,
+                       (unsigned)option_values.max_residual_partition_order,
+                       option_values.verify? " -V":""
+               );
        }
 
        if(option_values.mode_decode) {
@@ -510,17 +508,17 @@ int do_it()
                                for(i = 0; i < option_values.num_files; i++) {
                                        const char *error, *outfilename = get_encoded_outfilename(option_values.filenames[i]);
                                        if(0 == outfilename) {
-                                               if(!option_values.silent) fprintf(stderr, "ERROR: filename too long: %s", option_values.filenames[i]);
+                                               flac__utils_printf(stderr, 1, "ERROR: filename too long: %s", option_values.filenames[i]);
                                                return 1;
                                        }
                                        if(0 == strcmp(option_values.filenames[i], "-")) {
                                                FLAC__ASSERT(0);
                                                /* double protection */
-                                               if(!option_values.silent) fprintf(stderr, "internal error\n");
+                                               flac__utils_printf(stderr, 1, "internal error\n");
                                                return 2;
                                        }
                                        if(0 != (error = grabbag__replaygain_store_to_file_album(outfilename, album_gain, album_peak, /*preserve_modtime=*/true))) {
-                                               if(!option_values.silent) fprintf(stderr, "%s: ERROR writing ReplayGain album tags\n", outfilename);
+                                               flac__utils_printf(stderr, 1, "%s: ERROR writing ReplayGain album tags\n", outfilename);
                                                retval = 1;
                                        }
                                }
@@ -537,8 +535,6 @@ FLAC__bool init_options()
        option_values.show_explain = false;
        option_values.mode_decode = false;
        option_values.verify = false;
-       option_values.verbose = true;
-       option_values.silent = false;
        option_values.force_file_overwrite = false;
        option_values.continue_through_decode_errors = false;
        option_values.replaygain_synthesis_spec.apply = false;
@@ -648,8 +644,7 @@ int parse_option(int short_option, const char *long_option, const char *option_a
        if(short_option == 0) {
                FLAC__ASSERT(0 != long_option);
                if(0 == strcmp(long_option, "totally-silent")) {
-                       option_values.verbose = false;
-                       option_values.silent = true;
+                       flac__utils_verbosity_ = 0;
                }
                else if(0 == strcmp(long_option, "delete-input-file")) {
                        option_values.delete_input = true;
@@ -781,8 +776,7 @@ int parse_option(int short_option, const char *long_option, const char *option_a
                        option_values.continue_through_decode_errors = false;
                }
                else if(0 == strcmp(long_option, "no-silent")) {
-                       option_values.verbose = true;
-                       option_values.silent = false;
+                       flac__utils_verbosity_ = 2;
                }
                else if(0 == strcmp(long_option, "no-force")) {
                        option_values.force_file_overwrite = false;
@@ -869,7 +863,7 @@ int parse_option(int short_option, const char *long_option, const char *option_a
                                option_values.force_to_stdout = true;
                                break;
                        case 's':
-                               option_values.verbose = false;
+                               flac__utils_verbosity_ = 1;
                                break;
                        case 'f':
                                option_values.force_file_overwrite = true;
@@ -1072,7 +1066,7 @@ void free_options()
 
 int usage_error(const char *message, ...)
 {
-       if(!option_values.silent) {
+       if(flac__utils_verbosity_ >= 1) {
                va_list args;
 
                FLAC__ASSERT(0 != message);
@@ -1456,7 +1450,7 @@ void show_explain()
 
 void format_mistake(const char *infilename, const char *wrong, const char *right)
 {
-       if(!option_values.silent) fprintf(stderr, "WARNING: %s is not a %s file; treating as a %s file\n", infilename, wrong, right);
+       flac__utils_printf(stderr, 1, "WARNING: %s is not a %s file; treating as a %s file\n", infilename, wrong, right);
 }
 
 int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_last_file)
@@ -1471,7 +1465,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
        const char *outfilename = get_encoded_outfilename(infilename);
 
        if(0 == outfilename) {
-               if(!option_values.silent) fprintf(stderr, "ERROR: filename too long: %s", infilename);
+               flac__utils_printf(stderr, 1, "ERROR: filename too long: %s", infilename);
                return 1;
        }
 
@@ -1480,7 +1474,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
         * Use grabbag__file_get_filesize() as a cheap way to check.
         */
        if(!option_values.test_only && !option_values.force_file_overwrite && grabbag__file_get_filesize(outfilename) != (off_t)(-1)) {
-               if(!option_values.silent) fprintf(stderr, "ERROR: output file %s already exists, use -f to override\n", outfilename);
+               flac__utils_printf(stderr, 1, "ERROR: output file %s already exists, use -f to override\n", outfilename);
                return 1;
        }
 
@@ -1491,7 +1485,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
        else {
                infilesize = grabbag__file_get_filesize(infilename);
                if(0 == (encode_infile = fopen(infilename, "rb"))) {
-                       if(!option_values.silent) fprintf(stderr, "ERROR: can't open input file %s\n", infilename);
+                       flac__utils_printf(stderr, 1, "ERROR: can't open input file %s\n", infilename);
                        return 1;
                }
        }
@@ -1525,7 +1519,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
        }
 
        if(option_values.sector_align && fmt == RAW && infilesize < 0) {
-               if(!option_values.silent) fprintf(stderr, "ERROR: can't --sector-align when the input size is unknown\n");
+               flac__utils_printf(stderr, 1, "ERROR: can't --sector-align when the input size is unknown\n");
                return 1;
        }
 
@@ -1548,8 +1542,6 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
        if(0 == option_values.until_specification)
                common_options.until_specification.is_relative = true;
 
-       common_options.verbose = option_values.verbose;
-       common_options.silent = option_values.silent;
        common_options.verify = option_values.verify;
 #ifdef FLAC__HAS_OGG
        common_options.use_ogg = option_values.use_ogg;
@@ -1619,7 +1611,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
                                const char *error;
                                grabbag__replaygain_get_title(&title_gain, &title_peak);
                                if(0 != (error = grabbag__replaygain_store_to_file_title(outfilename, title_gain, title_peak, /*preserve_modtime=*/true))) {
-                                       if(!option_values.silent) fprintf(stderr, "%s: ERROR writing ReplayGain title tags\n", outfilename);
+                                       flac__utils_printf(stderr, 1, "%s: ERROR writing ReplayGain title tags\n", outfilename);
                                }
                        }
                        grabbag__file_copy_metadata(infilename, outfilename);
@@ -1639,7 +1631,7 @@ int decode_file(const char *infilename)
        const char *outfilename = get_decoded_outfilename(infilename);
 
        if(0 == outfilename) {
-               if(!option_values.silent) fprintf(stderr, "ERROR: filename too long: %s", infilename);
+               flac__utils_printf(stderr, 1, "ERROR: filename too long: %s", infilename);
                return 1;
        }
 
@@ -1648,7 +1640,7 @@ int decode_file(const char *infilename)
         * Use grabbag__file_get_filesize() as a cheap way to check.
         */
        if(!option_values.test_only && !option_values.force_file_overwrite && grabbag__file_get_filesize(outfilename) != (off_t)(-1)) {
-               if(!option_values.silent) fprintf(stderr, "ERROR: output file %s already exists, use -f to override\n", outfilename);
+               flac__utils_printf(stderr, 1, "ERROR: output file %s already exists, use -f to override\n", outfilename);
                return 1;
        }
 
@@ -1666,7 +1658,7 @@ int decode_file(const char *infilename)
 
 #ifndef FLAC__HAS_OGG
        if(treat_as_ogg) {
-               if(!option_values.silent) fprintf(stderr, "%s: Ogg support has not been built into this copy of flac\n", infilename);
+               flac__utils_printf(stderr, 1, "%s: Ogg support has not been built into this copy of flac\n", infilename);
                return 1;
        }
 #endif
@@ -1688,8 +1680,6 @@ int decode_file(const char *infilename)
        else
                common_options.has_cue_specification = false;
 
-       common_options.verbose = option_values.verbose;
-       common_options.silent = option_values.silent;
        common_options.continue_through_decode_errors = option_values.continue_through_decode_errors;
        common_options.replaygain_synthesis_spec = option_values.replaygain_synthesis_spec;
 #ifdef FLAC__HAS_OGG
@@ -1796,7 +1786,7 @@ const char *get_outfilename(const char *infilename, const char *suffix)
 void die(const char *message)
 {
        FLAC__ASSERT(0 != message);
-       if(!option_values.silent) fprintf(stderr, "ERROR: %s\n", message);
+       flac__utils_printf(stderr, 1, "ERROR: %s\n", message);
        exit(1);
 }
 
index ff82ab7..1eefb7b 100644 (file)
 #include "utils.h"
 #include "FLAC/assert.h"
 #include <math.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 
+int flac__utils_verbosity_ = 2;
+
 static FLAC__bool local__parse_uint64_(const char *s, FLAC__uint64 *value)
 {
        FLAC__uint64 ret = 0;
@@ -133,6 +136,21 @@ static FLAC__uint64 local__find_closest_cue_(const FLAC__StreamMetadata_CueSheet
        }
 }
 
+void flac__utils_printf(FILE *stream, int level, const char *format, ...)
+{
+       if(flac__utils_verbosity_ >= level) {
+               va_list args;
+
+               FLAC__ASSERT(0 != format);
+
+               va_start(args, format);
+
+               (void) vfprintf(stream, format, args);
+
+               va_end(args);
+       }
+}
+
 #ifdef FLAC__VALGRIND_TESTING
 size_t flac__utils_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
 {
index 5cca12c..3248c9f 100644 (file)
@@ -43,6 +43,10 @@ size_t flac__utils_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stre
 #else
 #define flac__utils_fwrite fwrite
 #endif
+
+extern int flac__utils_verbosity_;
+void flac__utils_printf(FILE *stream, int level, const char *format, ...);
+
 FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__SkipUntilSpecification *spec);
 void flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, unsigned sample_rate);