- PARA_INFO_LOG("checking %s\n", wa);
- FOR_EACH_WRITER(i) {
- const char *name = writer_names[i];
- size_t len = strlen(name);
- char c;
- if (strlen(wa) < len)
- continue;
- if (strncmp(name, wa, len))
- continue;
- c = wa[len];
- if (c && c != ' ')
- continue;
- *writer_num = i;
- return writers[i].parse_config_or_die(c? wa + len + 1 : "");
+/**
+ * Check if the given string is a valid command line for any writer.
+ *
+ * \param wa String of the form writer_name options.
+ * \param lprp Contains the parsed command line on success.
+ *
+ * If wa is \p NULL, the (configuration-dependent) default writer is assumed.
+ * Otherwise, the function checks whether \a wa starts with the name of a
+ * supported writer. If a valid writer name was found, the rest of the command
+ * line is passed to the config parser of this writer.
+ *
+ * \return On success, the positive writer ID is returned. Otherwise the
+ * function prints an error message and calls exit().
+ */
+int check_writer_arg_or_die(const char *wa, struct lls_parse_result **lprp)
+{
+ int ret, writer_num, argc;
+ char **argv = NULL, *errctx = NULL;
+ const struct lls_command *cmd;
+
+ if (!wa || !*wa) {
+ writer_num = default_writer_id();
+ cmd = WRITE_CMD(writer_num);
+ argv = para_malloc(2 * sizeof(char *));
+ argc = 1;
+ argv[0] = para_strdup(lls_command_name(cmd));
+ argv[1] = NULL;
+ goto parse;