Coverage report: /home/ellis/.stash/quicklisp/dists/ultralisp/software/edicl-flexi-streams-20240429143708/output.lisp
Kind | Covered | All | % |
expression | 0 | 88 | 0.0 |
branch | 0 | 8 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: FLEXI-STREAMS; Base: 10 -*-
2
;;; $Header: /usr/local/cvsrep/flexi-streams/output.lisp,v 1.65 2008/05/24 23:15:25 edi Exp $
4
;;; Copyright (c) 2005-2008, Dr. Edmund Weitz. All rights reserved.
6
;;; Redistribution and use in source and binary forms, with or without
7
;;; modification, are permitted provided that the following conditions
10
;;; * Redistributions of source code must retain the above copyright
11
;;; notice, this list of conditions and the following disclaimer.
13
;;; * Redistributions in binary form must reproduce the above
14
;;; copyright notice, this list of conditions and the following
15
;;; disclaimer in the documentation and/or other materials
16
;;; provided with the distribution.
18
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
19
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
(in-package :flexi-streams)
32
(defgeneric write-byte* (byte stream)
33
(declare #.*standard-optimize-settings*)
34
(:documentation "Writes one byte \(octet) to the underlying stream
38
(defmethod write-byte* (byte (flexi-output-stream flexi-output-stream))
39
(declare #.*standard-optimize-settings*)
40
(with-accessors ((stream flexi-stream-stream))
42
(write-byte byte stream)))
45
(defmethod write-byte* (byte (flexi-output-stream flexi-output-stream))
46
(declare #.*standard-optimize-settings*)
47
(with-accessors ((stream flexi-stream-stream))
49
(write-byte byte stream)))
52
(defmethod write-byte* (byte (flexi-output-stream flexi-char-output-stream))
53
"This method is only used for LispWorks bivalent streams which
55
(declare #.*standard-optimize-settings*)
56
;; we use WRITE-SEQUENCE because WRITE-BYTE doesn't work with all
57
;; bivalent streams in LispWorks (4.4.6)
58
(with-accessors ((stream flexi-stream-stream))
60
(write-sequence (make-array 1 :element-type 'octet
61
:initial-element byte)
65
(defmethod stream-write-char ((stream flexi-output-stream) char)
66
(declare #.*standard-optimize-settings*)
67
(with-accessors ((external-format flexi-stream-external-format))
69
(flet ((writer (octet)
70
(write-byte* octet stream)))
71
(declare (dynamic-extent (function writer)))
72
(char-to-octets external-format char #'writer))))
74
(defmethod stream-write-char :after ((stream flexi-output-stream) char)
75
(declare #.*standard-optimize-settings*)
76
;; update the column unless we're in the middle of the line and
77
;; the current value is NIL
78
(with-accessors ((column flexi-stream-column))
80
(cond ((char= char #\Newline) (setq column 0))
81
(column (incf (the integer column))))))
83
(defmethod stream-clear-output ((flexi-output-stream flexi-output-stream))
84
"Simply calls the corresponding method for the underlying
86
(declare #.*standard-optimize-settings*)
87
(with-accessors ((stream flexi-stream-stream))
89
(clear-output stream)))
91
(defmethod stream-finish-output ((flexi-output-stream flexi-output-stream))
92
"Simply calls the corresponding method for the underlying
94
(declare #.*standard-optimize-settings*)
95
(with-accessors ((stream flexi-stream-stream))
97
(finish-output stream)))
99
(defmethod stream-force-output ((flexi-output-stream flexi-output-stream))
100
"Simply calls the corresponding method for the underlying
102
(declare #.*standard-optimize-settings*)
103
(with-accessors ((stream flexi-stream-stream))
105
(force-output stream)))
107
(defmethod stream-line-column ((flexi-output-stream flexi-output-stream))
108
"Returns the column stored in the COLUMN slot of the
109
FLEXI-OUTPUT-STREAM object STREAM."
110
(declare #.*standard-optimize-settings*)
111
(with-accessors ((column flexi-stream-column))
115
(defmethod stream-write-byte ((flexi-output-stream flexi-output-stream) byte)
116
"Writes a byte \(octet) to the underlying stream."
117
(declare #.*standard-optimize-settings*)
118
(with-accessors ((column flexi-stream-column))
120
;; set column to NIL because we don't know how to handle binary
121
;; output mixed with character output
123
(write-byte* byte flexi-output-stream)))
126
(defmethod stream-terpri ((stream flexi-output-stream))
127
"Writes a #\Newline character to the underlying stream."
128
(declare #.*standard-optimize-settings*)
129
;; needed for AllegroCL - grrr...
130
(stream-write-char stream #\Newline))
132
(defmethod stream-write-sequence ((flexi-output-stream flexi-output-stream) sequence start end &key)
133
"An optimized version which uses a buffer underneath. The function
134
can accepts characters as well as octets and it decides what to do
135
based on the element type of the sequence \(if possible) or on the
136
individual elements, i.e. you can mix characters and octets in
137
SEQUENCE if you want. Whether that really works might also depend on
138
your Lisp, some of the implementations are more picky than others."
139
(declare #.*standard-optimize-settings*)
140
(declare (fixnum start end))
141
(with-accessors ((column flexi-stream-column)
142
(external-format flexi-stream-external-format)
143
(stream flexi-stream-stream))
146
(return-from stream-write-sequence sequence))
147
(when (and (vectorp sequence)
148
(subtypep (array-element-type sequence) 'integer))
149
;; if this is pure binary output, just send all the stuff to the
150
;; underlying stream directly and skip the rest
152
(return-from stream-write-sequence
153
(write-sequence sequence stream :start start :end end)))
154
;; otherwise hand over to the external format to do the work
155
(write-sequence* external-format flexi-output-stream sequence start end))
158
(defmethod stream-write-string ((stream flexi-output-stream) string
159
&optional (start 0) (end (length string)))
160
"Simply hands over to the optimized method for STREAM-WRITE-SEQUENCE."
161
(declare #.*standard-optimize-settings*)
162
(stream-write-sequence stream string start (or end (length string))))