- * \return On success, the number of the filter is returned and \a conf
- * is initialized to point to the filter configuration determined by \a fa.
- * On errors, a negative value is returned.
- *
- * Note: If \a fa specifies a filter that has no command line parser success is
- * returned, and \a conf is initialized to \p NULL.
+ * \return This function either succeeds or does not return. On success, the
+ * number of the filter is returned and conf is initialized to point to the
+ * filter configuration as returned by the filter's ->setup() method, if any.
+ * Moreover, *lprp is initialized to contain the parsed command line options.
+ * On errors, the function calls exit(EXIT_FAILURE).
+ */
+int filter_setup(const char *fa, void **conf, struct lls_parse_result **lprp)
+{
+ int ret, filter_num, argc;
+ char *errctx = NULL, **argv;
+ const struct lls_command *cmd;
+ const struct filter *f;
+
+ ret = create_argv(fa, " \t\n", &argv);
+ if (ret < 0)
+ goto fail;
+ argc = ret;
+ ret = lls(lls_lookup_subcmd(argv[0], filter_cmd_suite, &errctx));
+ if (ret < 0)
+ goto free_argv;
+ filter_num = ret;
+ cmd = FILTER_CMD(filter_num);
+ if (!filter_supported(filter_num)) {
+ ret = -E_UNSUPPORTED_FILTER;
+ errctx = make_message("bad filter name: %s",
+ lls_command_name(cmd));
+ goto free_argv;
+ }
+ ret = lls(lls_parse(argc, argv, cmd, lprp, &errctx));
+ if (ret < 0)
+ goto free_argv;
+ f = filter_get(filter_num);
+ *conf = f->setup? f->setup(*lprp) : NULL;
+ ret = filter_num;
+free_argv:
+ free_argv(argv);
+ if (ret >= 0)
+ return ret;
+fail:
+ if (errctx)
+ PARA_ERROR_LOG("%s\n", errctx);
+ free(errctx);
+ PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+ exit(EXIT_FAILURE);
+}
+
+/**
+ * Print help text of each filter to stdout.