* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: siconv.c,v 1.35 2007-03-12 10:59:59 adam Exp $
+ * $Id: siconv.c,v 1.36 2007-03-17 00:10:40 adam Exp $
*/
/**
* \file siconv.c
return 0;
}
+static size_t yaz_write_marc8_page_chr(yaz_iconv_t cd,
+ char **outbuf, size_t *outbytesleft,
+ const char *page_chr)
+{
+ const char *old_page_chr = cd->write_marc8_page_chr;
+ if (strcmp(page_chr, old_page_chr))
+ {
+ size_t plen = 0;
+ const char *page_out = page_chr;
+
+ if (*outbytesleft < 8)
+ {
+ cd->my_errno = YAZ_ICONV_E2BIG;
+
+ return (size_t) (-1);
+ }
+ cd->write_marc8_page_chr = page_chr;
+
+ if (!strcmp(old_page_chr, "\033p")
+ || !strcmp(old_page_chr, "\033g")
+ || !strcmp(old_page_chr, "\033b"))
+ {
+ /* Technique 1 leave */
+ page_out = "\033s";
+ if (strcmp(page_chr, "\033(B")) /* Not going ASCII page? */
+ {
+ /* Must leave script + enter new page */
+ plen = strlen(page_out);
+ memcpy(*outbuf, page_out, plen);
+ (*outbuf) += plen;
+ (*outbytesleft) -= plen;
+ page_out = page_chr;
+ }
+ }
+ plen = strlen(page_out);
+ memcpy(*outbuf, page_out, plen);
+ (*outbuf) += plen;
+ (*outbytesleft) -= plen;
+ }
+ return 0;
+}
+
+
static size_t yaz_write_marc8_2(yaz_iconv_t cd, unsigned long x,
char **outbuf, size_t *outbytesleft,
int last)
else
{
size_t r = flush_combos(cd, outbuf, outbytesleft);
- const char *old_page_chr = cd->write_marc8_page_chr;
if (r)
return r;
- if (strcmp(page_chr, old_page_chr))
- {
- size_t plen = 0;
- const char *page_out = page_chr;
- if (*outbytesleft < 8)
- {
- cd->my_errno = YAZ_ICONV_E2BIG;
-
- return (size_t) (-1);
- }
- cd->write_marc8_page_chr = page_chr;
-
- if (!strcmp(old_page_chr, "\033p")
- || !strcmp(old_page_chr, "\033g")
- || !strcmp(old_page_chr, "\033b"))
- {
- /* Technique 1 leave */
- page_out = "\033s";
- if (strcmp(page_chr, "\033(B")) /* Not going ASCII page? */
- {
- /* Must leave script + enter new page */
- plen = strlen(page_out);
- memcpy(*outbuf, page_out, plen);
- (*outbuf) += plen;
- (*outbytesleft) -= plen;
- page_out = page_chr;
- }
- }
- plen = strlen(page_out);
- memcpy(*outbuf, page_out, plen);
- (*outbuf) += plen;
- (*outbytesleft) -= plen;
- }
+ r = yaz_write_marc8_page_chr(cd, outbuf, outbytesleft, page_chr);
+ if (r)
+ return r;
cd->write_marc8_last = y;
}
if (last)
static size_t yaz_flush_marc8(yaz_iconv_t cd,
char **outbuf, size_t *outbytesleft)
{
- if (strcmp(cd->write_marc8_page_chr, "\033(B"))
- {
- if (*outbytesleft < 3)
- {
- cd->my_errno = YAZ_ICONV_E2BIG;
- return (size_t) (-1);
- }
- memcpy(*outbuf, "\033(B", 3);
- (*outbuf) += 3;
- *outbytesleft -= 3;
- }
- return 0;
+ size_t r = flush_combos(cd, outbuf, outbytesleft);
+ if (r)
+ return r;
+ return yaz_write_marc8_page_chr(cd, outbuf, outbytesleft, "\033(B");
}
static size_t yaz_write_marc8(yaz_iconv_t cd, unsigned long x,
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tsticonv.c,v 1.26 2007-03-12 10:59:59 adam Exp $
+ * $Id: tsticonv.c,v 1.27 2007-03-17 00:10:41 adam Exp $
*/
#if HAVE_CONFIG_H
"(\033p0\x1bs)"));
+ {
+ char *inbuf0 = "\xe2\x81\xb0";
+ char *inbuf = inbuf0;
+ size_t inbytesleft = strlen(inbuf);
+ char outbuf0[64];
+ char *outbuf = outbuf0;
+ size_t outbytesleft = sizeof(outbuf0)-1;
+ size_t r;
+#if 0
+ int i;
+#endif
+ r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+ YAZ_CHECK(r != (size_t) (-1));
+
+#if 0
+ *outbuf = '\0'; /* so we know when to stop printing */
+ for (i = 0; outbuf0[i]; i++)
+ {
+ int ch = outbuf0[i] & 0xff;
+ yaz_log(YLOG_LOG, "ch%d %02X %c", i, ch, ch >= ' ' ? ch : '?');
+ }
+#endif
+
+ r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
+ YAZ_CHECK(r != (size_t) (-1));
+ *outbuf = '\0'; /* for strcmp test below and printing */
+#if 0
+ for (i = 0; outbuf0[i]; i++)
+ {
+ int ch = outbuf0[i] & 0xff;
+ yaz_log(YLOG_LOG, "ch%d %02X %c", i, ch, ch >= ' ' ? ch : '?');
+ }
+#endif
+ YAZ_CHECK(strcmp("\033p0\x1bs", outbuf0) == 0);
+ }
yaz_iconv_close(cd);
}