]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - write.c
Introduce and use generic_filter_pre_select().
[paraslash.git] / write.c
diff --git a/write.c b/write.c
index 8b0e183f9fdf68908ec0dec8ee410295e577d261..c3848946c8b124e1a0ba0f0672fbbf475d6de2a4 100644 (file)
--- a/write.c
+++ b/write.c
 #include "sched.h"
 #include "ggo.h"
 #include "stdin.h"
+#include "buffer_tree.h"
 #include "write.h"
 #include "write_common.h"
 #include "fd.h"
 #include "error.h"
-#include "buffer_tree.h"
 
 INIT_WRITE_ERRLISTS;
 
@@ -134,6 +134,7 @@ static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result)
 {
        struct check_wav_task_btr *cwt = btr_context(btrn);
 
+
        if (!strcmp(cmd, "samplerate")) {
                if (cwt->state != CWS_HAVE_HEADER)
                        return -ERRNO_TO_PARA_ERROR(ENAVAIL);
@@ -143,7 +144,7 @@ static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result)
        if (!strcmp(cmd, "channels")) {
                if (cwt->state != CWS_HAVE_HEADER)
                        return -ERRNO_TO_PARA_ERROR(ENAVAIL);
-               *result = make_message("%d", cwt->samplerate);
+               *result = make_message("%d", cwt->channels);
                return 1;
        }
        return -ERRNO_TO_PARA_ERROR(ENOTSUP);
@@ -282,10 +283,9 @@ __noreturn static void print_help_and_die(void)
  */
 static int main_btr(struct sched *s)
 {
-       struct writer_node *wn = para_malloc(sizeof(*wn));
-       struct writer *w = writers + DEFAULT_WRITER;
-       int ret;
+       int i, ret;
        struct check_wav_task_btr _cwt, *cwt = &_cwt;
+       struct writer_node **wns;
 
        sit.btrn = btr_new_node("stdin", NULL /* stdin has no parent */, NULL, NULL);
        stdin_set_defaults(&sit);
@@ -296,23 +296,41 @@ static int main_btr(struct sched *s)
        sprintf(cwt->task.status, "check wav");
        cwt->task.pre_select = check_wav_pre_select_btr;
        cwt->task.post_select = check_wav_post_select_btr;
+       cwt->task.error = 0;
        register_task(&cwt->task);
 
-       wn->writer_num = DEFAULT_WRITER;
-       wn->conf = writers[DEFAULT_WRITER].parse_config("-B");
-       wn->btrn = btr_new_node("writer", cwt->btrn, NULL, NULL);
-       sprintf(wn->task.status, "some writer");
-       w->open(wn);
-       wn->task.post_select = w->post_select_btr;
-       wn->task.pre_select = w->pre_select_btr;
-       register_task(&wn->task);
-
+       PARA_CRIT_LOG("writers:\n");
 
+       ret = -E_WRITE_SYNTAX;
+       if (!conf.writer_given) {
+               i = 0;
+               wns = para_malloc(sizeof(*wns));
+               wns[0] = setup_writer_node(NULL, cwt->btrn);
+               if (!wns[0])
+                       goto out;
+       } else {
+               wns = para_malloc(conf.writer_given * sizeof(*wns));
+               for (i = 0; i < conf.writer_given; i++) {
+                       PARA_CRIT_LOG("i: %d\n", i);
+                       wns[i] = setup_writer_node(conf.writer_arg[i],
+                               cwt->btrn);
+                       if (!wns[i])
+                               goto out;
+               }
+       }
 
        s->default_timeout.tv_sec = 10;
        s->default_timeout.tv_usec = 50000;
        ret = schedule(s);
-       w->close(wn);
+out:
+       for (i--; i >= 0; i--) {
+               struct writer_node *wn = wns[i];
+               struct writer *w = writers + wn->writer_num;
+               w->close(wn);
+               free(wn->conf); /* FIXME should call gengetopt cleanup funtion */
+               free(wn);
+       }
+       free(wns);
        return ret;
 }