pax_global_header00006660000000000000000000000064112706577630014530gustar00rootroot0000000000000052 comment=3f4fe905db9e9dd644c63ea11d122f3e67dcf907 trivial-gray-streams-20091021/000077500000000000000000000000001127065776300160565ustar00rootroot00000000000000trivial-gray-streams-20091021/COPYING000066400000000000000000000021541127065776300171130ustar00rootroot00000000000000 Copyright (c) 2005 David Lichteblau Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. trivial-gray-streams-20091021/Makefile000066400000000000000000000001041127065776300175110ustar00rootroot00000000000000.PHONY: clean clean: rm -f *.fasl *.x86f *.fas *.ufsl *.lib *.pfsl trivial-gray-streams-20091021/README000066400000000000000000000025301127065776300167360ustar00rootroot00000000000000trivial-gray-streams ==================== This system provides an extremely thin compatibility layer for gray streams. It is nearly *too* trivial for a complete package, except that I have copy&pasted this code into enough projects now that I decided to factor it out once again now, and then *never* have to touch it again. How to use it ============= 1. Use the package TRIVIAL-GRAY-STREAMS instead of whatever implementation-specific package you would have to use otherwise to get at gray stream symbols. 2. For STREAM-READ-SEQUENCE and STREAM-WRITE-SEQUENCE, notice that we use two required arguments and allow additional keyword arguments. So the lambda list when defining a method on either function should look like this: (stream sequence start end &key) 3. In order for (2) to work on all Lisps, make sure to subclass all your stream classes from TRIVIAL-GRAY-STREAM-MIXIN if you intend to define methods on those two generic functions. Extensions ========== Generic function STREAM-READ-SEQUENCE (stream sequence start end &key) Generic function STREAM-WRITE-SEQUENCE (stream sequence start end &key) See above. Generic function STREAM-FILE-POSITION (stream) => file position Generic function (SETF STREAM-FILE-POSITION) (position-spec stream) => successp Will only be called by LispWorks, CLISP and SBCL. trivial-gray-streams-20091021/build.xcvb000066400000000000000000000002161127065776300200400ustar00rootroot00000000000000#+xcvb (module (:fullname "trivial-gray-streams" :depends-on ("package" "mixin") :supersedes-asdf ("trivial-gray-streams"))) trivial-gray-streams-20091021/mixin.lisp000066400000000000000000000137361127065776300201050ustar00rootroot00000000000000#+xcvb (module (:depends-on ("package"))) (in-package :trivial-gray-streams) (defclass trivial-gray-stream-mixin () ()) (defgeneric stream-read-sequence (stream sequence start end &key &allow-other-keys)) (defgeneric stream-write-sequence (stream sequence start end &key &allow-other-keys)) (defgeneric stream-file-position (stream)) (defgeneric (setf stream-file-position) (newval stream)) (defmethod stream-write-string ((stream trivial-gray-stream-mixin) seq &optional start end) (stream-write-sequence stream seq (or start 0) (or end (length seq)))) ;; Implementations should provide this default method, I believe, but ;; at least sbcl and allegro don't. (defmethod stream-terpri ((stream trivial-gray-stream-mixin)) (write-char #\newline stream)) (defmethod stream-file-position ((stream trivial-gray-stream-mixin)) nil) (defmethod (setf stream-file-position) (newval (stream trivial-gray-stream-mixin)) (declare (ignore newval)) nil) #+allegro (progn (defmethod excl:stream-read-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-read-sequence s seq (or start 0) (or end (length seq)))) (defmethod stream:stream-write-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-write-sequence s seq (or start 0) (or end (length seq))))) #+cmu (progn (defmethod ext:stream-read-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-read-sequence s seq (or start 0) (or end (length seq)))) (defmethod ext:stream-write-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-write-sequence s seq (or start 0) (or end (length seq))))) #+lispworks (progn (defmethod stream:stream-read-sequence ((s trivial-gray-stream-mixin) seq start end) (stream-read-sequence s seq start end)) (defmethod stream:stream-write-sequence ((s trivial-gray-stream-mixin) seq start end) (stream-write-sequence s seq start end)) (defmethod stream:stream-file-position ((stream trivial-gray-stream-mixin)) (stream-file-position stream)) (defmethod (setf stream:stream-file-position) (newval (stream trivial-gray-stream-mixin)) (setf (stream-file-position stream) newval))) #+openmcl (progn (defmethod ccl:stream-read-vector ((s trivial-gray-stream-mixin) seq start end) (stream-read-sequence s seq start end)) (defmethod ccl:stream-write-vector ((s trivial-gray-stream-mixin) seq start end) (stream-write-sequence s seq start end))) ;; up to version 2.43 there were no ;; stream-read-sequence, stream-write-sequence ;; functions in CLISP #+clisp (eval-when (:compile-toplevel :load-toplevel :execute) (when (find-symbol "STREAM-READ-SEQUENCE" "GRAY") (pushnew :clisp-has-stream-read/write-sequence *features*))) #+clisp (progn #+clisp-has-stream-read/write-sequence (defmethod gray:stream-read-sequence (seq (s trivial-gray-stream-mixin) &key start end) (stream-read-sequence s seq (or start 0) (or end (length seq)))) #+clisp-has-stream-read/write-sequence (defmethod gray:stream-write-sequence (seq (s trivial-gray-stream-mixin) &key start end) (stream-write-sequence s seq (or start 0) (or end (length seq)))) ;; Even despite the stream-read/write-sequence are present in newer ;; CLISP, it's better to provide stream-(read/write)-(byte/char)-sequence ;; methods too. ;; Example: if fundamental-binary-input-stream comes in the ;; class precedence list of your user-defined stream before ;; the trivial-gray-steam-mixin, the default CLISP's implementation ;; of the gray:stream-read-sequence will be used; and this default ;; implementation calls the gray:stream-read-byte-sequence. ;; Therefore we override gray:stream-read-byte-sequence and call ;; our stream-read-sequence. (defmethod gray:stream-read-byte-sequence ((s trivial-gray-stream-mixin) seq &optional start end no-hang interactive) (when no-hang (error "this stream does not support the NO-HANG argument")) (when interactive (error "this stream does not support the INTERACTIVE argument")) (stream-read-sequence s seq start end)) (defmethod gray:stream-write-byte-sequence ((s trivial-gray-stream-mixin) seq &optional start end no-hang interactive) (when no-hang (error "this stream does not support the NO-HANG argument")) (when interactive (error "this stream does not support the INTERACTIVE argument")) (stream-write-sequence s seq start end)) (defmethod gray:stream-read-char-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-read-sequence s seq start end)) (defmethod gray:stream-write-char-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-write-sequence s seq start end)) (defmethod gray:stream-position ((stream trivial-gray-stream-mixin) position) (if position (setf (stream-file-position stream) position) (stream-file-position stream)))) #+sbcl (progn (defmethod sb-gray:stream-read-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-read-sequence s seq (or start 0) (or end (length seq)))) (defmethod sb-gray:stream-write-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-write-sequence s seq (or start 0) (or end (length seq)))) (defmethod sb-gray:stream-file-position ((stream trivial-gray-stream-mixin) &optional position) (if position (setf (stream-file-position stream) position) (stream-file-position stream))) ;; SBCL extension: (defmethod sb-gray:stream-line-length ((stream trivial-gray-stream-mixin)) 80)) #+ecl (progn (defmethod gray:stream-read-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-read-sequence s seq (or start 0) (or end (length seq)))) (defmethod gray:stream-write-sequence ((s trivial-gray-stream-mixin) seq &optional start end) (stream-write-sequence s seq (or start 0) (or end (length seq))))) trivial-gray-streams-20091021/package.lisp000066400000000000000000000032111127065776300203370ustar00rootroot00000000000000#+xcvb (module ()) (in-package :cl-user) #+cmu (eval-when (:compile-toplevel :load-toplevel :execute) (require :gray-streams)) #+allegro (eval-when (:compile-toplevel :load-toplevel :execute) (unless (fboundp 'stream:stream-write-string) (require "streamc.fasl"))) #+ecl (eval-when (:compile-toplevel :load-toplevel :execute) (gray::redefine-cl-functions)) (macrolet ((frob () (let ((common-symbols '(#:fundamental-stream #:fundamental-input-stream #:fundamental-output-stream #:fundamental-character-stream #:fundamental-binary-stream #:fundamental-character-input-stream #:fundamental-character-output-stream #:fundamental-binary-input-stream #:fundamental-binary-output-stream #:stream-read-char #:stream-unread-char #:stream-read-char-no-hang #:stream-peek-char #:stream-listen #:stream-read-line #:stream-clear-input #:stream-write-char #:stream-line-column #:stream-start-line-p #:stream-write-string #:stream-terpri #:stream-fresh-line #:stream-finish-output #:stream-force-output #:stream-clear-output #:stream-advance-to-column #:stream-read-byte #:stream-write-byte))) `(defpackage :trivial-gray-streams (:use :cl) (:import-from #+sbcl :sb-gray #+allegro :excl #+cmu :ext #+clisp :gray #+openmcl :ccl #+lispworks :stream #+ecl :gray #-(or sbcl allegro cmu clisp openmcl lispworks ecl) ... ,@common-symbols) (:export #:trivial-gray-stream-mixin #:stream-read-sequence #:stream-write-sequence #:stream-file-position ,@common-symbols))))) (frob)) trivial-gray-streams-20091021/trivial-gray-streams.asd000066400000000000000000000003361127065776300226370ustar00rootroot00000000000000;;; -*- mode: lisp -*- (defpackage :trivial-gray-streams-system (:use :cl :asdf)) (in-package :trivial-gray-streams-system) (defsystem :trivial-gray-streams :serial t :components ((:file "package") (:file "mixin")))