1996-07-25 22:56:11 +00:00
|
|
|
|
;;; installed-scm-file
|
|
|
|
|
|
|
2006-04-16 23:43:48 +00:00
|
|
|
|
;;;; Copyright (C) 1996, 1998, 2001, 2003, 2006 Free Software Foundation, Inc.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; 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
|
2009-06-17 00:22:09 +01:00
|
|
|
|
;;;; version 3 of the License, or (at your option) any later version.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; This library is distributed in the hope that it will be useful,
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
;;;; Lesser General Public License for more details.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License along with this library; if not, write to the Free Software
|
2005-05-23 19:57:22 +00:00
|
|
|
|
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-01-21 22:11:29 +00:00
|
|
|
|
(define-module (ice-9 lineio)
|
2009-08-18 17:52:46 +02:00
|
|
|
|
:use-module (ice-9 rdelim)
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
:export (unread-string read-string lineio-port?
|
|
|
|
|
|
make-line-buffering-input-port))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; {Line Buffering Input Ports}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; [This is a work-around to get past certain deficiencies in the capabilities
|
|
|
|
|
|
;;; of ports. Eventually, ports should be fixed and this module nuked.]
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; A line buffering input port supports:
|
|
|
|
|
|
;;;
|
|
|
|
|
|
;;; read-string which returns the next line of input
|
|
|
|
|
|
;;; unread-string which pushes a line back onto the stream
|
1998-07-19 04:29:08 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; 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.
|
1996-07-25 22:56:11 +00:00
|
|
|
|
;;;
|
|
|
|
|
|
;;; 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
|
|
|
|
|
|
;;; -- that is, read-string returns strings passed to unread-string (or
|
|
|
|
|
|
;;; shared substrings of them).
|
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
;; read-string port
|
|
|
|
|
|
;; unread-string port str
|
|
|
|
|
|
;; Read (or buffer) a line from PORT.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; Not all ports support these functions -- only those with
|
|
|
|
|
|
;; 'unread-string and 'read-string properties, bound to hooks
|
|
|
|
|
|
;; implementing these functions.
|
|
|
|
|
|
;;
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
(define (unread-string str line-buffering-input-port)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
((object-property line-buffering-input-port 'unread-string) str))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
(define (read-string line-buffering-input-port)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
((object-property line-buffering-input-port 'read-string)))
|
|
|
|
|
|
|
|
|
|
|
|
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
(define (lineio-port? port)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(not (not (object-property port 'read-string))))
|
|
|
|
|
|
|
|
|
|
|
|
;; make-line-buffering-input-port port
|
|
|
|
|
|
;; Return a wrapper for PORT. The wrapper handles read-string/unread-string.
|
|
|
|
|
|
;;
|
|
|
|
|
|
;; The port returned by this function reads newline terminated lines from PORT.
|
|
|
|
|
|
;; It buffers these characters internally, and parsels them out via calls
|
|
|
|
|
|
;; to read-char, read-string, and unread-string.
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
* lib.scm: Move module the system directives `export',
`export-syntax', `re-export' and `re-export-syntax' into the
`define-module' form. This is the recommended way of exporting
bindings.
* srfi-2.scm, srfi-4.scm, srfi-8.scm, srfi-9.scm, srfi-10.scm,
srfi-11.scm, srfi-14.scm, srfi-16.scm: Move module the system
directives `export', `export-syntax', `re-export' and
`re-export-syntax' into the `define-module' form. This is the
recommended way of exporting bindings.
* goops.scm, goops/active-slot.scm, goops/compile.scm,
goops/composite-slot.scm, goops/describe.scm, goops/dispatch.scm,
goops/old-define-method.scm, goops/save.scm, goops/util.scm: Move
module the system directives `export', `export-syntax',
`re-export' and `re-export-syntax' into the `define-module' form.
This is the recommended way of exporting bindings.
* slib.scm (array-indexes): New procedure.
(*features*): Extend. (Probably some of these options should be
set elsewhere.) (Thanks to Aubrey Jaffer.)
* and-let-star-compat.scm, and-let-star.scm, calling.scm,
channel.scm, common-list.scm, debug.scm, debugger.scm,
expect.scm, hcons.scm, lineio.scm, ls.scm, mapping.scm,
null.scm, optargs.scm, poe.scm, popen.scm, pretty-print.scm,
q.scm, r5rs.scm, rdelim.scm, regex.scm, runq.scm, safe-r5rs.scm,
safe.scm, session.scm, slib.scm, streams.scm, string-fun.scm,
syncase.scm, threads.scm: Move module the system directives
`export', `export-syntax', `re-export' and `re-export-syntax'
into the `define-module' form. This is the recommended way of
exporting bindings.
2001-10-21 09:49:19 +00:00
|
|
|
|
(define (make-line-buffering-input-port underlying-port)
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(let* (;; buffers - a list of strings put back by unread-string or cached
|
|
|
|
|
|
;; using read-line.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(buffers '())
|
|
|
|
|
|
|
|
|
|
|
|
;; getc - return the next character from a buffer or from the underlying
|
|
|
|
|
|
;; port.
|
|
|
|
|
|
;;
|
|
|
|
|
|
(getc (lambda ()
|
|
|
|
|
|
(if (not buffers)
|
|
|
|
|
|
(read-char underlying-port)
|
2003-05-03 20:24:22 +00:00
|
|
|
|
(let ((c (string-ref (car buffers) 0)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
(if (= 1 (string-length (car buffers)))
|
|
|
|
|
|
(set! buffers (cdr buffers))
|
2000-11-28 13:40:40 +00:00
|
|
|
|
(set-car! buffers (substring (car buffers) 1)))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
c))))
|
|
|
|
|
|
|
|
|
|
|
|
(propogate-close (lambda () (close-port underlying-port)))
|
|
|
|
|
|
|
|
|
|
|
|
(self (make-soft-port (vector #f #f #f getc propogate-close) "r"))
|
|
|
|
|
|
|
|
|
|
|
|
(unread-string (lambda (str)
|
|
|
|
|
|
(and (< 0 (string-length str))
|
1998-07-19 04:29:08 +00:00
|
|
|
|
(set! buffers (cons str buffers)))))
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(read-string (lambda ()
|
|
|
|
|
|
(cond
|
1997-01-08 01:27:12 +00:00
|
|
|
|
((not (null? buffers))
|
|
|
|
|
|
(let ((answer (car buffers)))
|
|
|
|
|
|
(set! buffers (cdr buffers))
|
|
|
|
|
|
answer))
|
|
|
|
|
|
(else
|
1998-07-19 04:29:08 +00:00
|
|
|
|
(read-line underlying-port 'concat)))))) ;handle-newline->concat
|
1996-07-25 22:56:11 +00:00
|
|
|
|
|
|
|
|
|
|
(set-object-property! self 'unread-string unread-string)
|
|
|
|
|
|
(set-object-property! self 'read-string read-string)
|
|
|
|
|
|
self))
|
|
|
|
|
|
|
|
|
|
|
|
|