From 9cb58fff8a8116029cf12ed923b8077cd56affe9 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 18 Aug 2003 16:19:02 -0700 Subject: [PATCH] Allow DOS-style '\r' characters in the input files. Complain about non-ASCII behaviour if the sequence isn't the normal '\r\n' --- tokenize.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tokenize.c b/tokenize.c index baa23161..9f3b369b 100644 --- a/tokenize.c +++ b/tokenize.c @@ -207,7 +207,10 @@ static int nextchar(stream_t *stream) int offset = stream->offset; int size = stream->size; int c; + int complain = -1; +repeat: + complain++; if (offset >= size) { size = read(stream->fd, stream->buffer, BUFSIZE); if (size <= 0) @@ -217,13 +220,24 @@ static int nextchar(stream_t *stream) offset = 0; } c = stream->buffer[offset]; - stream->offset = offset + 1; + stream->offset = ++offset; + stream->pos.pos++; + + /* Ignore DOS-stype '\r' characters */ + if (c == '\r') + goto repeat; + if (c == '\n') { stream->pos.line++; stream->pos.newline = 1; stream->pos.pos = 0; + complain = 0; } + + if (complain) + warn(stream->pos, "non-ASCII data stream"); + return c; } -- 2.11.4.GIT