On 2012-07-31, Stephen J. Turnbull <stephen(a)xemacs.org> wrote:
Julian Bradfield writes:
> The worst aspect is that it does it silently. Once I modified my own
> branch of 21.4 to throw up warnings whenever there's a coding
> error,
Would you post that code?
Can't really just post a diff, because I've done so much other mucking
around. However, what I've done is this:
For decoding:
added
int num_decoding_errors;
to struct decoding_stream
modified all the decoding functions (except CCL, where of course
there's nothing I can do) to increment that whenever they meet an
invalid byte, and then in decoding_closer I replace the final
return Lstream_close (str->other_end);
by
int r = Lstream_close (str->other_end);
if ( str->num_decoding_errors ) {
warn_when_safe_lispobj(Qstream,Qwarning,
emacs_doprnt_string_lisp_2(
"%d invalid bytes were encountered while reading from file %s in coding system
%s\nThis probably means the file is in a different coding system.\nYour data will be
corrupted if you save this data.",
Qnil,-1,3,make_int(str->num_decoding_errors),fname,CODING_SYSTEM_NAME(str->codesys)));
}
return r;
For encoding, it's much the same, except that I also store the last
unencoded character, and print that in the error message:
if ( str->num_unencodable ) {
warn_when_safe_lispobj(Qstream,Qwarning,
emacs_doprnt_string_lisp_2(
"%d characters could not be encoded while writing to file %s in coding system
%s.\nThe last unencodable character was %s \nThis means your data has not been correctly
written. Try a universal coding system (utf-8 or iso-2022-7).",
Qnil,-1,4,make_int(str->num_unencodable),fname,CODING_SYSTEM_NAME(str->codesys),make_char(str->last_unencodable)));
}
This all fairly painful to encounter, but that's part of the point: it
should be painful enough to make me find and fix the coding system
errors!
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta