From: Sven Verdoolaege Date: Sat, 5 Mar 2011 09:30:08 +0000 (+0100) Subject: isl_stream: maintain private ungetc buffer X-Git-Tag: isl-0.06~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c118af0dae059f713b5ae361943b9ce0ad3f6eb;p=platform%2Fupstream%2Fisl.git isl_stream: maintain private ungetc buffer We may want to unget more than one character. Signed-off-by: Sven Verdoolaege --- diff --git a/include/isl/stream.h b/include/isl/stream.h index 33d0ffe..4a9fae8 100644 --- a/include/isl/stream.h +++ b/include/isl/stream.h @@ -60,6 +60,8 @@ struct isl_stream { size_t size; size_t len; int c; + int un[5]; + int n_un; struct isl_token *tokens[5]; int n_token; diff --git a/isl_stream.c b/isl_stream.c index 09ef60d..bb0f817 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -127,6 +127,7 @@ static struct isl_stream* isl_stream_new(struct isl_ctx *ctx) s->col = 0; s->eof = 0; s->c = -1; + s->n_un = 0; for (i = 0; i < 5; ++i) s->tokens[i] = NULL; s->n_token = 0; @@ -164,6 +165,8 @@ static int stream_getc(struct isl_stream *s) int c; if (s->eof) return -1; + if (s->n_un) + return s->c = s->un[--s->n_un]; if (s->file) c = fgetc(s->file); else { @@ -200,10 +203,8 @@ static int isl_stream_getc(struct isl_stream *s) static void isl_stream_ungetc(struct isl_stream *s, int c) { - if (s->file) - ungetc(c, s->file); - else - --s->str; + isl_assert(s->ctx, s->n_un < 5, return); + s->un[s->n_un++] = c; s->c = -1; }