X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=retrieval%2Fd1_marc.c;h=75acbb92109804b89d1d0db5601b3003937ed026;hp=84c656917fd4d2a62315b3903d50cfa24dfa81ce;hb=40de6aa3aafbf959d7fc3a1002e8a43874c77d7c;hpb=b440dce0831a72bebe4f4821ab7771cc05e8facb diff --git a/retrieval/d1_marc.c b/retrieval/d1_marc.c index 84c6569..75acbb9 100644 --- a/retrieval/d1_marc.c +++ b/retrieval/d1_marc.c @@ -1,73 +1,23 @@ /* - * Copyright (c) 1995-1999, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: d1_marc.c,v $ - * Revision 1.14 1999-08-27 09:40:32 adam - * Renamed logf function to yaz_log. Removed VC++ project files. - * - * Revision 1.13 1998/10/13 16:09:52 adam - * Added support for arbitrary OID's for tagsets, schemas and attribute sets. - * Added support for multiple attribute set references and tagset references - * from an abstract syntax file. - * Fixed many bad logs-calls in routines that read the various - * specifications regarding data1 (*.abs,*.att,...) and made the messages - * consistent whenever possible. - * Added extra 'lineno' argument to function readconf_line. - * - * Revision 1.12 1998/02/23 10:57:09 adam - * Take care of integer data nodes as well in conversion. - * - * Revision 1.11 1998/02/11 11:53:35 adam - * Changed code so that it compiles as C++. - * - * Revision 1.10 1997/09/30 11:50:04 adam - * Added handler data1_get_map_buf that is used by data1_nodetomarc. - * - * Revision 1.9 1997/09/24 13:35:45 adam - * Added two members to data1_marctab to ease reading of weird MARC records. - * - * Revision 1.8 1997/09/17 12:10:37 adam - * YAZ version 1.4. - * - * Revision 1.7 1997/09/05 09:50:57 adam - * Removed global data1_tabpath - uses data1_get_tabpath() instead. - * - * Revision 1.6 1997/09/04 13:51:58 adam - * Added data1 to marc conversion with indicators. - * - * Revision 1.5 1997/09/04 13:48:04 adam - * Added data1 to marc conversion. - * - * Revision 1.4 1996/03/25 10:18:03 quinn - * Removed trailing whitespace from data elements - * - * Revision 1.3 1995/11/01 16:34:57 quinn - * Making data1 look for tables in data1_tabpath - * - * Revision 1.2 1995/11/01 13:54:48 quinn - * Minor adjustments - * - * Revision 1.1 1995/11/01 11:56:08 quinn - * Added Retrieval (data management) functions en masse. - * - * + * $Id: d1_marc.c,v 1.19 2002-05-28 21:09:44 adam Exp $ */ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include data1_marctab *data1_read_marctab (data1_handle dh, const char *file) { @@ -78,7 +28,7 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file) int lineno = 0; int argc; - if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) + if (!(f = data1_path_fopen(dh, file, "r"))) { yaz_log(LOG_WARN|LOG_ERRNO, "%s", file); return 0; @@ -213,7 +163,7 @@ static char *get_data(data1_node *n, int *len) } *len = n->u.data.len; - while (*len && isspace(n->u.data.data[*len - 1])) + while (*len && d1_isspace(n->u.data.data[*len - 1])) (*len)--; return n->u.data.data; } @@ -235,10 +185,10 @@ static int is_indicator (data1_marctab *p, data1_node *subf) { #if 1 if (p->indicator_length != 2 || - (subf->which == DATA1N_tag && strlen(subf->u.tag.tag) == 2)) + (subf && subf->which == DATA1N_tag && strlen(subf->u.tag.tag) == 2)) return 1; #else - if (subf->which == DATA1N_tag && subf->child->which == DATA1N_tag) + if (subf && subf->which == DATA1N_tag && subf->child->which == DATA1N_tag) return 1; #endif return 0; @@ -257,6 +207,8 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, yaz_log (LOG_DEBUG, "nodetomarc"); for (field = n->child; field; field = field->next) { + int is00X = 0; + if (field->which != DATA1N_tag) { yaz_log(LOG_WARN, "Malformed field composition for marc output."); @@ -268,23 +220,20 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, + p->length_implementation; base_address += 3 + p->length_data_entry + p->length_starting + p->length_implementation; - if (strncmp(field->u.tag.tag, "00", 2)) - len += p->indicator_length; /* this is fairly bogus */ subf = field->child; + + if (subf->which == DATA1N_data) + is00X = 1; + if (!is00X) + len += p->indicator_length; /* we'll allow no indicator if length is not 2 */ if (is_indicator (p, subf)) subf = subf->child; for (; subf; subf = subf->next) { - if (subf->which != DATA1N_tag) - { - yaz_log(LOG_WARN, - "Malformed subfield composition for marc output."); - return -1; - } - if (strncmp(field->u.tag.tag, "00", 2)) + if (!is00X) len += p->identifier_length; get_data(subf, &dlen); len += dlen; @@ -314,6 +263,8 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, for (field = n->child; field; field = field->next) { + int is00X = 0; + int data_0 = data_p; char *indicator_data = " "; if (selected && !field->u.tag.node_selected) @@ -321,12 +272,15 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, subf = field->child; + if (subf->which == DATA1N_data) + is00X = 1; + if (is_indicator (p, subf)) { indicator_data = subf->u.tag.tag; subf = subf->child; } - if (strncmp(field->u.tag.tag, "00", 2)) /* bogus */ + if (!is00X) { memcpy (op + data_p, indicator_data, p->indicator_length); data_p += p->indicator_length; @@ -335,10 +289,15 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, { char *data; - if (strncmp(field->u.tag.tag, "00", 2)) + if (!is00X) { + const char *identifier = "a"; + if (subf->which != DATA1N_tag) + yaz_log(LOG_WARN, "Malformed fields for marc output."); + else + identifier = subf->u.tag.tag; op[data_p] = ISO2709_IDFS; - memcpy (op + data_p+1, subf->u.tag.tag, p->identifier_length-1); + memcpy (op + data_p+1, identifier, p->identifier_length-1); data_p += p->identifier_length; } data = get_data(subf, &dlen);