Eliminate last few style-warnings in make-host-2
[sbcl.git] / contrib / sb-simple-streams / string.lisp
blob3b85a2b0e21ac653364512cdb660022b36b1e49c
1 ;;; -*- lisp -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written by Paul Foley and has been placed in the public
5 ;;; domain.
6 ;;;
8 ;;; Sbcl port by Rudi Schlatte.
10 (in-package "SB-SIMPLE-STREAMS")
12 ;;;
13 ;;; **********************************************************************
14 ;;;
15 ;;; String-Simple-Stream and relatives
17 (def-stream-class string-input-simple-stream (string-simple-stream)
18 ())
20 (def-stream-class string-output-simple-stream (string-simple-stream)
21 ((out-buffer :initform nil :type (or simple-stream-buffer null))
22 (outpos :initform 0 :type fixnum)
23 (max-out-pos :initform 0 :type fixnum)))
25 (def-stream-class composing-stream (string-simple-stream)
26 ())
28 (def-stream-class fill-pointer-output-simple-stream
29 (string-output-simple-stream)
30 ())
32 (def-stream-class xp-simple-stream (string-output-simple-stream)
33 ())
35 (def-stream-class annotation-output-simple-stream (string-output-simple-stream)
36 ())
38 (defmethod device-open :before ((stream string-input-simple-stream) options)
39 ;; Taken with permission from ftp://ftp.franz.com/pub/duane/Simp-stms.ppt
40 (with-stream-class (string-input-simple-stream stream)
41 (let ((string (getf options :string)))
42 (when (and string (null (sm buffer stream)))
43 (let ((start (getf options :start))
44 (end (or (getf options :end) (length string))))
45 (setf (sm buffer stream) string
46 (sm buffpos stream) start
47 (sm buffer-ptr stream) end))))
48 (install-string-input-character-strategy stream)
49 (add-stream-instance-flags stream :string :input :simple)))
51 (defmethod device-open :before ((stream string-output-simple-stream) options)
52 ;; Taken with permission from ftp://ftp.franz.com/pub/duane/Simp-stms.ppt
53 (with-stream-class (string-output-simple-stream stream)
54 (unless (sm out-buffer stream)
55 (let ((string (getf options :string)))
56 (if string
57 (setf (sm out-buffer stream) string
58 (sm max-out-pos stream) (length string))
59 (let ((buflen (max (device-buffer-length stream) 16)))
60 (setf (sm out-buffer stream) (make-string buflen)
61 (sm max-out-pos stream) buflen)))))
62 (unless (sm control-out stream)
63 (setf (sm control-out stream) *std-control-out-table*))
64 (install-string-output-character-strategy stream)
65 (add-stream-instance-flags stream :string :output :simple)))
67 (defmethod device-open ((stream string-simple-stream) options)
68 (declare (ignore options))
69 (with-stream-class (string-simple-stream stream)
70 (if (and (any-stream-instance-flags stream :simple)
71 (any-stream-instance-flags stream :input :output))
73 nil)))
75 (defmethod device-file-position ((stream string-simple-stream))
76 (with-stream-class (simple-stream stream)
77 (sm buffpos stream)))
79 (defmethod (setf device-file-position) (value (stream string-simple-stream))
80 (with-stream-class (simple-stream stream)
81 (cond ((or (> value (sm buffer-ptr stream))
82 (< value (- -1 (sm buffer-ptr stream))))
83 nil)
84 ((>= value 0)
85 (setf (sm buffpos stream) value)
88 (setf (sm buffpos stream) (+ (sm buffer-ptr stream) value 1))
89 t))))
91 (defmethod device-file-length ((stream string-simple-stream))
92 (with-stream-class (simple-stream stream)
93 (sm buffer-ptr stream)))
95 (defmethod device-open ((stream fill-pointer-output-simple-stream) options)
96 #| do something |#
97 stream)
99 (defmethod device-file-position ((stream fill-pointer-output-simple-stream))
100 (with-stream-class (fill-pointer-output-simple-stream stream)
101 (fill-pointer (sm out-buffer stream))))
103 (defmethod (setf device-file-position)
104 (value (stream fill-pointer-output-simple-stream))
105 (with-stream-class (fill-pointer-output-simple-stream stream)
106 (let ((buffer (sm out-buffer stream)))
107 (cond ((or (> value (array-total-size buffer))
108 (< value (- -1 (array-total-size buffer))))
109 nil)
110 ((>= value 0)
111 (setf (fill-pointer buffer) value))
113 (setf (fill-pointer buffer)
114 (+ (array-total-size buffer) value 1)))))))
116 (defmethod device-open ((stream xp-simple-stream) options)
117 #| do something |#
118 stream)