From f342f3019d38f0faf737bf89631651837a66cd06 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 26 Apr 2016 14:50:33 +1200 Subject: Handle comments as whitespace --- pgm-interlace.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pgm-interlace.c b/pgm-interlace.c index 9c8e417..5f74daf 100644 --- a/pgm-interlace.c +++ b/pgm-interlace.c @@ -77,9 +77,23 @@ void read_whitespace(FILE *fd) do { c = fgetc(fd); - } while (isspace(c)); + if (isspace(c)) + continue; - ungetc(c, fd); + switch (c) + { + case '#': + /* suck up the current line of the file */ + while (c != '\n' && c != '\r' && c != EOF) + c = fgetc(fd); + break; + + default: + ungetc(c, fd); + case EOF: + break; + } + } while (isspace(c) || c == '#'); } int read_token(FILE *fd, char *token, size_t token_size, const char *allowable) -- cgit v1.1