Commit 2c6f01a2 authored by Erick's avatar Erick

Added the R7RS primitives read-u8 peek-u8 and u8-ready?

parent be9445de
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
;; USA. ;; USA.
;; Author: Erick Gallesio [eg@unice.fr] ;; Author: Erick Gallesio [eg@unice.fr]
;; Creation date: 26-Nov-2000 18:19 (eg) ;; Creation date: 26-Nov-2000 18:19 (eg)
;; Last file update: 1-Aug-2018 18:11 (eg) ;; Last file update: 1-Aug-2018 19:09 (eg)
;; ;;
;; ====================================================================== ;; ======================================================================
...@@ -597,6 +597,9 @@ be accessed as a normal port with the standard Scheme primitives.]) ...@@ -597,6 +597,9 @@ be accessed as a normal port with the standard Scheme primitives.])
(insertdoc 'eof-object) (insertdoc 'eof-object)
(insertdoc 'char-ready?) (insertdoc 'char-ready?)
(insertdoc 'read-string) (insertdoc 'read-string)
(insertdoc 'read-u8)
(insertdoc 'peek-u8)
(insertdoc 'u8-ready?)
(insertdoc 'read-line) (insertdoc 'read-line)
(insertdoc 'read-from-string) (insertdoc 'read-from-string)
(insertdoc 'port->string-list)) (insertdoc 'port->string-list))
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
;;;; ;;;;
;;;; Author: Erick Gallesio [eg@unice.fr] ;;;; Author: Erick Gallesio [eg@unice.fr]
;;;; Creation date: 17-Apr-2011 19:36 (eg) ;;;; Creation date: 17-Apr-2011 19:36 (eg)
;;;; Last file update: 1-Aug-2018 18:17 (eg) ;;;; Last file update: 1-Aug-2018 19:08 (eg)
;;;; ;;;;
;;;; ---------------------------------------------------------------------- ;;;; ----------------------------------------------------------------------
...@@ -720,3 +720,67 @@ doc> ...@@ -720,3 +720,67 @@ doc>
buffer) buffer)
(else (string-set! buffer i c) (else (string-set! buffer i c)
(Loop (+ i 1) (read-char port)))))))) (Loop (+ i 1) (read-char port))))))))
#|
<doc R7RS read-u8
* (read-u8)
* (read-u8 port)
*
* Returns the next byte available from the binary input |port|,
* updating the |port| to point to the following byte. If no more
* bytes are available, an end-of-file object is returned.
*
* @l
* ,(bold "Note"): This function is similar to the |read-byte|
* function, excepted that it can be used only on a binary port.
doc>
|#
(define (read-u8 :optional (port (current-input-port)))
(%claim-error
'read-u8
(unless (binary-port? port)
(error "bad binary port ~S" port))
(read-byte port)))
#|
<doc R7RS peek-u8
* (peek-u8)
* (peek-u8 port)
*
* Returns the next byte available from the binary input |port|,
* but without updating the |port| to point to the following
* byte. If no more bytes are available, an end-of-file object
* is returned.
*
* @l
* ,(bold "Note"): This function is similar to the |peek-byte|
* function, excepted that it can be used only on a binary port.
doc>
|#
(define (peek-u8 :optional (port (current-input-port)))
(%claim-error
'peek-u8
(unless (binary-port? port)
(error "bad binary port ~S" port))
(peek-byte port)))
#|
<doc R7RS u8-ready?
* (u8-ready?)
* (u8-ready? port)
*
* Returns #t if a byte is ready on the binary input |port| and
* returns #f otherwise. If |u8-ready?| returns #t then the
* next read-u8 operation on the given port is guaranteed
* not to hang. If the |port| is at end of file then |u8-ready?|
* returns #t.
doc>
|#
(define (u8-ready? :optional (port (current-input-port)))
(%claim-error
'u8-ready?
(unless (binary-port? port)
(error "bad binary port ~S" port))
(char-ready? port)))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment