Updated information about YAZ.
[yaz-moved-to-github.git] / retrieval / d1_sumout.c
1 /*
2  * Copyright (c) 1995-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
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.
9  *
10  * Revision 1.4  1999/08/27 09:40:32  adam
11  * Renamed logf function to yaz_log. Removed VC++ project files.
12  *
13  * Revision 1.3  1998/02/11 11:53:35  adam
14  * Changed code so that it compiles as C++.
15  *
16  * Revision 1.2  1997/09/17 12:10:38  adam
17  * YAZ version 1.4.
18  *
19  * Revision 1.1  1996/06/10 08:56:03  quinn
20  * Work on Summary.
21  *
22  *
23  */
24
25 #include <assert.h>
26 #include <string.h>
27 #include <stdlib.h>
28
29 #include <yaz/log.h>
30 #include <yaz/proto.h>
31 #include <yaz/data1.h>
32
33 static int *f_integer(data1_node *c, ODR o)
34 {
35     int *r;
36     char intbuf[64];
37
38     if (!c->child || c->child->which != DATA1N_data ||
39         c->child->u.data.len > 63)
40         return 0;
41     r = (int *)odr_malloc(o, sizeof(*r));
42     sprintf(intbuf, "%.*s", 63, c->child->u.data.data);
43     *r = atoi(intbuf);
44     return r;
45 }
46
47 static char *f_string(data1_node *c, ODR o)
48 {
49     char *r;
50
51     if (!c->child || c->child->which != DATA1N_data)
52         return 0;
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';
56     return r;
57 }
58
59 Z_BriefBib *data1_nodetosummary (data1_handle dh, data1_node *n,
60                                  int select, ODR o)
61 {
62     Z_BriefBib *res = (Z_BriefBib *)odr_malloc(o, sizeof(*res));
63     data1_node *c;
64
65     assert(n->which == DATA1N_root);
66     if (strcmp(n->u.root.type, "summary"))
67     {
68         yaz_log(LOG_WARN, "Attempt to convert a non-summary record");
69         return 0;
70     }
71
72     res->title = "[UNKNOWN]";
73     res->author = 0;
74     res->callNumber = 0;
75     res->recordType = 0;
76     res->bibliographicLevel = 0;
77     res->num_format = 0;
78     res->format = 0;
79     res->publicationPlace = 0;
80     res->publicationDate = 0;
81     res->targetSystemKey = 0;
82     res->satisfyingElement = 0;
83     res->rank = 0;
84     res->documentId = 0;
85     res->abstract = 0;
86     res->otherInfo = 0;
87
88     for (c = n->child; c; c = c->next)
89     {
90         if (c->which != DATA1N_tag || !c->u.tag.element)
91         {
92             yaz_log(LOG_WARN, "Malformed element in Summary record");
93             return 0;
94         }
95         if (select && !c->u.tag.node_selected)
96             continue;
97         switch (c->u.tag.element->tag->value.numeric)
98         {
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 */
113             default:
114                 yaz_log(LOG_WARN, "Unknown element in Summary record.");
115         }
116     }
117     return res;
118 }