+/*
+ * Copyright (C) 2012 Andre Noll <maan@systemlinux.org>
+ *
+ * Licensed under the GPL v2. For licencing details see COPYING.
+ */
+
+/** \file play.c Paraslash's standalone player. */
+
+#include <regex.h>
+
+#include "para.h"
+#include "list.h"
+#include "play.cmdline.h"
+#include "filter.cmdline.h"
+#include "error.h"
+#include "ggo.h"
+#include "buffer_tree.h"
+#include "version.h"
+#include "string.h"
+#include "sched.h"
+#include "filter.h"
+#include "afh.h"
+#include "recv.h"
+#include "write.h"
+#include "write_common.h"
+#include "fd.h"
+
+static struct play_args_info conf;
+
+/** Initialize the array of errors for para_play. */
+INIT_PLAY_ERRLISTS;
+
+/* Activate the afh receiver. */
+extern void afh_recv_init(struct receiver *r);
+#undef AFH_RECEIVER
+#define AFH_RECEIVER {.name = "afh", .init = afh_recv_init},
+DEFINE_RECEIVER_ARRAY;
+
+/* FIXME: This is needed by the amp filter. */
+char *stat_item_values[NUM_STAT_ITEMS] = {NULL};
+
+static int loglevel = LL_WARNING;
+INIT_STDERR_LOGGING(loglevel);
+
+__noreturn static void print_help_and_die(void)
+{
+ int d = conf.detailed_help_given;
+ const char **p = d? play_args_info_detailed_help
+ : play_args_info_help;
+
+ printf_or_die("%s\n\n", PLAY_CMDLINE_PARSER_PACKAGE "-"
+ PLAY_CMDLINE_PARSER_VERSION);
+ printf_or_die("%s\n\n", play_args_info_usage);
+ for (; *p; p++)
+ printf_or_die("%s\n", *p);
+ print_filter_helps(d);
+ print_writer_helps(d);
+ exit(0);
+}
+
+static void parse_config_or_die(int argc, char *argv[])
+{
+ int ret;
+ char *config_file;
+ struct play_cmdline_parser_params params = {
+ .override = 0,
+ .initialize = 1,
+ .check_required = 0,
+ .check_ambiguity = 0,
+ .print_errors = 1
+ };
+
+ if (play_cmdline_parser_ext(argc, argv, &conf, ¶ms))
+ exit(EXIT_FAILURE);
+ HANDLE_VERSION_FLAG("play", conf);
+ if (conf.help_given || conf.detailed_help_given)
+ print_help_and_die();
+ loglevel = get_loglevel_by_name(conf.loglevel_arg);
+ if (conf.config_file_given)
+ config_file = para_strdup(conf.config_file_arg);
+ else {
+ char *home = para_homedir();
+ config_file = make_message("%s/.paraslash/play.conf", home);
+ free(home);
+ }
+ ret = file_exists(config_file);
+ if (conf.config_file_given && !ret) {
+ PARA_EMERG_LOG("can not read config file %s\n", config_file);
+ goto err;
+ }
+ if (ret) {
+ params.initialize = 0;
+ params.check_required = 1;
+ play_cmdline_parser_config_file(config_file, &conf, ¶ms);
+ }
+ free(config_file);
+ return;
+err:
+ free(config_file);
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char *argv[])
+{
+ /* needed this early to make help work */
+ recv_init();
+ filter_init();
+ writer_init();
+
+ parse_config_or_die(argc, argv);
+ return 0;
+}