X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmarchash.c;h=f304fa38b90026c23b469d4f9d817fa93ae74155;hb=HEAD;hp=9d00f891bcffad3d8c560151a459d075afb3a856;hpb=85a4a8d3f48c3d2c95efb6437b25f0804d966161;p=pazpar2-moved-to-github.git diff --git a/src/marchash.c b/src/marchash.c index 9d00f89..f304fa3 100644 --- a/src/marchash.c +++ b/src/marchash.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 @@ -17,10 +17,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -/** \file +/** \file \brief MARC MAP utilities (hash lookup etc) */ +#if HAVE_CONFIG_H +#include +#else +/* disable inline if AC_C_INLINE is not in use (Windows) */ +#define inline +#endif + #include #include #include @@ -31,9 +38,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "jenkins_hash.h" -#include +#include "marchash.h" -inline void strtrimcat(char *dest, const char *src) +static inline void strtrimcat(char *dest, const char *src) { const char *in; char *out; @@ -59,7 +66,7 @@ inline void strtrimcat(char *dest, const char *src) *(++last_nonspace) = '\0'; } -inline void strtrimcpy(char *dest, const char *src) +static inline void strtrimcpy(char *dest, const char *src) { *dest = '\0'; strtrimcat(dest, src); @@ -88,33 +95,43 @@ void marchash_ingest_marcxml(struct marchash *marchash, xmlNodePtr rec_node) field = NULL; if (!strcmp((const char *) field_node->name, "controlfield")) { - field = marchash_add_field( - marchash, - (const char *) xmlGetProp(field_node, BAD_CAST "tag"), - (const char *) xmlNodeGetContent(field_node)); + xmlChar *content = xmlNodeGetContent(field_node); + xmlChar *tag = xmlGetProp(field_node, BAD_CAST "tag"); + if (tag && content) + field = marchash_add_field( + marchash, (const char *) tag, (const char *) content); + xmlFree(content); + xmlFree(tag); } else if (!strcmp((const char *) field_node->name, "datafield")) { - field = marchash_add_field( - marchash, - (const char *) xmlGetProp(field_node, BAD_CAST "tag"), - (const char *) xmlNodeGetContent(field_node)); + xmlChar *content = xmlNodeGetContent(field_node); + xmlChar *tag = xmlGetProp(field_node, BAD_CAST "tag"); + if (tag && content) + field = marchash_add_field( + marchash, (const char *) tag, (const char *) content); + xmlFree(content); + xmlFree(tag); } if (field) { sub_node = field_node->children; - while (sub_node) + while (sub_node) { if ((sub_node->type == XML_ELEMENT_NODE) && !strcmp((const char *) sub_node->name, "subfield")) { - marchash_add_subfield( - marchash, field, - xmlGetProp(sub_node, BAD_CAST "code")[0], - (const char *) xmlNodeGetContent(sub_node)); + xmlChar *content = xmlNodeGetContent(sub_node); + xmlChar *code = xmlGetProp(sub_node, BAD_CAST "code"); + if (code && content) + marchash_add_subfield( + marchash, field, + code[0], (const char *) content); + xmlFree(content); + xmlFree(code); } sub_node = sub_node->next; - } + } } } field_node = field_node->next; @@ -127,15 +144,15 @@ struct marcfield *marchash_add_field(struct marchash *marchash, int slot; struct marcfield *new; struct marcfield *last; - + slot = jenkins_hash((const unsigned char *) key) & MARCHASH_MASK; new = marchash->table[slot]; last = NULL; - - while (new) + + while (new) { - last = new; - new = new->next; + last = new; + new = new->next; } new = nmem_malloc(marchash->nmem, sizeof (struct marcfield)); @@ -148,8 +165,8 @@ struct marcfield *marchash_add_field(struct marchash *marchash, new->next = NULL; new->subfields = NULL; strncpy(new->key, key, 4); - - // only 3 char in a marc field name + + // only 3 char in a marc field name if (new->key[3] != '\0') return 0; @@ -194,7 +211,7 @@ struct marcfield *marchash_get_field (struct marchash *marchash, struct marcfield *cur; if (last) cur = last->next; - else + else cur = marchash->table[jenkins_hash((const unsigned char *)key) & MARCHASH_MASK]; while (cur) { @@ -236,9 +253,9 @@ char *marchash_catenate_subfields(struct marcfield *field, { outsize += strlen(cur->val) + delimsize; cur = cur->next; - } + } if (outsize > 0) - output = nmem_malloc(nmem, outsize); + output = nmem_malloc(nmem, outsize); else return NULL; *output = '\0'; @@ -247,9 +264,9 @@ char *marchash_catenate_subfields(struct marcfield *field, { strtrimcat(output, cur->val); if (cur->next) - strcat(output, delim); + strcat(output, delim); cur = cur->next; - } + } return output; } /*