1 ;;;;------------------------------------------------------------------
3 ;;;; Copyright (C) 2001, 2003-2004,
4 ;;;; Department of Computer Science, University of Tromso, Norway.
6 ;;;; For distribution policy, see the accompanying file COPYING.
8 ;;;; Filename: streams.lisp
9 ;;;; Description: Basic I/O streams code.
10 ;;;; Author: Frode Vatvedt Fjeld <frodef@acm.org>
11 ;;;; Created at: Mon Jun 30 14:33:15 2003
13 ;;;; $Id: streams.lisp,v 1.5 2006/04/10 11:57:24 ffjeld Exp $
15 ;;;;------------------------------------------------------------------
17 (require :muerte
/basic-macros
)
18 (require :muerte
/los-closette
)
19 (provide :muerte
/streams
)
23 (defgeneric stream-write-char
(stream character
)
24 (:no-clos-fallback stream-no-clos
))
26 (defmethod stream-write-char ((stream string
) character
)
27 (vector-push-extend character stream
)
30 (defmethod stream-write-char ((stream function
) character
)
31 (funcall stream
'stream-write-char character
))
33 (defgeneric stream-read-char
(stream)
34 (:no-clos-fallback stream-no-clos
))
36 (defmethod stream-read-char ((stream function
))
37 (funcall stream
'stream-read-char
))
39 (defun output-stream-designator (d)
41 ((eq nil d
) *standard-output
*)
42 ((eq t d
) *terminal-io
*)
45 (defun input-stream-designator (d)
47 ((eq nil d
) *standard-input
*)
48 ((eq t d
) *terminal-io
*)
51 (defun install-streams-printing (&optional
(new-stdout (make-instance 'muerte.x86-pc
::vga-text-console
)))
52 ;; (check-type new-stdout stream)
54 (setf *standard-output
* s
61 (defgeneric stream-write-string
(stream string
&optional start end
)
62 (:no-clos-fallback
:unspecialized-method
))
64 (defmethod stream-write-string (stream string
&optional
(start 0) (end (length string
)))
65 (with-subvector-accessor (string-ref string start end
)
66 (do ((i start
(1+ i
)))
68 (stream-write-char stream
(string-ref i
))))
71 (defgeneric stream-write-escaped-string
(stream string escaped-char
&optional start end
)
72 (:no-clos-fallback
:unspecialized-method
))
74 (defmethod stream-write-escaped-string (stream string escaped-char
75 &optional
(start 0) (end (length string
)))
76 (stream-write-char stream escaped-char
)
77 (with-subvector-accessor (string-ref string start end
)
78 (do ((i start
(1+ i
)))
80 (let ((c (string-ref i
)))
81 (when (or (eql c escaped-char
) (char= c
#\\))
82 (stream-write-char stream
#\\))
83 (stream-write-char stream c
))))
84 (stream-write-char stream escaped-char
)
87 (defgeneric stream-fresh-line
(stream)
88 (:no-clos-fallback stream-no-clos
))
90 (defmethod stream-fresh-line (stream)
91 (stream-write-char stream
#\Newline
)
94 (defmethod stream-fresh-line ((stream function
))
95 (funcall stream
'stream-fresh-line
))
97 (defun stream-no-clos (stream &rest args
)
98 (declare (dynamic-extent args
))
101 (case (funobj-name *forward-generic-function
*)
103 (vector-push-extend (car args
) stream
)
106 (vector-push-extend #\newline stream
)
109 (apply stream
(funobj-name *forward-generic-function
*) args
))))
115 (defun read-char (&optional input-stream
(eof-error-p t
) eof-value recursive-p
)
117 (%read-char
(input-stream-designator input-stream
) eof-error-p eof-value recursive-p t
))
119 (defun read-key (&optional input-stream
(eof-error-p t
) eof-value recursive-p
)
120 " => char, symbol, etc."
121 (%read-key
(input-stream-designator input-stream
) eof-error-p eof-value recursive-p t
))
123 (defun finish-output (&optional stream
)
124 "finish-output attempts to ensure that any buffered output sent to output-stream has reached its
125 destination, and then returns."
126 (let ((stream (output-stream-designator stream
)))
130 (%finish-output stream
)))))