From: Adam Dickmeiss Date: Tue, 10 Dec 2002 10:59:28 +0000 (+0000) Subject: More debugging tools for yaz_iconv X-Git-Tag: YAZ.1.9.2.oleg~5 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=9841cfd6e74acdc325bf5158fddf0b3cc2d82fab;p=yaz-moved-to-github.git More debugging tools for yaz_iconv --- diff --git a/include/yaz/yaz-util.h b/include/yaz/yaz-util.h index 10c40fe..5139f37 100644 --- a/include/yaz/yaz-util.h +++ b/include/yaz/yaz-util.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: yaz-util.h,v 1.5 2002-10-04 19:06:36 adam Exp $ + * $Id: yaz-util.h,v 1.6 2002-12-10 10:59:28 adam Exp $ */ #ifndef YAZ_UTIL_H @@ -35,6 +35,8 @@ YAZ_EXPORT int yaz_iconv_error (yaz_iconv_t cd); YAZ_EXPORT int yaz_iconv_close (yaz_iconv_t cd); +YAZ_EXPORT int yaz_iconv_isbuiltin(yaz_iconv_t cd); + YAZ_EXPORT int yaz_matchstr(const char *s1, const char *s2); YAZ_END_CDECL diff --git a/util/siconv.c b/util/siconv.c index c89de49..75c5979 100644 --- a/util/siconv.c +++ b/util/siconv.c @@ -2,7 +2,7 @@ * Copyright (c) 1997-2002, Index Data * See the file LICENSE for details. * - * $Id: siconv.c,v 1.6 2002-09-25 12:37:08 adam Exp $ + * $Id: siconv.c,v 1.7 2002-12-10 10:59:28 adam Exp $ */ /* mini iconv and wrapper for system iconv library (if present) */ @@ -309,6 +309,11 @@ static size_t yaz_write_UCS4LE (yaz_iconv_t cd, unsigned long x, return 0; } +int yaz_iconv_isbuiltin(yaz_iconv_t cd) +{ + return cd->read_handle && cd->write_handle; +} + yaz_iconv_t yaz_iconv_open (const char *tocode, const char *fromcode) { yaz_iconv_t cd = (yaz_iconv_t) xmalloc (sizeof(*cd)); @@ -318,27 +323,33 @@ yaz_iconv_t yaz_iconv_open (const char *tocode, const char *fromcode) cd->init_handle = 0; cd->my_errno = YAZ_ICONV_UNKNOWN; - if (!yaz_matchstr(fromcode, "UTF8")) + /* a useful hack: if fromcode has leading @, + the library not use YAZ's own conversions .. */ + if (fromcode[0] == '@') + fromcode++; + else { - cd->read_handle = yaz_read_UTF8; - cd->init_handle = yaz_init_UTF8; + if (!yaz_matchstr(fromcode, "UTF8")) + { + cd->read_handle = yaz_read_UTF8; + cd->init_handle = yaz_init_UTF8; + } + else if (!yaz_matchstr(fromcode, "ISO88591")) + cd->read_handle = yaz_read_ISO8859_1; + else if (!yaz_matchstr(fromcode, "UCS4")) + cd->read_handle = yaz_read_UCS4; + else if (!yaz_matchstr(fromcode, "UCS4LE")) + cd->read_handle = yaz_read_UCS4LE; + + if (!yaz_matchstr(tocode, "UTF8")) + cd->write_handle = yaz_write_UTF8; + else if (!yaz_matchstr(tocode, "ISO88591")) + cd->write_handle = yaz_write_ISO8859_1; + else if (!yaz_matchstr (tocode, "UCS4")) + cd->write_handle = yaz_write_UCS4; + else if (!yaz_matchstr(tocode, "UCS4LE")) + cd->write_handle = yaz_write_UCS4LE; } - else if (!yaz_matchstr(fromcode, "ISO88591")) - cd->read_handle = yaz_read_ISO8859_1; - else if (!yaz_matchstr(fromcode, "UCS4")) - cd->read_handle = yaz_read_UCS4; - else if (!yaz_matchstr(fromcode, "UCS4LE")) - cd->read_handle = yaz_read_UCS4LE; - - if (!yaz_matchstr(tocode, "UTF8")) - cd->write_handle = yaz_write_UTF8; - else if (!yaz_matchstr(tocode, "ISO88591")) - cd->write_handle = yaz_write_ISO8859_1; - else if (!yaz_matchstr (tocode, "UCS4")) - cd->write_handle = yaz_write_UCS4; - else if (!yaz_matchstr(tocode, "UCS4LE")) - cd->write_handle = yaz_write_UCS4LE; - #if HAVE_ICONV_H cd->iconv_cd = 0; if (!cd->read_handle || !cd->write_handle) diff --git a/util/siconvtst.c b/util/siconvtst.c index baded66..072997b 100644 --- a/util/siconvtst.c +++ b/util/siconvtst.c @@ -2,7 +2,7 @@ * Copyright (c) 1997-2002, Index Data * See the file LICENSE for details. * - * $Id: siconvtst.c,v 1.5 2002-12-10 10:23:21 adam Exp $ + * $Id: siconvtst.c,v 1.6 2002-12-10 10:59:28 adam Exp $ */ #if HAVE_CONFIG_H @@ -111,13 +111,14 @@ void convert (FILE *inf, yaz_iconv_t cd) int main (int argc, char **argv) { int ret; + int verbose = 0; char *from = 0; char *to = 0; char *arg; yaz_iconv_t cd; FILE *inf = stdin; - while ((ret = options ("f:t:", argv, argc, &arg)) != -2) + while ((ret = options ("vf:t:", argv, argc, &arg)) != -2) { switch (ret) { @@ -135,9 +136,12 @@ int main (int argc, char **argv) case 't': to = arg; break; + case 'v': + verbose++; + break; default: fprintf (stderr, "yaziconv: Usage\n" - "siconv -f encoding -t encoding [file]\n"); + "siconv -f encoding -t encoding [-v] [file]\n"); exit(1); } } @@ -157,7 +161,14 @@ int main (int argc, char **argv) fprintf (stderr, "yaziconv: unsupported encoding\n"); exit (5); } - + else + { + if (verbose) + { + fprintf (stderr, "yaziconv: using %s\n", + yaz_iconv_isbuiltin(cd) ? "YAZ" : "iconv"); + } + } convert (inf, cd); yaz_iconv_close (cd); return 0;