/* 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.
*/
/**
#include <assert.h>
#include <errno.h>
#include <string.h>
-#include <ctype.h>
#include <yaz/xmalloc.h>
-#include <yaz/nmem.h>
#include <yaz/snprintf.h>
#include "iconv-p.h"
static void init_marc8(yaz_iconv_encoder_t w)
{
- struct encoder_data *data = w->data;
+ struct encoder_data *data = (struct encoder_data *) w->data;
data->write_marc8_second_half_char = 0;
data->write_marc8_last = 0;
data->write_marc8_ncr = 0;
data->write_marc8_g1 = 0;
}
-static size_t yaz_write_marc8_page_chr(yaz_iconv_t cd,
+static size_t yaz_write_marc8_page_chr(yaz_iconv_t cd,
struct encoder_data *w,
char **outbuf, size_t *outbytesleft,
const char *page_chr);
size_t inbytesleft, no_read_sub = 0;
unsigned long x;
- *utf8_outbuf = '\0';
+ *utf8_outbuf = '\0';
inp = (unsigned char *) utf8_buf;
inbytesleft = strlen(utf8_buf);
{
*(*outbuf)++ = w->write_marc8_second_half_char;
(*outbytesleft)--;
- }
+ }
w->write_marc8_last = 0;
w->write_marc8_ncr = 0;
return 0;
}
-static size_t yaz_write_marc8_page_chr(yaz_iconv_t cd,
+static size_t yaz_write_marc8_page_chr(yaz_iconv_t cd,
struct encoder_data *w,
char **outbuf, size_t *outbytesleft,
const char *page_chr)
{
size_t plen = 0;
const char *page_out = page_chr;
-
+
if (*outbytesleft < 8)
{
yaz_iconv_set_errno(cd, YAZ_ICONV_E2BIG);
-
+
return (size_t) (-1);
}
if (*old_page_chr)
{
- if (!strcmp(*old_page_chr, ESC "p")
+ if (!strcmp(*old_page_chr, ESC "p")
|| !strcmp(*old_page_chr, ESC "g")
|| !strcmp(*old_page_chr, ESC "b"))
{
if (!y)
{
- if (loss_mode == 0)
- return (size_t) (-1);
page_chr = ESC "(B";
- if (loss_mode == 1)
- y = '|';
- else
+ switch (loss_mode)
{
- y = x;
+ 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);
}
}
static size_t flush_marc8(yaz_iconv_t cd, yaz_iconv_encoder_t en,
char **outbuf, size_t *outbytesleft)
{
- struct encoder_data *w = en->data;
+ struct encoder_data *w = (struct encoder_data *) en->data;
size_t r = flush_combos(cd, w, outbuf, outbytesleft);
if (r)
return r;
int ncr = w->write_marc8_ncr;
const char *lpage = w->write_marc8_lpage;
size_t r;
-
+
r = yaz_write_marc8_2(cd, w, x1,
outbuf, outbytesleft, loss_mode);
if (r)
unsigned long x,
char **outbuf, size_t *outbytesleft)
{
- return yaz_write_marc8_generic(cd, e->data, x, outbuf, outbytesleft, 0);
+ return yaz_write_marc8_generic(cd, (struct encoder_data *) e->data,
+ x, outbuf, outbytesleft, 0);
}
static size_t write_marc8_lossy(yaz_iconv_t cd, yaz_iconv_encoder_t e,
unsigned long x,
char **outbuf, size_t *outbytesleft)
{
- return yaz_write_marc8_generic(cd, e->data, x, outbuf, outbytesleft, 1);
+ return yaz_write_marc8_generic(cd, (struct encoder_data *) e->data,
+ x, outbuf, outbytesleft, 1);
}
static size_t write_marc8_lossless(yaz_iconv_t cd, yaz_iconv_encoder_t e,
unsigned long x,
char **outbuf, size_t *outbytesleft)
{
- return yaz_write_marc8_generic(cd, e->data, x, outbuf, outbytesleft, 2);
+ return yaz_write_marc8_generic(cd, (struct encoder_data *) e->data,
+ 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)
yaz_iconv_encoder_t yaz_marc8_encoder(const char *tocode,
yaz_iconv_encoder_t e)
-
+
{
if (!yaz_matchstr(tocode, "MARC8"))
e->write_handle = write_marc8_normal;
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;
{
- struct encoder_data *data = xmalloc(sizeof(*data));
+ struct encoder_data *data = (struct encoder_data *)
+ xmalloc(sizeof(*data));
e->data = data;
e->destroy_handle = destroy_marc8;
e->flush_handle = flush_marc8;
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
+