- * \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 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 a negative paraslash error code is
+ * returned.
+ */
+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;
+
+ *lprp = NULL;
+ ret = create_argv(fa, " \t\n", &argv);
+ if (ret < 0)
+ return ret;
+ 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);
+ assert(f);
+ *conf = f->setup? f->setup(*lprp) : NULL;
+ ret = filter_num;
+free_argv:
+ free_argv(argv);
+ if (ret >= 0)
+ return ret;
+ if (errctx)
+ PARA_ERROR_LOG("%s\n", errctx);
+ free(errctx);
+ return ret;
+}
+
+/**
+ * Print help text of each filter to stdout.