X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=retrieval%2Fd1_marc.c;h=0bf408f0c4c00fccfec60262a1d15699e3c76a02;hb=548d8ab9b0b5930db27643b47fc55afce5511219;hp=3c65dfed47e1ca401cceba8546ef7c523ce49a68;hpb=2c73c63dbd44310ca9a06b20d82e01f7ad617ddc;p=yaz-moved-to-github.git diff --git a/retrieval/d1_marc.c b/retrieval/d1_marc.c index 3c65dfe..0bf408f 100644 --- a/retrieval/d1_marc.c +++ b/retrieval/d1_marc.c @@ -1,10 +1,37 @@ /* - * Copyright (c) 1995-1997, Index Data. + * Copyright (c) 1995-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: d1_marc.c,v $ - * Revision 1.9 1997-09-24 13:35:45 adam + * Revision 1.16 1999-11-30 13:47:12 adam + * Improved installation. Moved header files to include/yaz. + * + * Revision 1.15 1999/10/21 12:06:29 adam + * Retrieval module no longer uses ctype.h - functions. + * + * 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 @@ -38,27 +65,27 @@ #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) { FILE *f; NMEM mem = data1_nmem_get (dh); - data1_marctab *res = nmem_malloc(mem, sizeof(*res)); + data1_marctab *res = (data1_marctab *)nmem_malloc(mem, sizeof(*res)); char line[512], *argv[50]; + int lineno = 0; int argc; if (!(f = yaz_path_fopen(data1_get_tabpath(dh), file, "r"))) { - logf(LOG_WARN|LOG_ERRNO, "%s", file); + yaz_log(LOG_WARN|LOG_ERRNO, "%s", file); return 0; } @@ -77,87 +104,96 @@ data1_marctab *data1_read_marctab (data1_handle dh, const char *file) res->force_indicator_length = -1; res->force_identifier_length = -1; strcpy(res->user_systems, "z "); - - while ((argc = readconf_line(f, line, 512, argv, 50))) - if (!strcmp(argv[0], "name")) + + while ((argc = readconf_line(f, &lineno, line, 512, argv, 50))) + if (!strcmp(*argv, "name")) { if (argc != 2) { - logf(LOG_WARN, "%s: Bad name directive"); + yaz_log(LOG_WARN, "%s:%d:Missing arg for %s", file, lineno, + *argv); continue; } res->name = nmem_strdup(mem, argv[1]); } - else if (!strcmp(argv[0], "reference")) + else if (!strcmp(*argv, "reference")) { if (argc != 2) { - logf(LOG_WARN, "%s: Bad name directive"); + yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno, + *argv); continue; } if ((res->reference = oid_getvalbyname(argv[1])) == VAL_NONE) { - logf(LOG_WARN, "%s: Unknown tagset ref '%s' in %s", file, - argv[1]); + yaz_log(LOG_WARN, "%s:%d: Unknown tagset reference '%s'", + file, lineno, argv[1]); continue; } } - else if (!strcmp(argv[0], "length-data-entry")) + else if (!strcmp(*argv, "length-data-entry")) { if (argc != 2) { - logf(LOG_WARN, "%s: Bad data-length-entry"); + yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno, + *argv); continue; } res->length_data_entry = atoi(argv[1]); } - else if (!strcmp(argv[0], "length-starting")) + else if (!strcmp(*argv, "length-starting")) { if (argc != 2) { - logf(LOG_WARN, "%s: Bad length-starting"); + yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno, + *argv); continue; } res->length_starting = atoi(argv[1]); } - else if (!strcmp(argv[0], "length-implementation")) + else if (!strcmp(*argv, "length-implementation")) { if (argc != 2) { - logf(LOG_WARN, "%s: Bad length-implentation"); + yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno, + *argv); continue; } res->length_implementation = atoi(argv[1]); } - else if (!strcmp(argv[0], "future-use")) + else if (!strcmp(*argv, "future-use")) { if (argc != 2) { - logf(LOG_WARN, "%s: Bad future-use"); + yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno, + *argv); continue; } strncpy(res->future_use, argv[1], 2); } - else if (!strcmp(argv[0], "force-indicator-length")) + else if (!strcmp(*argv, "force-indicator-length")) { if (argc != 2) { - logf(LOG_WARN, "%s: Bad future-use"); + yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno, + *argv); continue; } res->force_indicator_length = atoi(argv[1]); } - else if (!strcmp(argv[0], "force-identifier-length")) + else if (!strcmp(*argv, "force-identifier-length")) { if (argc != 2) { - logf(LOG_WARN, "%s: Bad future-use"); + yaz_log(LOG_WARN, "%s:%d: Missing arg for %s", file, lineno, + *argv); continue; } res->force_identifier_length = atoi(argv[1]); } else - logf(LOG_WARN, "%s: Bad directive '%s'", file, argv[0]); + yaz_log(LOG_WARN, "%s:%d: Unknown directive '%s'", file, lineno, + *argv); fclose(f); return res; @@ -173,7 +209,8 @@ static char *get_data(data1_node *n, int *len) while (n->which != DATA1N_data && n->child) n = n->child; - if (n->which != DATA1N_data || n->u.data.what != DATA1I_text) + if (n->which != DATA1N_data || + (n->u.data.what != DATA1I_text && n->u.data.what != DATA1I_num)) { r = "[Structured/included data]"; *len = strlen(r); @@ -181,7 +218,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; } @@ -222,11 +259,12 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, char *op; data1_node *field, *subf; + yaz_log (LOG_DEBUG, "nodetomarc"); for (field = n->child; field; field = field->next) { if (field->which != DATA1N_tag) { - logf(LOG_WARN, "Malformed field composition for marc output."); + yaz_log(LOG_WARN, "Malformed field composition for marc output."); return -1; } if (selected && !field->u.tag.node_selected) @@ -247,7 +285,7 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, { if (subf->which != DATA1N_tag) { - logf(LOG_WARN, + yaz_log(LOG_WARN, "Malformed subfield composition for marc output."); return -1; } @@ -259,9 +297,9 @@ static int nodetomarc(data1_marctab *p, data1_node *n, int selected, } if (!*buf) - *buf = xmalloc(*size = len); + *buf = (char *)xmalloc(*size = len); else if (*size <= len) - *buf = xrealloc(*buf, *size = len); + *buf = (char *)xrealloc(*buf, *size = len); op = *buf; memint (op, len, 5); @@ -333,7 +371,7 @@ char *data1_nodetomarc(data1_handle dh, data1_marctab *p, data1_node *n, int selected, int *len) { int *size; - char **buf = data1_get_read_buf (dh, &size); + char **buf = data1_get_map_buf (dh, &size); *len = nodetomarc(p, n, selected, buf, size); return *buf;