summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2011-01-24 23:41:55 +0000
committerIngo Schwarze <schwarze@openbsd.org>2011-01-24 23:41:55 +0000
commit3e2f9c514f010f73bc76e64814aa325889ce9a80 (patch)
treea13ef6976c7fd495607b01df529a82b7eb3df0fe /main.c
parent547cbe6e08fe7a057d0c1f2d41b71d0b90417eda (diff)
downloadmandoc-3e2f9c514f010f73bc76e64814aa325889ce9a80.tar.gz
Skip carriage return before newline, if any.
As pointed out by Joerg Sonnenberger, this is useful because we use mmap(3) and look for '\n' by hand. "check it in" kristaps@
Diffstat (limited to 'main.c')
-rw-r--r--main.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/main.c b/main.c
index 6075d520..30aab3ad 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -684,6 +684,16 @@ parsebuf(struct curparse *curp, struct buf blk, int start)
}
while (i < (int)blk.sz && (start || '\0' != blk.buf[i])) {
+
+ /*
+ * When finding an unescaped newline character,
+ * leave the character loop to process the line.
+ * Skip a preceding carriage return, if any.
+ */
+
+ if ('\r' == blk.buf[i] && i + 1 < (int)blk.sz &&
+ '\n' == blk.buf[i + 1])
+ ++i;
if ('\n' == blk.buf[i]) {
++i;
++lnn;
@@ -718,11 +728,18 @@ parsebuf(struct curparse *curp, struct buf blk, int start)
continue;
}
- /* Found escape & at least one other char. */
+ /*
+ * Found escape and at least one other character.
+ * When it's a newline character, skip it.
+ * When there is a carriage return in between,
+ * skip that one as well.
+ */
+ if ('\r' == blk.buf[i + 1] && i + 2 < (int)blk.sz &&
+ '\n' == blk.buf[i + 2])
+ ++i;
if ('\n' == blk.buf[i + 1]) {
i += 2;
- /* Escaped newlines are skipped over */
++lnn;
continue;
}