diff options
author | Sven Verdoolaege <skimo@kotnet.org> | 2011-03-05 10:30:08 +0100 |
---|---|---|
committer | Sven Verdoolaege <skimo@kotnet.org> | 2011-03-05 10:56:06 +0100 |
commit | 6c118af0dae059f713b5ae361943b9ce0ad3f6eb (patch) | |
tree | 02018a82cb022894ccf7b2682d158352356a3682 | |
parent | a88daa9ede4f1531cc702749b2ebae9b66e7a9a2 (diff) | |
download | isl-6c118af0dae059f713b5ae361943b9ce0ad3f6eb.tar.gz isl-6c118af0dae059f713b5ae361943b9ce0ad3f6eb.tar.bz2 isl-6c118af0dae059f713b5ae361943b9ce0ad3f6eb.zip |
isl_stream: maintain private ungetc buffer
We may want to unget more than one character.
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
-rw-r--r-- | include/isl/stream.h | 2 | ||||
-rw-r--r-- | isl_stream.c | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/include/isl/stream.h b/include/isl/stream.h index 33d0ffe2..4a9fae8e 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 09ef60dd..bb0f817d 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; } |