Commit 36378658 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Avoid fprintf() for error reporting, use error() instead.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent e342441e
...@@ -284,7 +284,7 @@ gentest (const string& infile, const string& outfile) ...@@ -284,7 +284,7 @@ gentest (const string& infile, const string& outfile)
Error err = wav_data.load (infile); Error err = wav_data.load (infile);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error loading %s: %s\n", infile.c_str(), err.message()); error ("audiowmark: error loading %s: %s\n", infile.c_str(), err.message());
return 1; return 1;
} }
const vector<float>& in_signal = wav_data.samples(); const vector<float>& in_signal = wav_data.samples();
...@@ -296,7 +296,7 @@ gentest (const string& infile, const string& outfile) ...@@ -296,7 +296,7 @@ gentest (const string& infile, const string& outfile)
const size_t n_samples = 165 * wav_data.n_channels() * wav_data.sample_rate(); const size_t n_samples = 165 * wav_data.n_channels() * wav_data.sample_rate();
if (in_signal.size() < (offset + n_samples)) if (in_signal.size() < (offset + n_samples))
{ {
fprintf (stderr, "audiowmark: input file %s too short\n", infile.c_str()); error ("audiowmark: input file %s too short\n", infile.c_str());
return 1; return 1;
} }
for (size_t i = 0; i < n_samples; i++) for (size_t i = 0; i < n_samples; i++)
...@@ -307,7 +307,7 @@ gentest (const string& infile, const string& outfile) ...@@ -307,7 +307,7 @@ gentest (const string& infile, const string& outfile)
err = out_wav_data.save (outfile); err = out_wav_data.save (outfile);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), err.message()); error ("audiowmark: error saving %s: %s\n", outfile.c_str(), err.message());
return 1; return 1;
} }
return 0; return 0;
...@@ -320,7 +320,7 @@ cut_start (const string& infile, const string& outfile, const string& start_str) ...@@ -320,7 +320,7 @@ cut_start (const string& infile, const string& outfile, const string& start_str)
Error err = wav_data.load (infile); Error err = wav_data.load (infile);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error loading %s: %s\n", infile.c_str(), err.message()); error ("audiowmark: error loading %s: %s\n", infile.c_str(), err.message());
return 1; return 1;
} }
...@@ -335,7 +335,7 @@ cut_start (const string& infile, const string& outfile, const string& start_str) ...@@ -335,7 +335,7 @@ cut_start (const string& infile, const string& outfile, const string& start_str)
err = out_wav_data.save (outfile); err = out_wav_data.save (outfile);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), err.message()); error ("audiowmark: error saving %s: %s\n", outfile.c_str(), err.message());
return 1; return 1;
} }
return 0; return 0;
...@@ -380,7 +380,7 @@ test_subtract (const string& infile1, const string& infile2, const string& outfi ...@@ -380,7 +380,7 @@ test_subtract (const string& infile1, const string& infile2, const string& outfi
err = out_wav_data.save (outfile); err = out_wav_data.save (outfile);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error saving %s: %s\n", outfile.c_str(), err.message()); error ("audiowmark: error saving %s: %s\n", outfile.c_str(), err.message());
return 1; return 1;
} }
return 0; return 0;
...@@ -392,7 +392,7 @@ gen_key (const string& outfile) ...@@ -392,7 +392,7 @@ gen_key (const string& outfile)
FILE *f = fopen (outfile.c_str(), "w"); FILE *f = fopen (outfile.c_str(), "w");
if (!f) if (!f)
{ {
fprintf (stderr, "audiowmark: error writing to file %s\n", outfile.c_str()); error ("audiowmark: error writing to file %s\n", outfile.c_str());
return 1; return 1;
} }
fprintf (f, "# watermarking key for audiowmark\n\nkey %s\n", Random::gen_key().c_str()); fprintf (f, "# watermarking key for audiowmark\n\nkey %s\n", Random::gen_key().c_str());
...@@ -407,7 +407,7 @@ main (int argc, char **argv) ...@@ -407,7 +407,7 @@ main (int argc, char **argv)
if (Params::have_key > 1) if (Params::have_key > 1)
{ {
fprintf (stderr, "audiowmark: watermark key can at most be set once (--key / --test-key option)\n"); error ("audiowmark: watermark key can at most be set once (--key / --test-key option)\n");
return 1; return 1;
} }
string op = (argc >= 2) ? argv[1] : ""; string op = (argc >= 2) ? argv[1] : "";
...@@ -442,7 +442,7 @@ main (int argc, char **argv) ...@@ -442,7 +442,7 @@ main (int argc, char **argv)
} }
else else
{ {
fprintf (stderr, "audiowmark: error parsing commandline args (use audiowmark -h)\n"); error ("audiowmark: error parsing commandline args (use audiowmark -h)\n");
return 1; return 1;
} }
} }
...@@ -32,7 +32,7 @@ mp3_init() ...@@ -32,7 +32,7 @@ mp3_init()
int err = mpg123_init(); int err = mpg123_init();
if (err != MPG123_OK) if (err != MPG123_OK)
{ {
fprintf (stderr, "audiowmark: init mpg123 lib failed\n"); error ("audiowmark: init mpg123 lib failed\n");
exit (1); exit (1);
} }
mpg123_init_ok = true; mpg123_init_ok = true;
......
...@@ -20,7 +20,7 @@ gcrypt_init() ...@@ -20,7 +20,7 @@ gcrypt_init()
/* version check: start libgcrypt initialization */ /* version check: start libgcrypt initialization */
if (!gcry_check_version (GCRYPT_VERSION)) if (!gcry_check_version (GCRYPT_VERSION))
{ {
fprintf (stderr, "audiowmark: libgcrypt version mismatch\n"); error ("audiowmark: libgcrypt version mismatch\n");
exit (1); exit (1);
} }
...@@ -144,11 +144,11 @@ Random::refill_buffer() ...@@ -144,11 +144,11 @@ Random::refill_buffer()
} }
void void
Random::die_on_error (const char *func, gcry_error_t error) Random::die_on_error (const char *func, gcry_error_t err)
{ {
if (error) if (err)
{ {
fprintf (stderr, "%s failed: %s/%s\n", func, gcry_strsource (error), gcry_strerror (error)); error ("%s failed: %s/%s\n", func, gcry_strsource (err), gcry_strerror (err));
exit (1); /* can't recover here */ exit (1); /* can't recover here */
} }
...@@ -166,7 +166,7 @@ Random::load_global_key (const string& key_file) ...@@ -166,7 +166,7 @@ Random::load_global_key (const string& key_file)
FILE *f = fopen (key_file.c_str(), "r"); FILE *f = fopen (key_file.c_str(), "r");
if (!f) if (!f)
{ {
fprintf (stderr, "audiowmark: error opening key file: '%s'\n", key_file.c_str()); error ("audiowmark: error opening key file: '%s'\n", key_file.c_str());
exit (1); exit (1);
} }
...@@ -191,7 +191,7 @@ Random::load_global_key (const string& key_file) ...@@ -191,7 +191,7 @@ Random::load_global_key (const string& key_file)
vector<unsigned char> key = hex_str_to_vec (match[1].str()); vector<unsigned char> key = hex_str_to_vec (match[1].str());
if (key.size() != aes_key.size()) if (key.size() != aes_key.size())
{ {
fprintf (stderr, "audiowmark: wrong key length in key file '%s', line %d\n => required key length is %zd bits\n", key_file.c_str(), line, aes_key.size() * 8); error ("audiowmark: wrong key length in key file '%s', line %d\n => required key length is %zd bits\n", key_file.c_str(), line, aes_key.size() * 8);
exit (1); exit (1);
} }
aes_key = key; aes_key = key;
...@@ -199,7 +199,7 @@ Random::load_global_key (const string& key_file) ...@@ -199,7 +199,7 @@ Random::load_global_key (const string& key_file)
} }
else else
{ {
fprintf (stderr, "audiowmark: parse error in key file '%s', line %d\n", key_file.c_str(), line); error ("audiowmark: parse error in key file '%s', line %d\n", key_file.c_str(), line);
exit (1); exit (1);
} }
line++; line++;
...@@ -208,12 +208,12 @@ Random::load_global_key (const string& key_file) ...@@ -208,12 +208,12 @@ Random::load_global_key (const string& key_file)
if (keys > 1) if (keys > 1)
{ {
fprintf (stderr, "audiowmark: key file '%s' contains more than one key\n", key_file.c_str()); error ("audiowmark: key file '%s' contains more than one key\n", key_file.c_str());
exit (1); exit (1);
} }
if (keys == 0) if (keys == 0)
{ {
fprintf (stderr, "audiowmark: key file '%s' contains no key\n", key_file.c_str()); error ("audiowmark: key file '%s' contains no key\n", key_file.c_str());
exit (1); exit (1);
} }
} }
......
...@@ -549,12 +549,12 @@ add_watermark (const string& infile, const string& outfile, const string& bits) ...@@ -549,12 +549,12 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
auto bitvec = bit_str_to_vec (bits); auto bitvec = bit_str_to_vec (bits);
if (bitvec.empty()) if (bitvec.empty())
{ {
fprintf (stderr, "audiowmark: cannot parse bits %s\n", bits.c_str()); error ("audiowmark: cannot parse bits %s\n", bits.c_str());
return 1; return 1;
} }
if (bitvec.size() > Params::payload_size) if (bitvec.size() > Params::payload_size)
{ {
fprintf (stderr, "audiowmark: number of bits in message '%s' larger than payload size\n", bits.c_str()); error ("audiowmark: number of bits in message '%s' larger than payload size\n", bits.c_str());
return 1; return 1;
} }
if (bitvec.size() < Params::payload_size) if (bitvec.size() < Params::payload_size)
...@@ -592,13 +592,13 @@ add_watermark (const string& infile, const string& outfile, const string& bits) ...@@ -592,13 +592,13 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
err = mistream->open (infile); err = mistream->open (infile);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error opening mp3 %s: %s\n", infile.c_str(), err.message()); error ("audiowmark: error opening mp3 %s: %s\n", infile.c_str(), err.message());
return 1; return 1;
} }
} }
else if (err) else if (err)
{ {
fprintf (stderr, "audiowmark: error opening %s: %s\n", infile.c_str(), err.message()); error ("audiowmark: error opening %s: %s\n", infile.c_str(), err.message());
return 1; return 1;
} }
} }
...@@ -609,7 +609,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits) ...@@ -609,7 +609,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
Error err = ristream->open (infile, Params::raw_input_format); Error err = ristream->open (infile, Params::raw_input_format);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error opening %s: %s\n", infile.c_str(), err.message()); error ("audiowmark: error opening %s: %s\n", infile.c_str(), err.message());
return 1; return 1;
} }
} }
...@@ -634,7 +634,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits) ...@@ -634,7 +634,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
Error err = rostream->open (outfile, Params::raw_output_format); Error err = rostream->open (outfile, Params::raw_output_format);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error opening %s: %s\n", outfile.c_str(), err.message()); error ("audiowmark: error opening %s: %s\n", outfile.c_str(), err.message());
return 1; return 1;
} }
} }
......
...@@ -74,7 +74,7 @@ resample (const WavData& wav_data, int rate) ...@@ -74,7 +74,7 @@ resample (const WavData& wav_data, int rate)
process_resampler (vresampler, in, out); process_resampler (vresampler, in, out);
return WavData (out, wav_data.n_channels(), rate, wav_data.bit_depth()); return WavData (out, wav_data.n_channels(), rate, wav_data.bit_depth());
} }
fprintf (stderr, "audiowmark: resampling from rate %d to rate %d not supported.\n", wav_data.sample_rate(), rate); error ("audiowmark: resampling from rate %d to rate %d not supported.\n", wav_data.sample_rate(), rate);
exit (1); exit (1);
} }
...@@ -607,7 +607,7 @@ get_watermark (const string& infile, const string& orig_pattern) ...@@ -607,7 +607,7 @@ get_watermark (const string& infile, const string& orig_pattern)
Error err = wav_data.load (infile); Error err = wav_data.load (infile);
if (err) if (err)
{ {
fprintf (stderr, "audiowmark: error loading %s: %s\n", infile.c_str(), err.message()); error ("audiowmark: error loading %s: %s\n", infile.c_str(), err.message());
return 1; return 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment