[btr]: Minor improvements and cleanups.
[paraslash.git] / write.c
diff --git a/write.c b/write.c
index c12736a66bfb81c9dcf85c412b1a581a2cade0ce..818175a4ebb56117e58843844edca6b092cced48 100644 (file)
--- a/write.c
+++ b/write.c
@@ -6,8 +6,10 @@
 
 /** \file write.c Paraslash's standalone wav/raw player. */
 
+#include <regex.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <stdbool.h>
 
 #include "para.h"
 #include "string.h"
@@ -20,6 +22,7 @@
 #include "write_common.h"
 #include "fd.h"
 #include "error.h"
+#include "buffer_tree.h"
 
 INIT_WRITE_ERRLISTS;
 
@@ -178,6 +181,37 @@ __noreturn static void print_help_and_die(void)
        exit(0);
 }
 
+/*
+ TODO: check wav, initial delay, multiple writers, non-default writers
+ */
+static int main_btr(struct sched *s)
+{
+       struct writer_node *wn = para_malloc(sizeof(*wn));
+       struct writer *w = writers + DEFAULT_WRITER;
+       int ret;
+
+       sit.btrn = btr_new_node("stdin", NULL /* stdin has no parent */, NULL);
+       stdin_set_defaults(&sit);
+       register_task(&sit.task);
+
+       wn->writer_num = DEFAULT_WRITER;
+       wn->conf = writers[DEFAULT_WRITER].parse_config("-B");
+       wn->btrn = btr_new_node("writer", sit.btrn, 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);
+
+
+
+       s->default_timeout.tv_sec = 10;
+       s->default_timeout.tv_usec = 50000;
+       ret = schedule(s);
+       w->close(wn);
+       return ret;
+}
+
 /**
  * Para_write's main function.
  *
@@ -202,6 +236,10 @@ int main(int argc, char *argv[])
        if (conf.help_given || conf.detailed_help_given)
                print_help_and_die();
 
+       if (conf.buffer_tree_given) {
+               ret = main_btr(&s);
+               goto out;
+       }
        wng = check_args();
        if (!wng)
                goto out;