Changed license terms to the plain LGPL thru-out.
[bpt/guile.git] / ice-9 / lineio.scm
index 28e4a65..aa7d91b 100644 (file)
@@ -1,25 +1,28 @@
 ;;; installed-scm-file
 
-;;;;   Copyright (C) 1996 Free Software Foundation, Inc.
+;;;;   Copyright (C) 1996, 1998, 2001 Free Software Foundation, Inc.
 ;;;; 
-;;;; This program is free software; you can redistribute it and/or modify
-;;;; it under the terms of the GNU General Public License as published by
-;;;; the Free Software Foundation; either version 2, or (at your option)
-;;;; any later version.
+;;;; This library is free software; you can redistribute it and/or
+;;;; modify it under the terms of the GNU Lesser General Public
+;;;; License as published by the Free Software Foundation; either
+;;;; version 2.1 of the License, or (at your option) any later version.
 ;;;; 
-;;;; This program is distributed in the hope that it will be useful,
+;;;; 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 General Public License for more details.
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;;;; Lesser General Public License for more details.
 ;;;; 
-;;;; You should have received a copy of the GNU General Public License
-;;;; along with this software; see the file COPYING.  If not, write to
-;;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;;;; You should have received a copy of the GNU Lesser 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
 ;;;; 
 
 \f
 
-(define-module #/ice-9/lineio)
+(define-module (ice-9 lineio)
+  :use-module (ice-9 readline)
+  :export (unread-string read-string lineio-port?
+          make-line-buffering-input-port))
 
 \f
 ;;; {Line Buffering Input Ports}
 ;;;
 ;;;    read-string     which returns the next line of input
 ;;;    unread-string   which pushes a line back onto the stream
+;;; 
+;;; The implementation of unread-string is kind of limited; it doesn't
+;;; interact properly with unread-char, or any of the other port
+;;; reading functions.  Only read-string will get you back the things that
+;;; unread-string accepts.
 ;;;
 ;;; Normally a "line" is all characters up to and including a newline.
 ;;; If lines are put back using unread-string, they can be broken arbitrarily
 ;; 'unread-string and 'read-string properties, bound to hooks
 ;; implementing these functions.
 ;;
-(define-public (unread-string str line-buffering-input-port)
+(define (unread-string str line-buffering-input-port)
   ((object-property line-buffering-input-port 'unread-string) str))
 
 ;;
-(define-public (read-string line-buffering-input-port)
+(define (read-string line-buffering-input-port)
   ((object-property line-buffering-input-port 'read-string)))
 
 
-(define-public (lineio-port? port)
+(define (lineio-port? port)
   (not (not (object-property port 'read-string))))
 
 ;; make-line-buffering-input-port port
@@ -65,7 +73,7 @@
 ;; to read-char, read-string, and unread-string.
 ;;
 
-(define-public (make-line-buffering-input-port underlying-port)
+(define (make-line-buffering-input-port underlying-port)
   (let* (;; buffers - a list of strings put back by unread-string or cached
         ;; using read-line.
         ;;
@@ -80,7 +88,7 @@
                     (let ((c (string-ref (car buffers))))
                       (if (= 1 (string-length (car buffers)))
                           (set! buffers (cdr buffers))
-                          (set-car! buffers (make-shared-substring (car buffers) 1)))
+                          (set-car! buffers (substring (car buffers) 1)))
                       c))))
 
         (propogate-close (lambda () (close-port underlying-port)))
@@ -89,9 +97,7 @@
 
         (unread-string (lambda (str)
                          (and (< 0 (string-length str))
-                              (if (ungetc-char-ready? self)
-                                  (set! buffers (append! (list str (string (read-char self))) buffers))
-                                  (set! buffers (cons str buffers))))))
+                                  (set! buffers (cons str buffers)))))
 
         (read-string (lambda ()
                       (cond
                         (let ((answer (car buffers)))
                           (set! buffers (cdr buffers))
                           answer))
-                       ((ungetc-char-ready? self)
-                        (read-line self 'include-newline))
                        (else
-                        (read-line underlying-port 'include-newline))))))
+                        (read-line underlying-port 'concat)))))) ;handle-newline->concat
 
     (set-object-property! self 'unread-string unread-string)
     (set-object-property! self 'read-string read-string)