diff --git a/code/extfmts.lisp b/code/extfmts.lisp index 6482929c7dcfd05a4652dd96ee9893d9e92a8eac..469c21a09136af03d989988b5ea6708ca2141b95 100644 --- a/code/extfmts.lisp +++ b/code/extfmts.lisp @@ -5,7 +5,7 @@ ;;; domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/extfmts.lisp,v 1.30 2010/07/03 13:39:19 rtoy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/extfmts.lisp,v 1.31 2010/07/03 16:44:37 rtoy Exp $") ;;; ;;; ********************************************************************** ;;; @@ -149,29 +149,47 @@ ;;; Define an external format based on a previously-defined external ;;; format, Base. The slot names used in Slots must match those in Base. ;;; -;;; octets-to-code (state input unput &rest vars) +;;; octets-to-code (state input unput error &rest vars) ;;; Defines a form to be used by the external format to convert ;;; octets to a code point. State is a form that can be used by the ;;; body to access the state of the stream. Input is a form that ;;; can be used to read one octet from the input stream. (It can be ;;; called as many times as needed.) Similarly, Unput is a form to -;;; put back one octet to the input stream. Vars is a list of vars -;;; that need to be defined for any symbols used within the form. +;;; put back one octet to the input stream. Error is an error +;;; handler. The default is NIL to indicate that the code should do +;;; its default handling. Otherwise, it should be a function or +;;; symbol to indicate how errors are handled. Vars is a list of +;;; vars that need to be defined for any symbols used within the +;;; form. +;;; +;;; The error handler is a function of 3 arguments: a format message +;;; string, the offending octet (or NIL) and the number of octets +;;; read for this encoding. If the function returns, it should +;;; return the codepoint to be used in place of the erroneous +;;; sequence. ;;; ;;; This should return two values: the code and the number of octets ;;; read to form the code. ;;; -;;; code-to-octets (code state output &rest vars) +;;; code-to-octets (code state output error &rest vars) ;;; Defines a form to be used by the external format to convert a ;;; code point to octets for output. Code is the code point to be ;;; converted. State is a form to access the current value of the ;;; stream's state variable. Output is a form that writes one octet -;;; to the output stream. +;;; to the output stream. Error is the error handler. A value of +;;; NIL means the external format should use its default method. +;;; Otherwise, it should be a symbol or function that will e called +;;; to handle the error. +;;; +;;; The error function takes 2 arguments: a format message string +;;; and the offending codepoint. If the function returns, it should +;;; be the desired replacement codepoint. ;;; ;;; flush-state (state output error &rest vars) ;;; Defines a form to be used by the external format to flush out ;;; any state when an output stream is closed. Similar to -;;; CODE-TO-OCTETS, but there is no code. +;;; CODE-TO-OCTETS, but there is no code. Error is similar to the +;;; error parameter for code-to-octets. ;;; ;;; copy-state (state &rest vars) ;;; Defines a form to copy any state needed by the external format. diff --git a/code/fd-stream.lisp b/code/fd-stream.lisp index 51508387e04f19df130f8d8e7df8b57108fd723a..f4f385cf4897d34b82ad7221f4bcd6c6498066f7 100644 --- a/code/fd-stream.lisp +++ b/code/fd-stream.lisp @@ -5,7 +5,7 @@ ;;; Carnegie Mellon University, and has been placed in the public domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/fd-stream.lisp,v 1.109 2010/07/03 15:20:25 rtoy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/fd-stream.lisp,v 1.110 2010/07/03 16:44:37 rtoy Exp $") ;;; ;;; ********************************************************************** ;;; @@ -275,14 +275,14 @@ ;; of octets read so far in decoding; if the function returns it ;; should return the codepoint of the desired replacement character. #+unicode - (octets-to-char-error nil) + (octets-to-char-error nil :type (or null symbol function)) ;; ;; Like OCTETS-TO-CHAR-ERROR, but for converting characters to ;; octets for output. The function takes two arguments: a message ;; string and the codepoint that cannot be converted. The function ;; should return the octet that should be output. #+unicode - (char-to-octets-error nil)) + (char-to-octets-error nil :type (or null symbol function))) (defun %print-fd-stream (fd-stream stream depth) (declare (ignore depth) (stream stream)) @@ -1819,7 +1819,10 @@ Timeout (if true) is the number of seconds to wait for input. If NIL (the default), then wait forever. When we time out, we signal IO-TIMEOUT. File is the name of the file (will be returned by PATHNAME). - Name is used to identify the stream when printed." + Name is used to identify the stream when printed. + External-format is the external format to use for the stream. + Decoding-error and Encoding-error indicate how decoding/encoding errors on + the stream should be handled. The default is to use a replacement character." (cond ((not (or input-p output-p)) (setf input t)) ((not (or input output)) @@ -1842,7 +1845,7 @@ ((eq t decoding-error) #'(lambda (&rest args) (apply 'cerror - "Use Unicode replacement character instead" + (intl:gettext "Use Unicode replacement character instead") args) stream:+replacement-character-code+)) (t @@ -2199,6 +2202,17 @@ :overwrite, :append, :supersede or nil :if-does-not-exist - one of :error, :create or nil :external-format - an external format name + :decoding-error - How to handle decoding errors from the external format. + Should be a symbol or function of 3 arguments. If it + returns, it should return a code point to use as the + replacment. NIL means use the default replacement scheme + specified by the external format. The function arguments + are a format message string, the offending octet, and the + number of octets read in the current encoding. + :encoding-error - Like :decoding-error, but for errors when encoding the + stream. The function arguments are a format message + string and the incorrect codepoint. + See the manual for details." (declare (ignore element-type external-format input-handle output-handle decoding-error encoding-error))