From: Andre Noll Date: Thu, 31 Dec 2009 03:35:57 +0000 (+0100) Subject: filter: Make btr mode understand command line options. X-Git-Tag: v0.4.2~232 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=4403d70f8ec547a17fcce25b0ba997e208732248;p=paraslash.git filter: Make btr mode understand command line options. --- diff --git a/filter.c b/filter.c index 45f4bff0..88a0bd75 100644 --- a/filter.c +++ b/filter.c @@ -155,30 +155,38 @@ static int parse_config(int argc, char *argv[]) } /* TODO: support more than one filter, actually parse options */ -static int __noreturn main_btr(int argc, char *argv[]) +static int __noreturn main_btr(void) { static struct sched s; - struct filter_node *fn = para_calloc(sizeof(*fn)); - int ret; + 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); - ret = check_filter_arg("mp3dec ", &fn->conf); - if (ret < 0) - goto err; - fn->filter_num = ret; - f = filters + fn->filter_num; - fn->btrn = btr_new_node(f->name, sit->btrn, f->execute, fn); - fn->task.pre_select = f->pre_select; - fn->task.post_select = f->post_select; - sprintf(fn->task.status, "mp3dec"); - f->open(fn); - register_task(&fn->task); - - sot->btrn = btr_new_node("stdout", fn->btrn, NULL, NULL); + 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); @@ -186,7 +194,6 @@ static int __noreturn main_btr(int argc, char *argv[]) s.default_timeout.tv_usec = 0; ret = schedule(&s); err: - free(fn); if (ret < 0) PARA_EMERG_LOG("%s\n", para_strerror(-ret)); exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS); @@ -214,7 +221,7 @@ int main(int argc, char *argv[]) if (ret < 0) goto out; if (conf.buffer_tree_given) { - ret = main_btr(argc, argv); + ret = main_btr(); goto out; } stdin_set_defaults(sit);