Changeset 5292
- Timestamp:
- Oct 5, 2006, 4:35:22 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-streams.lisp (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-streams.lisp
r5275 r5292 664 664 ) 665 665 666 (declaim (inline %ioblock-read-swapped-u16-byte)) 667 (defun %ioblock-read-swapped-u16-byte (ioblock) 666 667 ;;; Read a 16-bit code element from a stream with element-type 668 ;;; (UNSIGNED-BYTE 8), in native byte-order. 669 670 (declaim (inline %ioblock-read-u16-code-element)) 671 (defun %ioblock-read-u16-code-element (ioblock) 668 672 (declare (optimize (speed 3) (safety 0))) 669 673 (let* ((buf (ioblock-inbuf ioblock)) 670 674 (idx (io-buffer-idx buf)) 671 (limit (io-buffer-count buf))) 672 (declare (fixnum idx limit)) 673 (when (= idx limit) 674 (unless (%ioblock-advance ioblock t) 675 (return-from %ioblock-read-swapped-u16-byte :eof)) 676 (setq idx (io-buffer-idx buf) 677 limit (io-buffer-count buf))) 678 (setf (io-buffer-idx buf) (the fixnum (1+ idx))) 679 (%swap-u16 (aref (the (simple-array (unsigned-byte 16) (*)) 680 (io-buffer-buffer buf)) idx)))) 681 682 (declaim (inline %ioblock-read-swapped-u32-element)) 683 (defun %ioblock-read-swapped-u32-element (ioblock) 675 (limit (io-buffer-count buf)) 676 (vector (io-buffer-buffer buf))) 677 (declare (fixnum idx limit) 678 (type (simple-array (unsigned-byte 8) (*)) vector)) 679 (if (<= (the fixnum (+ idx 2)) limit) 680 (let* ((b0 (aref vector idx)) 681 (b1 (aref vector (the fixnum (1+ idx))))) 682 (declare (type (unsigned-byte 8) b0 b1)) 683 (setf (io-buffer-idx buf) (the fixnum (+ idx 2))) 684 #+big-endian-target 685 (logior (the (unsigned-byte 16) (ash b0 8)) b1) 686 #+little-endian-target 687 (logior (the (unsigned-byte 16) (ash b1 8)) b0)) 688 (if (< idx limit) 689 (let* ((b0 (aref vector idx)) 690 (n (%ioblock-advance ioblock t))) 691 (declare (type (unsigned-byte 8) b0)) 692 (if (null n) 693 :eof 694 (let* ((b1 (aref vector 0))) 695 (declare (type (unsigned-byte 8) b1)) 696 (setf (io-buffer-idx buf) 1) 697 #+big-endian-target 698 (logior (the (unsigned-byte 16) (ash b0 8)) b1) 699 #+little-endian-target 700 (logior (the (unsigned-byte 16) (ash b1 8)) b0)))) 701 (let* ((n (%ioblock-advance ioblock t))) 702 (if (null n) 703 :eof 704 (if (eql n 1) 705 (progn 706 (setf (io-buffer-idx buf) 1) 707 :eof) 708 (let* ((b0 (aref vector 0)) 709 (b1 (aref vector 1))) 710 (declare (type (unsigned-byte 8) b0 b1)) 711 (setf (io-buffer-idx buf) 2) 712 #+big-endian-target 713 (logior (the (unsigned-byte 16) (ash b0 8)) b1) 714 #+little-endian-target 715 (logior (the (unsigned-byte 16) (ash b1 8)) b0))))))))) 716 717 (declaim (inline %ioblock-read-swapped-u16-code-element)) 718 (defun %ioblock-read-swapped-u16-code-element (ioblock) 719 (declare (optimize (speed 3) (safety 0))) 720 (let* ((buf (ioblock-inbuf ioblock)) 721 (idx (io-buffer-idx buf)) 722 (limit (io-buffer-count buf)) 723 (vector (io-buffer-buffer buf))) 724 (declare (fixnum idx limit) 725 (type (simple-array (unsigned-byte 8) (*)) vector)) 726 (if (<= (the fixnum (+ idx 2)) limit) 727 (let* ((b0 (aref vector idx)) 728 (b1 (aref vector (the fixnum (1+ idx))))) 729 (declare (type (unsigned-byte 8) b0 b1)) 730 (setf (io-buffer-idx buf) (the fixnum (+ idx 2))) 731 #+little-endian-target 732 (logior (the (unsigned-byte 16) (ash b0 8)) b1) 733 #+big-endian-target 734 (logior (the (unsigned-byte 16) (ash b1 8)) b0)) 735 (if (< idx limit) 736 (let* ((b0 (aref vector idx)) 737 (n (%ioblock-advance ioblock t))) 738 (declare (type (unsigned-byte 8) b0)) 739 (if (null n) 740 :eof 741 (let* ((b1 (aref vector 0))) 742 (declare (type (unsigned-byte 8) b1)) 743 (setf (io-buffer-idx buf) 1) 744 #+little-endian-target 745 (logior (the (unsigned-byte 16) (ash b0 8)) b1) 746 #+big-endian-target 747 (logior (the (unsigned-byte 16) (ash b1 8)) b0)))) 748 (let* ((n (%ioblock-advance ioblock t))) 749 (if (null n) 750 :eof 751 (if (eql n 1) 752 (progn 753 (setf (io-buffer-idx buf) 1) 754 :eof) 755 (let* ((b0 (aref vector 0)) 756 (b1 (aref vector 1))) 757 (declare (type (unsigned-byte 8) b0 b1)) 758 (setf (io-buffer-idx buf) 2) 759 #+little-endian-target 760 (logior (the (unsigned-byte 16) (ash b0 8)) b1) 761 #+big-endian-target 762 (logior (the (unsigned-byte 16) (ash b1 8)) b0))))))))) 763 764 765 (declaim (inline %ioblock-read-u32-code-element)) 766 (defun %ioblock-read-u32-code-element (ioblock) 684 767 (declare (optimize (speed 3) (safety 0))) 685 768 (let* ((buf (ioblock-inbuf ioblock)) 686 769 (idx (io-buffer-idx buf)) 687 (limit (io-buffer-count buf))) 688 (declare (fixnum idx limit)) 689 (when (= idx limit) 690 (unless (%ioblock-advance ioblock t) 691 (return-from %ioblock-read-swapped-u32-element :eof)) 692 (setq idx (io-buffer-idx buf) 693 limit (io-buffer-count buf))) 694 (setf (io-buffer-idx buf) (the fixnum (1+ idx))) 695 (%swap-u32 (aref (the (simple-array (unsigned-byte 32) (*)) 696 (io-buffer-buffer buf)) idx)))) 770 (limit (io-buffer-count buf)) 771 (vector (io-buffer-buffer buf))) 772 (declare (fixnum idx limit) 773 (type (simple-array (unsigned-byte 8) (*)) vector)) 774 (cond ((<= (the fixnum (+ idx 4)) limit) 775 (let* ((b0 (aref vector idx)) 776 (b1 (aref vector (the fixnum (1+ idx)))) 777 (b2 (aref vector (the fixnum (+ idx 2)))) 778 (b3 (aref vector (the fixnum (+ idx 3))))) 779 (declare (type (unsigned-byte 8) b0 b1 b2 b3)) 780 (setf (io-buffer-idx buf) (the fixnum (+ idx 4))) 781 #+big-endian-target 782 (logior (the (unsigned-byte 32) (ash b0 24)) 783 (the (unsigned-byte 24) (ash b1 16)) 784 (the (unsigned-byte 16) (ash b2 8)) 785 b3) 786 #+little-endian-target 787 (logior (the (unsigned-byte 32) (ash b3 24)) 788 (the (unsigned-byte 24) (ash b2 16)) 789 (the (unsigned-byte 16) (ash b1 8)) 790 b0))) 791 ((= (the fixnum (+ idx 3)) limit) 792 (let* ((b0 (aref vector idx)) 793 (b1 (aref vector (the fixnum (1+ idx)))) 794 (b2 (aref vector (the fixnum (+ idx 2)))) 795 (n (%ioblock-advance ioblock t))) 796 (declare (type (unsigned-byte 8) b0 b1 b2)) 797 (if (null n) 798 :eof 799 (let* ((b3 (aref vector 0))) 800 (declare (type (unsigned-byte 8) b3)) 801 (setf (io-buffer-idx buf) 1) 802 #+big-endian-target 803 (logior (the (unsigned-byte 32) (ash b0 24)) 804 (the (unsigned-byte 24) (ash b1 16)) 805 (the (unsigned-byte 16) (ash b2 8)) 806 b3) 807 #+little-endian-target 808 (logior (the (unsigned-byte 32) (ash b3 24)) 809 (the (unsigned-byte 24) (ash b2 16)) 810 (the (unsigned-byte 16) (ash b1 8)) 811 b0))))) 812 ((= (the fixnum (+ idx 2)) limit) 813 (let* ((b0 (aref vector idx)) 814 (b1 (aref vector (the fixnum (1+ idx)))) 815 (n (%ioblock-advance ioblock t))) 816 (declare (type (unsigned-byte 8) b0 b1)) 817 (if (null n) 818 :eof 819 (if (eql n 1) 820 (progn 821 (setf (io-buffer-idx buf) 1) 822 :eof) 823 (let* ((b2 (aref vector 0)) 824 (b3 (aref vector 1))) 825 (declare (type (unsigned-byte 8) b2 b3)) 826 (setf (io-buffer-idx buf) 2) 827 #+big-endian-target 828 (logior (the (unsigned-byte 32) (ash b0 24)) 829 (the (unsigned-byte 24) (ash b1 16)) 830 (the (unsigned-byte 16) (ash b2 8)) 831 b3) 832 #+little-endian-target 833 (logior (the (unsigned-byte 32) (ash b3 24)) 834 (the (unsigned-byte 24) (ash b2 16)) 835 (the (unsigned-byte 16) (ash b1 8)) 836 b0)))))) 837 ((= (the fixnum (1+ idx)) limit) 838 (let* ((b0 (aref vector idx)) 839 (n (%ioblock-advance ioblock t))) 840 (declare (type (unsigned-byte 8) b0)) 841 (if (null n) 842 :eof 843 (if (< n 3) 844 (progn 845 (setf (io-buffer-idx buf) n) 846 :eof) 847 (let* ((b1 (aref vector 0)) 848 (b2 (aref vector 1)) 849 (b3 (aref vector 2))) 850 (setf (io-buffer-idx buf) 3) 851 #+big-endian-target 852 (logior (the (unsigned-byte 32) (ash b0 24)) 853 (the (unsigned-byte 24) (ash b1 16)) 854 (the (unsigned-byte 16) (ash b2 8)) 855 b3) 856 #+little-endian-target 857 (logior (the (unsigned-byte 32) (ash b3 24)) 858 (the (unsigned-byte 24) (ash b2 16)) 859 (the (unsigned-byte 16) (ash b1 8)) 860 b0)))))) 861 (t 862 (let* ((n (%ioblock-advance ioblock t))) 863 (if (null n) 864 :eof 865 (if (< n 4) 866 (progn 867 (setf (io-buffer-idx buf) n) 868 :eof) 869 (let* ((b0 (aref vector 0)) 870 (b1 (aref vector 1)) 871 (b2 (aref vector 2)) 872 (b3 (aref vector 3))) 873 (declare (type (unsigned-byte 8) b0 b1 b2 b3)) 874 (setf (io-buffer-idx buf) 4) 875 #+big-endian-target 876 (logior (the (unsigned-byte 32) (ash b0 24)) 877 (the (unsigned-byte 24) (ash b1 16)) 878 (the (unsigned-byte 16) (ash b2 8)) 879 b3) 880 #+little-endian-target 881 (logior (the (unsigned-byte 32) (ash b3 24)) 882 (the (unsigned-byte 24) (ash b2 16)) 883 (the (unsigned-byte 16) (ash b1 8)) 884 b0))))))))) 885 886 (declaim (inline %ioblock-read-swapped-u32-code-element)) 887 (defun %ioblock-read-swapped-u32-code-element (ioblock) 888 (declare (optimize (speed 3) (safety 0))) 889 (let* ((buf (ioblock-inbuf ioblock)) 890 (idx (io-buffer-idx buf)) 891 (limit (io-buffer-count buf)) 892 (vector (io-buffer-buffer buf))) 893 (declare (fixnum idx limit) 894 (type (simple-array (unsigned-byte 8) (*)) vector)) 895 (cond ((<= (the fixnum (+ idx 4)) limit) 896 (let* ((b0 (aref vector idx)) 897 (b1 (aref vector (the fixnum (1+ idx)))) 898 (b2 (aref vector (the fixnum (+ idx 2)))) 899 (b3 (aref vector (the fixnum (+ idx 3))))) 900 (declare (type (unsigned-byte 8) b0 b1 b2 b3)) 901 (setf (io-buffer-idx buf) (the fixnum (+ idx 4))) 902 #+little-endian-target 903 (logior (the (unsigned-byte 32) (ash b0 24)) 904 (the (unsigned-byte 24) (ash b1 16)) 905 (the (unsigned-byte 16) (ash b2 8)) 906 b3) 907 #+big-endian-target 908 (logior (the (unsigned-byte 32) (ash b3 24)) 909 (the (unsigned-byte 24) (ash b2 16)) 910 (the (unsigned-byte 16) (ash b1 8)) 911 b0))) 912 ((= (the fixnum (+ idx 3)) limit) 913 (let* ((b0 (aref vector idx)) 914 (b1 (aref vector (the fixnum (1+ idx)))) 915 (b2 (aref vector (the fixnum (+ idx 2)))) 916 (n (%ioblock-advance ioblock t))) 917 (declare (type (unsigned-byte 8) b0 b1 b2)) 918 (if (null n) 919 :eof 920 (let* ((b3 (aref vector 0))) 921 (declare (type (unsigned-byte 8) b3)) 922 (setf (io-buffer-idx buf) 1) 923 #+little-endian-target 924 (logior (the (unsigned-byte 32) (ash b0 24)) 925 (the (unsigned-byte 24) (ash b1 16)) 926 (the (unsigned-byte 16) (ash b2 8)) 927 b3) 928 #+big-endian-target 929 (logior (the (unsigned-byte 32) (ash b3 24)) 930 (the (unsigned-byte 24) (ash b2 16)) 931 (the (unsigned-byte 16) (ash b1 8)) 932 b0))))) 933 ((= (the fixnum (+ idx 2)) limit) 934 (let* ((b0 (aref vector idx)) 935 (b1 (aref vector (the fixnum (1+ idx)))) 936 (n (%ioblock-advance ioblock t))) 937 (declare (type (unsigned-byte 8) b0 b1)) 938 (if (null n) 939 :eof 940 (if (eql n 1) 941 (progn 942 (setf (io-buffer-idx buf) 1) 943 :eof) 944 (let* ((b2 (aref vector 0)) 945 (b3 (aref vector 1))) 946 (declare (type (unsigned-byte 8) b2 b3)) 947 (setf (io-buffer-idx buf) 2) 948 #+little-endian-target 949 (logior (the (unsigned-byte 32) (ash b0 24)) 950 (the (unsigned-byte 24) (ash b1 16)) 951 (the (unsigned-byte 16) (ash b2 8)) 952 b3) 953 #+big-endian-target 954 (logior (the (unsigned-byte 32) (ash b3 24)) 955 (the (unsigned-byte 24) (ash b2 16)) 956 (the (unsigned-byte 16) (ash b1 8)) 957 b0)))))) 958 ((= (the fixnum (1+ idx)) limit) 959 (let* ((b0 (aref vector idx)) 960 (n (%ioblock-advance ioblock t))) 961 (declare (type (unsigned-byte 8) b0)) 962 (if (null n) 963 :eof 964 (if (< n 3) 965 (progn 966 (setf (io-buffer-idx buf) n) 967 :eof) 968 (let* ((b1 (aref vector 0)) 969 (b2 (aref vector 1)) 970 (b3 (aref vector 2))) 971 (setf (io-buffer-idx buf) 3) 972 #+little-endian-target 973 (logior (the (unsigned-byte 32) (ash b0 24)) 974 (the (unsigned-byte 24) (ash b1 16)) 975 (the (unsigned-byte 16) (ash b2 8)) 976 b3) 977 #+big-endian-target 978 (logior (the (unsigned-byte 32) (ash b3 24)) 979 (the (unsigned-byte 24) (ash b2 16)) 980 (the (unsigned-byte 16) (ash b1 8)) 981 b0)))))) 982 (t 983 (let* ((n (%ioblock-advance ioblock t))) 984 (if (null n) 985 :eof 986 (if (< n 4) 987 (progn 988 (setf (io-buffer-idx buf) n) 989 :eof) 990 (let* ((b0 (aref vector 0)) 991 (b1 (aref vector 1)) 992 (b2 (aref vector 2)) 993 (b3 (aref vector 3))) 994 (declare (type (unsigned-byte 8) b0 b1 b2 b3)) 995 (setf (io-buffer-idx buf) 4) 996 #+little-endian-target 997 (logior (the (unsigned-byte 32) (ash b0 24)) 998 (the (unsigned-byte 24) (ash b1 16)) 999 (the (unsigned-byte 16) (ash b2 8)) 1000 b3) 1001 #+big-endian-target 1002 (logior (the (unsigned-byte 32) (ash b3 24)) 1003 (the (unsigned-byte 24) (ash b2 16)) 1004 (the (unsigned-byte 16) (ash b1 8)) 1005 b0))))))))) 697 1006 698 1007 … … 829 1138 (prog1 ch 830 1139 (setf (ioblock-untyi-char ioblock) nil)) 831 (let* ((1st-unit (%ioblock-read-u16- byteioblock)))1140 (let* ((1st-unit (%ioblock-read-u16-code-element ioblock))) 832 1141 (if (eq 1st-unit :eof) 833 1142 1st-unit … … 839 1148 (funcall (ioblock-decode-input-function ioblock) 840 1149 1st-unit 841 #'%ioblock-read-u16- byte1150 #'%ioblock-read-u16-code-element 842 1151 ioblock)))))))) 843 1152 … … 859 1168 (prog1 ch 860 1169 (setf (ioblock-untyi-char ioblock) nil)) 861 (let* ((1st-unit (%ioblock-read-swapped-u16- byteioblock)))1170 (let* ((1st-unit (%ioblock-read-swapped-u16-code-element ioblock))) 862 1171 (if (eq 1st-unit :eof) 863 1172 1st-unit … … 869 1178 (funcall (ioblock-decode-input-function ioblock) 870 1179 1st-unit 871 #'%ioblock-read-swapped-u16- byte1180 #'%ioblock-read-swapped-u16-code-element 872 1181 ioblock)))))))) 873 1182 … … 944 1253 945 1254 946 ;;; Return #\Return if an encoded #\Return is found first in vector,947 ;;; #\Linefeed if and encoded #\Linefeed is found first or if neither948 ;;; is found.949 (defun u8-infer-line-termination (vector n)950 (declare (type (simple-array (unsigned-byte 8) (*)) vector)951 (type index n)952 (optimize (speed 3) (safety 0)))953 (dotimes (i n #\linefeed)954 (let* ((code (aref vector i)))955 (declare (type (unsigned-byte 8) code))956 (if (= code (char-code #\linefeed))957 (return #\linefeed)958 (if (= code (char-code #\return))959 (return #\return))))))960 961 (defun u16-infer-line-termination (vector n)962 (declare (type (simple-array (unsigned-byte 16) (*)) vector)963 (type index n)964 (optimize (speed 3) (safety 0)))965 (dotimes (i n #\linefeed)966 (let* ((code (aref vector i)))967 (declare (type (unsigned-byte 16) code))968 (if (= code (char-code #\linefeed))969 (return #\linefeed)970 (if (= code (char-code #\return))971 (return #\return))))))972 973 (defun swapped-u16-infer-line-termination (vector n)974 (declare (type (simple-array (unsigned-byte 16) (*)) vector)975 (type index n)976 (optimize (speed 3) (safety 0)))977 (dotimes (i n #\linefeed)978 (let* ((code (%swap-u16 (aref vector i))))979 (declare (type (unsigned-byte 16) code))980 (if (= code (char-code #\linefeed))981 (return #\linefeed)982 (if (= code (char-code #\return))983 (return #\return))))))984 985 (defun u32-infer-line-termination (vector n)986 (declare (type (simple-array (unsigned-byte 32) (*)) vector)987 (type index n)988 (optimize (speed 3) (safety 0)))989 (dotimes (i n #\linefeed)990 (let* ((code (aref vector i)))991 (declare (type (unsigned-byte 32) code))992 (if (= code (char-code #\linefeed))993 (return #\linefeed)994 (if (= code (char-code #\return))995 (return #\return))))))996 997 (defun swapped-u32-infer-line-termination (vector n)998 (declare (type (simple-array (unsigned-byte 32) (*)) vector)999 (type index n)1000 (optimize (speed 3) (safety 0)))1001 (dotimes (i n #\linefeed)1002 (let* ((code (%swap-u32 (aref vector i))))1003 (declare (type (unsigned-byte 32) code))1004 (if (= code (char-code #\linefeed))1005 (return #\linefeed)1006 (if (= code (char-code #\return))1007 (return #\return))))))1008 1009 1255 1010 1256 … … 1029 1275 1030 1276 1031 (defun u16-translate-cr-to-lf (vector n)1032 (declare (type (simple-array (unsigned-byte 16) (*)) vector)1277 (defun big-endian-u16-translate-cr-to-lf (vector n) 1278 (declare (type (simple-array (unsigned-byte 8) (*)) vector) 1033 1279 (type index n) 1034 1280 (optimize (speed 3) (safety 0))) 1035 (dotimes (i n t) 1036 (if (= (the (unsigned-byte 16) (aref vector i)) (char-code #\Return)) 1037 (setf (aref vector i) (char-code #\Linefeed))))) 1038 1039 (defun u16-translate-lf-to-cr (vector n) 1040 (declare (type (simple-array (unsigned-byte 16) (*)) vector) 1281 (do* ((i 0 (+ i 2)) 1282 (j 1 (+ j 2))) 1283 ((>= i n) (= i n)) 1284 (declare (type index i j)) 1285 (if (and (= 0 (the (unsigned-byte 8) (aref vector i))) 1286 (= (the (unsigned-byte 8) (aref vector j)) (char-code #\Return))) 1287 (setf (aref vector j) (char-code #\Linefeed))))) 1288 1289 (defun big-endian-u16-translate-lf-to-cr (vector n) 1290 (declare (type (simple-array (unsigned-byte 8) (*)) vector) 1041 1291 (type index n) 1042 1292 (optimize (speed 3) (safety 0))) 1043 (dotimes (i n t) 1044 (if (= (the (unsigned-byte 16) (aref vector i)) (char-code #\Linefeed)) 1045 (setf (aref vector i) (char-code #\Return))))) 1046 1047 (defun u32-translate-cr-to-lf (vector n) 1048 (declare (type (simple-array (unsigned-byte 32) (*)) vector) 1293 (do* ((i 0 (+ i 2)) 1294 (j 1 (+ j 2))) 1295 ((>= i n) (= i n)) 1296 (declare (type index i j)) 1297 (if (and (= 0 (the (unsigned-byte 8) (aref vector i))) 1298 (= (the (unsigned-byte 8) (aref vector j)) (char-code #\Linefeed))) 1299 (setf (aref vector j) (char-code #\Return))))) 1300 1301 (defun big-endian-u32-translate-cr-to-lf (vector n) 1302 (declare (type (simple-array (unsigned-byte 8) (*)) vector) 1049 1303 (type index n) 1050 1304 (optimize (speed 3) (safety 0))) 1051 (dotimes (i n t) 1052 (if (= (the (unsigned-byte 32) (aref vector i)) (char-code #\Return)) 1053 (setf (aref vector i) (char-code #\Linefeed))))) 1054 1055 (defun u32-translate-lf-to-cr (vector n) 1056 (declare (type (simple-array (unsigned-byte 32) (*)) vector) 1305 (do* ((w 0 (+ w 4)) 1306 (x 1 (+ x 4)) 1307 (y 2 (+ y 4)) 1308 (z 3 (+ z 4))) 1309 ((>= w n) (= w n)) 1310 (declare (type index w x y z)) 1311 (if (and (= 0 (the (unsigned-byte 8) (aref vector w))) 1312 (= 0 (the (unsigned-byte 8) (aref vector x))) 1313 (= 0 (the (unsigned-byte 8) (aref vector y))) 1314 (= (the (unsigned-byte 8) (aref vector z)) (char-code #\Return))) 1315 (setf (aref vector z) (char-code #\Linefeed))))) 1316 1317 (defun big-endian-u32-translate-lf-to-cr (vector n) 1318 (declare (type (simple-array (unsigned-byte 8) (*)) vector) 1057 1319 (type index n) 1058 1320 (optimize (speed 3) (safety 0))) 1059 (dotimes (i n t) 1060 (if (= (the (unsigned-byte 32) (aref vector i)) (char-code #\Linefeed)) 1061 (setf (aref vector i) (char-code #\Return))))) 1062 1063 1064 (defun swapped-u16-translate-cr-to-lf (vector n) 1065 (declare (type (simple-array (unsigned-byte 16) (*)) vector) 1321 (do* ((w 0 (+ w 4)) 1322 (x 1 (+ x 4)) 1323 (y 2 (+ y 4)) 1324 (z 3 (+ z 4))) 1325 ((>= w n) (= w n)) 1326 (declare (type index w x y z)) 1327 (if (and (= 0 (the (unsigned-byte 8) (aref vector w))) 1328 (= 0 (the (unsigned-byte 8) (aref vector x))) 1329 (= 0 (the (unsigned-byte 8) (aref vector y))) 1330 (= (the (unsigned-byte 8) (aref vector z)) (char-code #\Linefeed))) 1331 (setf (aref vector z) (char-code #\Return))))) 1332 1333 1334 (defun little-endian-u16-translate-cr-to-lf (vector n) 1335 (declare (type (simple-array (unsigned-byte 8) (*)) vector) 1066 1336 (type index n) 1067 1337 (optimize (speed 3) (safety 0))) 1068 (dotimes (i n t) 1069 (if (= (the (unsigned-byte 16) (aref vector i)) #xd00) 1070 (setf (aref vector i) #xa00)))) 1071 1072 (defun swapped-u16-translate-lf-to-cr (vector n) 1073 (declare (type (simple-array (unsigned-byte 16) (*)) vector) 1338 (do* ((i 0 (+ i 2)) 1339 (j 1 (+ j 2))) 1340 ((>= i n) (= i n)) 1341 (declare (type index i j)) 1342 (if (and (= 0 (the (unsigned-byte 8) (aref vector j))) 1343 (= (the (unsigned-byte 8) (aref vector i)) (char-code #\Return))) 1344 (setf (aref vector i) (char-code #\Linefeed))))) 1345 1346 1347 (defun little-endian-u16-translate-lf-to-cr (vector n) 1348 (declare (type (simple-array (unsigned-byte 8) (*)) vector) 1074 1349 (type index n) 1075 1350 (optimize (speed 3) (safety 0))) 1076 (dotimes (i n t) 1077 (if (= (the (unsigned-byte 16) (aref vector i)) #xa00) 1078 (setf (aref vector i) #xd00)))) 1079 1080 (defun swapped-u32-translate-cr-to-lf (vector n) 1081 (declare (type (simple-array (unsigned-byte 32) (*)) vector) 1351 (do* ((i 0 (+ i 2)) 1352 (j 1 (+ j 2))) 1353 ((>= i n) (= i n)) 1354 (declare (type index i j)) 1355 (if (and (= 0 (the (unsigned-byte 8) (aref vector j))) 1356 (= (the (unsigned-byte 8) (aref vector i)) (char-code #\Linefeed))) 1357 (setf (aref vector i) (char-code #\Return))))) 1358 1359 (defun little-endian-u32-translate-cr-to-lf (vector n) 1360 (declare (type (simple-array (unsigned-byte 8) (*)) vector) 1082 1361 (type index n) 1083 1362 (optimize (speed 3) (safety 0))) 1084 (dotimes (i n t) 1085 (if (= (the (unsigned-byte 32) (aref vector i)) #xd000000) 1086 (setf (aref vector i) #xa000000)))) 1087 1088 (defun swapped-32-translate-lf-to-cr (vector n) 1089 (declare (type (simple-array (unsigned-byte 32) (*)) vector) 1363 (do* ((w 0 (+ w 4)) 1364 (x 1 (+ x 4)) 1365 (y 2 (+ y 4)) 1366 (z 3 (+ z 4))) 1367 ((>= w n) (= w n)) 1368 (declare (type index w x y z)) 1369 (if (and (= (the (unsigned-byte 8) (aref vector w)) (char-code #\Return)) 1370 (= 0 (the (unsigned-byte 8) (aref vector x))) 1371 (= 0 (the (unsigned-byte 8) (aref vector y))) 1372 (= 0 (the (unsigned-byte 8) (aref vector z)))) 1373 (setf (aref vector 2) (char-code #\Linefeed))))) 1374 1375 (defun little-endian-32-translate-lf-to-cr (vector n) 1376 (declare (type (simple-array (unsigned-byte 8) (*)) vector) 1090 1377 (type index n) 1091 1378 (optimize (speed 3) (safety 0))) 1092 (dotimes (i n t) 1093 (if (= (the (unsigned-byte 32) (aref vector i)) #xa000000) 1094 (setf (aref vector i) #xd0000000)))) 1379 (do* ((w 0 (+ w 4)) 1380 (x 1 (+ x 4)) 1381 (y 2 (+ y 4)) 1382 (z 3 (+ z 4))) 1383 ((>= w n) (= w n)) 1384 (declare (type index w x y z)) 1385 (if (and (= (the (unsigned-byte 8) (aref vector w)) (char-code #\Linefeed)) 1386 (= 0 (the (unsigned-byte 8) (aref vector x))) 1387 (= 0 (the (unsigned-byte 8) (aref vector y))) 1388 (= 0 (the (unsigned-byte 8) (aref vector z)))) 1389 (setf (aref vector 2) (char-code #\Return))))) 1095 1390 1096 1391 (declaim (inline %ioblock-force-output)) … … 1280 1575 element)) 1281 1576 1282 (declaim (inline %ioblock-write-swapped-u16-element)) 1283 (defun %ioblock-write-swapped-u16-element (ioblock element) 1284 (declare (optimize (speed 3) (safety 0))) 1577 (declaim (inline %ioblock-write-u16-code-element)) 1578 (defun %ioblock-write-u16-code-element (ioblock element) 1579 (declare (optimize (speed 3) (safety 0)) 1580 (type (unsigned-byte 16) element)) 1285 1581 (let* ((buf (ioblock-outbuf ioblock)) 1286 1582 (idx (io-buffer-idx buf)) 1287 1583 (count (io-buffer-count buf)) 1288 (limit (io-buffer-limit buf))) 1289 (declare (fixnum idx limit count)) 1584 (limit (io-buffer-limit buf)) 1585 (vector (io-buffer-buffer buf)) 1586 (b0 #+big-endian-target (ldb (byte 8 8) element) 1587 #+little-endian-target (ldb (byte 8 0) element)) 1588 (b1 #+big-endian-target (ldb (byte 8 0) element) 1589 #+little-endian-target (ldb (byte 8 8) element))) 1590 (declare (fixnum idx limit count) 1591 (type (simple-array (unsigned-byte 8) (*)) vector) 1592 (type (unsigned-byte 8) b0 b1)) 1593 1290 1594 (when (= idx limit) 1291 1595 (%ioblock-force-output ioblock nil) 1292 1596 (setq idx 0 count 0)) 1293 (setf (aref (the (simple-array (unsigned-byte 16) (*)) 1294 (io-buffer-buffer buf)) idx) 1295 (%swap-u16 element)) 1597 (setf (aref vector idx) b0) 1598 (incf idx) 1599 (when (= idx limit) 1600 (%ioblock-force-output ioblock nil) 1601 (setq idx 0 count 0)) 1602 (setf (aref vector idx) b1) 1603 (incf idx) 1604 (setf (io-buffer-idx buf) idx) 1605 (when (> idx count) 1606 (setf (io-buffer-count buf) idx)) 1607 (setf (ioblock-dirty ioblock) t) 1608 element)) 1609 1610 (declaim (inline %ioblock-write-swapped-u16-code-element)) 1611 (defun %ioblock-write-swapped-u16-code-element (ioblock element) 1612 (declare (optimize (speed 3) (safety 0))) 1613 (let* ((buf (ioblock-outbuf ioblock)) 1614 (idx (io-buffer-idx buf)) 1615 (count (io-buffer-count buf)) 1616 (limit (io-buffer-limit buf)) 1617 (vector (io-buffer-buffer buf)) 1618 (b0 #+big-endian-target (ldb (byte 8 8) element) 1619 #+little-endian-target (ldb (byte 8 0) element)) 1620 (b1 #+big-endian-target (ldb (byte 8 0) element) 1621 #+little-endian-target (ldb (byte 8 8) element))) 1622 (declare (fixnum idx limit count) 1623 (type (simple-array (unsigned-byte 8) (*)) vector) 1624 (type (unsigned-byte 8) b0 b1)) 1625 1626 (when (= idx limit) 1627 (%ioblock-force-output ioblock nil) 1628 (setq idx 0 count 0)) 1629 (setf (aref vector idx) b1) 1630 (incf idx) 1631 (when (= idx limit) 1632 (%ioblock-force-output ioblock nil) 1633 (setq idx 0 count 0)) 1634 (setf (aref vector idx) b0) 1296 1635 (incf idx) 1297 1636 (setf (io-buffer-idx buf) idx) … … 1495 1834 (funcall (ioblock-encode-output-function ioblock) 1496 1835 byte-order-mark 1497 #'%ioblock-write-u16- element1836 #'%ioblock-write-u16-code-element 1498 1837 ioblock)) 1499 1838 (if (eq char #\linefeed) … … 1506 1845 (funcall (ioblock-encode-output-function ioblock) 1507 1846 char 1508 #'%ioblock-write-u16- element1847 #'%ioblock-write-u16-code-element 1509 1848 ioblock)))) 1510 1849 … … 1526 1865 (when (ioblock-pending-byte-order-mark ioblock) 1527 1866 (setf (ioblock-pending-byte-order-mark ioblock) nil) 1528 (%ioblock-write-u16- element ioblock byte-order-mark-char-code))1867 (%ioblock-write-u16-code-element ioblock byte-order-mark-char-code)) 1529 1868 (do* ((i 0 (1+ i)) 1530 1869 (col (ioblock-charpos ioblock)) … … 1541 1880 (incf col)) 1542 1881 (if (< code limit) 1543 (%ioblock-write-u16- element ioblock code)1544 (funcall encode-function char #'%ioblock-write-u16- element ioblock)))))1882 (%ioblock-write-u16-code-element ioblock code) 1883 (funcall encode-function char #'%ioblock-write-u16-code-element ioblock))))) 1545 1884 1546 1885 (declaim (inline %ioblock-write-swapped-u16-encoded-char)) … … 1553 1892 (declare (type (mod #x110000) code)) 1554 1893 (if (< code (the fixnum (ioblock-literal-char-code-limit ioblock))) 1555 (%ioblock-write-swapped-u16- element ioblock code)1894 (%ioblock-write-swapped-u16-code-element ioblock code) 1556 1895 (funcall (ioblock-encode-output-function ioblock) 1557 1896 char 1558 #'%ioblock-write-swapped-u16- element1897 #'%ioblock-write-swapped-u16-code-element 1559 1898 ioblock)))) 1560 1899 … … 1587 1926 (incf col)) 1588 1927 (if (< code limit) 1589 (%ioblock-write-swapped-u16- element ioblock code)1590 (funcall encode-function char #'%ioblock-write-swapped-u16- element ioblock)))))1928 (%ioblock-write-swapped-u16-code-element ioblock code) 1929 (funcall encode-function char #'%ioblock-write-swapped-u16-code-element ioblock))))) 1591 1930 1592 1931 … … 2215 2554 2216 2555 (defun buffer-element-type-for-character-encoding (encoding) 2217 (if encoding 2218 (ecase (character-encoding-code-unit-size encoding) 2219 (8 '(unsigned-byte 8)) 2220 (16 '(unsigned-byte 16)) 2221 (32 '(unsigned-byte 32))) 2222 '(unsigned-byte 8))) 2556 (declare (ignore encoding)) 2557 '(unsigned-byte 8)) 2223 2558 2224 2559 (defun init-stream-ioblock (stream … … 2346 2681 ;;; 2347 2682 (defun ioblock-check-input-bom (ioblock swapped-encoding-name sharing) 2348 ( when (%ioblock-advance ioblock nil); try to read, don't block2349 ( setf (ioblock-pending-byte-order-mark ioblock) nil)2350 (let* ((inbuf (ioblock-inbuf ioblock))2351 (buf (io-buffer-buffer inbuf))2352 (swapped-encoding2353 (and2354 ( case (aref buf 0)2355 (#.byte-order-mark-char-code2356 (setf (io-buffer-idx inbuf) 1)2357 nil)2358 ( #.swapped-byte-order-mark-char-code2359 (setf (io-buffer-idx inbuf) 1)2360 t)2361 (t #+little-endian-target t))2362 (lookup-character-encoding swapped-encoding-name))))2363 (when swapped-encoding2364 (let* ((unit-size (character-encoding-code-unit-size swapped-encoding))2365 (output-p (not (null (ioblock-outbuf ioblock)))))2366 (setf (ioblock-native-byte-order ioblock)2367 (character-encoding-native-endianness swapped-encoding))2368 (ecase unit-size2369 (162370 (setf (ioblock-read-char-when-locked-function ioblock)2371 '%ioblock-read-swapped-u16-encoded-char)2372 (case sharing2373 (:private '%private-ioblock-read-swapped-u16-encoded-char)2374 (:lock '%locked-ioblock-read-swapped-u16-encoded-char)2375 (t '%ioblock-read-swapped-u16-encoded-char))))2376 (when output-p2683 (let* ((n (%ioblock-advance ioblock nil))) ; try to read, don't block 2684 (when n 2685 (setf (ioblock-pending-byte-order-mark ioblock) nil) 2686 (let* ((inbuf (ioblock-inbuf ioblock)) 2687 (unit-size (character-encoding-code-unit-size (ioblock-encoding ioblock))) 2688 (min (ash unit-size -3)) 2689 (buf (io-buffer-buffer inbuf)) 2690 (swapped-encoding 2691 (and 2692 (>= n min) 2693 (case (case unit-size 2694 (16 (logior (ash (aref buf 0) 8) 2695 (aref buf 1))) 2696 (32 (logior (ash (aref buf 0) 24) 2697 (ash (aref buf 1) 16) 2698 (ash (aref buf 2) 8) 2699 (aref buf 3)))) 2700 (#.byte-order-mark-char-code 2701 (setf (io-buffer-idx inbuf) min) 2702 nil) 2703 (#.swapped-byte-order-mark-char-code 2704 (setf (io-buffer-idx inbuf) min) 2705 t) 2706 (t #+little-endian-target t)) 2707 (lookup-character-encoding swapped-encoding-name)))) 2708 (when swapped-encoding 2709 (let* ((output-p (not (null (ioblock-outbuf ioblock))))) 2710 (setf (ioblock-native-byte-order ioblock) 2711 (character-encoding-native-endianness swapped-encoding)) 2377 2712 (ecase unit-size 2378 2713 (16 2379 (setf (ioblock-write-char-when-locked-function ioblock) 2380 '%ioblock-write-swapped-u16-encoded-char) 2381 (case sharing 2382 (:private '%private-ioblock-write-swapped-u16-encoded-char) 2383 (:lock '%locked-ioblock-write-swapped-u16-encoded-char) 2384 (t '%ioblock-write-swapped-u16-encoded-char)) 2385 (setf (ioblock-write-simple-string-function ioblock) 2386 '%ioblock-write-swapped-u8-encoded-simple-string))))))))) 2714 (setf (ioblock-read-char-when-locked-function ioblock) 2715 '%ioblock-read-swapped-u16-encoded-char) 2716 (case sharing 2717 (:private '%private-ioblock-read-swapped-u16-encoded-char) 2718 (:lock '%locked-ioblock-read-swapped-u16-encoded-char) 2719 (t '%ioblock-read-swapped-u16-encoded-char)))) 2720 (when output-p 2721 (ecase unit-size 2722 (16 2723 (setf (ioblock-write-char-when-locked-function ioblock) 2724 '%ioblock-write-swapped-u16-encoded-char) 2725 (case sharing 2726 (:private '%private-ioblock-write-swapped-u16-encoded-char) 2727 (:lock '%locked-ioblock-write-swapped-u16-encoded-char) 2728 (t '%ioblock-write-swapped-u16-encoded-char)) 2729 (setf (ioblock-write-simple-string-function ioblock) 2730 '%ioblock-write-swapped-u8-encoded-simple-string)))))))))) 2387 2731 2388 2732
Note:
See TracChangeset
for help on using the changeset viewer.
