mpd/test/dump_text_file.cxx

84 lines
1.5 KiB
C++
Raw Permalink Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#include "config.h"
#include "ConfigGlue.hxx"
#include "event/Thread.hxx"
2014-01-24 16:18:21 +01:00
#include "input/Init.hxx"
#include "input/InputStream.hxx"
#include "input/TextInputStream.hxx"
2018-07-17 21:56:43 +02:00
#include "util/PrintException.hxx"
#ifdef ENABLE_ARCHIVE
2014-01-24 00:09:37 +01:00
#include "archive/ArchiveList.hxx"
#endif
#include <stdexcept>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
class GlobalInit {
const ConfigData config;
EventThread io_thread;
2019-02-05 21:40:07 +01:00
#ifdef ENABLE_ARCHIVE
const ScopeArchivePluginsInit archive_plugins_init{config};
2019-02-05 21:40:07 +01:00
#endif
const ScopeInputPluginsInit input_plugins_init{config, io_thread.GetEventLoop()};
2019-02-05 21:50:31 +01:00
public:
explicit GlobalInit(Path config_path)
:config(AutoLoadConfigFile(config_path))
2019-02-05 21:50:31 +01:00
{
io_thread.Start();
}
};
static void
2013-05-12 16:02:27 +02:00
dump_text_file(TextInputStream &is)
{
const char *line;
while ((line = is.ReadLine()) != nullptr)
printf("'%s'\n", line);
}
static int
dump_input_stream(InputStreamPtr &&is)
{
2013-05-12 16:02:27 +02:00
{
TextInputStream tis(std::move(is));
2013-05-12 16:02:27 +02:00
dump_text_file(tis);
}
const std::scoped_lock protect{is->mutex};
is->Check();
return 0;
}
int main(int argc, char **argv)
try {
if (argc != 2) {
fprintf(stderr, "Usage: dump_text_file URI\n");
return EXIT_FAILURE;
}
/* initialize MPD */
const GlobalInit init{nullptr};
/* open the stream and dump it */
Mutex mutex;
auto is = InputStream::OpenReady(argv[1], mutex);
return dump_input_stream(std::move(is));
2018-07-17 21:56:43 +02:00
} catch (...) {
PrintException(std::current_exception());
return EXIT_FAILURE;
}