source: trunk/gsdl/src/colservr/read-grs.cpp@ 9926

Last change on this file since 9926 was 9926, checked in by davidb, 19 years ago

Introduction of Z39.50 Server code for Greenstone. Based on the work of
Chris Martin (2001 approx). Updated to work with newer version of YAZ
library.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
5 *
6 * $Log$
7 * Revision 1.1 2005/05/23 04:06:20 davidb
8 *
9 * Introduction of Z39.50 Server code for Greenstone. Based on the work of
10 * Chris Martin (2001 approx). Updated to work with newer version of YAZ
11 * library.
12 *
13 * Revision 1.5 1999/11/30 13:47:12 adam
14 * Improved installation. Moved header files to include/yaz.
15 *
16 * Revision 1.4 1999/08/27 09:40:32 adam
17 * Renamed logf function to yaz_log. Removed VC++ project files.
18 *
19 * Revision 1.3 1999/03/31 11:18:25 adam
20 * Implemented odr_strdup. Added Reference ID to backend server API.
21 *
22 * Revision 1.2 1998/02/11 11:53:36 adam
23 * Changed code so that it compiles as C++.
24 *
25 * Revision 1.1 1997/09/01 08:55:53 adam
26 * New windows NT/95 port using MSV5.0. Test server ztest now in
27 * separate directory. When using NT, this test server may operate
28 * as an NT service. Note that the service.[ch] should be part of
29 * generic, but it isn't yet.
30 *
31 * Revision 1.1 1995/08/17 12:45:23 quinn
32 * Fixed minor problems with GRS-1. Added support in c&s.
33 *
34 *
35 */
36
37/*
38 * Little toy-thing to read a GRS-1 record from a file.
39 */
40
41#include <stdio.h>
42#include <ctype.h>
43#include <stdlib.h>
44
45#include <yaz/proto.h>
46#include <yaz/log.h>
47
48#define GRS_MAX_FIELDS 50
49
50Z_GenericRecord *read_grs1(FILE *f, ODR o)
51{
52 char line[512], *buf;
53 int type, ivalue;
54 char value[512];
55 Z_GenericRecord *r = 0;
56
57 for (;;)
58 {
59 Z_TaggedElement *t;
60 Z_ElementData *c;
61
62 while (fgets(buf = line, 512, f))
63 {
64 while (*buf && isspace(*buf))
65 buf++;
66 if (!*buf || *buf == '#')
67 continue;
68 break;
69 }
70 if (*buf == '}')
71 return r;
72 if (sscanf(buf, "(%d,%[^)])", &type, value) != 2)
73 {
74 yaz_log(LOG_WARN, "Bad data in '%s'", buf);
75 return 0;
76 }
77 if (!type && *value == '0')
78 return r;
79 if (!(buf = strchr(buf, ')')))
80 return 0;
81 buf++;
82 while (*buf && isspace(*buf))
83 buf++;
84 if (!*buf)
85 return 0;
86 if (!r)
87 {
88 r = (Z_GenericRecord *)odr_malloc(o, sizeof(*r));
89 r->elements = (Z_TaggedElement **)
90 odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS);
91 r->num_elements = 0;
92 }
93 r->elements[r->num_elements] = t = (Z_TaggedElement *)
94 odr_malloc(o, sizeof(Z_TaggedElement));
95 t->tagType = (int *)odr_malloc(o, sizeof(int));
96 *t->tagType = type;
97 t->tagValue = (Z_StringOrNumeric *)
98 odr_malloc(o, sizeof(Z_StringOrNumeric));
99 if ((ivalue = atoi(value)))
100 {
101 t->tagValue->which = Z_StringOrNumeric_numeric;
102 t->tagValue->u.numeric = (int *)odr_malloc(o, sizeof(int));
103 *t->tagValue->u.numeric = ivalue;
104 }
105 else
106 {
107 t->tagValue->which = Z_StringOrNumeric_string;
108 t->tagValue->u.string = (char *)odr_malloc(o, strlen(value)+1);
109 strcpy(t->tagValue->u.string, value);
110 }
111 t->tagOccurrence = 0;
112 t->metaData = 0;
113 t->appliedVariant = 0;
114 t->content = c = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData));
115 if (*buf == '{')
116 {
117 c->which = Z_ElementData_subtree;
118 c->u.subtree = read_grs1(f, o);
119 }
120 else
121 {
122 c->which = Z_ElementData_string;
123 buf[strlen(buf)-1] = '\0';
124 c->u.string = odr_strdup(o, buf);
125 }
126 r->num_elements++;
127 }
128}
Note: See TracBrowser for help on using the repository browser.