X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmarcmap.c;h=7b62c1ec5b47e4340f3b0f176f3d2031cd846838;hb=46eea7c36057b34c235be40c5d4df9256a7668fd;hp=b3a447c804aba2b7e1f6b92fdd54c2eea62032ad;hpb=08303b063a01c5531f175e76358d78570e68bbb6;p=pazpar2-moved-to-github.git diff --git a/src/marcmap.c b/src/marcmap.c index b3a447c..7b62c1e 100644 --- a/src/marcmap.c +++ b/src/marcmap.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2009 Index Data + Copyright (C) 2006-2010 Index Data Pazpar2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -21,6 +21,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \brief MARC map implementation */ +#if HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -30,10 +34,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include -#include -#include +#include "marcmap.h" +#include "marchash.h" -struct marcmap *marcmap_load(char *filename, NMEM nmem) { +struct marcmap *marcmap_load(const char *filename, NMEM nmem) +{ struct marcmap *mm; struct marcmap *mmhead; FILE *fp; @@ -133,9 +138,11 @@ xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in) struct marcmap *mmcur; xml_out = xmlNewDoc(BAD_CAST "1.0"); + xml_out->encoding = xmlCharStrdup("UTF-8"); xml_out_root = xmlNewNode(NULL, BAD_CAST "record"); xmlDocSetRootElement(xml_out, xml_out_root); ns_pz = xmlNewNs(xml_out_root, BAD_CAST "http://www.indexdata.com/pazpar2/1.0", BAD_CAST "pz"); + xmlSetNs(xml_out_root, ns_pz); nmem = nmem_create(); rec_node = xmlDocGetRootElement(xml_in); marchash = marchash_create(nmem); @@ -144,36 +151,38 @@ xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in) mmcur = marcmap; while (mmcur != NULL) { - if (field = marchash_get_field(marchash, mmcur->field, NULL)) - do + field = 0; + while ((field = marchash_get_field(marchash, mmcur->field, field)) != 0) + { + // field value + if ((mmcur->subfield == '$') && (s = field->val)) { - // field value - if ((mmcur->subfield == '$') && (s = field->val)) - { - meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", s); - xmlSetProp(meta_node, BAD_CAST "type", mmcur->pz); - } - // catenate all subfields - else if ((mmcur->subfield == '*') && (s = marchash_catenate_subfields(field, " ", nmem))) - { - meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", s); - xmlSetProp(meta_node, BAD_CAST "type", mmcur->pz); - } - // subfield value - else if (mmcur->subfield) + meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s); + xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); + } + // catenate all subfields + else if ((mmcur->subfield == '*') && (s = marchash_catenate_subfields(field, " ", nmem))) + { + meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s); + xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); + } + // subfield value + else if (mmcur->subfield) + { + subfield = 0; + while ((subfield = + marchash_get_subfield(mmcur->subfield, + field, subfield)) != 0) { - if (subfield = marchash_get_subfield(mmcur->subfield, field, NULL)) - do - if (s = subfield->val) - { - meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", s); - xmlSetProp(meta_node, BAD_CAST "type", mmcur->pz); - } - while (subfield = marchash_get_subfield(mmcur->subfield, field, subfield)); + if ((s = subfield->val) != 0) + { + meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s); + xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); + } } - } - while (field = marchash_get_field(marchash, mmcur->field, field)); + + } mmcur = mmcur->next; } @@ -202,12 +211,12 @@ xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in) if ((field = marchash_get_field(marchash, "245", NULL)) && (subfield = marchash_get_subfield('a', field, NULL))) strncat(mergekey, subfield->val, 1023 - strlen(mergekey)); strncat(mergekey, " author ", 1023 - strlen(mergekey)); - if ((field = marchash_get_field(marchash, "245", NULL)) && (subfield = marchash_get_subfield('a', field, NULL))) + if ((field = marchash_get_field(marchash, "100", NULL)) && (subfield = marchash_get_subfield('a', field, NULL))) strncat(mergekey, subfield->val, 1023 - strlen(mergekey)); strncat(mergekey, " medium ", 1023 - strlen(mergekey)); strncat(mergekey, medium, 1023 - strlen(mergekey)); - xmlSetProp(xml_out_root, BAD_CAST "mergekey", BAD_CAST mergekey); +// xmlSetProp(xml_out_root, BAD_CAST "mergekey", BAD_CAST mergekey); nmem_destroy(nmem); return xml_out;