Merge branch 'master' into next
[paraslash.git] / write_common.c
index d66b20ca112dd7cb1135d9211ff880cd2a2fc39c..5eb6b796cbff4a8ce74fae16017e4366485ae84f 100644 (file)
@@ -1,11 +1,13 @@
 /*
- * Copyright (C) 2006-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2006-2009 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file write_common.c common functions of para_audiod and para_write */
 
+#include <regex.h>
+
 #include "para.h"
 #include "string.h"
 #include "list.h"
@@ -27,7 +29,10 @@ static void wng_pre_select(__a_unused struct sched *s, struct task *t)
 
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
-               t->error = wn->writer->pre_select(s, wn);
+               struct writer *w = writers + wn->writer_num;
+               if (!w->pre_select)
+                       continue;
+               t->error = w->pre_select(s, wn);
                if (t->error < 0)
                        return;
        }
@@ -41,7 +46,8 @@ static void wng_post_select(struct sched *s, struct task *t)
 
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
-               t->error = wn->writer->post_select(s, wn);
+               struct writer *w = writers + wn->writer_num;
+               t->error = w->post_select(s, wn);
                if (t->error < 0)
                        return;
                if (!i)
@@ -61,7 +67,7 @@ static void wng_post_select(struct sched *s, struct task *t)
        }
        if (*g->loaded && min_written) {
 //             PARA_INFO_LOG("moving %zd bytes\n", *g->loaded);
-               memmove(g->buf, g->buf + min_written, *g->loaded);
+               memmove(*g->bufp, *g->bufp + min_written, *g->loaded);
        }
 }
 
@@ -82,12 +88,11 @@ int wng_open(struct writer_node_group *g)
        PARA_NOTICE_LOG("opening wng %p with %d writer(s)\n", g, g->num_writers);
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
+               struct writer *w = writers + wn->writer_num;
                wn->wng = g;
-               ret = wn->writer->open(wn);
+               ret = w->open(wn);
                if (ret < 0)
                        goto err_out;
-               wn->chunk_bytes = ret;
-               g->max_chunk_bytes = PARA_MAX(g->max_chunk_bytes, ret);
        }
        sprintf(g->task.status, "%s", "writer node group");
        register_task(&g->task);
@@ -97,9 +102,12 @@ err_out:
        PARA_ERROR_LOG("%s\n", para_strerror(-ret));
        while (i > 0) {
                struct writer_node *wn = &g->writer_nodes[--i];
-               wn->writer->close(wn);
+               struct writer *w = writers + wn->writer_num;
+               w->close(wn);
        }
+       free(g->writer_nodes);
        g->num_writers = 0;
+       g->task.error = -E_TASK_UNREGISTERED;
        return ret;
 }
 
@@ -119,7 +127,8 @@ void wng_close(struct writer_node_group *g)
        PARA_NOTICE_LOG("closing wng with %d writer(s)\n", g->num_writers);
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
-               wn->writer->close(wn);
+               struct writer *w = writers + wn->writer_num;
+               w->close(wn);
        }
        free(g->writer_nodes);
        free(g);
@@ -144,9 +153,9 @@ struct writer_node_group *wng_new(unsigned num_writers)
 }
 
 /**
- * call the init function of each supported paraslash writer
+ * Call the init function of each supported paraslash writer.
  */
-void init_supported_writers(void)
+void writer_init(void)
 {
        int i;
 
@@ -205,9 +214,31 @@ void *check_writer_arg(const char *wa, int *writer_num)
 struct writer_node_group *setup_default_wng(void)
 {
        struct writer_node_group *wng = wng_new(1);
-       wng->writer_nodes[0].writer = &writers[DEFAULT_WRITER];
+       wng->writer_nodes[0].writer_num = DEFAULT_WRITER;
        PARA_INFO_LOG("using default writer: %s %p\n",
                writer_names[DEFAULT_WRITER], writers[DEFAULT_WRITER].parse_config);
        wng->writer_nodes[0].conf = writers[DEFAULT_WRITER].parse_config("");
        return wng;
 }
+/**
+ * Print the help text of all writers to stdout.
+ *
+ * \param detailed Whether to print the detailed help text.
+ */
+void print_writer_helps(int detailed)
+{
+       int i;
+
+       printf_or_die("\nAvailable writers: \n\t");
+       FOR_EACH_WRITER(i)
+               printf_or_die("%s%s", i? " " : "", writer_names[i]);
+       printf_or_die("\n\n");
+       FOR_EACH_WRITER(i) {
+               struct writer *w = writers + i;
+
+               if (!w->help.short_help)
+                       continue;
+               printf_or_die("Options for %s:\n", writer_names[i]);
+               ggo_print_help(&w->help, detailed);
+       }
+}