Changeset 5245
- Timestamp:
- Sep 23, 2006, 4:28:38 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-streams.lisp (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-streams.lisp
r5226 r5245 368 368 (write-char-function 'ioblock-no-char-output) 369 369 (encoding nil) 370 ( alternate-line-termination nil)370 (line-termination nil) 371 371 (literal-char-code-limit 256) 372 372 (encode-output-function nil) … … 379 379 (read-byte-when-locked-function 'ioblock-no-binary-input) 380 380 (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) 381 384 (reserved1 nil) 382 385 (reserved2 nil) 383 (reserved 2nil)384 (reserved 3nil))386 (reserved3 nil) 387 (reserved4 nil)) 385 388 386 389 … … 396 399 (report-bad-arg (ioblock-stream ioblock) '(and binary-stream output-stream))) 397 400 398 (defun ioblock-no-char r-input (ioblock &rest others)401 (defun ioblock-no-char-input (ioblock &rest others) 399 402 (declare (ignore others)) 400 403 (report-bad-arg (ioblock-stream ioblock) '(and character-stream input-stream))) … … 816 819 (%ioblock-read-u8-encoded-char ioblock)) 817 820 818 (defun % private-ioblock-read-u8-encoded-char (ioblock)821 (defun %locked-ioblock-read-u8-encoded-char (ioblock) 819 822 (declare (optimize (speed 3) (safety 0))) 820 823 (with-ioblock-input-locked (ioblock) … … 853 856 854 857 (declaim (inline %ioblock-tyi-no-hang)) 855 856 858 (defun %ioblock-tyi-no-hang (ioblock) 857 859 (declare (optimize (speed 3) (safety 0))) … … 865 867 (when (= idx limit) 866 868 (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. 874 873 (defun %ioblock-peek-char (ioblock) 875 874 (or (ioblock-untyi-char ioblock) … … 885 884 (%code-char (aref (the (simple-array (unsigned-byte 8) (*)) (io-buffer-buffer buf)) idx))))) 886 885 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 887 896 (defun %ioblock-clear-input (ioblock) 888 897 (let* ((buf (ioblock-inbuf ioblock))) … … 906 915 (defun ioblock-outpos (ioblock) 907 916 (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)))) 908 1001 909 1002 (declaim (inline %ioblock-force-output)) … … 1554 1647 buf idx string len more) 1555 1648 (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)))) 1556 1662 1557 1663 (defun %ioblock-unencoded-character-read-vector (ioblock vector start end) … … 1579 1685 (incf i avail) 1580 1686 (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 1581 1699 1582 1700 (defun %ioblock-binary-read-vector (ioblock vector start end) … … 1721 1839 (if encoding 1722 1840 (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) 1723 1846 (setf (ioblock-decode-input-function ioblock) 1724 1847 (character-encoding-stream-decode-function encoding)) … … 1733 1856 (t '%ioblock-read-u8-encoded-char)))))) 1734 1857 (progn 1858 (setf (ioblock-peek-char-function ioblock) '%ioblock-peek-char) 1735 1859 (setf (ioblock-read-char-function ioblock) 1736 1860 (case sharing … … 1836 1960 (case sharing 1837 1961 (:private '%private-ioblock-write-u8-encoded-char) 1838 (:lock '%locked-ioblock-write-u8-encoded-char char)1962 (:lock '%locked-ioblock-write-u8-encoded-char) 1839 1963 (t '%ioblock-write-u8-encoded-char))))) 1840 1964 (setf (ioblock-write-simple-string-function ioblock) … … 1957 2081 character-p 1958 2082 encoding 2083 line-termination 1959 2084 &allow-other-keys) 1960 2085 (declare (ignorable element-shift)) … … 1978 2103 (setf (ioblock-owner ioblock) *current-process*)) 1979 2104 (setf (ioblock-encoding ioblock) encoding) 2105 (setf (ioblock-line-termination ioblock) line-termination) 1980 2106 (setf (ioblock-literal-char-code-limit ioblock) 1981 2107 (if encoding … … 2089 2215 (subtypep element-type 'character))) 2090 2216 (basic nil) 2091 encoding) 2217 encoding 2218 line-termination) 2092 2219 (when basic 2093 2220 (setq class (map-to-basic-stream-class-name class)) … … 2115 2242 :sharing sharing 2116 2243 :character-p character-p 2117 :encoding encoding))) 2244 :encoding encoding 2245 :line-termination line-termination))) 2118 2246 2119 2247 ;;; Fundamental streams. … … 2248 2376 (generic-stream-write-string stream string start end)) 2249 2377 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)))))2277 2378 2278 2379 ;;; The read-/write-vector methods could be specialized for stream classes … … 2423 2524 (declare (dynamic-extent args)) 2424 2525 (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))))) 2425 2583 2426 2584 (defmethod stream-read-vector ((stream basic-character-input-stream) … … 3459 3617 (%ioblock-binary-in-ivect ioblock iv start nb))) 3460 3618 3619 3461 3620 (defmethod stream-write-vector ((stream buffered-character-output-stream-mixin) 3462 3621 vector start end) … … 3467 3626 (let* ((total (- end start))) 3468 3627 (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))))) 3478 3642 3479 3643 (defmethod stream-write-vector ((stream buffered-binary-output-stream-mixin) … … 4139 4303 (stream-line-column stream))) 4140 4304 4141 4305 4142 4306 4143 4307
Note:
See TracChangeset
for help on using the changeset viewer.
