CMUCL commit: src/code (extfmts.lisp fd-stream.lisp)
Raymond Toy
rtoy at common-lisp.net
Sat Jul 3 18:44:37 CEST 2010
Date: Saturday, July 3, 2010 @ 12:44:37
Author: rtoy
Path: /project/cmucl/cvsroot/src/code
Modified: extfmts.lisp fd-stream.lisp
extfmts.lisp:
o Update comments for the various slots in DEFINE-EXTERNAL-FORMAT.
fd-stream.lisp:
o Declare the types for the CHAR-TO-OCTETS-ERROR and
OCTETS-TO-CHAR-ERROR slots in FD-STREAM.
o Update docstrings for MAKE-FD-STREAM and OPEN for :DECODING-ERROR
and :ENCODING-ERROR parameters.
----------------+
extfmts.lisp | 32 +++++++++++++++++++++++++-------
fd-stream.lisp | 24 +++++++++++++++++++-----
2 files changed, 44 insertions(+), 12 deletions(-)
Index: src/code/extfmts.lisp
diff -u src/code/extfmts.lisp:1.30 src/code/extfmts.lisp:1.31
--- src/code/extfmts.lisp:1.30 Sat Jul 3 09:39:19 2010
+++ src/code/extfmts.lisp Sat Jul 3 12:44:37 2010
@@ -5,7 +5,7 @@
;;; domain.
;;;
(ext:file-comment
- "$Header: /project/cmucl/cvsroot/src/code/extfmts.lisp,v 1.30 2010-07-03 13:39:19 rtoy Exp $")
+ "$Header: /project/cmucl/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.
Index: src/code/fd-stream.lisp
diff -u src/code/fd-stream.lisp:1.109 src/code/fd-stream.lisp:1.110
--- src/code/fd-stream.lisp:1.109 Sat Jul 3 11:20:25 2010
+++ src/code/fd-stream.lisp Sat Jul 3 12:44:37 2010
@@ -5,7 +5,7 @@
;;; Carnegie Mellon University, and has been placed in the public domain.
;;;
(ext:file-comment
- "$Header: /project/cmucl/cvsroot/src/code/fd-stream.lisp,v 1.109 2010-07-03 15:20:25 rtoy Exp $")
+ "$Header: /project/cmucl/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))
More information about the cmucl-commit
mailing list