X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=filter.c;h=88a0bd75dcb2ec3a70cd83854827aca3dce9b8a6;hp=796e445a8ed64149a0475567a8426d296a1d61d3;hb=1e012cf40238883621692051a22fb9c7cad5e944;hpb=271c83d4fd9411be628fa650ce595ac79754d22e diff --git a/filter.c b/filter.c index 796e445a..88a0bd75 100644 --- a/filter.c +++ b/filter.c @@ -7,12 +7,14 @@ /** \file filter.c The stand-alone filter program. */ #include +#include #include "para.h" #include "filter.cmdline.h" #include "list.h" #include "sched.h" #include "ggo.h" +#include "buffer_tree.h" #include "filter.h" #include "string.h" #include "stdin.h" @@ -85,7 +87,7 @@ static int init_filter_chain(void) fc->input_error = &sit->task.error; fc->task.error = 0; fc->output_error = &sot->task.error; - fc->task.pre_select = filter_pre_select; + fc->task.post_select = filter_post_select; sprintf(fc->task.status, "filter chain"); FOR_EACH_FILTER_NODE(fn, fc, i) { @@ -152,6 +154,51 @@ static int parse_config(int argc, char *argv[]) return 1; } +/* TODO: support more than one filter, actually parse options */ +static int __noreturn main_btr(void) +{ + static struct sched s; + int i, ret; + struct filter *f; + struct btr_node *parent; + + sit->btrn = btr_new_node("stdin", NULL, NULL, NULL); + stdin_set_defaults(sit); + register_task(&sit->task); + + for (i = 0, parent = sit->btrn; i < conf.filter_given; i++) { + char *fa = conf.filter_arg[i]; + struct filter_node *fn = para_calloc(sizeof(*fn)); + + ret = check_filter_arg(fa, &fn->conf); + if (ret < 0) { + free(fn); + goto err; + } + 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; + ret = schedule(&s); +err: + if (ret < 0) + PARA_EMERG_LOG("%s\n", para_strerror(-ret)); + exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS); +} + /** * The main function of para_filter. * @@ -169,13 +216,17 @@ int main(int argc, char *argv[]) int ret; static struct sched s; - stdin_set_defaults(sit); - sit->buf = para_malloc(sit->bufsize), - filter_init(); ret = parse_config(argc, argv); if (ret < 0) goto out; + if (conf.buffer_tree_given) { + ret = main_btr(); + goto out; + } + stdin_set_defaults(sit); + sit->buf = para_malloc(sit->bufsize), + ret = init_filter_chain(); if (ret < 0) goto out; @@ -187,8 +238,8 @@ int main(int argc, char *argv[]) sot->input_error = &fc->task.error; register_task(&sit->task); - register_task(&fc->task); register_task(&sot->task); + register_task(&fc->task); s.default_timeout.tv_sec = 1; s.default_timeout.tv_usec = 0; ret = schedule(&s);