source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Use the freshly improved roff_getname() function for the .de
Date: Sun, 29 Jun 2014 18:38:47 -0400 (EDT)	[thread overview]
Message-ID: <201406292238.s5TMclHC003530@krisdoz.my.domain> (raw)

Log Message:
-----------
Use the freshly improved roff_getname() function
for the .de parsing routine, roff_block(),
to correctly handle names terminated by escape sequences.
Besides, this saves us 20 lines of code.

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.212
retrieving revision 1.213
diff -Lroff.c -Lroff.c -u -p -r1.212 -r1.213
--- roff.c
+++ roff.c
@@ -910,14 +910,14 @@ roff_ccond(struct roff *r, int ln, int p
 static enum rofferr
 roff_block(ROFF_ARGS)
 {
-	int		sv;
-	size_t		sz;
-	char		*name;
+	char		*name, *cp;
+	size_t		 namesz;
 
-	name = NULL;
+	name = cp = *bufp + pos;
+	namesz = 0;
 
 	if (ROFF_ig != tok) {
-		if ('\0' == (*bufp)[pos]) {
+		if ('\0' == *cp) {
 			mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL);
 			return(ROFF_IGN);
 		}
@@ -929,18 +929,14 @@ roff_block(ROFF_ARGS)
 
 		if (ROFF_de1 == tok)
 			tok = ROFF_de;
-		if (ROFF_de == tok)
-			name = *bufp + pos;
-		else
+		else if (ROFF_de != tok)
 			mandoc_msg(MANDOCERR_REQUEST, r->parse, ln, ppos,
 			    roffs[tok].name);
 
-		while ((*bufp)[pos] && ! isspace((unsigned char)(*bufp)[pos]))
-			pos++;
-
-		while (isspace((unsigned char)(*bufp)[pos]))
-			(*bufp)[pos++] = '\0';
-	}
+		namesz = roff_getname(r, &cp, ln, ppos);
+		name[namesz] = '\0';
+	} else
+		name = NULL;
 
 	roffnode_push(r, tok, name, ln, ppos);
 
@@ -950,36 +946,20 @@ roff_block(ROFF_ARGS)
 	 * appended from roff_block_text() in multiline mode.
 	 */
 
-	if (ROFF_de == tok)
-		roff_setstr(r, name, "", 0);
+	if (namesz && ROFF_de == tok)
+		roff_setstrn(&r->strtab, name, namesz, "", 0, 0);
 
-	if ('\0' == (*bufp)[pos])
+	if ('\0' == *cp)
 		return(ROFF_IGN);
 
 	/* If present, process the custom end-of-line marker. */
 
-	sv = pos;
-	while ((*bufp)[pos] && ! isspace((unsigned char)(*bufp)[pos]))
-		pos++;
-
-	/*
-	 * Note: groff does NOT like escape characters in the input.
-	 * Instead of detecting this, we're just going to let it fly and
-	 * to hell with it.
-	 */
-
-	assert(pos > sv);
-	sz = (size_t)(pos - sv);
-
-	if (1 == sz && '.' == (*bufp)[sv])
-		return(ROFF_IGN);
-
-	r->last->end = mandoc_malloc(sz + 1);
-
-	memcpy(r->last->end, *bufp + sv, sz);
-	r->last->end[(int)sz] = '\0';
+	name = cp;
+	namesz = roff_getname(r, &cp, ln, ppos);
+	if (namesz)
+		r->last->end = mandoc_strndup(name, namesz);
 
-	if ((*bufp)[pos])
+	if ('\0' != *cp)
 		mandoc_msg(MANDOCERR_ARGSLOST, r->parse, ln, pos, NULL);
 
 	return(ROFF_IGN);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-06-29 22:38 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=201406292238.s5TMclHC003530@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).