From 97476a28d8aa0c1403d4ba4815f8f07a7caa7b4e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 19 Apr 2016 19:02:18 -0700 Subject: Allow unlimited character pushback in unget-char. Fixing read_until_match will require this feature. * socket.c (dgram_get_char): Treat unget_c as a cons-based stack; pop a character from it if available. (dgram_unget_char): Push the character onto unget_c rather than storing the characer into unget_c. * stream.c (stdio_get_char, stdio_unget_char): Closely analogous changes to the ones in dgram_get_char and dgram_unget_char, respectively. * txr.1: Documentation improved and updated. --- stream.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'stream.c') diff --git a/stream.c b/stream.c index 6b234e22..24dc79d2 100644 --- a/stream.c +++ b/stream.c @@ -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; } -- cgit v1.2.3