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

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

;;; 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.

25
26
27
28
29
(in-package :climacs-core)

(defmethod save-buffer-to-stream ((buffer climacs-buffer) stream)
  (let ((seq (buffer-sequence buffer 0 (size buffer))))
    (write-sequence seq stream)))
30
31

(defun input-from-stream (stream buffer offset)
32
33
34
  (let* ((seq (make-string (file-length stream)))
         (count (#+mcclim read-sequence #-mcclim cl:read-sequence
                          seq stream)))
35
36
37
38
    (insert-buffer-sequence buffer offset
                            (if (= count (length seq))
                                seq
                                (subseq seq 0 count)))))
39

40
41
42
43
(defmethod make-buffer-from-stream (stream (application-frame climacs))
  (let* ((buffer (make-new-buffer application-frame)))
    (input-from-stream stream buffer 0)
    buffer))