Minimize charset conversion errors, ignoring when we can't do better.

If a file name is encoded in a different encoding than default input, current
implementation make image generation to be cancelled. As this can happen quite
frequent, due to files from discs or Windows partitions incorrectly mounted,
the best we can do is just ignore this, replacing the wrong character with a
'_'.
release-1.5.4.branch
Vreixo Formoso 15 years ago
parent de3c4e4962
commit 9e9c077c6e

@ -34,6 +34,7 @@ int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name)
// TODO add support for other input charset
ret = str2ascii("UTF-8", iso->name, &ascii_name);
if (ret < 0) {
iso_msg_debug(img->image, "Can't convert %s", iso->name);
return ret;
}

@ -68,20 +68,34 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
n = iconv(conv, &src, &inbytes, &ret, &outbytes);
while (n == -1) {
if( errno != EINVAL ) {
if (errno == E2BIG) {
/* error, should never occur */
iconv_close(conv);
free(wstr);
return ISO_CHARSET_CONV_ERROR;
}
} else {
wchar_t *wret;
/* invalid input string charset, just ignore */
/* printf("String %s is not encoded in %s\n", str, codeset); */
inbytes--;
if (!inbytes)
break;
n = iconv(conv, &src, &inbytes, &ret, &outbytes);
/*
* Invalid input string charset.
* This can happen if input is in fact encoded in a charset
* different than icharset.
* We can't do anything better than replace by "_" and continue.
*/
/* TODO we need a way to report this */
/* printf("String %s is not encoded in %s\n", str, codeset); */
inbytes--;
src++;
wret = (wchar_t*) ret;
*wret++ = (wchar_t) '_';
ret = (char *) wret;
outbytes -= sizeof(wchar_t);
if (!inbytes)
break;
n = iconv(conv, &src, &inbytes, &ret, &outbytes);
}
}
iconv_close(conv);

Loading…
Cancel
Save