adding io.pos, io.readlines, read-all

fixing a small ios bug
This commit is contained in:
JeffBezanson 2009-07-22 03:50:57 +00:00
parent 66c671bfee
commit 88d08edecc
5 changed files with 27 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -169,6 +169,16 @@ value_t fl_ioseek(value_t *args, u_int32_t nargs)
return FL_T;
}
value_t fl_iopos(value_t *args, u_int32_t nargs)
{
argcount("io.pos", nargs, 1);
ios_t *s = toiostream(args[0], "io.pos");
off_t res = ios_pos(s);
if (res == -1)
return FL_F;
return size_wrap((size_t)res);
}
static void do_ioprint(value_t *args, u_int32_t nargs, char *fname)
{
if (nargs < 2)
@ -340,6 +350,7 @@ static builtinspec_t iostreamfunc_info[] = {
{ "io.close", fl_ioclose },
{ "io.eof?" , fl_ioeof },
{ "io.seek" , fl_ioseek },
{ "io.pos", fl_iopos },
{ "io.getc" , fl_iogetc },
{ "io.putc" , fl_ioputc },
{ "io.discardbuffer", fl_iopurge },

View File

@ -503,6 +503,17 @@
(define (io.readline s) (io.readuntil s #\x0a))
; call f on a stream until the stream runs out of data
(define (read-all-of f s)
(let loop ((lines ())
(curr (f s)))
(if (io.eof? s)
(reverse! lines)
(loop (cons curr lines) (f s)))))
(define (io.readlines s) (read-all-of io.readline s))
(define (read-all s) (read-all-of read s))
; vector functions ------------------------------------------------------------
(define (list->vector l) (apply vector l))

View File

@ -878,10 +878,10 @@ IOStream API
io.trunc
io.read! - destructively take data
*io.tostring!
io.readlines
*io.readlines
io.readall
print-to-string
princ-to-string
*print-to-string
*princ-to-string
path.combine

View File

@ -306,6 +306,7 @@ size_t ios_readprep(ios_t *s, size_t n)
size_t space = s->size - s->bpos;
if (s->state == bst_wr)
return space;
s->state = bst_rd;
if (space >= n || s->bm == bm_mem || s->fd == -1)
return space;
if (s->maxsize < s->bpos+n) {