Fix check for cql.c in dist-hook
[yaz-moved-to-github.git] / src / opacdisp.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: opacdisp.c,v 1.6 2005-03-02 23:59:22 adam Exp $
6  */
7 /**
8  * \file opacdisp.c
9  * \brief Implements OPAC record display
10  */
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <ctype.h>
16
17 #include <yaz/proto.h>
18 #include <yaz/marcdisp.h>
19
20 static void opac_element_str(WRBUF wrbuf, int l, const char *elem,
21                              const char *data)
22 {
23     if (data)
24     {
25         while (--l >= 0)
26             wrbuf_puts(wrbuf, " ");
27         wrbuf_puts(wrbuf, "<");
28         wrbuf_puts(wrbuf, elem);
29         wrbuf_puts(wrbuf, ">");
30         wrbuf_xmlputs(wrbuf, data);
31         wrbuf_puts(wrbuf, "</");
32         wrbuf_puts(wrbuf, elem);
33         wrbuf_puts(wrbuf, ">\n");
34     }
35 }
36
37 static void opac_element_bool(WRBUF wrbuf, int l, const char *elem, int *data)
38 {
39     if (data)
40     {
41         while (--l >= 0)
42             wrbuf_puts(wrbuf, " ");
43         wrbuf_puts(wrbuf, "<");
44         wrbuf_puts(wrbuf, elem);
45         if (*data)
46             wrbuf_puts(wrbuf, " value=\"1\"");
47         else
48             wrbuf_puts(wrbuf, " value=\"0\"");
49         wrbuf_puts(wrbuf, "/>\n");
50     }
51 }
52
53 void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf)
54 {
55     int i;
56
57     wrbuf_puts(wrbuf, "<opacRecord>\n");
58     if (r->bibliographicRecord)
59     {
60         Z_External *ext = r->bibliographicRecord;
61         
62         wrbuf_puts (wrbuf, "  <bibliographicRecord>\n");
63         if (ext->which == Z_External_octet)
64             yaz_marc_decode_wrbuf(mt, ext->u.octet_aligned->buf,
65                                   ext->u.octet_aligned->len, wrbuf);
66         wrbuf_puts (wrbuf, "  </bibliographicRecord>\n");
67     }
68     wrbuf_puts(wrbuf, "<holdings>\n");
69
70     for (i = 0; i < r->num_holdingsData; i++)
71     {
72         Z_HoldingsRecord *h = r->holdingsData[i];
73         wrbuf_puts(wrbuf, " <holding>\n");
74
75         if (h->which == Z_HoldingsRecord_marcHoldingsRecord)
76         {
77             Z_External *ext = h->u.marcHoldingsRecord;
78
79             wrbuf_puts (wrbuf, "  <marcHoldingsRecord>\n");
80             if (ext->which == Z_External_octet)
81                 yaz_marc_decode_wrbuf(mt, ext->u.octet_aligned->buf,
82                                       ext->u.octet_aligned->len, wrbuf);
83             wrbuf_puts (wrbuf, "  </marcHoldingsRecord>\n");
84         }
85         else if (h->which == Z_HoldingsRecord_holdingsAndCirc)
86         {
87             int j;
88             
89             Z_HoldingsAndCircData *d = h->u.holdingsAndCirc;
90         
91             opac_element_str(wrbuf, 2, "typeOfRecord", d->typeOfRecord);
92             opac_element_str(wrbuf, 2, "encodingLevel", d->encodingLevel);
93             opac_element_str(wrbuf, 2, "format", d->format);
94             opac_element_str(wrbuf, 2, "receiptAcqStatus", d->receiptAcqStatus);
95             opac_element_str (wrbuf, 2, "generalRetention", d->generalRetention);
96             opac_element_str (wrbuf, 2, "completeness", d->completeness);
97             opac_element_str (wrbuf, 2, "dateOfReport", d->dateOfReport);
98             opac_element_str (wrbuf, 2, "nucCode", d->nucCode);
99             opac_element_str (wrbuf, 2, "localLocation", d->localLocation);
100             opac_element_str (wrbuf, 2, "shelvingLocation", d->shelvingLocation);
101             opac_element_str (wrbuf, 2, "callNumber", d->callNumber);
102             opac_element_str (wrbuf, 2, "shelvingData", d->shelvingData);
103             
104             opac_element_str (wrbuf, 2, "copyNumber", d->copyNumber);
105             opac_element_str (wrbuf, 2, "publicNote", d->publicNote);
106             opac_element_str (wrbuf, 2, "reproductionNote", d->reproductionNote);
107             opac_element_str (wrbuf, 2, "termsUseRepro", d->termsUseRepro);
108             opac_element_str (wrbuf, 2, "enumAndChron", d->enumAndChron);
109             if (d->num_volumes)
110             {
111                 wrbuf_puts (wrbuf, "  <volumes>\n");
112                 for (j = 0; j<d->num_volumes; j++)
113                 {
114                     wrbuf_puts (wrbuf, "   <volume>\n");
115                     opac_element_str (wrbuf, 4, "enumeration",
116                                       d->volumes[j]->enumeration);
117                     opac_element_str (wrbuf, 4, "chronology",
118                                       d->volumes[j]->chronology);
119                     opac_element_str (wrbuf, 4, "enumAndChron",
120                                       d->volumes[j]->enumAndChron);
121                     wrbuf_puts (wrbuf, "   </volume>\n");
122                 }
123                 wrbuf_puts (wrbuf, "  </volumes>\n");
124             }
125             if (d->num_circulationData)
126             {
127                 wrbuf_puts (wrbuf, "  <circulations>\n");
128                 for (j = 0; j<d->num_circulationData; j++)
129                 {
130                     wrbuf_puts (wrbuf,"   <circulation>\n");
131                     opac_element_bool (wrbuf, 4, "availableNow",
132                                        d->circulationData[j]->availableNow);
133                     opac_element_str (wrbuf, 4, "availabiltyDate",
134                                       d->circulationData[j]->availablityDate);
135                     opac_element_str (wrbuf, 4, "availableThru",
136                                       d->circulationData[j]->availableThru);
137                     opac_element_str (wrbuf, 4, "restrictions",
138                                       d->circulationData[j]->restrictions);
139                     opac_element_str (wrbuf, 4, "itemId",
140                                       d->circulationData[j]->itemId);
141                     opac_element_bool (wrbuf, 4, "renewable",
142                                        d->circulationData[j]->renewable);
143                     opac_element_bool (wrbuf, 4, "onHold",
144                                        d->circulationData[j]->onHold);
145                     opac_element_str (wrbuf, 4, "enumAndChron",
146                                       d->circulationData[j]->enumAndChron);
147                     opac_element_str (wrbuf, 4, "midspine",
148                                       d->circulationData[j]->midspine);
149                     opac_element_str (wrbuf, 4, "temporaryLocation",
150                                       d->circulationData[j]->temporaryLocation);
151                     wrbuf_puts (wrbuf, "   </circulation>\n");
152                 }
153                 wrbuf_puts (wrbuf, "  </circulations>\n");
154             }
155         }
156         wrbuf_puts(wrbuf, " </holding>\n");
157     }
158     wrbuf_puts(wrbuf, "</holdings>\n");
159     wrbuf_puts(wrbuf, "</opacRecord>\n");
160 }
161
162 void yaz_display_OPAC(WRBUF wrbuf, Z_OPACRecord *opac_rec, int flags)
163 {
164     yaz_marc_t mt = yaz_marc_create();
165
166     yaz_marc_xml(mt, YAZ_MARC_MARCXML);
167     yaz_opac_decode_wrbuf(mt, opac_rec, wrbuf);
168     yaz_marc_destroy(mt);
169 }
170