1 /* $Id: d1_sumout.c,v 1.9 2007-01-15 15:10:14 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <yaz/proto.h>
29 #include <idzebra/data1.h>
31 static int *f_integer(data1_node *c, ODR o)
36 if (!c->child || c->child->which != DATA1N_data ||
37 c->child->u.data.len > 63)
39 r = (int *)odr_malloc(o, sizeof(*r));
40 sprintf(intbuf, "%.*s", 63, c->child->u.data.data);
45 static char *f_string(data1_node *c, ODR o)
49 if (!c->child || c->child->which != DATA1N_data)
51 r = (char *)odr_malloc(o, c->child->u.data.len+1);
52 memcpy(r, c->child->u.data.data, c->child->u.data.len);
53 r[c->child->u.data.len] = '\0';
57 Z_BriefBib *data1_nodetosummary (data1_handle dh, data1_node *n,
60 Z_BriefBib *res = (Z_BriefBib *)odr_malloc(o, sizeof(*res));
63 assert(n->which == DATA1N_root);
64 if (strcmp(n->u.root.type, "summary"))
66 yaz_log(YLOG_WARN, "Attempt to convert a non-summary record");
70 res->title = "[UNKNOWN]";
74 res->bibliographicLevel = 0;
77 res->publicationPlace = 0;
78 res->publicationDate = 0;
79 res->targetSystemKey = 0;
80 res->satisfyingElement = 0;
86 for (c = n->child; c; c = c->next)
88 if (c->which != DATA1N_tag || !c->u.tag.element)
90 yaz_log(YLOG_WARN, "Malformed element in Summary record");
93 if (select && !c->u.tag.node_selected)
95 switch (c->u.tag.element->tag->value.numeric)
97 case 0: res->title = f_string(c, o); break;
98 case 1: res->author = f_string(c, o); break;
99 case 2: res->callNumber = f_string(c, o); break;
100 case 3: res->recordType = f_string(c, o); break;
101 case 4: res->bibliographicLevel = f_string(c, o); break;
102 case 5: abort(); /* TODO */
103 case 10: res->publicationPlace = f_string(c, o); break;
104 case 11: res->publicationDate = f_string(c, o); break;
105 case 12: res->targetSystemKey = f_string(c, o); break;
106 case 13: res->satisfyingElement = f_string(c, o); break;
107 case 14: res->rank = f_integer(c, o); break;
108 case 15: res->documentId = f_string(c, o); break;
109 case 16: res->abstract = f_string(c, o); break;
110 case 17: abort(); /* TODO */
112 yaz_log(YLOG_WARN, "Unknown element in Summary record.");
120 * indent-tabs-mode: nil
122 * vim: shiftwidth=4 tabstop=8 expandtab