X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fzebramap.c;h=9c03d0b24d00cec3d0185359495559336734c9d9;hb=c7e31a7e62b9328d0753a4da4c46493bedec20e3;hp=991d16b39fd98fe10c0020ce4e7ac8761466379a;hpb=f9e7e7c0cbaab295c911c44002eb7009dee03b7b;p=idzebra-moved-to-github.git diff --git a/util/zebramap.c b/util/zebramap.c index 991d16b..9c03d0b 100644 --- a/util/zebramap.c +++ b/util/zebramap.c @@ -1,4 +1,4 @@ -/* $Id: zebramap.c,v 1.41 2005-06-14 12:42:49 adam Exp $ +/* $Id: zebramap.c,v 1.44 2006-03-13 17:40:28 mike Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -77,7 +77,8 @@ void zebra_maps_close (ZebraMaps zms) xfree (zms); } -static void zebra_map_read (ZebraMaps zms, const char *name) +/* Returns 0 if all is well, -1 on fatal error */ +static int zebra_map_read (ZebraMaps zms, const char *name, int fail_fatal) { FILE *f; char line[512]; @@ -88,8 +89,9 @@ static void zebra_map_read (ZebraMaps zms, const char *name) if (!(f = yaz_fopen(zms->tabpath, name, "r", zms->tabroot))) { - yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", name); - return ; + int level = fail_fatal ? YLOG_FATAL : YLOG_WARN; + yaz_log(level|YLOG_ERRNO, "%s", name); + return -1; } while ((argc = readconf_line(f, &lineno, line, 512, argv, 10))) { @@ -146,13 +148,15 @@ static void zebra_map_read (ZebraMaps zms, const char *name) for (zp = zms->map_list; zp; zp = zp->next) zms->lookup_array[zp->reg_id] = zp; + + return 0; } static void zms_map_handle (void *p, const char *name, const char *value) { ZebraMaps zms = (ZebraMaps) p; - zebra_map_read (zms, value); + (void) zebra_map_read (zms, value, 0); } ZebraMaps zebra_maps_open (Res res, const char *base) @@ -180,7 +184,8 @@ ZebraMaps zebra_maps_open (Res res, const char *base) for (i = 0; i<256; i++) zms->lookup_array[i] = 0; if (!res || !res_trav (res, "index", zms, zms_map_handle)) - zebra_map_read (zms, "default.idx"); + if (zebra_map_read (zms, "default.idx", 1) < 0) + return 0; zms->wrbuf_1 = wrbuf_alloc(); @@ -189,6 +194,7 @@ ZebraMaps zebra_maps_open (Res res, const char *base) struct zebra_map *zebra_map_get (ZebraMaps zms, unsigned reg_id) { + assert(reg_id >= 0 && reg_id <= 255); return zms->lookup_array[reg_id]; } @@ -215,7 +221,7 @@ chrmaptab zebra_charmap_get (ZebraMaps zms, unsigned reg_id) if (!zm->maptab_name || !yaz_matchstr (zm->maptab_name, "@")) return NULL; if (!(zm->maptab = chrmaptab_create (zms->tabpath, - zm->maptab_name, 0, + zm->maptab_name, zms->tabroot))) yaz_log(YLOG_WARN, "Failed to read character table %s", zm->maptab_name);