X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ztest%2Fread-grs.c;h=2acbca5a9e3164735a5ec2b428238ae25eb39713;hp=c847187141eabc4893dc0890eb12000c24260a97;hb=f4c095a042b1bcccb78136be87944e46412386aa;hpb=2203bb027f811b89e75ef2c743232f97eaf1464f diff --git a/ztest/read-grs.c b/ztest/read-grs.c index c847187..2acbca5 100644 --- a/ztest/read-grs.c +++ b/ztest/read-grs.c @@ -1,35 +1,24 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-2003, Index Data. * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: read-grs.c,v $ - * 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.10 2004-12-13 14:21:59 heikki 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 #include #include -#include -#include +#include +#include #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; @@ -53,7 +42,7 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o) return r; if (sscanf(buf, "(%d,%[^)])", &type, value) != 2) { - logf(LOG_WARN, "Bad data in '%s'", buf); + yaz_log(YLOG_WARN, "Bad data in '%s'", buf); return 0; } if (!type && *value == '0') @@ -67,32 +56,31 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o) return 0; if (!r) { - r = odr_malloc(o, sizeof(*r)); - r->elements = odr_malloc(o, sizeof(Z_TaggedElement*) * - GRS_MAX_FIELDS); + r = (Z_GenericRecord *)odr_malloc(o, sizeof(*r)); + r->elements = (Z_TaggedElement **) + odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS); r->num_elements = 0; } - r->elements[r->num_elements] = t = odr_malloc(o, - sizeof(Z_TaggedElement)); - t->tagType = odr_malloc(o, sizeof(int)); - *t->tagType = type; - t->tagValue = odr_malloc(o, sizeof(Z_StringOrNumeric)); + r->elements[r->num_elements] = t = (Z_TaggedElement *) + odr_malloc(o, sizeof(Z_TaggedElement)); + 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 = odr_malloc(o, sizeof(int)); - *t->tagValue->u.numeric = ivalue; + t->tagValue->u.numeric = odr_intdup(o, ivalue); } else { t->tagValue->which = Z_StringOrNumeric_string; - t->tagValue->u.string = odr_malloc(o, strlen(value)+1); + t->tagValue->u.string = (char *)odr_malloc(o, strlen(value)+1); strcpy(t->tagValue->u.string, value); } t->tagOccurrence = 0; t->metaData = 0; t->appliedVariant = 0; - t->content = c = odr_malloc(o, sizeof(Z_ElementData)); + t->content = c = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData)); if (*buf == '{') { c->which = Z_ElementData_subtree; @@ -102,9 +90,28 @@ Z_GenericRecord *read_grs1(FILE *f, ODR o) { c->which = Z_ElementData_string; buf[strlen(buf)-1] = '\0'; - c->u.string = odr_malloc(o, strlen(buf)+1); - strcpy(c->u.string, buf); + c->u.string = odr_strdup(o, buf); } 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; +} +