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 Odr_int *f_integer(data1_node *c, ODR o)
32 if (!c->child || c->child->which != DATA1N_data ||
33 c->child->u.data.len > 63)
35 sprintf(intbuf, "%.*s", 63, c->child->u.data.data);
36 return odr_intdup(o, atoi(intbuf));
39 static char *f_string(data1_node *c, ODR o)
43 if (!c->child || c->child->which != DATA1N_data)
45 r = (char *)odr_malloc(o, c->child->u.data.len+1);
46 memcpy(r, c->child->u.data.data, c->child->u.data.len);
47 r[c->child->u.data.len] = '\0';
51 Z_BriefBib *data1_nodetosummary (data1_handle dh, data1_node *n,
54 Z_BriefBib *res = (Z_BriefBib *)odr_malloc(o, sizeof(*res));
57 assert(n->which == DATA1N_root);
58 if (strcmp(n->u.root.type, "summary"))
60 yaz_log(YLOG_WARN, "Attempt to convert a non-summary record");
64 res->title = "[UNKNOWN]";
68 res->bibliographicLevel = 0;
71 res->publicationPlace = 0;
72 res->publicationDate = 0;
73 res->targetSystemKey = 0;
74 res->satisfyingElement = 0;
80 for (c = n->child; c; c = c->next)
82 if (c->which != DATA1N_tag || !c->u.tag.element)
84 yaz_log(YLOG_WARN, "Malformed element in Summary record");
87 if (select && !c->u.tag.node_selected)
89 switch (c->u.tag.element->tag->value.numeric)
91 case 0: res->title = f_string(c, o); break;
92 case 1: res->author = f_string(c, o); break;
93 case 2: res->callNumber = f_string(c, o); break;
94 case 3: res->recordType = f_string(c, o); break;
95 case 4: res->bibliographicLevel = f_string(c, o); break;
96 case 5: abort(); /* TODO */
97 case 10: res->publicationPlace = f_string(c, o); break;
98 case 11: res->publicationDate = f_string(c, o); break;
99 case 12: res->targetSystemKey = f_string(c, o); break;
100 case 13: res->satisfyingElement = f_string(c, o); break;
101 case 14: res->rank = f_integer(c, o); break;
102 case 15: res->documentId = f_string(c, o); break;
103 case 16: res->abstract = f_string(c, o); break;
104 case 17: abort(); /* TODO */
106 yaz_log(YLOG_WARN, "Unknown element in Summary record.");
114 * c-file-style: "Stroustrup"
115 * indent-tabs-mode: nil
117 * vim: shiftwidth=4 tabstop=8 expandtab