~ chicken-core (chicken-5) 0f39091c5e21924b087f78eb62b919367a605985
commit 0f39091c5e21924b087f78eb62b919367a605985
Author: Evan Hanson <evhan@foldling.org>
AuthorDate: Wed Jan 20 22:14:08 2016 +1300
Commit: Evan Hanson <evhan@foldling.org>
CommitDate: Tue Mar 8 22:52:34 2016 +1300
Rename "read-file" to "read-all", drop filename argument handling
diff --git a/chicken-install.scm b/chicken-install.scm
index 73c60526..a1f2d2c1 100644
--- a/chicken-install.scm
+++ b/chicken-install.scm
@@ -192,12 +192,12 @@
((override)
(set! *override*
(if (and (pair? (cdr x)) (string? (cadr x)))
- (read-file (cadr x))
+ (call-with-input-file (cadr x) read-all)
(cdr x))))
((hack)
(set! *hacks* (append *hacks* (list (eval (cadr x))))))
(else (broken x))))
- (read-file deff))))
+ (call-with-input-file deff read-all))))
(pair? *default-sources*) ))
(define (resolve-location name)
@@ -777,7 +777,7 @@
(delete-duplicates
(filter-map
(lambda (sf)
- (let* ((info (first (read-file sf)))
+ (let* ((info (first (call-with-input-file sf read-all)))
(v (cond ((assq 'version info) => cadr)
(else ""))))
(cond ((assq 'egg-name info) =>
@@ -1018,7 +1018,7 @@ EOF
(loop (cddr args) eggs))
((string=? "-override" arg)
(unless (pair? (cdr args)) (usage 1))
- (set! *override* (read-file (cadr args)))
+ (set! *override* (call-with-input-file (cadr args) read-all))
(loop (cddr args) eggs))
((or (string=? "-x" arg) (string=? "-keep-installed" arg))
(set! *keep-existing* #t)
diff --git a/core.scm b/core.scm
index ac274b05..a3815b93 100644
--- a/core.scm
+++ b/core.scm
@@ -560,7 +560,7 @@
(imps (##sys#compiled-module-registration (##sys#current-module)))
(oldimps
(and (file-exists? fname)
- (read-file fname) ) ) )
+ (call-with-input-file fname read-all))))
(cond ((equal? imps oldimps)
(when verbose-mode
(print "not generating import library `" fname "' for module `"
diff --git a/extras.scm b/extras.scm
index 3b337981..a9421f83 100644
--- a/extras.scm
+++ b/extras.scm
@@ -30,7 +30,7 @@
(uses data-structures))
(module chicken.io
- (read-buffered read-byte read-file read-line
+ (read-all read-buffered read-byte read-line
read-lines read-string read-string! read-token
write-byte write-line write-string)
@@ -41,18 +41,15 @@
;;; Read expressions from file:
-(define read-file
- (let ([read read]
- [call-with-input-file call-with-input-file] )
+(define read-all
+ (let ((read read))
(lambda (#!optional (port ##sys#standard-input) (reader read) max)
- (define (slurp port)
- (do ((x (reader port) (reader port))
- (i 0 (fx+ i 1))
- (xs '() (cons x xs)) )
- ((or (eof-object? x) (and max (fx>= i max))) (##sys#fast-reverse xs)) ) )
- (if (port? port)
- (slurp port)
- (call-with-input-file port slurp) ) ) ) )
+ (##sys#check-input-port port #t 'read-all)
+ (do ((x (reader port) (reader port))
+ (i 0 (fx+ i 1))
+ (xs '() (cons x xs)))
+ ((or (eof-object? x) (and max (fx>= i max)))
+ (##sys#fast-reverse xs))))))
;;; Line I/O:
diff --git a/manual/Unit extras b/manual/Unit extras
index e66ea6ac..23ff690b 100644
--- a/manual/Unit extras
+++ b/manual/Unit extras
@@ -133,18 +133,17 @@ These procedures are provided by the {{(chicken io)}} module.
Read/write a byte to the port given in {{PORT}}, which default to the values
of {{(current-input-port)}} and {{(current-output-port)}}, respectively.
-==== read-file
-
-<procedure>(read-file [FILE-OR-PORT [READER [MAXCOUNT]]])</procedure>
-
-Returns a list containing all toplevel expressions
-read from the file or port {{FILE-OR-PORT}}. If no argument is given,
-input is read from the port that is the current value of {{(current-input-port)}}.
-After all expressions are read, and if the argument is a port, then the port will
-not be closed. The {{READER}} argument specifies the procedure used to read
-expressions from the given file or port and defaults to {{read}}. The reader
-procedure will be called with a single argument (an input port).
-If {{MAXCOUNT}} is given then only up to {{MAXCOUNT}} expressions will be read in.
+==== read-all
+
+<procedure>(read-all [PORT [READER [MAXCOUNT]]])</procedure>
+
+Returns a list containing all toplevel expressions read from the given
+{{PORT}}. If no argument is given, input is read from the value of
+{{(current-input-port)}}. The {{READER}} argument specifies the
+procedure used to read expressions and defaults to {{read}}. The reader
+procedure will be called with a single argument (an input port). If
+{{MAXCOUNT}} is given then only up to {{MAXCOUNT}} expressions will be
+read in.
==== read-line
diff --git a/scripts/reconstruct-egg-name.scm b/scripts/reconstruct-egg-name.scm
index c93e4309..8de03fd4 100644
--- a/scripts/reconstruct-egg-name.scm
+++ b/scripts/reconstruct-egg-name.scm
@@ -41,7 +41,7 @@
(current-directory cd) ) ) )
(define (get-info eggnam #!optional (dir (repository-path)))
- (car (read-file (make-pathname dir eggnam +info-extn+))) )
+ (car (call-with-input-file (make-pathname dir eggnam +info-extn+) read-all)))
(define (put-info info eggnam #!optional (dir (repository-path)))
(let ((tmpfil (create-temporary-file)))
diff --git a/scripts/setversion b/scripts/setversion
index 01660086..f1db588b 100755
--- a/scripts/setversion
+++ b/scripts/setversion
@@ -5,7 +5,7 @@ exec csi -s "$0" "$@"
(use srfi-1 utils posix irregex)
-(define buildversion (->string (car (read-file "buildversion"))))
+(define buildversion (->string (car (call-with-input-file "buildversion" read-all))))
(define files '("README" "manual/The User's Manual"))
diff --git a/scrutinizer.scm b/scrutinizer.scm
index 42d4c12e..66331d5e 100644
--- a/scrutinizer.scm
+++ b/scrutinizer.scm
@@ -1805,7 +1805,7 @@
(mark-variable name '##compiler#type-source 'db)
(when specs
(install-specializations name specs)))))
- (read-file dbfile))
+ (call-with-input-file dbfile read-all))
#t)))
(define (emit-type-file source-file type-file db block-compilation)
diff --git a/support.scm b/support.scm
index 8ad6e52b..d1e92a68 100644
--- a/support.scm
+++ b/support.scm
@@ -1634,7 +1634,7 @@
(##sys#put!
id '##core#db
(append (or (##sys#get id '##core#db) '()) (list (cdr e))) )))
- (read-file dbfile))))
+ (call-with-input-file dbfile read-all))))
;;; Print version/usage information:
diff --git a/types.db b/types.db
index 3fb8c28d..c0e7bbda 100644
--- a/types.db
+++ b/types.db
@@ -1525,9 +1525,9 @@
;; io
+(chicken.io#read-all (#(procedure #:enforce) chicken.io#read-all (#!optional input-port (procedure (input-port) *) fixnum) list))
(chicken.io#read-buffered (#(procedure #:enforce) chicken.io#read-buffered (#!optional input-port) string))
(chicken.io#read-byte (#(procedure #:enforce) chicken.io#read-byte (#!optional input-port) *))
-(chicken.io#read-file (#(procedure #:enforce) chicken.io#read-file (#!optional (or input-port string) (procedure (input-port) *) fixnum) list))
(chicken.io#read-line (#(procedure #:enforce) chicken.io#read-line (#!optional input-port (or false fixnum)) (or eof string)))
(chicken.io#read-lines (#(procedure #:enforce) chicken.io#read-lines (#!optional (or input-port string) fixnum) (list-of string)))
(chicken.io#read-string (#(procedure #:enforce) chicken.io#read-string (#!optional (or fixnum false) input-port) string))
Trap