- int ret, i, need_more_writes = 1;
- size_t min_written = 0;
-
- while (need_more_writes) {
- need_more_writes = 0;
- FOR_EACH_WRITER_NODE(i, g) {
- size_t w = g->written[i];
- unsigned char *p = buf + w;
- int bytes_to_write;
- struct writer_node *wn = &g->writer_nodes[i];
- if (!i)
- min_written = w;
- else
- min_written = PARA_MIN(min_written, w);
- if (w == *loaded)
- continue;
- if (!g->eof && (*loaded < wn->chunk_bytes + w))
- continue;
- bytes_to_write = PARA_MIN(wn->chunk_bytes,
- *loaded - w);
- ret = wn->writer->write(p, bytes_to_write, wn);
- if (ret < 0)
- goto out;
- if (ret != bytes_to_write)
- PARA_WARNING_LOG("short write: %d/%d\n", ret,
- bytes_to_write);
- g->written[i] += ret;
- need_more_writes = 1;
- }
+ int i;
+
+ FOR_EACH_WRITER(i)
+ writers[i].init(&writers[i]);
+}
+/**
+ * Check if given string is a valid command line for any writer.
+ *
+ * \param \wa String of the form writer_name:options.
+ * \param writer_num Contains the number of the writer upon success.
+ *
+ * This function checks whether \a wa starts with the name of a supported
+ * paraslash writer, optionally followed by a colon and any options for that
+ * writer. If a valid writer name was found and further are present, the
+ * remaining part of \a wa is passed to that writer's config parser.
+ *
+ * \return On success, a pointer to the gengetopt args info struct is returned
+ * and \a writer_num contains the number of the writer. Otherwise this function
+ * prints an error message and calls exit().
+ */
+void *check_writer_arg_or_die(const char *wa, int *writer_num)
+{
+ int i;
+
+ 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 : "");