add isl_stream_skip_line
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 19 Jun 2010 14:33:14 +0000 (16:33 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 19 Jun 2010 17:35:27 +0000 (19:35 +0200)
include/isl_stream.h
isl_stream.c

index fbe753d..134ee3b 100644 (file)
@@ -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);
index 5568127..c38363d 100644 (file)
@@ -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;