X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmarcmap.c;h=7b62c1ec5b47e4340f3b0f176f3d2031cd846838;hb=2ebf0b250fd141b7a3e186e7e99bfc76e29e39d7;hp=a468d3e91192fc277276c65fa01cc928bb79d50c;hpb=2c07c3edbd2fb4c6f72b6527632fab264b6ab66b;p=pazpar2-moved-to-github.git diff --git a/src/marcmap.c b/src/marcmap.c index a468d3e..7b62c1e 100644 --- a/src/marcmap.c +++ b/src/marcmap.c @@ -1,3 +1,30 @@ +/* This file is part of Pazpar2. + 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 +Software Foundation; either version 2, or (at your option) any later +version. + +Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** \file + \brief MARC map implementation +*/ + +#if HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -7,10 +34,11 @@ #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; @@ -110,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); @@ -121,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; } @@ -179,13 +211,22 @@ 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; } + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */