# HG changeset patch # User ali # Date 1374314822 -3600 # Node ID 4e6e7cc6b50d5ca0efdfa91d3e2f9e03234ef292 # Parent dab0af6882ee476932ff6fcc79e8e46bc8461f6a Give a useful error if input is neither UTF-8 nor Windows-1252 diff -r dab0af6882ee -r 4e6e7cc6b50d bookloupe/bookloupe.c --- a/bookloupe/bookloupe.c Thu May 30 20:27:48 2013 +0100 +++ b/bookloupe/bookloupe.c Sat Jul 20 11:07:02 2013 +0100 @@ -404,8 +404,10 @@ */ gchar *read_etext(const char *filename,GError **err) { + GError *tmp_err=NULL; gchar *contents,*utf8; - gsize len,nb; + gsize len,bytes_read,bytes_written; + int i,line,col; if (!g_file_get_contents(filename,&contents,&len,err)) return NULL; if (g_utf8_validate(contents,len,NULL)) @@ -418,7 +420,27 @@ } else { - utf8=g_convert(contents,len,"UTF-8","WINDOWS-1252",NULL,&nb,NULL); + utf8=g_convert(contents,len,"UTF-8","WINDOWS-1252",&bytes_read, + &bytes_written,&tmp_err); + if (g_error_matches(tmp_err,G_CONVERT_ERROR, + G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) + { + line=col=1; + for(i=0;i