source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Move checking of escapes into roff.c, where we're already
@ 2011-07-26 14:09 kristaps
  2011-07-26 14:30 ` Kristaps Dzonsons
  0 siblings, 1 reply; 2+ messages in thread
From: kristaps @ 2011-07-26 14:09 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mdocml: Move checking of escapes into roff.c, where we're already
  2011-07-26 14:09 mdocml: Move checking of escapes into roff.c, where we're already kristaps
@ 2011-07-26 14:30 ` Kristaps Dzonsons
  0 siblings, 0 replies; 2+ messages in thread
From: Kristaps Dzonsons @ 2011-07-26 14:30 UTC (permalink / raw)
  To: source

> 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.

Note this temporarily breaks the switch-back of ASCII_HYPH to a regular 
hyphen, as I'm moving that logic into roff.c as well (making it 
unnecessary, rather).
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-26 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-26 14:09 mdocml: Move checking of escapes into roff.c, where we're already kristaps
2011-07-26 14:30 ` Kristaps Dzonsons

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).