Implement procedures READ-STRING! and READ-LINE.
#| -*-Scheme-*-
-$Id: chrset.scm,v 14.4 1995/11/07 04:39:57 adams Exp $
+$Id: chrset.scm,v 14.5 1997/02/21 05:42:22 cph Exp $
-Copyright (c) 1988-1995 Massachusetts Institute of Technology
+Copyright (c) 1988-97 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
(= (string-length object) 256)
(not (string-find-next-char-in-set object char-set:not-01))))
-(define char-set:not-01)
-
(define (char-set . chars)
(chars->char-set chars))
(define char-set:alphabetic)
(define char-set:alphanumeric)
(define char-set:standard)
+(define char-set:not-01)
+(define char-set:newline)
(define (initialize-package!)
(set! char-set:upper-case (ascii-range->char-set #x41 #x5B))
(char-set-union char-set:alphabetic char-set:numeric))
(set! char-set:standard
(char-set-union char-set:graphic (char-set char:newline)))
- (set! char-set:not-01 (ascii-range->char-set #x02 #x100)))
+ (set! char-set:not-01 (ascii-range->char-set #x02 #x100))
+ (set! char-set:newline (char-set char:newline))
+ unspecific)
(define-integrable (char-upper-case? char)
(char-set-member? char-set:upper-case char))
#| -*-Scheme-*-
-$Id: input.scm,v 14.16 1993/10/21 11:49:45 cph Exp $
+$Id: input.scm,v 14.17 1997/02/21 05:42:32 cph Exp $
-Copyright (c) 1988-93 Massachusetts Institute of Technology
+Copyright (c) 1988-97 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
(define (input-port/discard-chars port delimiters)
((input-port/operation/discard-chars port) port delimiters))
+(define (input-port/read-substring! port string start end)
+ ((input-port/operation/read-substring port) port string start end))
+
+(define (input-port/read-string! port string)
+ (input-port/read-substring! port string 0 (string-length string)))
+
+(define (input-port/read-line port)
+ (let ((line (input-port/read-string port char-set:newline)))
+ ;; Discard delimiter, if any -- this is a no-op at EOF.
+ (input-port/discard-char port)
+ line))
+
(define eof-object
"EOF Object")
(guarantee-input-port port))
(if (default-object? parser-table)
(current-parser-table)
- parser-table)))
\ No newline at end of file
+ parser-table)))
+
+(define (read-line #!optional port)
+ (input-port/read-line (if (default-object? port)
+ (current-input-port)
+ (guarantee-input-port port))))
+
+(define (read-string! string #!optional start end port)
+ (input-port/read-substring! string
+ (if (default-object? start)
+ 0
+ start)
+ (if (default-object? end)
+ (string-length string)
+ end)
+ (if (default-object? port)
+ (current-input-port)
+ (guarantee-input-port port))))
\ No newline at end of file
#| -*-Scheme-*-
-$Id: port.scm,v 1.8 1994/08/15 19:14:15 cph Exp $
+$Id: port.scm,v 1.9 1997/02/21 05:42:40 cph Exp $
-Copyright (c) 1991-94 Massachusetts Institute of Technology
+Copyright (c) 1991-97 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
DISCARD-CHAR
READ-STRING
DISCARD-CHARS
+ READ-SUBSTRING
;; output operations:
WRITE-CHAR
WRITE-STRING
(define input-port/operation/discard-chars
(record-accessor port-rtd 'DISCARD-CHARS))
+(define input-port/operation/read-substring
+ (record-accessor port-rtd 'READ-SUBSTRING))
+
(define output-port/operation/write-char
(record-accessor port-rtd 'WRITE-CHAR))
(define output-port/operation/discretionary-flush
(record-accessor port-rtd 'DISCRETIONARY-FLUSH-OUTPUT))
-
+\f
(set-record-type-unparser-method! port-rtd
(lambda (state port)
((let ((name
(standard-unparser-method name #f))))
state
port)))
-\f
+
(define (port/copy port state)
(let ((port (record-copy port)))
(set-port/state! port state)
(define install-input-operations!
(let ((operation-names
'(CHAR-READY? PEEK-CHAR READ-CHAR
- DISCARD-CHAR READ-STRING DISCARD-CHARS)))
+ DISCARD-CHAR READ-STRING DISCARD-CHARS READ-SUBSTRING)))
(let ((updaters
(map (lambda (name)
(record-updater port-rtd name))
false
(caddr operations)
default-operation/read-string
- default-operation/discard-chars)
+ default-operation/discard-chars
+ default-operation/read-substring)
operation-names)
(set-port/operation-names!
port
(for-each (lambda (updater)
(updater port false))
updaters)))))))
-
+\f
(define (default-operation/char-ready? port interval)
port interval
true)
(begin
(discard-char port)
(loop)))))))
+
+(define (default-operation/read-substring port string start end)
+ (let ((read-char (input-port/operation/read-char port)))
+ (let loop ((index start))
+ (if (fix:< index end)
+ (let ((char (read-char port)))
+ (cond ((not char)
+ (if (fix:= index start)
+ #f
+ (fix:- index start)))
+ ((eof-object? char)
+ (fix:- index start))
+ (else
+ (string-set! string index char)
+ (loop (fix:+ index 1)))))
+ (fix:- index start)))))
\f
;;;; Output Operations
#| -*-Scheme-*-
-$Id: runtime.pkg,v 14.274 1997/01/05 23:45:13 cph Exp $
+$Id: runtime.pkg,v 14.275 1997/02/21 05:42:58 cph Exp $
Copyright (c) 1988-97 Massachusetts Institute of Technology
char-set:alphanumeric
char-set:graphic
char-set:lower-case
+ char-set:newline
char-set:not-graphic
char-set:not-whitespace
char-set:numeric
input-port/operation/peek-char
input-port/operation/read-char
input-port/operation/read-string
+ input-port/operation/read-substring
input-port/state
input-port?
interaction-i/o-port
input-port/discard-chars
input-port/peek-char
input-port/read-char
+ input-port/read-line
input-port/read-string
+ input-port/read-string!
+ input-port/read-substring!
make-eof-object
peek-char
read
read-char
read-char-no-hang
- read-string)
+ read-line
+ read-string
+ read-string!)
(export (runtime primitive-io)
eof-object))
#| -*-Scheme-*-
-$Id: runtime.pkg,v 14.281 1997/01/05 23:45:04 cph Exp $
+$Id: runtime.pkg,v 14.282 1997/02/21 05:42:48 cph Exp $
Copyright (c) 1988-97 Massachusetts Institute of Technology
char-set:alphanumeric
char-set:graphic
char-set:lower-case
+ char-set:newline
char-set:not-graphic
char-set:not-whitespace
char-set:numeric
input-port/operation/peek-char
input-port/operation/read-char
input-port/operation/read-string
+ input-port/operation/read-substring
input-port/state
input-port?
interaction-i/o-port
input-port/discard-chars
input-port/peek-char
input-port/read-char
+ input-port/read-line
input-port/read-string
+ input-port/read-string!
+ input-port/read-substring!
make-eof-object
peek-char
read
read-char
read-char-no-hang
- read-string)
+ read-line
+ read-string
+ read-string!)
(export (runtime primitive-io)
eof-object))