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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue