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