summaryrefslogtreecommitdiffstats
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-07-20 14:56:42 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-07-20 14:56:42 +0000
commit714ad8829b754f1142d7471b3dbf5e2400f8e96d (patch)
tree9965fff6f010f018954e66473e011ccd37583e5e /mdoc_validate.c
parentf4173e3c44a199bfbd7efb30b4ee4f84855706ba (diff)
downloadmandoc-714ad8829b754f1142d7471b3dbf5e2400f8e96d.tar.gz
Strip non-graphable input characters from input. The manuals
specifically say that this is not allowed, and were it allowed, output would be inconsistent across output media (-Tps will puke, non-your-charset terminals will puke, etc.). With this done, simplify check_text() to only check escapes and for tabs. Add in a new tab warning, too.
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 6bd6c14d..cc00a1ae 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -453,26 +453,29 @@ check_argv(struct mdoc *m, struct mdoc_node *n, struct mdoc_argv *v)
static int
-check_text(struct mdoc *mdoc, int line, int pos, char *p)
+check_text(struct mdoc *m, int ln, int pos, char *p)
{
int c;
-
- /*
- * FIXME: we absolutely cannot let \b get through or it will
- * destroy some assumptions in terms of format.
- */
+ size_t sz;
for ( ; *p; p++, pos++) {
+ sz = strcspn(p, "\t\\");
+ p += (int)sz;
+
+ if ('\0' == *p)
+ break;
+
+ pos += (int)sz;
+
if ('\t' == *p) {
- if ( ! (MDOC_LITERAL & mdoc->flags))
- if ( ! mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADCHAR))
- return(0);
- } else if ( ! isprint((u_char)*p) && ASCII_HYPH != *p)
- if ( ! mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADCHAR))
- return(0);
+ if (MDOC_LITERAL & m->flags)
+ continue;
+ if (mdoc_pmsg(m, ln, pos, MANDOCERR_BADTAB))
+ continue;
+ return(0);
+ }
- if ('\\' != *p)
- continue;
+ /* Check the special character. */
c = mandoc_special(p);
if (c) {
@@ -481,8 +484,8 @@ check_text(struct mdoc *mdoc, int line, int pos, char *p)
continue;
}
- c = mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADESCAPE);
- if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags) && ! c)
+ c = mdoc_pmsg(m, ln, pos, MANDOCERR_BADESCAPE);
+ if ( ! (MDOC_IGN_ESCAPE & m->pflags) && ! c)
return(c);
}
@@ -490,8 +493,6 @@ check_text(struct mdoc *mdoc, int line, int pos, char *p)
}
-
-
static int
check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t)
{
@@ -509,7 +510,6 @@ check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t)
}
-
static int
pre_display(PRE_ARGS)
{