aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/io.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-09-09 00:12:22 +0900
committernsfisis <nsfisis@gmail.com>2025-09-09 00:12:22 +0900
commitb447618c33683b947c1fb26f1e7cd9033e20e5cb (patch)
treec62d4d9bc5c119ae94022e0a3f8e8d0a085b0190 /src/io.c
parent32b15c9dbfec14417bb0a4e04c0eaa8a8028fd42 (diff)
downloadducc-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.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/io.c b/src/io.c
index 1d03e62..6b52318 100644
--- a/src/io.c
+++ b/src/io.c
@@ -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;