2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1998-02-11 11:53:36 adam
8 * Changed code so that it compiles as C++.
10 * Revision 1.1 1997/09/01 08:55:53 adam
11 * New windows NT/95 port using MSV5.0. Test server ztest now in
12 * separate directory. When using NT, this test server may operate
13 * as an NT service. Note that the service.[ch] should be part of
14 * generic, but it isn't yet.
16 * Revision 1.1 1995/08/17 12:45:23 quinn
17 * Fixed minor problems with GRS-1. Added support in c&s.
23 * Little toy-thing to read a GRS-1 record from a file.
33 #define GRS_MAX_FIELDS 50
35 Z_GenericRecord *read_grs1(FILE *f, ODR o)
40 Z_GenericRecord *r = 0;
47 while (fgets(buf = line, 512, f))
49 while (*buf && isspace(*buf))
51 if (!*buf || *buf == '#')
57 if (sscanf(buf, "(%d,%[^)])", &type, value) != 2)
59 logf(LOG_WARN, "Bad data in '%s'", buf);
62 if (!type && *value == '0')
64 if (!(buf = strchr(buf, ')')))
67 while (*buf && isspace(*buf))
73 r = (Z_GenericRecord *)odr_malloc(o, sizeof(*r));
74 r->elements = (Z_TaggedElement **)odr_malloc(o, sizeof(Z_TaggedElement*) *
78 r->elements[r->num_elements] = t = (Z_TaggedElement *)odr_malloc(o,
79 sizeof(Z_TaggedElement));
80 t->tagType = (int *)odr_malloc(o, sizeof(int));
82 t->tagValue = (Z_StringOrNumeric *)odr_malloc(o, sizeof(Z_StringOrNumeric));
83 if ((ivalue = atoi(value)))
85 t->tagValue->which = Z_StringOrNumeric_numeric;
86 t->tagValue->u.numeric = (int *)odr_malloc(o, sizeof(int));
87 *t->tagValue->u.numeric = ivalue;
91 t->tagValue->which = Z_StringOrNumeric_string;
92 t->tagValue->u.string = (char *)odr_malloc(o, strlen(value)+1);
93 strcpy(t->tagValue->u.string, value);
97 t->appliedVariant = 0;
98 t->content = c = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData));
101 c->which = Z_ElementData_subtree;
102 c->u.subtree = read_grs1(f, o);
106 c->which = Z_ElementData_string;
107 buf[strlen(buf)-1] = '\0';
108 c->u.string = (char *)odr_malloc(o, strlen(buf)+1);
109 strcpy(c->u.string, buf);