Changeset 5245


Ignore:
Timestamp:
Sep 23, 2006, 4:28:38 AM (18 years ago)
Author:
Gary Byers
Message:

Lots-o-changes.

File:
1 edited

Legend:

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

    r5226 r5245  
    368368  (write-char-function 'ioblock-no-char-output)
    369369  (encoding nil)
    370   (alternate-line-termination nil)
     370  (line-termination nil)
    371371  (literal-char-code-limit 256)
    372372  (encode-output-function nil)
     
    379379  (read-byte-when-locked-function 'ioblock-no-binary-input)
    380380  (write-byte-when-locked-function 'ioblock-no-binary-output)
     381  (peek-char-function 'ioblock-no-char-input)
     382  (input-filter #'false)
     383  (output-filter #'false)
    381384  (reserved1 nil)
    382385  (reserved2 nil)
    383   (reserved2 nil)
    384   (reserved3 nil))
     386  (reserved3 nil)
     387  (reserved4 nil))
    385388
    386389
     
    396399  (report-bad-arg (ioblock-stream ioblock) '(and binary-stream output-stream)))
    397400
    398 (defun ioblock-no-charr-input (ioblock &rest others)
     401(defun ioblock-no-char-input (ioblock &rest others)
    399402  (declare (ignore others))
    400403  (report-bad-arg (ioblock-stream ioblock) '(and character-stream input-stream)))
     
    816819  (%ioblock-read-u8-encoded-char ioblock))
    817820
    818 (defun %private-ioblock-read-u8-encoded-char (ioblock)
     821(defun %locked-ioblock-read-u8-encoded-char (ioblock)
    819822  (declare (optimize (speed 3) (safety 0)))
    820823  (with-ioblock-input-locked (ioblock)
     
    853856
    854857(declaim (inline %ioblock-tyi-no-hang))
    855 
    856858(defun %ioblock-tyi-no-hang (ioblock)
    857859  (declare (optimize (speed 3) (safety 0)))
     
    865867      (when (= idx limit)
    866868        (unless (%ioblock-advance ioblock nil)
    867           (return-from %ioblock-tyi-no-hang (if (ioblock-eof ioblock) :eof)))
    868         (setq idx (io-buffer-idx buf)
    869               limit (io-buffer-count buf)))
    870       (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
    871       (%code-char (aref (the (simple-array (unsigned-byte 8) (*)) (io-buffer-buffer buf)) idx)))))
    872 
    873 
     869          (return-from %ioblock-tyi-no-hang (if (ioblock-eof ioblock) :eof))))
     870      (funcall (ioblock-read-char-when-locked-function ioblock) ioblock))))
     871
     872;;; :iso-8859-1 only.
    874873(defun %ioblock-peek-char (ioblock)
    875874  (or (ioblock-untyi-char ioblock)
     
    885884        (%code-char (aref (the (simple-array (unsigned-byte 8) (*)) (io-buffer-buffer buf)) idx)))))
    886885
     886(defun %encoded-ioblock-peek-char (ioblock)
     887  (or (ioblock-untyi-char ioblock)
     888      (let* ((ch (funcall (ioblock-read-char-when-locked-function ioblock))))
     889        (unless (eq ch :eof)
     890          (setf (ioblock-untyi-char ioblock) ch))
     891        ch)))
     892
     893
     894
     895
    887896(defun %ioblock-clear-input (ioblock)   
    888897    (let* ((buf (ioblock-inbuf ioblock)))
     
    906915(defun ioblock-outpos (ioblock)
    907916  (io-buffer-count (ioblock-outbuf ioblock)))
     917
     918
     919
     920(defun u8-translate-cr-to-lf (vector n)
     921  (declare (type (simple-array (unsigned-byte 8) (*)) vector)
     922           (type index n)
     923           (optimize (speed 3) (safety 0)))
     924  (dotimes (i n t)
     925    (if (= (the (unsigned-byte 8) (aref vector i)) (char-code #\Return))
     926      (setf (aref vector i) (char-code #\Linefeed)))))
     927
     928(defun u8-translate-lf-to-cr (vector n)
     929  (declare (type (simple-array (unsigned-byte 8) (*)) vector)
     930           (type index n)
     931           (optimize (speed 3) (safety 0)))
     932  (dotimes (i n t)
     933    (if (= (the (unsigned-byte 8) (aref vector i)) (char-code #\Linefeed))
     934      (setf (aref vector i) (char-code #\Return)))))
     935
     936
     937(defun u16-translate-cr-to-lf (vector n)
     938  (declare (type (simple-array (unsigned-byte 16) (*)) vector)
     939           (type index n)
     940           (optimize (speed 3) (safety 0)))
     941  (dotimes (i n t)
     942    (if (= (the (unsigned-byte 16) (aref vector i)) (char-code #\Return))
     943      (setf (aref vector i) (char-code #\Linefeed)))))
     944
     945(defun u16-translate-lf-to-cr (vector n)
     946  (declare (type (simple-array (unsigned-byte 16) (*)) vector)
     947           (type index n)
     948           (optimize (speed 3) (safety 0)))
     949  (dotimes (i n t)
     950    (if (= (the (unsigned-byte 16) (aref vector i)) (char-code #\Linefeed))
     951      (setf (aref vector i) (char-code #\Return)))))
     952
     953(defun u32-translate-cr-to-lf (vector n)
     954  (declare (type (simple-array (unsigned-byte 32) (*)) vector)
     955           (type index n)
     956           (optimize (speed 3) (safety 0)))
     957  (dotimes (i n t)
     958    (if (= (the (unsigned-byte 32) (aref vector i)) (char-code #\Return))
     959      (setf (aref vector i) (char-code #\Linefeed)))))
     960
     961(defun u32-translate-lf-to-cr (vector n)
     962  (declare (type (simple-array (unsigned-byte 32) (*)) vector)
     963           (type index n)
     964           (optimize (speed 3) (safety 0)))
     965  (dotimes (i n t)
     966    (if (= (the (unsigned-byte 32) (aref vector i)) (char-code #\Linefeed))
     967      (setf (aref vector i) (char-code #\Return)))))
     968
     969
     970(defun swapped-u16-translate-cr-to-lf (vector n)
     971  (declare (type (simple-array (unsigned-byte 16) (*)) vector)
     972           (type index n)
     973           (optimize (speed 3) (safety 0)))
     974  (dotimes (i n t)
     975    (if (= (the (unsigned-byte 16) (aref vector i)) #xd00)
     976      (setf (aref vector i) #xa00))))
     977
     978(defun swapped-u16-translate-lf-to-cr (vector n)
     979  (declare (type (simple-array (unsigned-byte 16) (*)) vector)
     980           (type index n)
     981           (optimize (speed 3) (safety 0)))
     982  (dotimes (i n t)
     983    (if (= (the (unsigned-byte 16) (aref vector i)) #xa00)
     984      (setf (aref vector i) #xd00))))
     985
     986(defun swapped-u32-translate-cr-to-lf (vector n)
     987  (declare (type (simple-array (unsigned-byte 32) (*)) vector)
     988           (type index n)
     989           (optimize (speed 3) (safety 0)))
     990  (dotimes (i n t)
     991    (if (= (the (unsigned-byte 32) (aref vector i)) #xd000000)
     992      (setf (aref vector i) #xa000000))))
     993
     994(defun swapped-32-translate-lf-to-cr (vector n)
     995  (declare (type (simple-array (unsigned-byte 32) (*)) vector)
     996           (type index n)
     997           (optimize (speed 3) (safety 0)))
     998  (dotimes (i n t)
     999    (if (= (the (unsigned-byte 32) (aref vector i)) #xa000000)
     1000      (setf (aref vector i) #xd0000000))))
    9081001
    9091002(declaim (inline %ioblock-force-output))
     
    15541647               buf idx string len more)
    15551648              (incf len more))))))))
     1649
     1650;;; There are lots of ways of doing better here, but in the most general
     1651;;; case we can't tell (a) what a newline looks like in the buffer or (b)
     1652;;; whether there's a 1:1 mapping between code units and characters.
     1653(defun %ioblock-encoded-read-line (ioblock)
     1654  (let* ((str (make-array 20 :element-type 'base-char
     1655                          :adjustable t :fill-pointer 0))
     1656         (rcf (ioblock-read-char-when-locked-function ioblock))
     1657         (eof nil))
     1658    (do* ((ch (funcall rcf ioblock) (funcall rcf ioblock)))
     1659         ((or (eq ch #\newline) (setq eof (eq ch :eof)))
     1660          (values (ensure-simple-string str) eof))
     1661      (vector-push-extend ch str))))
    15561662         
    15571663(defun %ioblock-unencoded-character-read-vector (ioblock vector start end)
     
    15791685          (incf i avail)
    15801686          (decf need avail))))))
     1687
     1688(defun %ioblock-encoded-character-read-vector (ioblock vector start end)
     1689  (declare (fixnum start end))
     1690  (do* ((i start (1+ i))
     1691        (rcf (ioblock-read-char-when-locked-function ioblock)))
     1692       ((= i end) end)
     1693    (declare (fixnum i need))
     1694    (let* ((ch (funcall rcf ioblock)))
     1695      (if (eq ch :eof)
     1696        (return i))
     1697      (setf (schar vector i) ch))))
     1698
    15811699
    15821700(defun %ioblock-binary-read-vector (ioblock vector start end)
     
    17211839    (if encoding
    17221840      (let* ((unit-size (character-encoding-code-unit-size encoding)))
     1841        (setf (ioblock-peek-char-function ioblock) '%encoded-ioblock-peek-char)
     1842        (setf (ioblock-read-line-function ioblock)
     1843              '%ioblock-encoded-read-line)
     1844        (setf (ioblock-character-read-vector-function ioblock)
     1845              '%ioblock-encoded-character-read-vector)       
    17231846        (setf (ioblock-decode-input-function ioblock)
    17241847              (character-encoding-stream-decode-function encoding))
     
    17331856                   (t '%ioblock-read-u8-encoded-char))))))
    17341857      (progn
     1858        (setf (ioblock-peek-char-function ioblock) '%ioblock-peek-char)
    17351859        (setf (ioblock-read-char-function ioblock)
    17361860              (case sharing
     
    18361960                 (case sharing
    18371961                   (:private '%private-ioblock-write-u8-encoded-char)
    1838                    (:lock '%locked-ioblock-write-u8-encoded-charchar)
     1962                   (:lock '%locked-ioblock-write-u8-encoded-char)
    18391963                   (t '%ioblock-write-u8-encoded-char)))))
    18401964        (setf (ioblock-write-simple-string-function ioblock)
     
    19572081                            character-p
    19582082                            encoding
     2083                            line-termination
    19592084                            &allow-other-keys)
    19602085  (declare (ignorable element-shift))
     
    19782103      (setf (ioblock-owner ioblock) *current-process*))
    19792104    (setf (ioblock-encoding ioblock) encoding)
     2105    (setf (ioblock-line-termination ioblock) line-termination)
    19802106    (setf (ioblock-literal-char-code-limit ioblock)
    19812107          (if encoding
     
    20892215                                           (subtypep element-type 'character)))
    20902216                          (basic nil)
    2091                           encoding)
     2217                          encoding
     2218                          line-termination)
    20922219  (when basic
    20932220    (setq class (map-to-basic-stream-class-name class))
     
    21152242                         :sharing sharing
    21162243                         :character-p character-p
    2117                          :encoding encoding)))
     2244                         :encoding encoding
     2245                         :line-termination line-termination)))
    21182246 
    21192247;;;  Fundamental streams.
     
    22482376  (generic-stream-write-string stream string start end))
    22492377
    2250 (defmethod stream-write-list ((stream fundamental-character-output-stream)
    2251                               list count)
    2252   (declare (fixnum count))
    2253   (dotimes (i count)
    2254     (stream-write-char stream (pop list))))
    2255 
    2256 (defmethod stream-read-list ((stream fundamental-character-input-stream)
    2257                              list count)
    2258   (generic-character-read-list stream list count))
    2259 
    2260 (defmethod stream-write-list ((stream fundamental-binary-output-stream)
    2261                               list count)
    2262   (declare (fixnum count))
    2263   (dotimes (i count)
    2264     (stream-write-byte stream (pop list))))
    2265 
    2266 (defmethod stream-read-list ((stream fundamental-binary-input-stream)
    2267                              list count)
    2268   (declare (fixnum count))
    2269   (do* ((tail list (cdr tail))
    2270         (i 0 (1+ i)))
    2271        ((= i count) count)
    2272     (declare (fixnum i))
    2273     (let* ((b (stream-read-byte stream)))
    2274       (if (eq b :eof)
    2275         (return i)
    2276         (rplaca tail b)))))
    22772378
    22782379;;; The read-/write-vector methods could be specialized for stream classes
     
    24232524  (declare (dynamic-extent args))
    24242525  (apply #'make-ioblock :stream stream args))
     2526
     2527
     2528(defmethod stream-write-list ((stream fundamental-character-output-stream)
     2529                              list count)
     2530  (declare (fixnum count))
     2531  (dotimes (i count)
     2532    (stream-write-char stream (pop list))))
     2533
     2534(defmethod stream-write-list ((stream basic-character-output-stream)
     2535                              list count)
     2536  (declare (fixnum count))
     2537  (dotimes (i count)
     2538    (stream-write-char stream (pop list))))
     2539
     2540(defmethod stream-read-list ((stream fundamental-character-input-stream)
     2541                             list count)
     2542  (generic-character-read-list stream list count))
     2543
     2544(defmethod stream-read-list ((stream basic-character-input-stream)
     2545                             list count)
     2546  (generic-character-read-list stream list count))
     2547
     2548(defmethod stream-write-list ((stream fundamental-binary-output-stream)
     2549                              list count)
     2550  (declare (fixnum count))
     2551  (dotimes (i count)
     2552    (stream-write-byte stream (pop list))))
     2553
     2554(defmethod stream-write-list ((stream basic-binary-output-stream)
     2555                              list count)
     2556  (declare (fixnum count))
     2557  (dotimes (i count)
     2558    (write-byte (pop list) stream)))
     2559
     2560(defmethod stream-read-list ((stream fundamental-binary-input-stream)
     2561                             list count)
     2562  (declare (fixnum count))
     2563  (do* ((tail list (cdr tail))
     2564        (i 0 (1+ i)))
     2565       ((= i count) count)
     2566    (declare (fixnum i))
     2567    (let* ((b (stream-read-byte stream)))
     2568      (if (eq b :eof)
     2569        (return i)
     2570        (rplaca tail b)))))
     2571
     2572(defmethod stream-read-list ((stream basic-binary-input-stream)
     2573                             list count)
     2574  (declare (fixnum count))
     2575  (do* ((tail list (cdr tail))
     2576        (i 0 (1+ i)))
     2577       ((= i count) count)
     2578    (declare (fixnum i))
     2579    (let* ((b (read-byte stream)))
     2580      (if (eq b :eof)
     2581        (return i)
     2582        (rplaca tail b)))))
    24252583
    24262584(defmethod stream-read-vector ((stream basic-character-input-stream)
     
    34593617    (%ioblock-binary-in-ivect ioblock iv start nb)))
    34603618
     3619
    34613620(defmethod stream-write-vector ((stream buffered-character-output-stream-mixin)
    34623621                                vector start end)
     
    34673626      (let* ((total (- end start)))
    34683627        (declare (fixnum total))
    3469         (%ioblock-out-ivect ioblock vector start total)
    3470         (let* ((last-newline (position #\newline vector
    3471                                        :start start
    3472                                        :end end
    3473                                        :from-end t)))
    3474           (if last-newline
    3475             (setf (ioblock-charpos ioblock)
    3476                   (- end last-newline 1))
    3477             (incf (ioblock-charpos ioblock) total)))))))
     3628        (funcall (ioblock-write-simple-string-function ioblock)
     3629                 ioblock vector start total)))))
     3630
     3631(defmethod stream-write-vector ((stream basic-character-output-stream)
     3632                                vector start end)
     3633  (declare (fixnum start end))
     3634  (if (not (typep vector 'simple-base-string))
     3635    (call-next-method)
     3636    (let* ((ioblock (basic-stream-ioblock stream))
     3637           (total (- end start)))
     3638      (declare (fixnum total))
     3639      (with-ioblock-output-locked (ioblock)
     3640                (funcall (ioblock-write-simple-string-function ioblock)
     3641                 ioblock vector start total)))))
    34783642
    34793643(defmethod stream-write-vector ((stream buffered-binary-output-stream-mixin)
     
    41394303    (stream-line-column stream)))       
    41404304
    4141 
     4305 
    41424306
    41434307
Note: See TracChangeset for help on using the changeset viewer.