summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-07-26 14:09:01 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-07-26 14:09:01 +0000
commit860d4862be0dcf8d5e32e84e8ff985a8f9588aa2 (patch)
treea8189ad0df55799d4087ce84e9569f39f5ac5293
parent50079d4076610ce94c315c3ead86fa3dd19dc673 (diff)
downloadmandoc-860d4862be0dcf8d5e32e84e8ff985a8f9588aa2.tar.gz
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.
-rw-r--r--man_validate.c42
-rw-r--r--mdoc_validate.c36
-rw-r--r--roff.c14
3 files changed, 24 insertions, 68 deletions
diff --git a/man_validate.c b/man_validate.c
index 257bb6de..8d61d303 100644
--- a/man_validate.c
+++ b/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);
}
}
diff --git a/mdoc_validate.c b/mdoc_validate.c
index f8ea5b6a..77ad71b9 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -545,39 +545,13 @@ check_argv(struct mdoc *m, struct mdoc_node *n, struct mdoc_argv *v)
static void
check_text(struct mdoc *m, int ln, int pos, char *p)
{
- char *cpp, *pp;
- size_t sz;
-
- while ('\0' != *p) {
- sz = strcspn(p, "\t\\");
-
- p += (int)sz;
- pos += (int)sz;
+ char *cp;
- 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);
}
}
diff --git a/roff.c b/roff.c
index 2ee06873..140673e1 100644
--- a/roff.c
+++ b/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, size_t *szp, int ln, int pos)
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