X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=data1%2Fd1_marc.c;h=a332b2a0bbbcd10e694cc332b54887c929ba2419;hp=19d05df307c17880f37d4cfcc7b97de0dd6a518a;hb=85ad68ab178a261dc548284ee68aae9107cbfaaf;hpb=4478d785b7769691261005c98063b98a5a5971b3 diff --git a/data1/d1_marc.c b/data1/d1_marc.c index 19d05df..a332b2a 100644 --- a/data1/d1_marc.c +++ b/data1/d1_marc.c @@ -1,8 +1,5 @@ -/* $Id: d1_marc.c,v 1.16 2006-08-14 10:40:06 adam Exp $ - Copyright (C) 1995-2006 - Index Data ApS - -This file is part of the Zebra server. +/* This file is part of the Zebra server. + Copyright (C) 1994-2011 Index Data Zebra 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 @@ -22,12 +19,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /* converts data1 tree to ISO2709/MARC record */ +#if HAVE_CONFIG_H +#include +#endif #include #include #include #include -#include +#include #include #include #include @@ -47,7 +47,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file) return 0; res->name = 0; - res->reference = VAL_NONE; + res->oid = 0; res->next = 0; res->length_data_entry = 4; res->length_starting = 5; @@ -81,7 +81,10 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file) *argv); continue; } - if ((res->reference = oid_getvalbyname(argv[1])) == VAL_NONE) + res->oid = yaz_string_to_oid_nmem(yaz_oid_std(), + CLASS_TAGSET, argv[1], + mem); + if (!res->oid) { yaz_log(YLOG_WARN, "%s:%d: Unknown tagset reference '%s'", file, lineno, argv[1]); @@ -148,6 +151,21 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file) } res->force_identifier_length = atoi(argv[1]); } + else if (!strcmp(*argv, "implementation-codes")) + { + if (argc != 2) + { + yaz_log(YLOG_WARN, "%s:%d: Missing arg for %s", file, lineno, + *argv); + continue; + } + /* up to 4 characters .. space pad */ + if (strlen(argv[1]) > 4) + yaz_log(YLOG_WARN, "%s:%d: Max 4 characters for " + "implementation-codes", file, lineno); + else + memcpy(res->implementation_codes, argv[1], strlen(argv[1])); + } else yaz_log(YLOG_WARN, "%s:%d: Unknown directive '%s'", file, lineno, *argv); @@ -157,46 +175,30 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file) } -/* - * Locate some data under this node. This routine should handle variants - * prettily. - */ -static char *get_data(data1_node *n, int *len, int chop) +static void get_data2(data1_node *n, int *len, char *dst, size_t max) { - char *r; + *len = 0; while (n) { if (n->which == DATA1N_data) { - int i; - *len = n->u.data.len; - - if (chop) + if (dst && *len < max) { - for (i = 0; i<*len; i++) - if (!d1_isspace(n->u.data.data[i])) - break; - while (*len && d1_isspace(n->u.data.data[*len - 1])) - (*len)--; - *len = *len - i; - if (*len > 0) - return n->u.data.data + i; - } - else - if (*len > 0) - return n->u.data.data; + size_t copy_len = max - *len; + if (copy_len > n->u.data.len) + copy_len = n->u.data.len; + memcpy(dst + *len, n->u.data.data, copy_len); + } + *len += n->u.data.len; } - if (n->which == DATA1N_tag) + if (n->which == DATA1N_tag && *len == 0) n = n->child; else if (n->which == DATA1N_data) n = n->next; else break; } - r = ""; - *len = strlen(r); - return r; } static void memint (char *p, int val, int len) @@ -268,11 +270,7 @@ static int nodetomarc(data1_handle dh, else if (!strcmp(field->u.tag.tag, "leader")) { int dlen = 0; - char *dbuf = get_data(subf, &dlen, 0); - if (dlen > 24) - dlen = 24; - if (dbuf && dlen > 0) - memcpy (leader, dbuf, dlen); + get_data2(subf, &dlen, leader, 24); continue; } else if (!strcmp(field->u.tag.tag, "controlfield")) @@ -317,7 +315,7 @@ static int nodetomarc(data1_handle dh, continue; /* we skip comments, cdata .. */ len += p->identifier_length; } - get_data(subf, &dlen, control_field ? 0 : 1); + get_data2(subf, &dlen, 0, 0); len += dlen; } } @@ -410,8 +408,6 @@ static int nodetomarc(data1_handle dh, } for (; subf; subf = subf->next) { - char *data; - if (!control_field) { const char *identifier = "a"; @@ -436,8 +432,7 @@ static int nodetomarc(data1_handle dh, memcpy (op + data_p+1, identifier, p->identifier_length-1); data_p += p->identifier_length; } - data = get_data(subf, &dlen, control_field ? 0 : 1); - memcpy (op + data_p, data, dlen); + get_data2(subf, &dlen, op + data_p, 100000); data_p += dlen; } op[data_p++] = ISO2709_FS; @@ -485,6 +480,7 @@ char *data1_nodetomarc(data1_handle dh, data1_marctab *p, data1_node *n, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab