source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: correctly parse spacing around in-line equations at the
Date: Mon, 20 Oct 2014 11:04:56 -0400 (EDT)	[thread overview]
Message-ID: <201410201504.s9KF4unR023661@krisdoz.my.domain> (raw)

Log Message:
-----------
correctly parse spacing around in-line equations
at the beginning and at the end of input lines;
issue reported by kristaps@

Modified Files:
--------------
    mdocml:
        roff.c

Revision Data
-------------
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.232
retrieving revision 1.233
diff -Lroff.c -Lroff.c -u -p -r1.232 -r1.233
--- roff.c
+++ roff.c
@@ -1857,7 +1857,8 @@ roff_T_(ROFF_ARGS)
 static enum rofferr
 roff_eqndelim(struct roff *r, char **bufp, size_t *szp, int pos)
 {
-	char	*cp1, *cp2;
+	char		*cp1, *cp2;
+	const char	*bef_pr, *bef_nl, *mac, *aft_nl, *aft_pr;
 
 	/*
 	 * Outside equations, look for an opening delimiter.
@@ -1872,11 +1873,41 @@ roff_eqndelim(struct roff *r, char **buf
 	if (cp2 == NULL)
 		return(ROFF_CONT);
 
-	/* Replace the delimiter with an equation macro. */
-
 	*cp2++ = '\0';
-	*szp = mandoc_asprintf(&cp1, "%s%s%s", *bufp,
-	    r->eqn == NULL ? "\\&\n.EQ\n" : "\n.EN\n\\&", cp2) + 1;
+	bef_pr = bef_nl = aft_nl = aft_pr = "";
+
+	/* Handle preceding text, protecting whitespace. */
+
+	if (**bufp != '\0') {
+		if (r->eqn == NULL)
+			bef_pr = "\\&";
+		bef_nl = "\n";
+	}
+
+	/*
+	 * Prepare replacing the delimiter with an equation macro
+	 * and drop leading white space from the equation.
+	 */
+
+	if (r->eqn == NULL) {
+		while (*cp2 == ' ')
+			cp2++;
+		mac = ".EQ";
+	} else
+		mac = ".EN";
+
+	/* Handle following text, protecting whitespace. */
+
+	if (*cp2 != '\0') {
+		aft_nl = "\n";
+		if (r->eqn != NULL)
+			aft_pr = "\\&";
+	}
+
+	/* Do the actual replacement. */
+
+	*szp = mandoc_asprintf(&cp1, "%s%s%s%s%s%s%s", *bufp,
+	    bef_pr, bef_nl, mac, aft_nl, aft_pr, cp2) + 1;
 	free(*bufp);
 	*bufp = cp1;
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-10-20 15:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=201410201504.s9KF4unR023661@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@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).