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
'_'.
This commit is contained in:
Vreixo Formoso 2007-12-22 19:44:02 +01:00
parent de3c4e4962
commit 9e9c077c6e
2 changed files with 23 additions and 8 deletions

View File

@ -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;
}

View File

@ -68,21 +68,35 @@ 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 */
/*
* 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);
*( (wchar_t *)ret )='\0';