2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_sumout.c,v $
7 * Revision 1.5 1999-11-30 13:47:12 adam
8 * Improved installation. Moved header files to include/yaz.
10 * Revision 1.4 1999/08/27 09:40:32 adam
11 * Renamed logf function to yaz_log. Removed VC++ project files.
13 * Revision 1.3 1998/02/11 11:53:35 adam
14 * Changed code so that it compiles as C++.
16 * Revision 1.2 1997/09/17 12:10:38 adam
19 * Revision 1.1 1996/06/10 08:56:03 quinn
30 #include <yaz/proto.h>
31 #include <yaz/data1.h>
33 static int *f_integer(data1_node *c, ODR o)
38 if (!c->child || c->child->which != DATA1N_data ||
39 c->child->u.data.len > 63)
41 r = (int *)odr_malloc(o, sizeof(*r));
42 sprintf(intbuf, "%.*s", 63, c->child->u.data.data);
47 static char *f_string(data1_node *c, ODR o)
51 if (!c->child || c->child->which != DATA1N_data)
53 r = (char *)odr_malloc(o, c->child->u.data.len+1);
54 memcpy(r, c->child->u.data.data, c->child->u.data.len);
55 r[c->child->u.data.len] = '\0';
59 Z_BriefBib *data1_nodetosummary (data1_handle dh, data1_node *n,
62 Z_BriefBib *res = (Z_BriefBib *)odr_malloc(o, sizeof(*res));
65 assert(n->which == DATA1N_root);
66 if (strcmp(n->u.root.type, "summary"))
68 yaz_log(LOG_WARN, "Attempt to convert a non-summary record");
72 res->title = "[UNKNOWN]";
76 res->bibliographicLevel = 0;
79 res->publicationPlace = 0;
80 res->publicationDate = 0;
81 res->targetSystemKey = 0;
82 res->satisfyingElement = 0;
88 for (c = n->child; c; c = c->next)
90 if (c->which != DATA1N_tag || !c->u.tag.element)
92 yaz_log(LOG_WARN, "Malformed element in Summary record");
95 if (select && !c->u.tag.node_selected)
97 switch (c->u.tag.element->tag->value.numeric)
99 case 0: res->title = f_string(c, o); break;
100 case 1: res->author = f_string(c, o); break;
101 case 2: res->callNumber = f_string(c, o); break;
102 case 3: res->recordType = f_string(c, o); break;
103 case 4: res->bibliographicLevel = f_string(c, o); break;
104 case 5: abort(); /* TODO */
105 case 10: res->publicationPlace = f_string(c, o); break;
106 case 11: res->publicationDate = f_string(c, o); break;
107 case 12: res->targetSystemKey = f_string(c, o); break;
108 case 13: res->satisfyingElement = f_string(c, o); break;
109 case 14: res->rank = f_integer(c, o); break;
110 case 15: res->documentId = f_string(c, o); break;
111 case 16: res->abstract = f_string(c, o); break;
112 case 17: abort(); /* TODO */
114 yaz_log(LOG_WARN, "Unknown element in Summary record.");