+// Initialize YAZ Map structures for MARC-based targets
+static void prepare_yazmarc(void *ignore, struct database *db)
+{
+ struct setting *s;
+
+ if (!db->settings)
+ return;
+ for (s = db->settings[PZ_NATIVESYNTAX]; s; s = s->next)
+ if (!strcmp(s->value, "iso2709"))
+ {
+ char *encoding = "marc-8s";
+ yaz_iconv_t cm;
+
+ db->yaz_marc = yaz_marc_create();
+ yaz_marc_subfield_str(db->yaz_marc, "\t");
+
+ // See if a native encoding is specified
+ if (db->settings[PZ_ENCODING])
+ encoding = db->settings[PZ_ENCODING]->value;
+
+ cm = yaz_iconv_open("utf-8", encoding);
+ if (!cm)
+ {
+ yaz_log(YLOG_FATAL,
+ "Unable to map from %s to UTF-8 for target %s",
+ encoding, db->url);
+ exit(1);
+ }
+ yaz_marc_iconv(db->yaz_marc, cm);
+ }
+}
+
+// Prepare XSLT stylesheets for record normalization
+static void prepare_map(void *ignore, struct database *db)
+{
+ struct setting *s;
+
+ if (!db->settings)
+ return;
+ for (s = db->settings[PZ_XSLT]; s; s = s->next)
+ {
+ char **stylesheets;
+ struct database_retrievalmap **m = &db->map;
+ int num, i;
+
+ nmem_strsplit(nmem, ",", s->value, &stylesheets, &num);
+ for (i = 0; i < num; i++)
+ {
+ (*m) = nmem_malloc(nmem, sizeof(**m));
+ (*m)->next = 0;
+ if (!((*m)->stylesheet = conf_load_stylesheet(stylesheets[i])))
+ {
+ yaz_log(YLOG_FATAL, "Unable to load stylesheet: %s",
+ stylesheets[i]);
+ exit(1);
+ }
+ m = &(*m)->next;
+ }
+ }
+ if (!db->map)
+ yaz_log(YLOG_WARN, "No Normalization stylesheet for target %s", db->url);
+}
+
+// Read settings for each database, and prepare support data structures
+void prepare_databases(void)
+{
+ grep_databases(0, 0, prepare_yazmarc);
+ grep_databases(0, 0, prepare_map);
+}
+