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