1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
6 * \brief Little toy-thing to read GRS-1 records from a file.
15 #include <yaz/proto.h>
20 #define GRS_MAX_FIELDS 50
22 static Z_GenericRecord *read_grs1(FILE *f, ODR o)
27 Z_GenericRecord *r = 0;
34 while (fgets(buf = line, 512, f))
36 while (*buf && yaz_isspace(*buf))
38 if (!*buf || *buf == '#')
44 if (sscanf(buf, "(%d,%[^)])", &type, value) != 2)
46 yaz_log(YLOG_WARN, "Bad data in '%s'", buf);
49 if (!type && *value == '0')
51 if (!(buf = strchr(buf, ')')))
54 while (*buf && yaz_isspace(*buf))
60 r = (Z_GenericRecord *)odr_malloc(o, sizeof(*r));
61 r->elements = (Z_TaggedElement **)
62 odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS);
65 r->elements[r->num_elements] = t = (Z_TaggedElement *)
66 odr_malloc(o, sizeof(Z_TaggedElement));
67 t->tagType = odr_intdup(o, type);
68 t->tagValue = (Z_StringOrNumeric *)
69 odr_malloc(o, sizeof(Z_StringOrNumeric));
70 if ((ivalue = atoi(value)))
72 t->tagValue->which = Z_StringOrNumeric_numeric;
73 t->tagValue->u.numeric = odr_intdup(o, ivalue);
77 t->tagValue->which = Z_StringOrNumeric_string;
78 t->tagValue->u.string = (char *)odr_malloc(o, strlen(value)+1);
79 strcpy(t->tagValue->u.string, value);
83 t->appliedVariant = 0;
84 t->content = c = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData));
87 c->which = Z_ElementData_subtree;
88 c->u.subtree = read_grs1(f, o);
92 c->which = Z_ElementData_string;
93 buf[strlen(buf)-1] = '\0';
94 c->u.string = odr_strdup(o, buf);
100 Z_GenericRecord *dummy_grs_record (int num, ODR o)
102 FILE *f = fopen("dummy-grs", "r");
104 Z_GenericRecord *r = 0;
109 while (fgets(line, 512, f))
110 if (*line == '#' && sscanf(line, "#%d", &n) == 1 && n == num)
122 * c-file-style: "Stroustrup"
123 * indent-tabs-mode: nil
125 * vim: shiftwidth=4 tabstop=8 expandtab