X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fmarc_read_line.c;h=d6695765076c467d570962547cd3319232cf6ad0;hp=f6f58ea3979ec542c4250eafc3b727d58c6738ac;hb=30a1eadf63ab5d1357d10847f905243a250703b8;hpb=99b3cb2b79d12430d0b0788bee64a5706a235f31 diff --git a/src/marc_read_line.c b/src/marc_read_line.c index f6f58ea..d669576 100644 --- a/src/marc_read_line.c +++ b/src/marc_read_line.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. - * - * $Id: marc_read_line.c,v 1.5 2007-03-17 09:13:29 adam Exp $ */ /** @@ -21,21 +19,19 @@ #include #include #include -#include #include #include #include -int yaz_gets(int (*getbyte)(void *client_data), - void (*ungetbyte)(int b, void *client_data), - void *client_data, - WRBUF w) +static int yaz_gets(int (*getbyte)(void *client_data), + void (*ungetbyte)(int b, void *client_data), + void *client_data, + WRBUF w) { size_t sz = 0; int ch = getbyte(client_data); - wrbuf_rewind(w); while (ch != '\0' && ch != '\r' && ch != '\n') { wrbuf_putc(w, ch); @@ -60,7 +56,42 @@ int yaz_gets(int (*getbyte)(void *client_data), } return 0; } - + +static int yaz_marc_line_gets(int (*getbyte)(void *client_data), + void (*ungetbyte)(int b, void *client_data), + void *client_data, + WRBUF w) +{ + int more; + + wrbuf_rewind(w); + more = yaz_gets(getbyte, ungetbyte, client_data, w); + if (!more) + return 0; + + while (more) + { + int i; + for (i = 0; i<4; i++) + { + int ch = getbyte(client_data); + if (ch != ' ') + { + if (ch) + ungetbyte(ch, client_data); + return 1; + } + } + if (wrbuf_len(w) > 60 && wrbuf_buf(w)[wrbuf_len(w)-1] == '=') + wrbuf_cut_right(w, 1); + else + wrbuf_puts(w, " "); + more = yaz_gets(getbyte, ungetbyte, client_data, w); + } + return 1; +} + + int yaz_marc_read_line(yaz_marc_t mt, int (*getbyte)(void *client_data), void (*ungetbyte)(int b, void *client_data), @@ -79,7 +110,7 @@ int yaz_marc_read_line(yaz_marc_t mt, yaz_marc_reset(mt); - while (yaz_gets(getbyte, ungetbyte, client_data, wrbuf_line)) + while (yaz_marc_line_gets(getbyte, ungetbyte, client_data, wrbuf_line)) { const char *line = wrbuf_cstr(wrbuf_line); int val; @@ -96,7 +127,7 @@ int yaz_marc_read_line(yaz_marc_t mt, } else if (line[0] == '(') /* annotation, skip it */ ; - else if (line_len == 24 && atoi_n_check(line, 5, &val) && val >= 24) + else if (line_len == 24 && atoi_n_check(line, 5, &val)) { /* deal with header lines: 00366nam 22001698a 4500 */ @@ -112,11 +143,8 @@ int yaz_marc_read_line(yaz_marc_t mt, &length_implementation); header_created = 1; } - else if (line_len > 5 && memcmp(line, " ", 4) == 0) - { /* continuation line */ - ; - } - else if (line_len > 5 && line[3] == ' ') + else if (line_len > 4 && line[0] != ' ' && line[1] != ' ' + && line[2] != ' ' && line[3] == ' ' ) { /* deal with data/control lines: 245 12 ........ */ char tag[4]; @@ -167,14 +195,15 @@ int yaz_marc_read_line(yaz_marc_t mt, { const char *next; size_t len; - + assert(cp[0] == marker_ch); cp++; next = cp; while ((next = strchr(next, marker_ch))) { if ((next[1] >= 'A' && next[1] <= 'Z') - ||(next[1] >= 'a' && next[1] <= 'z')) + ||(next[1] >= 'a' && next[1] <= 'z') + ||(next[1] >= '0' && next[1] <= '9')) { if (!marker_skip) break; @@ -202,7 +231,6 @@ int yaz_marc_read_line(yaz_marc_t mt, cp++; } } - assert(len >= 0); yaz_marc_add_subfield(mt, cp, len); if (!next) break; @@ -210,6 +238,10 @@ int yaz_marc_read_line(yaz_marc_t mt, } } } + else + { + yaz_marc_cprintf(mt, "Ignoring line: %s", line); + } } wrbuf_destroy(wrbuf_line); if (!header_created) @@ -220,6 +252,7 @@ int yaz_marc_read_line(yaz_marc_t mt, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab