summaryrefslogtreecommitdiffstats
path: root/lineio.scm
diff options
context:
space:
mode:
authorJames LewisMoss <dres@debian.org>1999-12-06 19:32:57 -0500
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:28 -0800
commitc394920caedf3dac1981bb6b10eeb47fd6e4bb21 (patch)
treef21194653a3554f747dde3df908df993c48db5a0 /lineio.scm
parent926b1b647ac830660933a5e63eb52d4a2552e264 (diff)
parentbd9733926076885e3417b74de76e4c9c7bc56254 (diff)
downloadslib-c394920caedf3dac1981bb6b10eeb47fd6e4bb21.tar.gz
slib-c394920caedf3dac1981bb6b10eeb47fd6e4bb21.zip
Import Debian changes 2c7-1debian/2c7-1
slib (2c7-1) unstable; urgency=low * New upstream. * Add slibconfig back in. slib (2c6-2) unstable; urgency=low * Remove the slib$(VERSION).info file. Cut the diff back down to size. slib (2c6-1) unstable; urgency=low * New upstream. * Move docs to /usr/share. Up standards version. add /usr/doc symlink. Move info files. Remove undocumented link. slib (2c5-6) unstable; urgency=low * Lowercase two vars in yasyn.scm (Fixes bug #37222) slib (2c5-5) unstable; urgency=low * Fix it so string-index isn't defined (now there is a strsrch:string-index) (Fixes #38812) slib (2c5-4) unstable; urgency=low * Don't run slibconfig in postinst. (Fixes bug #38253, #37733, #37715, #37746, #37809, #37917, #38123, #38462) slib (2c5-3) unstable; urgency=low * Run slibconfig in postinst. It was commented out there, but I don't see any old bug reports on why it was commented out, so let's try again. :) (Fixes bug #37221) slib (2c5-2) unstable; urgency=low * Link mklibcat.scm to mklibcat. Fixes a problem with using slib with guile. slib (2c5-1) unstable; urgency=low * New upstream. slib (2c3-4) unstable; urgency=low * New maintainer.
Diffstat (limited to 'lineio.scm')
-rw-r--r--lineio.scm68
1 files changed, 50 insertions, 18 deletions
diff --git a/lineio.scm b/lineio.scm
index ad8320b..c80ece8 100644
--- a/lineio.scm
+++ b/lineio.scm
@@ -17,34 +17,66 @@
;promotional, or sales literature without prior written consent in
;each case.
-(define (read-line . arg)
- (let* ((char (apply read-char arg)))
+
+;;@args
+;;@args port
+;;Returns a string of the characters up to, but not including a
+;;newline or end of file, updating @var{port} to point to the
+;;character following the newline. If no characters are available, an
+;;end of file object is returned. The @var{port} argument may be
+;;omitted, in which case it defaults to the value returned by
+;;@code{current-input-port}.
+(define (read-line . port)
+ (let* ((char (apply read-char port)))
(if (eof-object? char)
char
- (do ((char char (apply read-char arg))
+ (do ((char char (apply read-char port))
(clist '() (cons char clist)))
((or (eof-object? char) (char=? #\newline char))
(list->string (reverse clist)))))))
-(define (read-line! str . arg)
- (let* ((char (apply read-char arg))
- (len (+ -1 (string-length str))))
+;;@args string
+;;@args string port
+;;Fills @1 with characters up to, but not including a newline or end
+;;of file, updating the @var{port} to point to the last character read
+;;or following the newline if it was read. If no characters are
+;;available, an end of file object is returned. If a newline or end
+;;of file was found, the number of characters read is returned.
+;;Otherwise, @code{#f} is returned. The @var{port} argument may be
+;;omitted, in which case it defaults to the value returned by
+;;@code{current-input-port}.
+(define (read-line! str . port)
+ (let* ((char (apply read-char port))
+ (midx (+ -1 (string-length str))))
(if (eof-object? char)
char
- (do ((char char (apply read-char arg))
+ (do ((char char (apply read-char port))
(i 0 (+ 1 i)))
((or (eof-object? char)
(char=? #\newline char)
- (>= i len))
- (cond ((or (eof-object? char) (char=? #\newline char))
- i)
- (else
- (string-set! str i char)
- (set! char (apply peek-char arg))
- (if (or (eof-object? char) (char=? #\newline char))
- (+ 1 i) #f))))
+ (> i midx))
+ (if (> i midx) #f i))
(string-set! str i char)))))
-(define (write-line str . arg)
- (apply display str arg)
- (apply newline arg))
+;;@args string
+;;@args string port
+;;Writes @1 followed by a newline to the given @var{port} and returns
+;;an unspecified value. The @var{Port} argument may be omited, in
+;;which case it defaults to the value returned by
+;;@code{current-input-port}.@refill
+(define (write-line str . port)
+ (apply display str port)
+ (apply newline port))
+
+;;@args path
+;;@args path port
+;;Displays the contents of the file named by @1 to @var{port}. The
+;;@var{port} argument may be ommited, in which case it defaults to the
+;;value returned by @code{current-output-port}.
+(define (display-file path . port)
+ (set! port (if (null? port) (current-output-port) (car port)))
+ (call-with-input-file path
+ (lambda (inport)
+ (do ((line (read-line inport) (read-line inport)))
+ ((eof-object? line))
+ (write-line line port)))))