+
+Z_GenericRecord *read_grs1(char *str, ODR o)
+{
+ int type, ivalue;
+ char line[512], *buf, *ptr, *original;
+ char value[512];
+ Z_GenericRecord *r = 0;
+
+ original = str;
+ for (;;)
+ {
+ Z_TaggedElement *t;
+ Z_ElementData *c;
+
+ ptr = strchr(str, '\n');
+ if (!ptr) {
+ return r;
+ }
+ strncpy(line, str, ptr - str);
+ line[ptr - str] = 0;
+ buf = line;
+ str = ptr + 1;
+ while (*buf && isspace(*buf))
+ buf++;
+ if (*buf == '}') {
+ memmove(original, str, strlen(str));
+ return r;
+ }
+ if (sscanf(buf, "(%d,%[^)])", &type, value) != 2)
+ {
+ yaz_log(LOG_WARN, "Bad data in '%s'", buf);
+ return 0;
+ }
+ if (!type && *value == '0')
+ return r;
+ if (!(buf = strchr(buf, ')')))
+ return 0;
+ buf++;
+ while (*buf && isspace(*buf))
+ buf++;
+ if (!*buf)
+ return 0;
+ if (!r)
+ {
+ 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 = (Z_TaggedElement *) odr_malloc(o, sizeof(Z_TaggedElement));
+ t->tagType = (int *)odr_malloc(o, sizeof(int));
+ *t->tagType = 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;
+ }
+ else
+ {
+ t->tagValue->which = Z_StringOrNumeric_string;
+ 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 = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData));
+ if (*buf == '{')
+ {
+ c->which = Z_ElementData_subtree;
+ c->u.subtree = read_grs1(str, o);
+ }
+ else
+ {
+ c->which = Z_ElementData_string;
+/* buf[strlen(buf)-1] = '\0';*/
+ buf[strlen(buf)] = '\0';
+ c->u.string = odr_strdup(o, buf);
+ }
+ r->num_elements++;
+ }
+}
+
+
+
+