aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2009-06-01 13:19:08 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2012-04-13 20:54:48 -0400
commitd6b8d38f0ef16a1c24b62411e1aecfff86073f17 (patch)
treebf304d2a5d57089c76f112911c1997511799a37d
parentef2e777c1bda3fbb2b00c9332e1bf40d24afc136 (diff)
downloadsparse-d6b8d38f0ef16a1c24b62411e1aecfff86073f17.tar.gz
Fix tab handling in nextchar_slow()
... and streamline it a bit more, now that we get all \t hitting the damn thing. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--tokenize.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/tokenize.c b/tokenize.c
index d4f05e56..57afebc1 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -241,10 +241,10 @@ static int nextchar_slow(stream_t *stream)
int offset = stream->offset;
int size = stream->size;
int c;
- int spliced = 0, had_cr, had_backslash, complain;
+ int spliced = 0, had_cr, had_backslash;
restart:
- had_cr = had_backslash = complain = 0;
+ had_cr = had_backslash = 0;
repeat:
if (offset >= size) {
@@ -258,48 +258,53 @@ repeat:
}
c = stream->buffer[offset++];
-
- if (had_cr && c != '\n')
- complain = 1;
+ if (had_cr)
+ goto check_lf;
if (c == '\r') {
had_cr = 1;
goto repeat;
}
- stream->pos += (c == '\t') ? (tabstop - stream->pos % tabstop) : 1;
-
- if (c == '\n') {
- stream->line++;
- stream->pos = 0;
- }
-
+norm:
if (!had_backslash) {
- if (c == '\\') {
+ switch (c) {
+ case '\t':
+ stream->pos += tabstop - stream->pos % tabstop;
+ break;
+ case '\n':
+ stream->line++;
+ stream->pos = 0;
+ stream->newline = 1;
+ break;
+ case '\\':
had_backslash = 1;
+ stream->pos++;
goto repeat;
+ default:
+ stream->pos++;
}
- if (c == '\n')
- stream->newline = 1;
} else {
if (c == '\n') {
- if (complain)
- warning(stream_pos(stream), "non-ASCII data stream");
+ stream->line++;
+ stream->pos = 0;
spliced = 1;
goto restart;
}
- stream->pos--;
offset--;
c = '\\';
}
-
out:
stream->offset = offset;
- if (complain)
- warning(stream_pos(stream), "non-ASCII data stream");
return c;
+check_lf:
+ if (c != '\n')
+ offset--;
+ c = '\n';
+ goto norm;
+
got_eof:
if (had_backslash) {
c = '\\';
@@ -307,8 +312,6 @@ got_eof:
}
if (stream->pos)
warning(stream_pos(stream), "no newline at end of file");
- else if (had_cr)
- warning(stream_pos(stream), "non-ASCII data stream");
else if (spliced)
warning(stream_pos(stream), "backslash-newline at end of file");
return EOF;