dump_text_file.cxx 2.17 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 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 "ScopeIOThread.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/ConfigGlobal.hxx"
26
#include "thread/Cond.hxx"
27
#include "Log.hxx"
28

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

33 34
#include <stdexcept>

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

static void
40
dump_text_file(TextInputStream &is)
41
{
42 43 44
	const char *line;
	while ((line = is.ReadLine()) != nullptr)
		printf("'%s'\n", line);
45 46 47
}

static int
48
dump_input_stream(InputStreamPtr &&is)
49
{
50
	{
51
		TextInputStream tis(std::move(is));
52 53
		dump_text_file(tis);
	}
54

55
	const ScopeLock protect(is->mutex);
56

57
	is->Check();
58 59 60 61
	return 0;
}

int main(int argc, char **argv)
62
try {
63 64 65
	int ret;

	if (argc != 2) {
66 67
		fprintf(stderr, "Usage: run_input URI\n");
		return EXIT_FAILURE;
68 69 70 71 72 73
	}

	/* initialize MPD */

	config_global_init();

74
	const ScopeIOThread io_thread;
75 76 77 78 79

#ifdef ENABLE_ARCHIVE
	archive_plugin_init_all();
#endif

80
	input_stream_global_init();
81 82 83

	/* open the stream and dump it */

84 85 86 87
	{
		Mutex mutex;
		Cond cond;

88 89
		auto is = InputStream::OpenReady(argv[1], mutex, cond);
		ret = dump_input_stream(std::move(is));
90 91 92 93 94 95 96 97 98 99 100 101 102
	}

	/* deinitialize everything */

	input_stream_global_finish();

#ifdef ENABLE_ARCHIVE
	archive_plugin_deinit_all();
#endif

	config_global_finish();

	return ret;
103 104 105
} catch (const std::exception &e) {
	LogError(e);
	return EXIT_FAILURE;
106
}