From: Adam Dickmeiss Date: Fri, 25 Jan 2013 13:44:53 +0000 (+0100) Subject: Rename opacdisp.c to opac_to_xml.c X-Git-Tag: v4.2.50~15 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=d4effebe5599237746102ef51bf2421f77943082;p=yaz-moved-to-github.git Rename opacdisp.c to opac_to_xml.c --- diff --git a/src/Makefile.am b/src/Makefile.am index fcdc75c..1c79893 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -92,7 +92,7 @@ libyaz_la_SOURCES=base64.c version.c options.c log.c \ zoom-event.c \ record_render.c zoom-socket.c zoom-opt.c zoom-p.h sru-p.h \ grs1disp.c zgdu.c soap.c srw.c srwutil.c uri.c solr.c diag_map.c \ - opacdisp.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c cclp.h \ + opac_to_xml.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c cclp.h \ cclqfile.c cclstr.c cclxmlconfig.c ccl_stop_words.c \ cql.y cqlstdio.c cqltransform.c cqlutil.c xcqlutil.c cqlstring.c \ cql_sortkeys.c cql2ccl.c rpn2cql.c \ diff --git a/src/opac_to_xml.c b/src/opac_to_xml.c new file mode 100644 index 0000000..648c8b7 --- /dev/null +++ b/src/opac_to_xml.c @@ -0,0 +1,201 @@ +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2013 Index Data + * See the file LICENSE for details. + */ +/** + * \file opac_to_xml + * \brief Implements OPAC to XML conversion + */ +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include + +static void opac_element_str(WRBUF wrbuf, yaz_iconv_t cd1, yaz_iconv_t cd2, + int l, const char *elem, + const char *data) +{ + if (data) + { + size_t pos; + while (--l >= 0) + wrbuf_puts(wrbuf, " "); + wrbuf_puts(wrbuf, "<"); + wrbuf_puts(wrbuf, elem); + wrbuf_puts(wrbuf, ">"); + + pos = wrbuf->pos; /* save position */ + if (wrbuf_iconv_write_x(wrbuf, cd1, data, strlen(data), 1) && cd2) + { + wrbuf->pos = pos; /* rewind to pos */ + wrbuf_iconv_write_x(wrbuf, cd2, data, strlen(data), 1); + } + wrbuf_puts(wrbuf, "\n"); + } +} + +static void opac_element_bool(WRBUF wrbuf, int l, const char *elem, int *data) +{ + if (data) + { + while (--l >= 0) + wrbuf_puts(wrbuf, " "); + wrbuf_puts(wrbuf, "<"); + wrbuf_puts(wrbuf, elem); + if (*data) + wrbuf_puts(wrbuf, " value=\"1\""); + else + wrbuf_puts(wrbuf, " value=\"0\""); + wrbuf_puts(wrbuf, "/>\n"); + } +} + +void yaz_opac_decode_wrbuf2(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf, + yaz_iconv_t cd2) +{ + int i; + yaz_iconv_t cd1 = yaz_marc_get_iconv(mt); + + wrbuf_puts(wrbuf, "\n"); + if (r->bibliographicRecord) + { + Z_External *ext = r->bibliographicRecord; + + wrbuf_puts(wrbuf, " \n"); + if (ext->which == Z_External_octet) + yaz_marc_decode_wrbuf(mt, (const char *) ext->u.octet_aligned->buf, + ext->u.octet_aligned->len, wrbuf); + wrbuf_puts(wrbuf, " \n"); + } + wrbuf_puts(wrbuf, "\n"); + + for (i = 0; i < r->num_holdingsData; i++) + { + Z_HoldingsRecord *h = r->holdingsData[i]; + wrbuf_puts(wrbuf, " \n"); + + if (h->which == Z_HoldingsRecord_marcHoldingsRecord) + { + Z_External *ext = h->u.marcHoldingsRecord; + + wrbuf_puts(wrbuf, " \n"); + if (ext->which == Z_External_octet) + yaz_marc_decode_wrbuf(mt, (const char *) + ext->u.octet_aligned->buf, + ext->u.octet_aligned->len, wrbuf); + wrbuf_puts(wrbuf, " \n"); + } + else if (h->which == Z_HoldingsRecord_holdingsAndCirc) + { + int j; + + Z_HoldingsAndCircData *d = h->u.holdingsAndCirc; + + opac_element_str(wrbuf, cd1, cd2, 2, "typeOfRecord", + d->typeOfRecord); + opac_element_str(wrbuf, cd1, cd2, 2, "encodingLevel", + d->encodingLevel); + opac_element_str(wrbuf, cd1, cd2, 2, "format", + d->format); + opac_element_str(wrbuf, cd1, cd2, 2, "receiptAcqStatus", + d->receiptAcqStatus); + opac_element_str(wrbuf, cd1, cd2, 2, "generalRetention", + d->generalRetention); + opac_element_str(wrbuf, cd1, cd2, 2, "completeness", + d->completeness); + opac_element_str(wrbuf, cd1, cd2, 2, "dateOfReport", + d->dateOfReport); + opac_element_str(wrbuf, cd1, cd2, 2, "nucCode", d->nucCode); + opac_element_str(wrbuf, cd1, cd2, 2, "localLocation", + d->localLocation); + opac_element_str(wrbuf, cd1, cd2, 2, "shelvingLocation", + d->shelvingLocation); + opac_element_str(wrbuf, cd1, cd2, 2, "callNumber", + d->callNumber); + opac_element_str(wrbuf, cd1, cd2, 2, "shelvingData", + d->shelvingData); + opac_element_str(wrbuf, cd1, cd2, 2, "copyNumber", + d->copyNumber); + opac_element_str(wrbuf, cd1, cd2, 2, "publicNote", + d->publicNote); + opac_element_str(wrbuf, cd1, cd2, 2, "reproductionNote", + d->reproductionNote); + opac_element_str(wrbuf, cd1, cd2, 2, "termsUseRepro", + d->termsUseRepro); + opac_element_str(wrbuf, cd1, cd2, 2, "enumAndChron", + d->enumAndChron); + if (d->num_volumes) + { + wrbuf_puts (wrbuf, " \n"); + for (j = 0; jnum_volumes; j++) + { + wrbuf_puts (wrbuf, " \n"); + opac_element_str(wrbuf, cd1, cd2, 4, "enumeration", + d->volumes[j]->enumeration); + opac_element_str(wrbuf, cd1, cd2, 4, "chronology", + d->volumes[j]->chronology); + opac_element_str(wrbuf, cd1, cd2, 4, "enumAndChron", + d->volumes[j]->enumAndChron); + wrbuf_puts(wrbuf, " \n"); + } + wrbuf_puts(wrbuf, " \n"); + } + if (d->num_circulationData) + { + wrbuf_puts (wrbuf, " \n"); + for (j = 0; jnum_circulationData; j++) + { + wrbuf_puts(wrbuf," \n"); + opac_element_bool(wrbuf, 4, "availableNow", + d->circulationData[j]->availableNow); + opac_element_str(wrbuf, cd1, cd2, 4, "availabiltyDate", + d->circulationData[j]->availablityDate); + opac_element_str(wrbuf, cd1, cd2, 4, "availableThru", + d->circulationData[j]->availableThru); + opac_element_str(wrbuf, cd1, cd2, 4, "restrictions", + d->circulationData[j]->restrictions); + opac_element_str(wrbuf, cd1, cd2, 4, "itemId", + d->circulationData[j]->itemId); + opac_element_bool(wrbuf, 4, "renewable", + d->circulationData[j]->renewable); + opac_element_bool(wrbuf, 4, "onHold", + d->circulationData[j]->onHold); + opac_element_str(wrbuf, cd1, cd2, 4, "enumAndChron", + d->circulationData[j]->enumAndChron); + opac_element_str(wrbuf, cd1, cd2, 4, "midspine", + d->circulationData[j]->midspine); + opac_element_str(wrbuf, cd1, cd2, 4, "temporaryLocation", + d->circulationData[j]->temporaryLocation); + wrbuf_puts(wrbuf, " \n"); + } + wrbuf_puts(wrbuf, " \n"); + } + } + wrbuf_puts(wrbuf, " \n"); + } + wrbuf_puts(wrbuf, "\n"); + wrbuf_puts(wrbuf, "\n"); +} + +void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf) +{ + yaz_opac_decode_wrbuf2(mt, r, wrbuf, 0); +} + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + diff --git a/src/opacdisp.c b/src/opacdisp.c deleted file mode 100644 index f5e7235..0000000 --- a/src/opacdisp.c +++ /dev/null @@ -1,201 +0,0 @@ -/* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data - * See the file LICENSE for details. - */ -/** - * \file opacdisp.c - * \brief Implements OPAC record display - */ -#if HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include -#include - -static void opac_element_str(WRBUF wrbuf, yaz_iconv_t cd1, yaz_iconv_t cd2, - int l, const char *elem, - const char *data) -{ - if (data) - { - size_t pos; - while (--l >= 0) - wrbuf_puts(wrbuf, " "); - wrbuf_puts(wrbuf, "<"); - wrbuf_puts(wrbuf, elem); - wrbuf_puts(wrbuf, ">"); - - pos = wrbuf->pos; /* save position */ - if (wrbuf_iconv_write_x(wrbuf, cd1, data, strlen(data), 1) && cd2) - { - wrbuf->pos = pos; /* rewind to pos */ - wrbuf_iconv_write_x(wrbuf, cd2, data, strlen(data), 1); - } - wrbuf_puts(wrbuf, "\n"); - } -} - -static void opac_element_bool(WRBUF wrbuf, int l, const char *elem, int *data) -{ - if (data) - { - while (--l >= 0) - wrbuf_puts(wrbuf, " "); - wrbuf_puts(wrbuf, "<"); - wrbuf_puts(wrbuf, elem); - if (*data) - wrbuf_puts(wrbuf, " value=\"1\""); - else - wrbuf_puts(wrbuf, " value=\"0\""); - wrbuf_puts(wrbuf, "/>\n"); - } -} - -void yaz_opac_decode_wrbuf2(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf, - yaz_iconv_t cd2) -{ - int i; - yaz_iconv_t cd1 = yaz_marc_get_iconv(mt); - - wrbuf_puts(wrbuf, "\n"); - if (r->bibliographicRecord) - { - Z_External *ext = r->bibliographicRecord; - - wrbuf_puts(wrbuf, " \n"); - if (ext->which == Z_External_octet) - yaz_marc_decode_wrbuf(mt, (const char *) ext->u.octet_aligned->buf, - ext->u.octet_aligned->len, wrbuf); - wrbuf_puts(wrbuf, " \n"); - } - wrbuf_puts(wrbuf, "\n"); - - for (i = 0; i < r->num_holdingsData; i++) - { - Z_HoldingsRecord *h = r->holdingsData[i]; - wrbuf_puts(wrbuf, " \n"); - - if (h->which == Z_HoldingsRecord_marcHoldingsRecord) - { - Z_External *ext = h->u.marcHoldingsRecord; - - wrbuf_puts(wrbuf, " \n"); - if (ext->which == Z_External_octet) - yaz_marc_decode_wrbuf(mt, (const char *) - ext->u.octet_aligned->buf, - ext->u.octet_aligned->len, wrbuf); - wrbuf_puts(wrbuf, " \n"); - } - else if (h->which == Z_HoldingsRecord_holdingsAndCirc) - { - int j; - - Z_HoldingsAndCircData *d = h->u.holdingsAndCirc; - - opac_element_str(wrbuf, cd1, cd2, 2, "typeOfRecord", - d->typeOfRecord); - opac_element_str(wrbuf, cd1, cd2, 2, "encodingLevel", - d->encodingLevel); - opac_element_str(wrbuf, cd1, cd2, 2, "format", - d->format); - opac_element_str(wrbuf, cd1, cd2, 2, "receiptAcqStatus", - d->receiptAcqStatus); - opac_element_str(wrbuf, cd1, cd2, 2, "generalRetention", - d->generalRetention); - opac_element_str(wrbuf, cd1, cd2, 2, "completeness", - d->completeness); - opac_element_str(wrbuf, cd1, cd2, 2, "dateOfReport", - d->dateOfReport); - opac_element_str(wrbuf, cd1, cd2, 2, "nucCode", d->nucCode); - opac_element_str(wrbuf, cd1, cd2, 2, "localLocation", - d->localLocation); - opac_element_str(wrbuf, cd1, cd2, 2, "shelvingLocation", - d->shelvingLocation); - opac_element_str(wrbuf, cd1, cd2, 2, "callNumber", - d->callNumber); - opac_element_str(wrbuf, cd1, cd2, 2, "shelvingData", - d->shelvingData); - opac_element_str(wrbuf, cd1, cd2, 2, "copyNumber", - d->copyNumber); - opac_element_str(wrbuf, cd1, cd2, 2, "publicNote", - d->publicNote); - opac_element_str(wrbuf, cd1, cd2, 2, "reproductionNote", - d->reproductionNote); - opac_element_str(wrbuf, cd1, cd2, 2, "termsUseRepro", - d->termsUseRepro); - opac_element_str(wrbuf, cd1, cd2, 2, "enumAndChron", - d->enumAndChron); - if (d->num_volumes) - { - wrbuf_puts (wrbuf, " \n"); - for (j = 0; jnum_volumes; j++) - { - wrbuf_puts (wrbuf, " \n"); - opac_element_str(wrbuf, cd1, cd2, 4, "enumeration", - d->volumes[j]->enumeration); - opac_element_str(wrbuf, cd1, cd2, 4, "chronology", - d->volumes[j]->chronology); - opac_element_str(wrbuf, cd1, cd2, 4, "enumAndChron", - d->volumes[j]->enumAndChron); - wrbuf_puts(wrbuf, " \n"); - } - wrbuf_puts(wrbuf, " \n"); - } - if (d->num_circulationData) - { - wrbuf_puts (wrbuf, " \n"); - for (j = 0; jnum_circulationData; j++) - { - wrbuf_puts(wrbuf," \n"); - opac_element_bool(wrbuf, 4, "availableNow", - d->circulationData[j]->availableNow); - opac_element_str(wrbuf, cd1, cd2, 4, "availabiltyDate", - d->circulationData[j]->availablityDate); - opac_element_str(wrbuf, cd1, cd2, 4, "availableThru", - d->circulationData[j]->availableThru); - opac_element_str(wrbuf, cd1, cd2, 4, "restrictions", - d->circulationData[j]->restrictions); - opac_element_str(wrbuf, cd1, cd2, 4, "itemId", - d->circulationData[j]->itemId); - opac_element_bool(wrbuf, 4, "renewable", - d->circulationData[j]->renewable); - opac_element_bool(wrbuf, 4, "onHold", - d->circulationData[j]->onHold); - opac_element_str(wrbuf, cd1, cd2, 4, "enumAndChron", - d->circulationData[j]->enumAndChron); - opac_element_str(wrbuf, cd1, cd2, 4, "midspine", - d->circulationData[j]->midspine); - opac_element_str(wrbuf, cd1, cd2, 4, "temporaryLocation", - d->circulationData[j]->temporaryLocation); - wrbuf_puts(wrbuf, " \n"); - } - wrbuf_puts(wrbuf, " \n"); - } - } - wrbuf_puts(wrbuf, " \n"); - } - wrbuf_puts(wrbuf, "\n"); - wrbuf_puts(wrbuf, "\n"); -} - -void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf) -{ - yaz_opac_decode_wrbuf2(mt, r, wrbuf, 0); -} - -/* - * Local variables: - * c-basic-offset: 4 - * c-file-style: "Stroustrup" - * indent-tabs-mode: nil - * End: - * vim: shiftwidth=4 tabstop=8 expandtab - */ - diff --git a/win/makefile b/win/makefile index e87b0c5..f6f96d0 100644 --- a/win/makefile +++ b/win/makefile @@ -489,7 +489,7 @@ MISC_OBJS= \ $(OBJDIR)\sortspec.obj \ $(OBJDIR)\charneg.obj \ $(OBJDIR)\grs1disp.obj \ - $(OBJDIR)\opacdisp.obj \ + $(OBJDIR)\opac_to_xml.obj \ $(OBJDIR)\zgdu.obj \ $(OBJDIR)\soap.obj \ $(OBJDIR)\solr.obj \