+ZEBRA_RES zebra_maps_read_file(ZebraMaps zms, const char *fname)
+{
+ FILE *f;
+ char line[512];
+ char *argv[10];
+ int argc;
+ int lineno = 0;
+ int failures = 0;
+ struct zebra_map **zm = 0, *zp;
+
+ if (!(f = yaz_fopen(zms->tabpath, fname, "r", zms->tabroot)))
+ {
+ yaz_log(YLOG_ERRNO|YLOG_FATAL, "%s", fname);
+ return ZEBRA_FAIL;
+ }
+ while ((argc = readconf_line(f, &lineno, line, 512, argv, 10)))
+ {
+ if (argc == 1)
+ {
+ yaz_log(YLOG_WARN, "%s:%d: Missing arguments for '%s'",
+ fname, lineno, argv[0]);
+ failures++;
+ break;
+ }
+ if (argc > 2)
+ {
+ yaz_log(YLOG_WARN, "%s:%d: Too many arguments for '%s'",
+ fname, lineno, argv[0]);
+ failures++;
+ break;
+ }
+ if (!yaz_matchstr(argv[0], "index"))
+ {
+ if (!zm)
+ zm = &zms->map_list;
+ else
+ zm = &(*zm)->next;
+ *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm));
+ (*zm)->reg_id = argv[1][0];
+ (*zm)->maptab_name = NULL;
+ (*zm)->maptab = NULL;
+ (*zm)->type = ZEBRA_MAP_TYPE_INDEX;
+ (*zm)->completeness = 0;
+ (*zm)->positioned = 1;
+ (*zm)->alwaysmatches = 0;
+ (*zm)->first_in_field = 0;
+ zms->no_maps++;
+ }
+ else if (!yaz_matchstr(argv[0], "sort"))
+ {
+ if (!zm)
+ zm = &zms->map_list;
+ else
+ zm = &(*zm)->next;
+ *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm));
+ (*zm)->reg_id = argv[1][0];
+ (*zm)->maptab_name = NULL;
+ (*zm)->type = ZEBRA_MAP_TYPE_SORT;
+ (*zm)->u.sort.entry_size = 80;
+ (*zm)->maptab = NULL;
+ (*zm)->completeness = 0;
+ (*zm)->positioned = 0;
+ (*zm)->alwaysmatches = 0;
+ (*zm)->first_in_field = 0;
+ zms->no_maps++;
+ }
+ else if (!yaz_matchstr(argv[0], "staticrank"))
+ {
+ if (!zm)
+ zm = &zms->map_list;
+ else
+ zm = &(*zm)->next;
+ *zm = (struct zebra_map *) nmem_malloc(zms->nmem, sizeof(**zm));
+ (*zm)->reg_id = argv[1][0];
+ (*zm)->maptab_name = NULL;
+ (*zm)->type = ZEBRA_MAP_TYPE_STATICRANK;
+ (*zm)->maptab = NULL;
+ (*zm)->completeness = 1;
+ (*zm)->positioned = 0;
+ (*zm)->alwaysmatches = 0;
+ (*zm)->first_in_field = 0;
+ zms->no_maps++;
+ }
+ else if (!zm)
+ {
+ yaz_log(YLOG_WARN, "%s:%d: Missing sort/index before '%s'",
+ fname, lineno, argv[0]);
+ failures++;
+ }
+ else if (!yaz_matchstr(argv[0], "charmap") && argc == 2)
+ {
+ if ((*zm)->type != ZEBRA_MAP_TYPE_STATICRANK)
+ (*zm)->maptab_name = nmem_strdup(zms->nmem, argv[1]);
+ else
+ {
+ yaz_log(YLOG_WARN|YLOG_FATAL, "%s:%d: charmap for "
+ "staticrank is invalid", fname, lineno);
+ yaz_log(YLOG_LOG, "Type is %d", (*zm)->type);
+ failures++;
+ }
+ }
+ else if (!yaz_matchstr(argv[0], "completeness") && argc == 2)
+ {
+ (*zm)->completeness = atoi(argv[1]);
+ }
+ else if (!yaz_matchstr(argv[0], "position") && argc == 2)
+ {
+ (*zm)->positioned = atoi(argv[1]);
+ }
+ else if (!yaz_matchstr(argv[0], "alwaysmatches") && argc == 2)
+ {
+ if ((*zm)->type != ZEBRA_MAP_TYPE_STATICRANK)
+ (*zm)->alwaysmatches = atoi(argv[1]);
+ else
+ {
+ yaz_log(YLOG_WARN|YLOG_FATAL, "%s:%d: alwaysmatches for "
+ "staticrank is invalid", fname, lineno);
+ failures++;
+ }
+ }
+ else if (!yaz_matchstr(argv[0], "firstinfield") && argc == 2)
+ {
+ (*zm)->first_in_field = atoi(argv[1]);
+ }
+ else if (!yaz_matchstr(argv[0], "entrysize") && argc == 2)
+ {
+ if ((*zm)->type == ZEBRA_MAP_TYPE_SORT)
+ (*zm)->u.sort.entry_size = atoi(argv[1]);
+ }
+ else
+ {
+ yaz_log(YLOG_WARN, "%s:%d: Unrecognized directive '%s'",
+ fname, lineno, argv[0]);
+ failures++;
+ }