adding io.pos, io.readlines, read-all
fixing a small ios bug
This commit is contained in:
parent
66c671bfee
commit
88d08edecc
File diff suppressed because one or more lines are too long
|
@ -169,6 +169,16 @@ value_t fl_ioseek(value_t *args, u_int32_t nargs)
|
||||||
return FL_T;
|
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)
|
static void do_ioprint(value_t *args, u_int32_t nargs, char *fname)
|
||||||
{
|
{
|
||||||
if (nargs < 2)
|
if (nargs < 2)
|
||||||
|
@ -340,6 +350,7 @@ static builtinspec_t iostreamfunc_info[] = {
|
||||||
{ "io.close", fl_ioclose },
|
{ "io.close", fl_ioclose },
|
||||||
{ "io.eof?" , fl_ioeof },
|
{ "io.eof?" , fl_ioeof },
|
||||||
{ "io.seek" , fl_ioseek },
|
{ "io.seek" , fl_ioseek },
|
||||||
|
{ "io.pos", fl_iopos },
|
||||||
{ "io.getc" , fl_iogetc },
|
{ "io.getc" , fl_iogetc },
|
||||||
{ "io.putc" , fl_ioputc },
|
{ "io.putc" , fl_ioputc },
|
||||||
{ "io.discardbuffer", fl_iopurge },
|
{ "io.discardbuffer", fl_iopurge },
|
||||||
|
|
|
@ -503,6 +503,17 @@
|
||||||
|
|
||||||
(define (io.readline s) (io.readuntil s #\x0a))
|
(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 ------------------------------------------------------------
|
; vector functions ------------------------------------------------------------
|
||||||
|
|
||||||
(define (list->vector l) (apply vector l))
|
(define (list->vector l) (apply vector l))
|
||||||
|
|
|
@ -878,10 +878,10 @@ IOStream API
|
||||||
io.trunc
|
io.trunc
|
||||||
io.read! - destructively take data
|
io.read! - destructively take data
|
||||||
*io.tostring!
|
*io.tostring!
|
||||||
io.readlines
|
*io.readlines
|
||||||
io.readall
|
io.readall
|
||||||
print-to-string
|
*print-to-string
|
||||||
princ-to-string
|
*princ-to-string
|
||||||
|
|
||||||
|
|
||||||
path.combine
|
path.combine
|
||||||
|
|
|
@ -306,6 +306,7 @@ size_t ios_readprep(ios_t *s, size_t n)
|
||||||
size_t space = s->size - s->bpos;
|
size_t space = s->size - s->bpos;
|
||||||
if (s->state == bst_wr)
|
if (s->state == bst_wr)
|
||||||
return space;
|
return space;
|
||||||
|
s->state = bst_rd;
|
||||||
if (space >= n || s->bm == bm_mem || s->fd == -1)
|
if (space >= n || s->bm == bm_mem || s->fd == -1)
|
||||||
return space;
|
return space;
|
||||||
if (s->maxsize < s->bpos+n) {
|
if (s->maxsize < s->bpos+n) {
|
||||||
|
|
Loading…
Reference in New Issue