|
a/src/utils/transcode.cpp |
|
b/src/utils/transcode.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: transcode.cpp,v 1.7 2006-03-29 11:18:15 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: transcode.cpp,v 1.8 2006-04-28 07:23:46 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
45 |
iconv_t ic;
|
45 |
iconv_t ic;
|
46 |
bool ret = false;
|
46 |
bool ret = false;
|
47 |
const int OBSIZ = 8192;
|
47 |
const int OBSIZ = 8192;
|
48 |
char obuf[OBSIZ], *op;
|
48 |
char obuf[OBSIZ], *op;
|
49 |
bool icopen = false;
|
49 |
bool icopen = false;
|
50 |
if (ecnt)
|
50 |
int mecnt = 0;
|
51 |
*ecnt = 0;
|
|
|
52 |
out.erase();
|
51 |
out.erase();
|
53 |
size_t isiz = in.length();
|
52 |
size_t isiz = in.length();
|
54 |
out.reserve(isiz);
|
53 |
out.reserve(isiz);
|
55 |
const char *ip = in.c_str();
|
54 |
const char *ip = in.c_str();
|
56 |
|
55 |
|
|
... |
|
... |
73 |
out.erase();
|
72 |
out.erase();
|
74 |
out = string("iconv failed for ") + icode + " -> " + ocode +
|
73 |
out = string("iconv failed for ") + icode + " -> " + ocode +
|
75 |
" : " + strerror(errno);
|
74 |
" : " + strerror(errno);
|
76 |
#endif
|
75 |
#endif
|
77 |
if (errno == EILSEQ) {
|
76 |
if (errno == EILSEQ) {
|
78 |
LOGDEB(("transcode:iconv: bad input seq.: shift, retry\n"));
|
77 |
LOGDEB1(("transcode:iconv: bad input seq.: shift, retry\n"));
|
79 |
LOGDEB1((" Input consumed %d output produced %d\n",
|
78 |
LOGDEB1((" Input consumed %d output produced %d\n",
|
80 |
ip - in.c_str(), out.length() + OBSIZ - osiz));
|
79 |
ip - in.c_str(), out.length() + OBSIZ - osiz));
|
81 |
out.append(obuf, OBSIZ - osiz);
|
80 |
out.append(obuf, OBSIZ - osiz);
|
82 |
out += "?";
|
81 |
out += "?";
|
83 |
if (ecnt)
|
82 |
mecnt++;
|
84 |
(*ecnt)++;
|
|
|
85 |
ip++;isiz--;
|
83 |
ip++;isiz--;
|
86 |
continue;
|
84 |
continue;
|
87 |
}
|
85 |
}
|
88 |
goto error;
|
86 |
goto error;
|
89 |
}
|
87 |
}
|
|
... |
|
... |
101 |
ret = true;
|
99 |
ret = true;
|
102 |
error:
|
100 |
error:
|
103 |
if (icopen)
|
101 |
if (icopen)
|
104 |
iconv_close(ic);
|
102 |
iconv_close(ic);
|
105 |
//fprintf(stderr, "TRANSCODE OUT:\n%s\n", out.c_str());
|
103 |
//fprintf(stderr, "TRANSCODE OUT:\n%s\n", out.c_str());
|
|
|
104 |
if (mecnt)
|
|
|
105 |
LOGDEB(("transcode: %d errors\n", mecnt));
|
|
|
106 |
if (ecnt)
|
|
|
107 |
*ecnt = mecnt;
|
106 |
return ret;
|
108 |
return ret;
|
107 |
}
|
109 |
}
|
108 |
|
110 |
|
109 |
|
111 |
|
110 |
#else
|
112 |
#else
|