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