X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=filter.c;h=599aaad97815b67c68464c094866ce4d1bd6e5a4;hp=20ea1333b758b4302774a1c075980072d6ebf208;hb=c282c836791cedf57c128555af90af37c7c01c05;hpb=d1e55304068a6a82553f40ae7bee746f5ca2233d diff --git a/filter.c b/filter.c index 20ea1333..599aaad9 100644 --- a/filter.c +++ b/filter.c @@ -14,6 +14,7 @@ #include "list.h" #include "sched.h" #include "ggo.h" +#include "buffer_tree.h" #include "filter.h" #include "string.h" #include "stdin.h" @@ -153,10 +154,65 @@ static int parse_config(int argc, char *argv[]) return 1; } -/* TODO: support more than one filter, actually parse options */ -static int main_btr(void) +/* TODO: support buffer tree, not just a chain. */ +static int __noreturn main_btr(void) { - return 42; + static struct sched s; + int i, ret; + struct filter *f; + struct btr_node *parent; + struct filter_node **fns; + + sit->btrn = btr_new_node("stdin", NULL, NULL, NULL); + stdin_set_defaults(sit); + register_task(&sit->task); + + fns = para_malloc(conf.filter_given * sizeof(*fns)); + for (i = 0, parent = sit->btrn; i < conf.filter_given; i++) { + char *fa = conf.filter_arg[i]; + struct filter_node *fn; + + fn = fns[i] = para_calloc(sizeof(*fn)); + ret = check_filter_arg(fa, &fn->conf); + if (ret < 0) { + free(fn); + goto out; + } + fn->filter_num = ret; + f = filters + fn->filter_num; + sprintf(fn->task.status, "%s", f->name); + PARA_DEBUG_LOG("filter #%d: %s\n", i, f->name); + fn->btrn = btr_new_node(f->name, parent, f->execute, fn); + fn->task.pre_select = f->pre_select; + fn->task.post_select = f->post_select; + f->open(fn); + register_task(&fn->task); + parent = fn->btrn; + } + sot->btrn = btr_new_node("stdout", parent, NULL, NULL); + stdout_set_defaults(sot); + register_task(&sot->task); + + s.default_timeout.tv_sec = 1; + s.default_timeout.tv_usec = 0; + btr_log_tree(sit->btrn, LL_INFO); + ret = schedule(&s); +out: + for (i--; i >= 0; i--) { + struct filter_node *fn = fns[i]; + + f = filters + fn->filter_num; + f->close(fn); + btr_free_node(fn->btrn); + free(fn->conf); + free(fn); + } + free(fns); + btr_free_node(sit->btrn); + btr_free_node(sot->btrn); + if (ret < 0) + PARA_EMERG_LOG("%s\n", para_strerror(-ret)); + exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS); } /** @@ -203,7 +259,6 @@ int main(int argc, char *argv[]) s.default_timeout.tv_sec = 1; s.default_timeout.tv_usec = 0; ret = schedule(&s); - free_filter_confs(); close_filters(fc); out: free(sit->buf);