IDZEBRA 2.2.8
d1_sumout.c
Go to the documentation of this file.
1/* This file is part of the Zebra server.
2 Copyright (C) Index Data
3
4Zebra is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 2, or (at your option) any later
7version.
8
9Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
18*/
19
20#if HAVE_CONFIG_H
21#include <config.h>
22#endif
23#include <assert.h>
24#include <string.h>
25#include <stdlib.h>
26
27#include <yaz/log.h>
28#include <yaz/proto.h>
29#include <idzebra/data1.h>
30
31static Odr_int *f_integer(data1_node *c, ODR o)
32{
33 char intbuf[64];
34
35 if (!c->child || c->child->which != DATA1N_data ||
36 c->child->u.data.len >= sizeof(intbuf))
37 return 0;
38 memcpy(intbuf, c->child->u.data.data, c->u.data.len);
39 intbuf[c->u.data.len] = '\0';
40 return odr_intdup(o, atoi(intbuf));
41}
42
43static char *f_string(data1_node *c, ODR o)
44{
45 char *r;
46
47 if (!c->child || c->child->which != DATA1N_data)
48 return 0;
49 r = (char *)odr_malloc(o, c->child->u.data.len + 1);
50 memcpy(r, c->child->u.data.data, c->child->u.data.len);
51 r[c->child->u.data.len] = '\0';
52 return r;
53}
54
56 int select, ODR o)
57{
58 Z_BriefBib *res = (Z_BriefBib *)odr_malloc(o, sizeof(*res));
59 data1_node *c;
60
61 assert(n->which == DATA1N_root);
62 if (strcmp(n->u.root.type, "summary"))
63 {
64 yaz_log(YLOG_WARN, "Attempt to convert a non-summary record");
65 return 0;
66 }
67
68 res->title = "[UNKNOWN]";
69 res->author = 0;
70 res->callNumber = 0;
71 res->recordType = 0;
72 res->bibliographicLevel = 0;
73 res->num_format = 0;
74 res->format = 0;
75 res->publicationPlace = 0;
76 res->publicationDate = 0;
77 res->targetSystemKey = 0;
78 res->satisfyingElement = 0;
79 res->rank = 0;
80 res->documentId = 0;
81 res->abstract = 0;
82 res->otherInfo = 0;
83
84 for (c = n->child; c; c = c->next)
85 {
86 if (c->which != DATA1N_tag || !c->u.tag.element)
87 {
88 yaz_log(YLOG_WARN, "Malformed element in Summary record");
89 return 0;
90 }
91 if (select && !c->u.tag.node_selected)
92 continue;
93 switch (c->u.tag.element->tag->value.numeric)
94 {
95 case 0: res->title = f_string(c, o); break;
96 case 1: res->author = f_string(c, o); break;
97 case 2: res->callNumber = f_string(c, o); break;
98 case 3: res->recordType = f_string(c, o); break;
99 case 4: res->bibliographicLevel = f_string(c, o); break;
100 case 5: abort(); /* TODO */
101 case 10: res->publicationPlace = f_string(c, o); break;
102 case 11: res->publicationDate = f_string(c, o); break;
103 case 12: res->targetSystemKey = f_string(c, o); break;
104 case 13: res->satisfyingElement = f_string(c, o); break;
105 case 14: res->rank = f_integer(c, o); break;
106 case 15: res->documentId = f_string(c, o); break;
107 case 16: res->abstract = f_string(c, o); break;
108 case 17: abort(); /* TODO */
109 default:
110 yaz_log(YLOG_WARN, "Unknown element in Summary record.");
111 }
112 }
113 return res;
114}
115/*
116 * Local variables:
117 * c-basic-offset: 4
118 * c-file-style: "Stroustrup"
119 * indent-tabs-mode: nil
120 * End:
121 * vim: shiftwidth=4 tabstop=8 expandtab
122 */
123
Z_BriefBib * data1_nodetosummary(data1_handle dh, data1_node *n, int select, ODR o)
Definition d1_sumout.c:55
static Odr_int * f_integer(data1_node *c, ODR o)
Definition d1_sumout.c:31
static char * f_string(data1_node *c, ODR o)
Definition d1_sumout.c:43
#define DATA1N_tag
Definition data1.h:276
#define DATA1N_data
Definition data1.h:278
#define DATA1N_root
Definition data1.h:274
struct data1_node::@2::@3 root
char * type
Definition data1.h:290
struct data1_node * child
Definition data1.h:341
char * tag
Definition data1.h:296
char * data
Definition data1.h:307
struct data1_node * next
Definition data1.h:340
union data1_node::@2 u
int which
Definition data1.h:285