projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove yaz-client-commands.xml
[yaz-moved-to-github.git]
/
util
/
yaziconv.c
diff --git
a/util/yaziconv.c
b/util/yaziconv.c
index
9e966e9
..
0e8bb5a
100644
(file)
--- a/
util/yaziconv.c
+++ b/
util/yaziconv.c
@@
-1,5
+1,5
@@
/* This file is part of the YAZ toolkit.
/* 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.
*/
* See the file LICENSE for details.
*/
@@
-10,13
+10,25
@@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
-#include <ctype.h>
#include <yaz/yaz-util.h>
#define CHUNK_IN 64
#define CHUNK_OUT 64
#include <yaz/yaz-util.h>
#define CHUNK_IN 64
#define CHUNK_OUT 64
+void write_out(const char *b0, const char *b1)
+{
+ size_t sz = b1 - b0;
+ if (sz)
+ {
+ if (fwrite(b0, 1, sz, stdout) != sz)
+ {
+ fprintf(stderr, "yaz-iconv: write failed\n");
+ exit(8);
+ }
+ }
+}
+
void convert(FILE *inf, yaz_iconv_t cd, int verbose)
{
char inbuf0[CHUNK_IN], *inbuf = inbuf0;
void convert(FILE *inf, yaz_iconv_t cd, int verbose)
{
char inbuf0[CHUNK_IN], *inbuf = inbuf0;
@@
-35,18
+47,16
@@
void convert(FILE *inf, yaz_iconv_t cd, int verbose)
{
if (ferror(inf))
{
{
if (ferror(inf))
{
- fprintf(stderr, "yaziconv: error reading file\n");
+ fprintf(stderr, "yaz-iconv: error reading file\n");
exit(6);
}
if (r == 0)
{
exit(6);
}
if (r == 0)
{
- if (outbuf != outbuf0)
- fwrite(outbuf0, 1, outbuf - outbuf0, stdout);
+ write_out(outbuf0, outbuf);
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
- if (outbuf != outbuf0)
- fwrite(outbuf0, 1, outbuf - outbuf0, stdout);
+ write_out(outbuf0, outbuf);
break;
}
inbytesleft = r;
break;
}
inbytesleft = r;
@@
-68,7
+78,7
@@
void convert(FILE *inf, yaz_iconv_t cd, int verbose)
return ;
}
else if (e == YAZ_ICONV_EINVAL) /* incomplete input */
return ;
}
else if (e == YAZ_ICONV_EINVAL) /* incomplete input */
- {
+ {
size_t i;
for (i = 0; i<inbytesleft; i++)
inbuf0[i] = inbuf[i];
size_t i;
for (i = 0; i<inbytesleft; i++)
inbuf0[i] = inbuf[i];
@@
-78,7
+88,7
@@
void convert(FILE *inf, yaz_iconv_t cd, int verbose)
{
if (ferror(inf))
{
{
if (ferror(inf))
{
- fprintf(stderr, "yaziconv: error reading file\n");
+ fprintf(stderr, "yaz-iconv: error reading file\n");
exit(6);
}
}
exit(6);
}
}
@@
-93,14
+103,14
@@
void convert(FILE *inf, yaz_iconv_t cd, int verbose)
}
else if (e == YAZ_ICONV_E2BIG) /* no more output space */
{
}
else if (e == YAZ_ICONV_E2BIG) /* no more output space */
{
- fwrite(outbuf0, 1, outbuf - outbuf0, stdout);
+ write_out(outbuf0, outbuf);
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
mustread = 0;
}
else
{
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
mustread = 0;
}
else
{
- fprintf(stderr, "yaziconv: unknown error\n");
+ fprintf(stderr, "yaz-iconv: unknown error\n");
exit(7);
}
}
exit(7);
}
}
@@
-109,7
+119,7
@@
void convert(FILE *inf, yaz_iconv_t cd, int verbose)
inbuf = inbuf0;
inbytesleft = CHUNK_IN;
inbuf = inbuf0;
inbytesleft = CHUNK_IN;
- fwrite(outbuf0, 1, outbuf - outbuf0, stdout);
+ write_out(outbuf0, outbuf);
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
@@
-136,7
+146,7
@@
int main(int argc, char **argv)
inf = fopen(arg, "rb");
if (!inf)
{
inf = fopen(arg, "rb");
if (!inf)
{
- fprintf(stderr, "yaziconv: cannot open %s", arg);
+ fprintf(stderr, "yaz-iconv: cannot open %s", arg);
exit(2);
}
break;
exit(2);
}
break;
@@
-150,32
+160,32
@@
int main(int argc, char **argv)
verbose++;
break;
default:
verbose++;
break;
default:
- fprintf(stderr, "yaziconv: Usage\n"
+ fprintf(stderr, "yaz-iconv: Usage\n"
"yaziconv -f encoding -t encoding [-v] [file]\n");
exit(1);
}
}
if (!to)
{
"yaziconv -f encoding -t encoding [-v] [file]\n");
exit(1);
}
}
if (!to)
{
- fprintf(stderr, "yaziconv: -t encoding missing\n");
+ fprintf(stderr, "yaz-iconv: -t encoding missing\n");
exit(3);
}
if (!from)
{
exit(3);
}
if (!from)
{
- fprintf(stderr, "yaziconv: -f encoding missing\n");
+ fprintf(stderr, "yaz-iconv: -f encoding missing\n");
exit(4);
}
cd = yaz_iconv_open(to, from);
if (!cd)
{
exit(4);
}
cd = yaz_iconv_open(to, from);
if (!cd)
{
- fprintf(stderr, "yaziconv: unsupported encoding\n");
+ fprintf(stderr, "yaz-iconv: unsupported encoding\n");
exit(5);
}
else
{
if (verbose)
{
exit(5);
}
else
{
if (verbose)
{
- fprintf(stderr, "yaziconv: using %s\n",
+ fprintf(stderr, "yaz-iconv: using %s\n",
yaz_iconv_isbuiltin(cd) ? "YAZ" : "iconv");
}
}
yaz_iconv_isbuiltin(cd) ? "YAZ" : "iconv");
}
}
@@
-186,6
+196,7
@@
int main(int argc, char **argv)
/*
* Local variables:
* c-basic-offset: 4
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab