From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (schwarze@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p0ONftij018235 for ; Mon, 24 Jan 2011 18:41:55 -0500 (EST) Received: (from schwarze@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id p0ONftQp002869; Mon, 24 Jan 2011 18:41:55 -0500 (EST) Date: Mon, 24 Jan 2011 18:41:55 -0500 (EST) Message-Id: <201101242341.p0ONftQp002869@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Skip carriage return before newline, if any. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- 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@ Modified Files: -------------- mdocml: main.c Revision Data ------------- Index: main.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v retrieving revision 1.139 retrieving revision 1.140 diff -Lmain.c -Lmain.c -u -p -r1.139 -r1.140 --- main.c +++ main.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010 Ingo Schwarze + * Copyright (c) 2010, 2011 Ingo Schwarze * * 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 b } 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 b 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; } -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv