diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-09-09 00:12:22 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-09-09 00:12:22 +0900 |
| commit | b447618c33683b947c1fb26f1e7cd9033e20e5cb (patch) | |
| tree | c62d4d9bc5c119ae94022e0a3f8e8d0a085b0190 /src/io.c | |
| parent | 32b15c9dbfec14417bb0a4e04c0eaa8a8028fd42 (diff) | |
| download | ducc-b447618c33683b947c1fb26f1e7cd9033e20e5cb.tar.gz ducc-b447618c33683b947c1fb26f1e7cd9033e20e5cb.tar.zst ducc-b447618c33683b947c1fb26f1e7cd9033e20e5cb.zip | |
feat: support CRLF and CR
Diffstat (limited to 'src/io.c')
| -rw-r--r-- | src/io.c | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -65,16 +65,23 @@ char infile_peek_char(InFile* f) { if (c2 == '\0') { fatal_error("%s:%d: <new-line> expected, but got <eof>", f->loc.filename, f->loc.line); } - // TODO: crlf - if (c2 == '\r' || c2 == '\n') { - f->pos += 2; + // Handle line continuation. + if (c2 == '\r') { + if (f->buf[f->pos + 2] == '\n') { + f->pos += 3; // Backslash + CRLF + } else { + f->pos += 2; // Backslash + CR + } + ++f->loc.line; + return infile_peek_char(f); + } else if (c2 == '\n') { + f->pos += 2; // Backslash + LF ++f->loc.line; return infile_peek_char(f); } } // Normalize new-line. - // TODO: crlf if (c == '\r') c = '\n'; return c; @@ -82,7 +89,17 @@ char infile_peek_char(InFile* f) { char infile_next_char(InFile* f) { char c = infile_peek_char(f); - ++f->pos; + + if (f->buf[f->pos] == '\r') { + ++f->pos; + if (f->buf[f->pos] == '\n') { + ++f->pos; // CRLF + } + c = '\n'; + } else { + ++f->pos; + } + if (c == '\n') ++f->loc.line; return c; |
