Commit 66d90dd4 authored by Max Kellermann's avatar Max Kellermann

test/*: use fprintf(stderr,...) and Log() instead of g_printerr()

Avoid GLib.
parent d5dfe7d4
...@@ -21,40 +21,26 @@ ...@@ -21,40 +21,26 @@
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h> #include <assert.h>
static void
my_log_func(gcc_unused const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message, gcc_unused gpointer user_data)
{
if (log_level > G_LOG_LEVEL_WARNING)
return;
g_printerr("%s\n", message);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if (argc != 3) { if (argc != 3) {
g_printerr("Usage: read_conf FILE SETTING\n"); fprintf(stderr, "Usage: read_conf FILE SETTING\n");
return 1; return EXIT_FAILURE;
} }
const Path config_path = Path::FromFS(argv[1]); const Path config_path = Path::FromFS(argv[1]);
const char *name = argv[2]; const char *name = argv[2];
g_log_set_default_handler(my_log_func, NULL);
config_global_init(); config_global_init();
Error error; Error error;
if (!ReadConfigFile(config_path, error)) { if (!ReadConfigFile(config_path, error)) {
g_printerr("%s:", error.GetMessage()); LogError(error);
return 1; return EXIT_FAILURE;
} }
ConfigOption option = ParseConfigOptionName(name); ConfigOption option = ParseConfigOptionName(name);
...@@ -63,11 +49,11 @@ int main(int argc, char **argv) ...@@ -63,11 +49,11 @@ int main(int argc, char **argv)
: nullptr; : nullptr;
int ret; int ret;
if (value != NULL) { if (value != NULL) {
g_print("%s\n", value); printf("%s\n", value);
ret = 0; ret = EXIT_SUCCESS;
} else { } else {
g_printerr("No such setting: %s\n", name); fprintf(stderr, "No such setting: %s\n", name);
ret = 2; ret = EXIT_FAILURE;
} }
config_global_finish(); config_global_finish();
......
...@@ -30,25 +30,14 @@ ...@@ -30,25 +30,14 @@
#include "ConfigGlobal.hxx" #include "ConfigGlobal.hxx"
#include "util/FifoBuffer.hxx" #include "util/FifoBuffer.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include "stdbin.h" #include "stdbin.h"
#include <glib.h>
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
static void
my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level,
const gchar *message, gcc_unused gpointer user_data)
{
if (log_domain != NULL)
g_printerr("%s: %s\n", log_domain, message);
else
g_printerr("%s\n", message);
}
const char * const char *
config_get_string(gcc_unused enum ConfigOption option, config_get_string(gcc_unused enum ConfigOption option,
const char *default_value) const char *default_value)
...@@ -62,26 +51,23 @@ int main(int argc, char **argv) ...@@ -62,26 +51,23 @@ int main(int argc, char **argv)
const void *output; const void *output;
if (argc != 3) { if (argc != 3) {
g_printerr("Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT\n"); fprintf(stderr,
"Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT\n");
return 1; return 1;
} }
g_log_set_default_handler(my_log_func, NULL);
Error error; Error error;
if (!audio_format_parse(in_audio_format, argv[1], if (!audio_format_parse(in_audio_format, argv[1],
false, error)) { false, error)) {
g_printerr("Failed to parse audio format: %s\n", LogError(error, "Failed to parse audio format");
error.GetMessage()); return EXIT_FAILURE;
return 1;
} }
AudioFormat out_audio_format_mask; AudioFormat out_audio_format_mask;
if (!audio_format_parse(out_audio_format_mask, argv[2], if (!audio_format_parse(out_audio_format_mask, argv[2],
true, error)) { true, error)) {
g_printerr("Failed to parse audio format: %s\n", LogError(error, "Failed to parse audio format");
error.GetMessage()); return EXIT_FAILURE;
return 1;
} }
out_audio_format = in_audio_format; out_audio_format = in_audio_format;
...@@ -91,8 +77,7 @@ int main(int argc, char **argv) ...@@ -91,8 +77,7 @@ int main(int argc, char **argv)
PcmConvert state; PcmConvert state;
if (!state.Open(in_audio_format, out_audio_format_mask, error)) { if (!state.Open(in_audio_format, out_audio_format_mask, error)) {
g_printerr("Failed to open PcmConvert: %s\n", LogError(error, "Failed to open PcmConvert");
error.GetMessage());
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -124,8 +109,8 @@ int main(int argc, char **argv) ...@@ -124,8 +109,8 @@ int main(int argc, char **argv)
&length, error); &length, error);
if (output == NULL) { if (output == NULL) {
state.Close(); state.Close();
g_printerr("Failed to convert: %s\n", error.GetMessage()); LogError(error, "Failed to convert");
return 2; return EXIT_FAILURE;
} }
gcc_unused ssize_t ignored = write(1, output, length); gcc_unused ssize_t ignored = write(1, output, length);
......
...@@ -36,16 +36,7 @@ ...@@ -36,16 +36,7 @@
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
static void
my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level,
const gchar *message, gcc_unused gpointer user_data)
{
if (log_domain != NULL)
g_printerr("%s: %s\n", log_domain, message);
else
g_printerr("%s\n", message);
}
struct Decoder { struct Decoder {
const char *uri; const char *uri;
...@@ -66,9 +57,9 @@ decoder_initialized(Decoder &decoder, ...@@ -66,9 +57,9 @@ decoder_initialized(Decoder &decoder,
assert(!decoder.initialized); assert(!decoder.initialized);
assert(audio_format.IsValid()); assert(audio_format.IsValid());
g_printerr("audio_format=%s duration=%f\n", fprintf(stderr, "audio_format=%s duration=%f\n",
audio_format_to_string(audio_format, &af_string), audio_format_to_string(audio_format, &af_string),
duration); duration);
decoder.initialized = true; decoder.initialized = true;
} }
...@@ -167,13 +158,13 @@ decoder_replay_gain(gcc_unused Decoder &decoder, ...@@ -167,13 +158,13 @@ decoder_replay_gain(gcc_unused Decoder &decoder,
{ {
const ReplayGainTuple *tuple = &rgi->tuples[REPLAY_GAIN_ALBUM]; const ReplayGainTuple *tuple = &rgi->tuples[REPLAY_GAIN_ALBUM];
if (tuple->IsDefined()) if (tuple->IsDefined())
g_printerr("replay_gain[album]: gain=%f peak=%f\n", fprintf(stderr, "replay_gain[album]: gain=%f peak=%f\n",
tuple->gain, tuple->peak); tuple->gain, tuple->peak);
tuple = &rgi->tuples[REPLAY_GAIN_TRACK]; tuple = &rgi->tuples[REPLAY_GAIN_TRACK];
if (tuple->IsDefined()) if (tuple->IsDefined())
g_printerr("replay_gain[track]: gain=%f peak=%f\n", fprintf(stderr, "replay_gain[track]: gain=%f peak=%f\n",
tuple->gain, tuple->peak); tuple->gain, tuple->peak);
} }
void void
...@@ -186,8 +177,8 @@ int main(int argc, char **argv) ...@@ -186,8 +177,8 @@ int main(int argc, char **argv)
const char *decoder_name; const char *decoder_name;
if (argc != 3) { if (argc != 3) {
g_printerr("Usage: run_decoder DECODER URI >OUT\n"); fprintf(stderr, "Usage: run_decoder DECODER URI >OUT\n");
return 1; return EXIT_FAILURE;
} }
Decoder decoder; Decoder decoder;
...@@ -200,23 +191,21 @@ int main(int argc, char **argv) ...@@ -200,23 +191,21 @@ int main(int argc, char **argv)
#endif #endif
#endif #endif
g_log_set_default_handler(my_log_func, NULL);
io_thread_init(); io_thread_init();
io_thread_start(); io_thread_start();
Error error; Error error;
if (!input_stream_global_init(error)) { if (!input_stream_global_init(error)) {
LogError(error); LogError(error);
return 2; return EXIT_FAILURE;
} }
decoder_plugin_init_all(); decoder_plugin_init_all();
decoder.plugin = decoder_plugin_from_name(decoder_name); decoder.plugin = decoder_plugin_from_name(decoder_name);
if (decoder.plugin == NULL) { if (decoder.plugin == NULL) {
g_printerr("No such decoder: %s\n", decoder_name); fprintf(stderr, "No such decoder: %s\n", decoder_name);
return 1; return EXIT_FAILURE;
} }
decoder.initialized = false; decoder.initialized = false;
...@@ -233,17 +222,17 @@ int main(int argc, char **argv) ...@@ -233,17 +222,17 @@ int main(int argc, char **argv)
if (error.IsDefined()) if (error.IsDefined())
LogError(error); LogError(error);
else else
g_printerr("InputStream::Open() failed\n"); fprintf(stderr, "InputStream::Open() failed\n");
return 1; return EXIT_FAILURE;
} }
decoder.plugin->StreamDecode(decoder, *is); decoder.plugin->StreamDecode(decoder, *is);
is->Close(); is->Close();
} else { } else {
g_printerr("Decoder plugin is not usable\n"); fprintf(stderr, "Decoder plugin is not usable\n");
return 1; return EXIT_FAILURE;
} }
decoder_plugin_deinit_all(); decoder_plugin_deinit_all();
...@@ -251,8 +240,8 @@ int main(int argc, char **argv) ...@@ -251,8 +240,8 @@ int main(int argc, char **argv)
io_thread_deinit(); io_thread_deinit();
if (!decoder.initialized) { if (!decoder.initialized) {
g_printerr("Decoding failed\n"); fprintf(stderr, "Decoding failed\n");
return 1; return EXIT_FAILURE;
} }
return 0; return 0;
......
...@@ -24,10 +24,9 @@ ...@@ -24,10 +24,9 @@
#include "AudioParser.hxx" #include "AudioParser.hxx"
#include "ConfigData.hxx" #include "ConfigData.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "Log.hxx"
#include "stdbin.h" #include "stdbin.h"
#include <glib.h>
#include <stddef.h> #include <stddef.h>
#include <unistd.h> #include <unistd.h>
...@@ -50,8 +49,9 @@ int main(int argc, char **argv) ...@@ -50,8 +49,9 @@ int main(int argc, char **argv)
/* parse command line */ /* parse command line */
if (argc > 3) { if (argc > 3) {
g_printerr("Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n"); fprintf(stderr,
return 1; "Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n");
return EXIT_FAILURE;
} }
if (argc > 1) if (argc > 1)
...@@ -63,8 +63,8 @@ int main(int argc, char **argv) ...@@ -63,8 +63,8 @@ int main(int argc, char **argv)
const auto plugin = encoder_plugin_get(encoder_name); const auto plugin = encoder_plugin_get(encoder_name);
if (plugin == NULL) { if (plugin == NULL) {
g_printerr("No such encoder: %s\n", encoder_name); fprintf(stderr, "No such encoder: %s\n", encoder_name);
return 1; return EXIT_FAILURE;
} }
config_param param; config_param param;
...@@ -73,9 +73,8 @@ int main(int argc, char **argv) ...@@ -73,9 +73,8 @@ int main(int argc, char **argv)
Error error; Error error;
const auto encoder = encoder_init(*plugin, param, error); const auto encoder = encoder_init(*plugin, param, error);
if (encoder == NULL) { if (encoder == NULL) {
g_printerr("Failed to initialize encoder: %s\n", LogError(error, "Failed to initialize encoder");
error.GetMessage()); return EXIT_FAILURE;
return 1;
} }
/* open the encoder */ /* open the encoder */
...@@ -83,16 +82,14 @@ int main(int argc, char **argv) ...@@ -83,16 +82,14 @@ int main(int argc, char **argv)
AudioFormat audio_format(44100, SampleFormat::S16, 2); AudioFormat audio_format(44100, SampleFormat::S16, 2);
if (argc > 2) { if (argc > 2) {
if (!audio_format_parse(audio_format, argv[2], false, error)) { if (!audio_format_parse(audio_format, argv[2], false, error)) {
g_printerr("Failed to parse audio format: %s\n", LogError(error, "Failed to parse audio format");
error.GetMessage()); return EXIT_FAILURE;
return 1;
} }
} }
if (!encoder_open(encoder, audio_format, error)) { if (!encoder_open(encoder, audio_format, error)) {
g_printerr("Failed to open encoder: %s\n", LogError(error, "Failed to open encoder");
error.GetMessage()); return EXIT_FAILURE;
return 1;
} }
encoder_to_stdout(*encoder); encoder_to_stdout(*encoder);
...@@ -102,18 +99,16 @@ int main(int argc, char **argv) ...@@ -102,18 +99,16 @@ int main(int argc, char **argv)
ssize_t nbytes; ssize_t nbytes;
while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) {
if (!encoder_write(encoder, buffer, nbytes, error)) { if (!encoder_write(encoder, buffer, nbytes, error)) {
g_printerr("encoder_write() failed: %s\n", LogError(error, "encoder_write() failed");
error.GetMessage()); return EXIT_FAILURE;
return 1;
} }
encoder_to_stdout(*encoder); encoder_to_stdout(*encoder);
} }
if (!encoder_end(encoder, error)) { if (!encoder_end(encoder, error)) {
g_printerr("encoder_flush() failed: %s\n", LogError(error, "encoder_flush() failed");
error.GetMessage()); return EXIT_FAILURE;
return 1;
} }
encoder_to_stdout(*encoder); encoder_to_stdout(*encoder);
......
...@@ -40,16 +40,6 @@ ...@@ -40,16 +40,6 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
static void
my_log_func(const gchar *log_domain, gcc_unused GLogLevelFlags log_level,
const gchar *message, gcc_unused gpointer user_data)
{
if (log_domain != NULL)
g_printerr("%s: %s\n", log_domain, message);
else
g_printerr("%s\n", message);
}
static int static int
dump_input_stream(InputStream *is) dump_input_stream(InputStream *is)
{ {
...@@ -73,14 +63,14 @@ dump_input_stream(InputStream *is) ...@@ -73,14 +63,14 @@ dump_input_stream(InputStream *is)
/* print meta data */ /* print meta data */
if (!is->mime.empty()) if (!is->mime.empty())
g_printerr("MIME type: %s\n", is->mime.c_str()); fprintf(stderr, "MIME type: %s\n", is->mime.c_str());
/* read data and tags from the stream */ /* read data and tags from the stream */
while (!is->IsEOF()) { while (!is->IsEOF()) {
Tag *tag = is->ReadTag(); Tag *tag = is->ReadTag();
if (tag != NULL) { if (tag != NULL) {
g_printerr("Received a tag:\n"); fprintf(stderr, "Received a tag:\n");
tag_save(stderr, *tag); tag_save(stderr, *tag);
delete tag; delete tag;
} }
...@@ -116,8 +106,8 @@ int main(int argc, char **argv) ...@@ -116,8 +106,8 @@ int main(int argc, char **argv)
int ret; int ret;
if (argc != 2) { if (argc != 2) {
g_printerr("Usage: run_input URI\n"); fprintf(stderr, "Usage: run_input URI\n");
return 1; return EXIT_FAILURE;
} }
/* initialize GLib */ /* initialize GLib */
...@@ -128,8 +118,6 @@ int main(int argc, char **argv) ...@@ -128,8 +118,6 @@ int main(int argc, char **argv)
#endif #endif
#endif #endif
g_log_set_default_handler(my_log_func, NULL);
/* initialize MPD */ /* initialize MPD */
config_global_init(); config_global_init();
...@@ -159,8 +147,8 @@ int main(int argc, char **argv) ...@@ -159,8 +147,8 @@ int main(int argc, char **argv)
if (error.IsDefined()) if (error.IsDefined())
LogError(error); LogError(error);
else else
g_printerr("input_stream::Open() failed\n"); fprintf(stderr, "input_stream::Open() failed\n");
ret = 2; ret = EXIT_FAILURE;
} }
/* deinitialize everything */ /* deinitialize everything */
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <glib.h> #include <glib.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
...@@ -43,7 +44,7 @@ int main(int argc, char **argv) ...@@ -43,7 +44,7 @@ int main(int argc, char **argv)
ssize_t nbytes; ssize_t nbytes;
if (argc > 2) { if (argc > 2) {
g_printerr("Usage: run_normalize [FORMAT] <IN >OUT\n"); fprintf(stderr, "Usage: run_normalize [FORMAT] <IN >OUT\n");
return 1; return 1;
} }
...@@ -51,7 +52,7 @@ int main(int argc, char **argv) ...@@ -51,7 +52,7 @@ int main(int argc, char **argv)
if (argc > 1) { if (argc > 1) {
Error error; Error error;
if (!audio_format_parse(audio_format, argv[1], false, error)) { if (!audio_format_parse(audio_format, argv[1], false, error)) {
g_printerr("Failed to parse audio format: %s\n", fprintf(stderr, "Failed to parse audio format: %s\n",
error.GetMessage()); error.GetMessage());
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