2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1997-09-01 08:55:53 adam
8 * New windows NT/95 port using MSV5.0. Test server ztest now in
9 * separate directory. When using NT, this test server may operate
10 * as an NT service. Note that the service.[ch] should be part of
11 * generic, but it isn't yet.
13 * Revision 1.1 1995/08/17 12:45:23 quinn
14 * Fixed minor problems with GRS-1. Added support in c&s.
20 * Little toy-thing to read a GRS-1 record from a file.
30 #define GRS_MAX_FIELDS 50
32 Z_GenericRecord *read_grs1(FILE *f, ODR o)
37 Z_GenericRecord *r = 0;
44 while (fgets(buf = line, 512, f))
46 while (*buf && isspace(*buf))
48 if (!*buf || *buf == '#')
54 if (sscanf(buf, "(%d,%[^)])", &type, value) != 2)
56 logf(LOG_WARN, "Bad data in '%s'", buf);
59 if (!type && *value == '0')
61 if (!(buf = strchr(buf, ')')))
64 while (*buf && isspace(*buf))
70 r = odr_malloc(o, sizeof(*r));
71 r->elements = odr_malloc(o, sizeof(Z_TaggedElement*) *
75 r->elements[r->num_elements] = t = odr_malloc(o,
76 sizeof(Z_TaggedElement));
77 t->tagType = odr_malloc(o, sizeof(int));
79 t->tagValue = odr_malloc(o, sizeof(Z_StringOrNumeric));
80 if ((ivalue = atoi(value)))
82 t->tagValue->which = Z_StringOrNumeric_numeric;
83 t->tagValue->u.numeric = odr_malloc(o, sizeof(int));
84 *t->tagValue->u.numeric = ivalue;
88 t->tagValue->which = Z_StringOrNumeric_string;
89 t->tagValue->u.string = odr_malloc(o, strlen(value)+1);
90 strcpy(t->tagValue->u.string, value);
94 t->appliedVariant = 0;
95 t->content = c = odr_malloc(o, sizeof(Z_ElementData));
98 c->which = Z_ElementData_subtree;
99 c->u.subtree = read_grs1(f, o);
103 c->which = Z_ElementData_string;
104 buf[strlen(buf)-1] = '\0';
105 c->u.string = odr_malloc(o, strlen(buf)+1);
106 strcpy(c->u.string, buf);