io.lisp 1.49 KB
Newer Older
1
2
3
;;; -*- Mode: Lisp; Package: CLIMACS-BUFFER -*-

;;;  (c) copyright 2004 by
strandh's avatar
strandh committed
4
;;;           Robert Strandh (strandh@labri.fr)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library General Public
;;; License along with this library; if not, write to the
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;;; Boston, MA  02111-1307  USA.

;;; Input/Output of buffers to and from streams.

(in-package :climacs-base)

(defun input-from-stream (stream buffer offset)
26
27
28
29
30
31
32
33
  (loop with vec = (make-array 10000 :element-type 'character)
	for count = (read-sequence vec stream)
	while (plusp count)
	do (if (= count (length vec))
	       (insert-buffer-sequence buffer offset vec)
	       (insert-buffer-sequence buffer offset
				       (subseq vec 0 count)))
	   (incf offset count)))
34
35
36
37
38

(defun output-to-stream (stream buffer offset1 offset2)
  (loop for offset from offset1 below offset2
	when (characterp (buffer-object buffer offset))
	  do (write-char (buffer-object buffer offset) stream)))