source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Move checking of escapes into roff.c, where we're already
Date: Tue, 26 Jul 2011 10:09:01 -0400 (EDT)	[thread overview]
Message-ID: <201107261409.p6QE91Uq002355@krisdoz.my.domain> (raw)

Log Message:
-----------
Move checking of escapes into roff.c, where we're already stepping
through looking for user-defined escapes.  This clears up a nice bit of
validation code.

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

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.171
retrieving revision 1.172
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.171 -r1.172
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -545,39 +545,13 @@ check_argv(struct mdoc *m, struct mdoc_n
 static void
 check_text(struct mdoc *m, int ln, int pos, char *p)
 {
-	char		*cpp, *pp;
-	size_t		 sz;
+	char		*cp;
 
-	while ('\0' != *p) {
-		sz = strcspn(p, "\t\\");
-
-		p += (int)sz;
-		pos += (int)sz;
-
-		if ('\t' == *p) {
-			if ( ! (MDOC_LITERAL & m->flags))
-				mdoc_pmsg(m, ln, pos, MANDOCERR_BADTAB);
-			p++;
-			pos++;
+	cp = p;
+	for (cp = p; NULL != (p = strchr(p, '\t')); p++) {
+		if (MDOC_LITERAL & m->flags)
 			continue;
-		} else if ('\0' == *p)
-			break;
-
-		pos++;
-		pp = ++p;
-
-		if (ESCAPE_ERROR == mandoc_escape
-				((const char **)&pp, NULL, NULL)) {
-			mdoc_pmsg(m, ln, pos, MANDOCERR_BADESCAPE);
-			break;
-		}
-
-		cpp = p;
-		while (NULL != (cpp = memchr(cpp, ASCII_HYPH, pp - cpp)))
-			*cpp = '-';
-
-		pos += pp - p;
-		p = pp;
+		mdoc_pmsg(m, ln, (int)(p - cp), MANDOCERR_BADTAB);
 	}
 }
 
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.151
retrieving revision 1.152
diff -Lroff.c -Lroff.c -u -p -r1.151 -r1.152
--- roff.c
+++ roff.c
@@ -404,6 +404,7 @@ roff_alloc(struct mparse *parse)
 static int
 roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)
 {
+	enum mandoc_esc	 esc;
 	const char	*stesc;	/* start of an escape sequence ('\\') */
 	const char	*stnam;	/* start of the name, after "[(*" */
 	const char	*cp;	/* end of the name, e.g. before ']' */
@@ -426,8 +427,19 @@ roff_res(struct roff *r, char **bufp, si
 
 		if ('\0' == *cp)
 			return(1);
-		if ('*' != *cp++)
+
+		if ('*' != *cp) {
+			res = cp;
+			esc = mandoc_escape(&cp, NULL, NULL);
+			if (ESCAPE_ERROR != esc)
+				continue;
+			mandoc_msg(MANDOCERR_BADESCAPE, 
+					r->parse, ln, pos, NULL);
+			cp = res;
 			continue;
+		}
+
+		cp++;
 
 		/*
 		 * The third character decides the length
Index: man_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_validate.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -Lman_validate.c -Lman_validate.c -u -p -r1.71 -r1.72
--- man_validate.c
+++ man_validate.c
@@ -207,45 +207,15 @@ check_root(CHKARGS) 
 }
 
 static void
-check_text(CHKARGS) 
+check_text(CHKARGS)
 {
-	char		*p, *pp, *cpp;
-	int		 pos;
-	size_t		 sz;
+	char		*cp, *p;
 
-	p = n->string;
-	pos = n->pos + 1;
-
-	while ('\0' != *p) {
-		sz = strcspn(p, "\t\\");
-
-		p += (int)sz;
-		pos += (int)sz;
-
-		if ('\t' == *p) {
-			if ( ! (MAN_LITERAL & m->flags))
-				man_pmsg(m, n->line, pos, MANDOCERR_BADTAB);
-			p++;
-			pos++;
+	cp = p = n->string;
+	for (cp = p; NULL != (p = strchr(p, '\t')); p++) {
+		if (MAN_LITERAL & m->flags)
 			continue;
-		} else if ('\0' == *p)
-			break;
-
-		pos++;
-		pp = ++p;
-
-		if (ESCAPE_ERROR == mandoc_escape
-				((const char **)&pp, NULL, NULL)) {
-			man_pmsg(m, n->line, pos, MANDOCERR_BADESCAPE);
-			break;
-		}
-
-		cpp = p;
-		while (NULL != (cpp = memchr(cpp, ASCII_HYPH, pp - cpp)))
-			*cpp = '-';
-
-		pos += pp - p;
-		p = pp;
+		man_pmsg(m, n->line, (int)(p - cp), MANDOCERR_BADTAB);
 	}
 }
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

             reply	other threads:[~2011-07-26 14:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-26 14:09 kristaps [this message]
2011-07-26 14:30 ` Kristaps Dzonsons

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=201107261409.p6QE91Uq002355@krisdoz.my.domain \
    --to=kristaps@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).