X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Ficonv_decode_marc8.c;h=d0fa8753126748897710134a0a653e6bb3e7cdd2;hp=7b890add8777ddaa43690fe080ceee0b86f9bd48;hb=f96a9bc9697b4b6b63ce52055ba0cfbe6cf6652a;hpb=96c6e58f286787106e4a7b3bb3900a36051968d6 diff --git a/src/iconv_decode_marc8.c b/src/iconv_decode_marc8.c index 7b890ad..d0fa875 100644 --- a/src/iconv_decode_marc8.c +++ b/src/iconv_decode_marc8.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2008 Index Data + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. */ /** @@ -17,7 +17,6 @@ #include #include #include -#include #include #include "iconv-p.h" @@ -30,6 +29,7 @@ struct decoder_data { int comb_size; unsigned long comb_x[8]; size_t comb_no_read[8]; + int control_mode; }; yaz_conv_func_t yaz_marc8_42_conv; @@ -56,14 +56,14 @@ static unsigned long read_marc8(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inp, size_t inbytesleft, size_t *no_read) { - struct decoder_data *data = d->data; + struct decoder_data *data = (struct decoder_data *) d->data; unsigned long x; if (data->comb_offset < data->comb_size) { *no_read = data->comb_no_read[data->comb_offset]; x = data->comb_x[data->comb_offset]; - /* special case for double-diacritic combining characters, + /* special case for double-diacritic combining characters, INVERTED BREVE and DOUBLE TILDE. We'll increment the no_read counter by 1, since we want to skip over the processing of the closing ligature character @@ -110,7 +110,7 @@ static unsigned long read_marc8s(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inp, size_t inbytesleft, size_t *no_read) { - struct decoder_data *data = d->data; + struct decoder_data *data = (struct decoder_data *) d->data; unsigned long x = read_marc8(cd, d, inp, inbytesleft, no_read); if (x && data->comb_size == 1) { @@ -178,6 +178,11 @@ static unsigned long yaz_read_marc8_comb(yaz_iconv_t cd, *no_read += 1; return ' '; } + else if (*inp < ' ' && data->control_mode) + { + *no_read += 1; + return *inp; + } else { unsigned long x; @@ -243,32 +248,55 @@ static size_t init_marc8(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inp, size_t inbytesleft, size_t *no_read) { - struct decoder_data *data = d->data; + struct decoder_data *data = (struct decoder_data *) d->data; data->g0_mode = 'B'; data->g1_mode = 'E'; data->comb_offset = data->comb_size = 0; + data->control_mode = 0; + return 0; +} + +static size_t init_marc8c(yaz_iconv_t cd, yaz_iconv_decoder_t d, + unsigned char *inp, + size_t inbytesleft, size_t *no_read) +{ + struct decoder_data *data = (struct decoder_data *) d->data; + + init_marc8(cd, d, inp, inbytesleft, no_read); + data->control_mode = 1; return 0; } void destroy_marc8(yaz_iconv_decoder_t d) { - struct decoder_data *data = d->data; + struct decoder_data *data = (struct decoder_data *) d->data; xfree(data); } yaz_iconv_decoder_t yaz_marc8_decoder(const char *fromcode, yaz_iconv_decoder_t d) { - if (!yaz_matchstr(fromcode, "MARC8")) + if (!yaz_matchstr(fromcode, "MARC8") || !yaz_matchstr(fromcode, "ANSEL")) + { d->read_handle = read_marc8; + d->init_handle = init_marc8; + } else if (!yaz_matchstr(fromcode, "MARC8s")) + { d->read_handle = read_marc8s; + d->init_handle = init_marc8; + } + else if (!yaz_matchstr(fromcode, "MARC8c")) + { + d->read_handle = read_marc8; + d->init_handle = init_marc8c; + } else return 0; { - struct decoder_data *data = xmalloc(sizeof(*data)); + struct decoder_data *data = (struct decoder_data *) + xmalloc(sizeof(*data)); d->data = data; - d->init_handle = init_marc8; d->destroy_handle = destroy_marc8; } return d; @@ -278,7 +306,9 @@ yaz_iconv_decoder_t yaz_marc8_decoder(const char *fromcode, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +