+/* --- @key_merge@, @key_mergeline@ --- *
+ *
+ * Arguments: @key_file *f@ = pointer to file structure
+ * @const char *file@ = name of file (for error messages)
+ * @int lno@ = line number (for error messages, @key_mergeline@)
+ * @FILE *fp@ = file handle to read from (@key_merge@)
+ * @const char *line@ = line from the input (@key_mergeline@)
+ * @key_reporter *rep@ = error reporting function
+ * @void *arg@ = argument for function
+ *
+ * Returns: Error code (one of the @KERR@ constants).
+ *
+ * Use: The @key_merge@ function reads keys from a file, and inserts
+ * them into the keyring.
+ *
+ * The @key_mergeline@ function reads a key from a single input
+ * line (which may, but need not, have a final newline), and
+ * adds it to the keyring.
+ *
+ * The @key_mergeline@ function is intended to help with
+ * interfacing Catacomb to runtimes which don't use C's @stdio@
+ * streams, rather than as a general-purpose service, though if
+ * it turns out to be useful in other ways then so much the
+ * better.
+ */
+
+int key_merge(key_file *f, const char *file, FILE *fp,
+ key_reporter *rep, void *arg)
+{
+ dstr n = DSTR_INIT, v = DSTR_INIT;
+ dstr l = DSTR_INIT;
+ int lno = 1;
+
+ if (!(f->f & KF_WRITE))
+ return (KERR_READONLY);
+
+ for (; dstr_putline(&l, fp) != EOF; DRESET(&l))
+ merge_core(f, file, lno++, l.buf, rep, arg, &n, &v);