From 2fce374076337f13cb9e3d19884e9feaea4506d9 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 19 Jun 2010 16:33:14 +0200 Subject: [PATCH] add isl_stream_skip_line --- include/isl_stream.h | 1 + isl_stream.c | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/isl_stream.h b/include/isl_stream.h index fbe753db..134ee3ba 100644 --- a/include/isl_stream.h +++ b/include/isl_stream.h @@ -79,6 +79,7 @@ int isl_stream_eat_if_available(struct isl_stream *s, int type); char *isl_stream_read_ident_if_available(struct isl_stream *s); int isl_stream_eat(struct isl_stream *s, int type); int isl_stream_is_empty(struct isl_stream *s); +int isl_stream_skip_line(struct isl_stream *s); enum isl_token_type isl_stream_register_keyword(struct isl_stream *s, const char *name); diff --git a/isl_stream.c b/isl_stream.c index 5568127f..c38363df 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -230,6 +230,17 @@ static enum isl_token_type check_keywords(struct isl_stream *s) return ISL_TOKEN_IDENT; } +int isl_stream_skip_line(struct isl_stream *s) +{ + int c; + + while ((c = isl_stream_getc(s)) != -1 && c != '\n') + /* nothing */ + ; + + return c == -1 ? -1 : 0; +} + static struct isl_token *next_token(struct isl_stream *s, int same_line) { int c; @@ -251,10 +262,10 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line) /* skip spaces and comment lines */ while ((c = isl_stream_getc(s)) != -1) { if (c == '#') { - while ((c = isl_stream_getc(s)) != -1 && c != '\n') - /* nothing */ - ; - if (c == -1 || (same_line && c == '\n')) + if (isl_stream_skip_line(s) < 0) + break; + c = '\n'; + if (same_line) break; } else if (!isspace(c) || (same_line && c == '\n')) break; -- 2.11.4.GIT