diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:26 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:26 -0800 |
commit | f24b9140d6f74804d5599ec225717d38ca443813 (patch) | |
tree | 0da952f1a5a7c0eacfc05c296766523e32c05fe2 /scanf.scm | |
parent | 8ffbc2df0fde83082610149d24e594c1cd879f4a (diff) | |
download | slib-f24b9140d6f74804d5599ec225717d38ca443813.tar.gz slib-f24b9140d6f74804d5599ec225717d38ca443813.zip |
Import Upstream version 2c0upstream/2c0
Diffstat (limited to 'scanf.scm')
-rw-r--r-- | scanf.scm | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -1,5 +1,5 @@ ;;;;"scanf.scm" implemenation of formated input -;Copyright (C) 1996 Aubrey Jaffer +;Copyright (C) 1996, 1997 Aubrey Jaffer ; ;Permission to copy this software, to redistribute it, and to use it ;for any purpose is granted, subject to the following restrictions and @@ -54,7 +54,7 @@ (define (add-item report-field? next-item) (cond (args - (cond ((null? setters) + (cond ((and report-field? (null? setters)) (slib:error 'scanf "not enough variables for format" format-string)) ((not next-item) (return)) @@ -221,14 +221,12 @@ ((#\c #\C) (if (not width) (set! width 1)) (let ((str (make-string width))) - (do ((i 0 (+ 1 i))) - ((>= i width) - (add-item report-field? str)) - (let ((c (read-char input-port))) - (cond ((eof-object? c) - (set! str c) - (set! i width)) - (else (string-set! str i c))))))) + (do ((i 0 (+ 1 i)) + (c (peek-char input-port) (peek-char input-port))) + ((or (>= i width) + (eof-object? c)) + (add-item report-field? (substring str 0 i))) + (string-set! str i (read-input-char))))) ((#\s #\S) ;;(flush-whitespace-input) (add-item report-field? (read-word width char-whitespace?))) @@ -292,7 +290,7 @@ (read-input-char) (loop1)) (else (return)))) - + ;;(trace flush-whitespace-input flush-whitespace add-item return read-string read-word loop1) (loop1)))) (args 0) (else '()))) @@ -312,7 +310,8 @@ (call-with-input-string input-port (lambda (input-port) (stdio:scan-and-set format-string input-port #f)))) - (else (slib:error 'scanf-read-list "argument not port" input-port)))) + (else (slib:error 'scanf-read-list "argument 2 not a port" + input-port)))) (define (stdio:setter-procedure sexp) (let ((v (gentemp))) |