dump_text_file.cxx 2.15 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"
21
#include "event/Thread.hxx"
Max Kellermann's avatar
Max Kellermann committed
22 23 24
#include "input/Init.hxx"
#include "input/InputStream.hxx"
#include "input/TextInputStream.hxx"
25
#include "config/Data.hxx"
26
#include "util/PrintException.hxx"
27

28
#ifdef ENABLE_ARCHIVE
29
#include "archive/ArchiveList.hxx"
30 31
#endif

32 33
#include <stdexcept>

34 35 36 37
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

38
class GlobalInit {
39
	EventThread io_thread;
40

41 42 43 44
#ifdef ENABLE_ARCHIVE
	const ScopeArchivePluginsInit archive_plugins_init;
#endif

45 46
	const ScopeInputPluginsInit input_plugins_init;

47
public:
48 49 50
	GlobalInit()
		:input_plugins_init(ConfigData(), io_thread.GetEventLoop())
	{
51
		io_thread.Start();
52 53 54
	}
};

55
static void
56
dump_text_file(TextInputStream &is)
57
{
58 59 60
	const char *line;
	while ((line = is.ReadLine()) != nullptr)
		printf("'%s'\n", line);
61 62 63
}

static int
64
dump_input_stream(InputStreamPtr &&is)
65
{
66
	{
67
		TextInputStream tis(std::move(is));
68 69
		dump_text_file(tis);
	}
70

71
	const std::lock_guard<Mutex> protect(is->mutex);
72

73
	is->Check();
74 75 76 77
	return 0;
}

int main(int argc, char **argv)
78
try {
79
	if (argc != 2) {
80 81
		fprintf(stderr, "Usage: run_input URI\n");
		return EXIT_FAILURE;
82 83 84 85
	}

	/* initialize MPD */

86
	const GlobalInit init;
87 88 89

	/* open the stream and dump it */

90
	Mutex mutex;
91

92
	auto is = InputStream::OpenReady(argv[1], mutex);
93
	return dump_input_stream(std::move(is));
94 95
} catch (...) {
	PrintException(std::current_exception());
96
	return EXIT_FAILURE;
97
}