+/*
+ * Create a string containing the mapped characters provided.
+ */
+static void fun_mkstring(const char *s, void *data, int num)
+{
+ chrwork *arg = (chrwork *) data;
+ const char **res, *p = s;
+
+ res = chr_map_input(arg->map, &s, strlen(s));
+ if (*res == (char*) CHR_UNKNOWN)
+ logf(LOG_WARN, "Map: '%s' has no mapping", p);
+ strncat(arg->string, *res, CHR_MAXSTR - strlen(arg->string));
+ arg->string[CHR_MAXSTR] = '\0';
+}
+
+/*
+ * Add a map to the string contained in the argument.
+ */
+static void fun_add_map(const char *s, void *data, int num)
+{
+ chrwork *arg = (chrwork *) data;
+
+ assert(arg->map->input);
+ logf (LOG_DEBUG, "set map %.*s", (int) strlen(s), s);
+ set_map_string(arg->map->input, arg->map->nmem, s, strlen(s), arg->string,
+ 0);
+ for (s = arg->string; *s; s++)
+ logf (LOG_DEBUG, " %3d", (unsigned char) *s);
+}
+
+/*
+ * Add a query map to the string contained in the argument.
+ */
+static void fun_add_qmap(const char *s, void *data, int num)
+{
+ chrwork *arg = (chrwork *) data;
+
+ assert(arg->map->q_input);
+ logf (LOG_DEBUG, "set qmap %.*s", (int) strlen(s), s);
+ set_map_string(arg->map->q_input, arg->map->nmem, s,
+ strlen(s), arg->string, 0);
+ for (s = arg->string; *s; s++)
+ logf (LOG_DEBUG, " %3d", (unsigned char) *s);
+}
+
+static int scan_to_utf8 (yaz_iconv_t t, ucs4_t *from, size_t inlen,
+ char *outbuf, size_t outbytesleft)
+{
+ size_t inbytesleft = inlen * sizeof(ucs4_t);
+ char *inbuf = (char*) from;
+ size_t ret;
+
+ if (t == 0)
+ *outbuf++ = *from; /* ISO-8859-1 is OK here */
+ else
+ {
+ ret = yaz_iconv (t, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+ if (ret == (size_t) (-1))
+ {
+ yaz_log(LOG_LOG, "from: %2X %2X %2X %2X",
+ from[0], from[1], from[2], from[3]);
+ yaz_log (LOG_WARN|LOG_ERRNO, "bad unicode sequence");
+ return -1;
+ }
+ }
+ *outbuf = '\0';
+ return 0;
+}
+
+static int scan_string(char *s_native,
+ yaz_iconv_t t_unicode, yaz_iconv_t t_utf8,
+ void (*fun)(const char *c, void *data, int num),
+ void *data, int *num)