|
1 | 1 | (in-package :serapeum)
|
2 | 2 |
|
| 3 | +(defmacro with-open-files ((&rest args) &body body) |
| 4 | + "A simple macro to open one or more files providing the streams for the BODY. The ARGS is a list of `(stream filespec options*)` as supplied to WITH-OPEN-FILE." |
| 5 | + (case (length args) |
| 6 | + ((0) |
| 7 | + `(progn ,@body)) |
| 8 | + ((1) |
| 9 | + `(with-open-file ,(first args) ,@body)) |
| 10 | + (t `(with-open-file ,(first args) |
| 11 | + (with-open-files |
| 12 | + ,(rest args) ,@body))))) |
| 13 | + |
3 | 14 | (defun path-join (&rest pathnames)
|
4 | 15 | "Build a pathname by merging from right to left.
|
5 | 16 | With `path-join' you can pass the elements of the pathname being built
|
@@ -93,19 +104,19 @@ as vectors."
|
93 | 104 | :element-type 'octet
|
94 | 105 | :initial-element 0)))
|
95 | 106 | (declare (inline make-buffer))
|
96 |
| - (with-input-from-file (file1 file1 :element-type 'octet) |
97 |
| - (with-input-from-file (file2 file2 :element-type 'octet) |
98 |
| - (and (= (file-length file1) |
99 |
| - (file-length file2)) |
100 |
| - (loop with buffer1 = (make-buffer) |
101 |
| - with buffer2 = (make-buffer) |
102 |
| - for end1 = (read-sequence buffer1 file1) |
103 |
| - for end2 = (read-sequence buffer2 file2) |
104 |
| - until (or (zerop end1) (zerop end2)) |
105 |
| - always (and (= end1 end2) |
106 |
| - (octet-vector= buffer1 buffer2 |
107 |
| - :end1 end1 |
108 |
| - :end2 end2)))))))) |
| 107 | + (with-open-files ((file1 file1 :element-type 'octet :direction :input) |
| 108 | + (file2 file2 :element-type 'octet :direction :input)) |
| 109 | + (and (= (file-length file1) |
| 110 | + (file-length file2)) |
| 111 | + (loop with buffer1 = (make-buffer) |
| 112 | + with buffer2 = (make-buffer) |
| 113 | + for end1 = (read-sequence buffer1 file1) |
| 114 | + for end2 = (read-sequence buffer2 file2) |
| 115 | + until (or (zerop end1) (zerop end2)) |
| 116 | + always (and (= end1 end2) |
| 117 | + (octet-vector= buffer1 buffer2 |
| 118 | + :end1 end1 |
| 119 | + :end2 end2))))))) |
109 | 120 |
|
110 | 121 | (defun file-size (file &key (element-type '(unsigned-byte 8)))
|
111 | 122 | "The size of FILE, in units of ELEMENT-TYPE (defaults to bytes).
|
@@ -203,16 +214,3 @@ Inspired by the function of the same name in Emacs."
|
203 | 214 | :flavor flavor
|
204 | 215 | :suffix suffix
|
205 | 216 | :space space)))
|
206 |
| - |
207 |
| -(defmacro with-open-files ((&rest args) &body body) |
208 |
| - "A simple macro to open one or more files providing the streams for the BODY. The ARGS is a list of `(stream filespec options*)` as supplied to WITH-OPEN-FILE." |
209 |
| - (case (length args) |
210 |
| - ((0) |
211 |
| - `(progn ,@body)) |
212 |
| - ((1) |
213 |
| - `(with-open-file ,(first args) ,@body)) |
214 |
| - (t `(with-open-file ,(first args) |
215 |
| - (with-open-files |
216 |
| - ,(rest args) ,@body))))) |
217 |
| - |
218 |
| - |
0 commit comments