2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1999-11-30 13:47:12 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.4 1999/08/27 09:40:32 adam
11 * Renamed logf function to yaz_log. Removed VC++ project files.
13 * Revision 1.3 1999/03/31 11:18:25 adam
14 * Implemented odr_strdup. Added Reference ID to backend server API.
16 * Revision 1.2 1998/02/11 11:53:36 adam
17 * Changed code so that it compiles as C++.
19 * Revision 1.1 1997/09/01 08:55:53 adam
20 * New windows NT/95 port using MSV5.0. Test server ztest now in
21 * separate directory. When using NT, this test server may operate
22 * as an NT service. Note that the service.[ch] should be part of
23 * generic, but it isn't yet.
25 * Revision 1.1 1995/08/17 12:45:23 quinn
26 * Fixed minor problems with GRS-1. Added support in c&s.
32 * Little toy-thing to read a GRS-1 record from a file.
39 #include <yaz/proto.h>
42 #define GRS_MAX_FIELDS 50
44 Z_GenericRecord *read_grs1(FILE *f, ODR o)
49 Z_GenericRecord *r = 0;
56 while (fgets(buf = line, 512, f))
58 while (*buf && isspace(*buf))
60 if (!*buf || *buf == '#')
66 if (sscanf(buf, "(%d,%[^)])", &type, value) != 2)
68 yaz_log(LOG_WARN, "Bad data in '%s'", buf);
71 if (!type && *value == '0')
73 if (!(buf = strchr(buf, ')')))
76 while (*buf && isspace(*buf))
82 r = (Z_GenericRecord *)odr_malloc(o, sizeof(*r));
83 r->elements = (Z_TaggedElement **)
84 odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS);
87 r->elements[r->num_elements] = t = (Z_TaggedElement *)
88 odr_malloc(o, sizeof(Z_TaggedElement));
89 t->tagType = (int *)odr_malloc(o, sizeof(int));
91 t->tagValue = (Z_StringOrNumeric *)
92 odr_malloc(o, sizeof(Z_StringOrNumeric));
93 if ((ivalue = atoi(value)))
95 t->tagValue->which = Z_StringOrNumeric_numeric;
96 t->tagValue->u.numeric = (int *)odr_malloc(o, sizeof(int));
97 *t->tagValue->u.numeric = ivalue;
101 t->tagValue->which = Z_StringOrNumeric_string;
102 t->tagValue->u.string = (char *)odr_malloc(o, strlen(value)+1);
103 strcpy(t->tagValue->u.string, value);
105 t->tagOccurrence = 0;
107 t->appliedVariant = 0;
108 t->content = c = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData));
111 c->which = Z_ElementData_subtree;
112 c->u.subtree = read_grs1(f, o);
116 c->which = Z_ElementData_string;
117 buf[strlen(buf)-1] = '\0';
118 c->u.string = odr_strdup(o, buf);