-// Initialize CCL map for a target
-// Note: This approach ignores user-specific CCL maps, for which I
-// don't presently see any application.
-static void prepare_cclmap(void *ignore, struct database *db)
-{
- struct setting *s;
-
- if (!db->settings)
- return;
- db->ccl_map = ccl_qual_mk();
- for (s = db->settings[PZ_CCLMAP]; s; s = s->next)
- {
- char *p = strchr(s->name + 3, ':');
- if (!p)
- {
- yaz_log(YLOG_FATAL, "Malformed cclmap name: %s", s->name);
- exit(1);
- }
- p++;
- ccl_qual_fitem(db->ccl_map, s->value, p);
- }
-}
-
-// 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_cclmap);
- grep_databases(0, 0, prepare_yazmarc);
- grep_databases(0, 0, prepare_map);
-}
-
-// This function will most likely vanish when a proper target profile mechanism is
-// introduced.
-void load_simpletargets(const char *fn)
-{
- FILE *f = fopen(fn, "r");
- char line[256];
-
- if (!f)
- {
- yaz_log(YLOG_WARN|YLOG_ERRNO, "open %s", fn);
- exit(1);
- }
-
- while (fgets(line, 255, f))
- {
- char *url;
- char *name;
- struct database *db;
-
- if (strncmp(line, "target ", 7))
- continue;
- line[strlen(line) - 1] = '\0';
-
- if ((name = strchr(line, ';')))
- *(name++) = '\0';
-
- url = line + 7;
-
- if (!(db = find_database(url, 0)))
- yaz_log(YLOG_WARN, "Unable to load database %s", url);
- }
- fclose(f);
-}
-
-