Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e96eb9

Browse files
committed
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
1 parent b65a48e commit 2e96eb9

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Parser/tokenizer.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ tok_nextc(tok)
235235
else {
236236
int done = 0;
237237
int cur = 0;
238+
char *pt;
238239
if (tok->start == NULL) {
239240
if (tok->buf == NULL) {
240241
tok->buf = NEW(char, BUFSIZ);
@@ -295,6 +296,13 @@ tok_nextc(tok)
295296
done = tok->inp[-1] == '\n';
296297
}
297298
tok->cur = tok->buf + cur;
299+
/* replace "\r\n" with "\n" */
300+
pt = tok->inp - 2;
301+
if (pt >= tok->buf && *pt == '\r') {
302+
*pt++ = '\n';
303+
*pt = '\0';
304+
tok->inp = pt;
305+
}
298306
}
299307
if (tok->done != E_OK) {
300308
if (tok->prompt != NULL)

0 commit comments

Comments
 (0)