tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: line termination in manuals
Date: Sat, 22 Jan 2011 23:18:36 +0100	[thread overview]
Message-ID: <20110122221836.GJ12520@iris.usta.de> (raw)
In-Reply-To: <20110122213510.GA29547@britannica.bec.de>

Hi Joerg,

Joerg Sonnenberger wrote on Sat, Jan 22, 2011 at 10:35:10PM +0100:
> On Sat, Jan 22, 2011 at 10:28:14PM +0100, Ingo Schwarze wrote:

> At least add a comment that this falls through to the next statement
> for handling.  Otherwise it looks fine.

Gah, writing comments is good.
It makes you think again about the code,
so you find bugs.

When the last character in blk.buf is '\r' (without a newline
at the end of the file), my first attempt would have overrun
the buffer by one byte.

Thus, i'm committing the following shortly.

Yours,
  Ingo


Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/main.c,v
retrieving revision 1.69
diff -u -r1.69 main.c
--- main.c	20 Jan 2011 21:33:11 -0000	1.69
+++ main.c	22 Jan 2011 22:12:58 -0000
@@ -669,6 +669,15 @@
 		}
 
 		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] && '\n' == blk.buf[i+1])
+				++i;
 			if ('\n' == blk.buf[i]) {
 				++i;
 				++lnn;
@@ -703,11 +712,18 @@
 				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 + 1 < (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 tech+unsubscribe@mdocml.bsd.lv

  reply	other threads:[~2011-01-22 22:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-22 19:56 Ingo Schwarze
2011-01-22 20:05 ` Joerg Sonnenberger
2011-01-22 21:28   ` Ingo Schwarze
2011-01-22 21:35     ` Joerg Sonnenberger
2011-01-22 22:18       ` Ingo Schwarze [this message]
2011-01-22 22:28         ` Kristaps Dzonsons
2011-01-22 22:29         ` Joerg Sonnenberger
2011-01-22 22:59           ` Ingo Schwarze
2011-01-24 23:16             ` Kristaps Dzonsons
2011-01-25  0:09               ` Ingo Schwarze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110122221836.GJ12520@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).