1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <yaz/proto.h>
26 #include <idzebra/data1.h>
28 static int *f_integer(data1_node *c, ODR o)
33 if (!c->child || c->child->which != DATA1N_data ||
34 c->child->u.data.len > 63)
36 r = (int *)odr_malloc(o, sizeof(*r));
37 sprintf(intbuf, "%.*s", 63, c->child->u.data.data);
42 static char *f_string(data1_node *c, ODR o)
46 if (!c->child || c->child->which != DATA1N_data)
48 r = (char *)odr_malloc(o, c->child->u.data.len+1);
49 memcpy(r, c->child->u.data.data, c->child->u.data.len);
50 r[c->child->u.data.len] = '\0';
54 Z_BriefBib *data1_nodetosummary (data1_handle dh, data1_node *n,
57 Z_BriefBib *res = (Z_BriefBib *)odr_malloc(o, sizeof(*res));
60 assert(n->which == DATA1N_root);
61 if (strcmp(n->u.root.type, "summary"))
63 yaz_log(YLOG_WARN, "Attempt to convert a non-summary record");
67 res->title = "[UNKNOWN]";
71 res->bibliographicLevel = 0;
74 res->publicationPlace = 0;
75 res->publicationDate = 0;
76 res->targetSystemKey = 0;
77 res->satisfyingElement = 0;
83 for (c = n->child; c; c = c->next)
85 if (c->which != DATA1N_tag || !c->u.tag.element)
87 yaz_log(YLOG_WARN, "Malformed element in Summary record");
90 if (select && !c->u.tag.node_selected)
92 switch (c->u.tag.element->tag->value.numeric)
94 case 0: res->title = f_string(c, o); break;
95 case 1: res->author = f_string(c, o); break;
96 case 2: res->callNumber = f_string(c, o); break;
97 case 3: res->recordType = f_string(c, o); break;
98 case 4: res->bibliographicLevel = f_string(c, o); break;
99 case 5: abort(); /* TODO */
100 case 10: res->publicationPlace = f_string(c, o); break;
101 case 11: res->publicationDate = f_string(c, o); break;
102 case 12: res->targetSystemKey = f_string(c, o); break;
103 case 13: res->satisfyingElement = f_string(c, o); break;
104 case 14: res->rank = f_integer(c, o); break;
105 case 15: res->documentId = f_string(c, o); break;
106 case 16: res->abstract = f_string(c, o); break;
107 case 17: abort(); /* TODO */
109 yaz_log(YLOG_WARN, "Unknown element in Summary record.");
117 * c-file-style: "Stroustrup"
118 * indent-tabs-mode: nil
120 * vim: shiftwidth=4 tabstop=8 expandtab