IDZEBRA  2.1.2
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 
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
7 version.
8 
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
12 for more details.
13 
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
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 
31 static 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 > 63)
37  return 0;
38  sprintf(intbuf, "%.*s", 63, c->child->u.data.data);
39  return odr_intdup(o, atoi(intbuf));
40 }
41 
42 static char *f_string(data1_node *c, ODR o)
43 {
44  char *r;
45 
46  if (!c->child || c->child->which != DATA1N_data)
47  return 0;
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';
51  return r;
52 }
53 
55  int select, ODR o)
56 {
57  Z_BriefBib *res = (Z_BriefBib *)odr_malloc(o, sizeof(*res));
58  data1_node *c;
59 
60  assert(n->which == DATA1N_root);
61  if (strcmp(n->u.root.type, "summary"))
62  {
63  yaz_log(YLOG_WARN, "Attempt to convert a non-summary record");
64  return 0;
65  }
66 
67  res->title = "[UNKNOWN]";
68  res->author = 0;
69  res->callNumber = 0;
70  res->recordType = 0;
71  res->bibliographicLevel = 0;
72  res->num_format = 0;
73  res->format = 0;
74  res->publicationPlace = 0;
75  res->publicationDate = 0;
76  res->targetSystemKey = 0;
77  res->satisfyingElement = 0;
78  res->rank = 0;
79  res->documentId = 0;
80  res->abstract = 0;
81  res->otherInfo = 0;
82 
83  for (c = n->child; c; c = c->next)
84  {
85  if (c->which != DATA1N_tag || !c->u.tag.element)
86  {
87  yaz_log(YLOG_WARN, "Malformed element in Summary record");
88  return 0;
89  }
90  if (select && !c->u.tag.node_selected)
91  continue;
92  switch (c->u.tag.element->tag->value.numeric)
93  {
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 */
108  default:
109  yaz_log(YLOG_WARN, "Unknown element in Summary record.");
110  }
111  }
112  return res;
113 }
114 /*
115  * Local variables:
116  * c-basic-offset: 4
117  * c-file-style: "Stroustrup"
118  * indent-tabs-mode: nil
119  * End:
120  * vim: shiftwidth=4 tabstop=8 expandtab
121  */
122 
#define DATA1N_tag
Definition: data1.h:276
#define DATA1N_root
Definition: data1.h:274
Z_BriefBib * data1_nodetosummary(data1_handle dh, data1_node *n, int select, ODR o)
Definition: d1_sumout.c:54
static char * f_string(data1_node *c, ODR o)
Definition: d1_sumout.c:42
static Odr_int * f_integer(data1_node *c, ODR o)
Definition: d1_sumout.c:31
char * tag
Definition: data1.h:296
union data1_node::@2 u
struct data1_node::@2::@3 root
struct data1_node * child
Definition: data1.h:341
int which
Definition: data1.h:285
struct data1_node * next
Definition: data1.h:340
char * data
Definition: data1.h:307
#define DATA1N_data
Definition: data1.h:278