X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ficonv_encode_marc8.c;h=aed43c26cdf17a3834892a49918c202705844342;hb=67791b7efdc55585d77c3889699c9fe155a9abe6;hp=f29ccbfc21f5fd6f40056fa1635be415e64da53d;hpb=5242cb5a8634bfa38b9333ff7f903e718ac6e292;p=yaz-moved-to-github.git diff --git a/src/iconv_encode_marc8.c b/src/iconv_encode_marc8.c index f29ccbf..aed43c2 100644 --- a/src/iconv_encode_marc8.c +++ b/src/iconv_encode_marc8.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2012 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ /** @@ -283,15 +283,23 @@ static size_t yaz_write_marc8_2(yaz_iconv_t cd, struct encoder_data *w, if (!y) { - if (loss_mode == 0) - return (size_t) (-1); page_chr = ESC "(B"; - if (loss_mode == 1) - y = '|'; - else + switch (loss_mode) { + case 0: + return (size_t) (-1); + case 1: + y = '|'; + break; + case 2: y = x; enable_ncr = 1; + break; + case 3: + if (x < 32 && x != 27) + y = x; + else + return (size_t) (-1); } } @@ -314,7 +322,7 @@ static size_t yaz_write_marc8_2(yaz_iconv_t cd, struct encoder_data *w, yaz_iconv_set_errno(cd, YAZ_ICONV_E2BIG); return (size_t) (-1); } - *(*outbuf)++ = y; + *(*outbuf)++ = (char) y; (*outbytesleft)--; } else @@ -401,6 +409,14 @@ static size_t write_marc8_lossless(yaz_iconv_t cd, yaz_iconv_encoder_t e, x, outbuf, outbytesleft, 2); } +static size_t write_marc8_control(yaz_iconv_t cd, yaz_iconv_encoder_t e, + unsigned long x, + char **outbuf, size_t *outbytesleft) +{ + return yaz_write_marc8_generic(cd, (struct encoder_data *) e->data, + x, outbuf, outbytesleft, 3); +} + static void destroy_marc8(yaz_iconv_encoder_t e) { xfree(e->data); @@ -418,6 +434,8 @@ yaz_iconv_encoder_t yaz_marc8_encoder(const char *tocode, e->write_handle = write_marc8_lossy; else if (!yaz_matchstr(tocode, "MARC8lossless")) e->write_handle = write_marc8_lossless; + else if (!yaz_matchstr(tocode, "MARC8c")) + e->write_handle = write_marc8_control; else return 0;