diff options
-rw-r--r-- | socket.c | 15 | ||||
-rw-r--r-- | stream.c | 15 | ||||
-rw-r--r-- | txr.1 | 17 |
3 files changed, 25 insertions, 22 deletions
@@ -434,10 +434,9 @@ static int dgram_get_byte_callback(mem_t *ctx) static val dgram_get_char(val stream) { struct dgram_stream *d = coerce(struct dgram_stream *, stream->co.handle); - val uc = d->unget_c; - if (uc) { - d->unget_c = nil; - return uc; + + if (d->unget_c) { + return pop(&d->unget_c); } else { wint_t ch = utf8_decode(&d->ud, dgram_get_byte_callback, coerce(mem_t *, d)); @@ -455,13 +454,7 @@ static val dgram_get_byte(val stream) static val dgram_unget_char(val stream, val ch) { struct dgram_stream *d = coerce(struct dgram_stream *, stream->co.handle); - - if (d->unget_c){ - d->err = EOVERFLOW; - uw_throwf(file_error_s, lit("unget-char overflow on ~a: "), stream, nao); - } - - d->unget_c = ch; + mpush(ch, mkloc(d->unget_c, stream)); return ch; } @@ -683,11 +683,10 @@ val generic_get_line(val stream) static val stdio_get_char(val stream) { struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle); - val uc = h->unget_c; - if (uc) { - h->unget_c = nil; - return uc; - } + + if (h->unget_c) + return pop(&h->unget_c); + if (h->f) { wint_t ch = utf8_decode(&h->ud, stdio_get_char_callback, coerce(mem_t *, h->f)); @@ -709,11 +708,7 @@ static val stdio_get_byte(val stream) static val stdio_unget_char(val stream, val ch) { struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle); - - if (h->unget_c) - uw_throwf(file_error_s, lit("unget-char overflow on ~a: "), stream, nao); - - h->unget_c = ch; + mpush(ch, mkloc(h->unget_c, stream)); return ch; } @@ -34230,7 +34230,18 @@ and likewise for and .codn unget-byte . -Space is available for only one character or byte of pushback. +Streams may require a pushed back byte or character to match +the character which was previously read from that stream +position, and may not allow a byte or character to be pushed +back beyond the beginning of the stream. + +Space may be available for only one byte of pushback under the +.code unget-byte +operation. + +The number of characters that may be pushed back by +.code unget-char +is not limited. Pushing both a byte and a character, in either order, is also unsupported. Pushing a byte and then reading a character, or pushing a character and @@ -34240,6 +34251,10 @@ If the stream is binary, then pushing back a byte decrements its position, except if the position is already zero. At that point, the position becomes indeterminate. +The behavior of pushing back immediately after a +.code seek-stream +positioning operation is unspecified. + .coNP Functions @, put-string @, put-line @ put-char and @ put-byte .synb .mets (put-string < string <> [ stream ]) |