Changeset 441


Ignore:
Timestamp:
Jan 30, 2004, 3:56:26 PM (21 years ago)
Author:
Gary Byers
Message:

Lots of nit-picking; BROADCAST-STREAM methods (at least partly) fixed to
return value from last stream in list.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-1/l1-streams.lisp

    r424 r441  
    2424;;;
    2525
    26 
    2726(defclass stream ()
    2827  ((direction :initarg :direction :initform nil :reader stream-direction)
     
    3938
    4039;;; Some generic stream functions:
     40(defmethod stream-length ((x t) &optional new)
     41  (declare (ignore new))
     42  (report-bad-arg x 'stream))
     43
     44(defmethod stream-position ((x t) &optional new)
     45  (declare (ignore new))
     46  (report-bad-arg x 'stream))
     47
     48(defmethod stream-element-type ((x t))
     49  (report-bad-arg x 'stream))
    4150
    4251;;; For input streams:
     
    244253(defmethod stream-finish-output ((stream output-stream)) nil)
    245254
     255
     256
    246257(defmethod stream-clear-output ((stream output-stream)) nil)
    247258
     
    274285(defmethod interactive-stream-p ((stream stream)) nil)
    275286
     287(defmethod stream-clear-input ((x t))
     288  (report-bad-arg x 'stream))
    276289(defmethod stream-clear-input ((stream input-stream)) nil)
    277290
     
    11741187
    11751188(defun make-synonym-stream (symbol)
    1176   (make-instance 'synonym-stream :symbol symbol))
     1189  (make-instance 'synonym-stream :symbol (require-type symbol 'symbol)))
    11771190
    11781191
     
    12381251
    12391252(defun make-two-way-stream (in out)
     1253  (unless (input-stream-p in)
     1254    (require-type in 'input-stream))
     1255  (unless (output-stream-p out)
     1256    (require-type out 'output-stream))
    12401257  (make-instance 'two-way-stream :input-stream in :output-stream out))
    12411258
     
    13891406             (broadcast-method stream-advance-to-column (s new))
    13901407             (broadcast-method stream-start-line-p (s))
    1391              (broadcast-method stream-fresh-line (s))
    13921408             (broadcast-method stream-terpri (s))
    13931409             (broadcast-method stream-force-output (s))
     
    13961412             (broadcast-method stream-write-vector (s v start end)))
    13971413
     1414(defun last-broadcast-stream (s)
     1415  (car (last (broadcast-stream-streams s))))
     1416
     1417(defmethod stream-fresh-line ((s broadcast-stream))
     1418  (let* ((did-output-newline nil))
     1419    (dolist (sub (broadcast-stream-streams s) did-output-newline)
     1420      (setq did-output-newline (stream-fresh-line sub)))))
     1421
     1422(defmethod stream-element-type ((s broadcast-stream))
     1423  (let* ((last (last-broadcast-stream s)))
     1424    (if last
     1425      (stream-element-type last)
     1426      t)))
     1427
     1428(defmethod stream-length ((s broadcast-stream) &optional new)
     1429  (unless new
     1430    (let* ((last (last-broadcast-stream s)))
     1431      (if last
     1432        (stream-length last)
     1433        0))))
     1434
     1435(defmethod stream-position ((s broadcast-stream) &optional new)
     1436  (unless new
     1437    (let* ((last (last-broadcast-stream s)))
     1438      (if last
     1439        (stream-position last)
     1440        0))))
     1441
     1442(defmethod file-stream-external-format ((s broadcast-stream))
     1443  (let* ((last (last-broadcast-stream s)))
     1444    (if last
     1445      (file-stream-external-format last)
     1446      :default)))
    13981447
    13991448(defun make-broadcast-stream (&rest streams)
     
    21952244           (io-buffer (ioblock-outbuf ioblock))
    21962245           (buf (%null-ptr))
    2197            (octets (ioblock-elements-to-octets ioblock count)))
     2246           (octets-to-write (ioblock-elements-to-octets ioblock count))
     2247           (octets octets-to-write))
    21982248      (declare (fixnum octets))
    21992249      (declare (dynamic-extent buf))
     
    22062256              (case (%unix-fd-kind fd)
    22072257                (:file (fd-fsync fd))))
    2208             count)
     2258            octets-to-write)
    22092259        (let* ((written (with-eagain fd :output
    22102260                          (fd-write fd buf octets))))
     
    22492299                      (element-type 'base-char)
    22502300                      (if-exists :error)
    2251                       (if-does-not-exist (if (or (eq direction :input)
    2252                                                  ;(eq if-exists :overwrite)
    2253                                                  (eq if-exists :append))
    2254                                            :error
    2255                                            :create))
     2301                      (if-does-not-exist (cond ((eq direction :probe)
     2302                                                nil)
     2303                                               ((or (eq direction :input)
     2304                                                    (eq if-exists :overwrite)
     2305                                                    (eq if-exists :append))
     2306                                                :error)
     2307                                               (t :create)))
    22562308                      (external-format :default)
    22572309                      (class *default-file-stream-class*)
     
    22872339
    22882340(defun file-length (stream)
    2289   (stream-length stream))
     2341  (etypecase stream
     2342    ;; Don't use an OR type here
     2343    (file-stream (stream-length stream))
     2344    (broadcast-stream (stream-length stream))))
    22902345 
    22912346(defun file-position (stream &optional position)
Note: See TracChangeset for help on using the changeset viewer.