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)
Error err = wav_data.load (infile);
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;
}
const vector<float>& in_signal = wav_data.samples();
......@@ -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();
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;
}
for (size_t i = 0; i < n_samples; i++)
......@@ -307,7 +307,7 @@ gentest (const string& infile, const string& outfile)
err = out_wav_data.save (outfile);
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 0;
......@@ -320,7 +320,7 @@ cut_start (const string& infile, const string& outfile, const string& start_str)
Error err = wav_data.load (infile);
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;
}
......@@ -335,7 +335,7 @@ cut_start (const string& infile, const string& outfile, const string& start_str)
err = out_wav_data.save (outfile);
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 0;
......@@ -380,7 +380,7 @@ test_subtract (const string& infile1, const string& infile2, const string& outfi
err = out_wav_data.save (outfile);
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 0;
......@@ -392,7 +392,7 @@ gen_key (const string& outfile)
FILE *f = fopen (outfile.c_str(), "w");
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;
}
fprintf (f, "# watermarking key for audiowmark\n\nkey %s\n", Random::gen_key().c_str());
......@@ -407,7 +407,7 @@ main (int argc, char **argv)
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;
}
string op = (argc >= 2) ? argv[1] : "";
......@@ -442,7 +442,7 @@ main (int argc, char **argv)
}
else
{
fprintf (stderr, "audiowmark: error parsing commandline args (use audiowmark -h)\n");
error ("audiowmark: error parsing commandline args (use audiowmark -h)\n");
return 1;
}
}
......@@ -32,7 +32,7 @@ mp3_init()
int err = mpg123_init();
if (err != MPG123_OK)
{
fprintf (stderr, "audiowmark: init mpg123 lib failed\n");
error ("audiowmark: init mpg123 lib failed\n");
exit (1);
}
mpg123_init_ok = true;
......
......@@ -20,7 +20,7 @@ gcrypt_init()
/* version check: start libgcrypt initialization */
if (!gcry_check_version (GCRYPT_VERSION))
{
fprintf (stderr, "audiowmark: libgcrypt version mismatch\n");
error ("audiowmark: libgcrypt version mismatch\n");
exit (1);
}
......@@ -144,11 +144,11 @@ Random::refill_buffer()
}
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 */
}
......@@ -166,7 +166,7 @@ Random::load_global_key (const string& key_file)
FILE *f = fopen (key_file.c_str(), "r");
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);
}
......@@ -191,7 +191,7 @@ Random::load_global_key (const string& key_file)
vector<unsigned char> key = hex_str_to_vec (match[1].str());
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);
}
aes_key = key;
......@@ -199,7 +199,7 @@ Random::load_global_key (const string& key_file)
}
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);
}
line++;
......@@ -208,12 +208,12 @@ Random::load_global_key (const string& key_file)
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);
}
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);
}
}
......
......@@ -549,12 +549,12 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
auto bitvec = bit_str_to_vec (bits);
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;
}
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;
}
if (bitvec.size() < Params::payload_size)
......@@ -592,13 +592,13 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
err = mistream->open (infile);
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;
}
}
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;
}
}
......@@ -609,7 +609,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
Error err = ristream->open (infile, Params::raw_input_format);
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;
}
}
......@@ -634,7 +634,7 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
Error err = rostream->open (outfile, Params::raw_output_format);
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;
}
}
......
......@@ -74,7 +74,7 @@ resample (const WavData& wav_data, int rate)
process_resampler (vresampler, in, out);
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);
}
......@@ -607,7 +607,7 @@ get_watermark (const string& infile, const string& orig_pattern)
Error err = wav_data.load (infile);
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;
}
......
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