X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=ztest%2Fread-grs.c;h=09472d95b38d4e0b32171dd5b083cd5ce7a675d3;hb=967c7d6a006f0e4dc684b8086e08186d11311cfd;hp=27510464aba3a8394f2d4b7993cc5558184a847c;hpb=d9ee01635f03f9095a66f71b73580560d48798e8;p=yaz-moved-to-github.git diff --git a/ztest/read-grs.c b/ztest/read-grs.c index 2751046..09472d9 100644 --- a/ztest/read-grs.c +++ b/ztest/read-grs.c @@ -1,35 +1,12 @@ /* - * Copyright (c) 1995-1999, Index Data. + * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: read-grs.c,v $ - * Revision 1.5 1999-11-30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.4 1999/08/27 09:40:32 adam - * Renamed logf function to yaz_log. Removed VC++ project files. - * - * Revision 1.3 1999/03/31 11:18:25 adam - * Implemented odr_strdup. Added Reference ID to backend server API. - * - * Revision 1.2 1998/02/11 11:53:36 adam - * Changed code so that it compiles as C++. - * - * Revision 1.1 1997/09/01 08:55:53 adam - * New windows NT/95 port using MSV5.0. Test server ztest now in - * separate directory. When using NT, this test server may operate - * as an NT service. Note that the service.[ch] should be part of - * generic, but it isn't yet. - * - * Revision 1.1 1995/08/17 12:45:23 quinn - * Fixed minor problems with GRS-1. Added support in c&s. - * * + * $Id: read-grs.c,v 1.12 2005-01-15 19:47:16 adam Exp $ */ /* - * Little toy-thing to read a GRS-1 record from a file. + * Little toy-thing to read a GRS-1 records from a file. */ #include @@ -41,7 +18,7 @@ #define GRS_MAX_FIELDS 50 -Z_GenericRecord *read_grs1(FILE *f, ODR o) +static Z_GenericRecord *read_grs1(FILE *f, ODR o) { char line[512], *buf; int type, ivalue; @@ -55,7 +32,7 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o) while (fgets(buf = line, 512, f)) { - while (*buf && isspace(*buf)) + while (*buf && isspace(*(unsigned char *) buf)) buf++; if (!*buf || *buf == '#') continue; @@ -65,7 +42,7 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o) return r; if (sscanf(buf, "(%d,%[^)])", &type, value) != 2) { - yaz_log(LOG_WARN, "Bad data in '%s'", buf); + yaz_log(YLOG_WARN, "Bad data in '%s'", buf); return 0; } if (!type && *value == '0') @@ -73,7 +50,7 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o) if (!(buf = strchr(buf, ')'))) return 0; buf++; - while (*buf && isspace(*buf)) + while (*buf && isspace(*(unsigned char *) buf)) buf++; if (!*buf) return 0; @@ -86,15 +63,13 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o) } r->elements[r->num_elements] = t = (Z_TaggedElement *) odr_malloc(o, sizeof(Z_TaggedElement)); - t->tagType = (int *)odr_malloc(o, sizeof(int)); - *t->tagType = type; + t->tagType = odr_intdup(o, type); t->tagValue = (Z_StringOrNumeric *) odr_malloc(o, sizeof(Z_StringOrNumeric)); if ((ivalue = atoi(value))) { t->tagValue->which = Z_StringOrNumeric_numeric; - t->tagValue->u.numeric = (int *)odr_malloc(o, sizeof(int)); - *t->tagValue->u.numeric = ivalue; + t->tagValue->u.numeric = odr_intdup(o, ivalue); } else { @@ -120,3 +95,23 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o) r->num_elements++; } } + +Z_GenericRecord *dummy_grs_record (int num, ODR o) +{ + FILE *f = fopen("dummy-grs", "r"); + char line[512]; + Z_GenericRecord *r = 0; + int n; + + if (!f) + return 0; + while (fgets(line, 512, f)) + if (*line == '#' && sscanf(line, "#%d", &n) == 1 && n == num) + { + r = read_grs1(f, o); + break; + } + fclose(f); + return r; +} +