X-Git-Url: http://git.indexdata.com/?p=pazpar2-moved-to-github.git;a=blobdiff_plain;f=src%2Fmarcmap.c;h=f79b3232a123349fc6b1fc5c549680f0348e24b5;hp=6b5c42e0383f2569b3d95a732a967e55d9e03e7a;hb=HEAD;hpb=e21851ef5461875e3929605afe79f23be86c2404 diff --git a/src/marcmap.c b/src/marcmap.c index 6b5c42e..f79b323 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) 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 @@ -42,7 +42,7 @@ struct marcmap *marcmap_load(const char *filename, NMEM nmem) struct marcmap *mm; struct marcmap *mmhead; FILE *fp; - char c; + int c; char buf[256]; int len; int field; @@ -54,19 +54,21 @@ struct marcmap *marcmap_load(const char *filename, NMEM nmem) mm = NULL; mmhead = NULL; fp = fopen(filename, "r"); + if (!fp) + return mmhead; - while ((c = getc(fp) ) != EOF) + while ((c = getc(fp) ) != EOF) { // allocate some space if (newrec) { - if (mm != NULL) + if (mm != NULL) { mm->next = nmem_malloc(nmem, sizeof(struct marcmap)); mm = mm->next; } // first one! - else + else { mm = nmem_malloc(nmem, sizeof(struct marcmap)); mmhead = mm; } @@ -93,8 +95,8 @@ struct marcmap *marcmap_load(const char *filename, NMEM nmem) mm->subfield = buf[len-2]; } // third, pz fieldname - else if (field == 2) - { + else if (field == 2) + { mm->pz = nmem_malloc(nmem, len * sizeof(char)); strncpy(mm->pz, buf, len); } @@ -131,16 +133,17 @@ xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in) xmlDocPtr xml_out; xmlNodePtr xml_out_root; xmlNodePtr rec_node; - xmlNodePtr meta_node; + xmlNodePtr meta_node; struct marchash *marchash; struct marcfield *field; struct marcsubfield *subfield; 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"); + 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); @@ -157,7 +160,7 @@ xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in) if ((mmcur->subfield == '$') && (s = field->val)) { meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s); - xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); + xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); } // catenate all subfields else if ((mmcur->subfield == '*') && (s = marchash_catenate_subfields(field, " ", nmem))) @@ -166,10 +169,10 @@ xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in) xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); } // subfield value - else if (mmcur->subfield) + else if (mmcur->subfield) { subfield = 0; - while ((subfield = + while ((subfield = marchash_get_subfield(mmcur->subfield, field, subfield)) != 0) { @@ -180,7 +183,7 @@ xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in) } } } - + } mmcur = mmcur->next; }