diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-06-23 22:31:27 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-06-23 22:31:27 +0000 |
commit | efac769419567f13c2a4f60f6fd0c0c955cd6811 (patch) | |
tree | fdb0ee8495a1837402aff8f73ea6c137c38da98e /usr.bin/mandoc | |
parent | ad4bfb99fde5cb4c7f0f05ec493e09b53f62b67d (diff) |
sync to 1.7.20: root and text validation for -man
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/main.c | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/man.h | 6 | ||||
-rw-r--r-- | usr.bin/mandoc/man_validate.c | 53 |
4 files changed, 51 insertions, 21 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 8b4d12650f7..cbf33a3afb4 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.7 2009/06/21 20:10:31 schwarze Exp $ */ +/* $Id: main.c,v 1.8 2009/06/23 22:31:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -219,10 +219,12 @@ man_init(struct curparse *curp) /* Defaults from mandoc.1. */ - pflags = MAN_IGN_MACRO; + pflags = MAN_IGN_MACRO | MAN_IGN_CHARS; if (curp->fflags & NO_IGN_MACRO) pflags &= ~MAN_IGN_MACRO; + if (curp->fflags & NO_IGN_CHARS) + pflags &= ~MAN_IGN_CHARS; if (NULL == (man = man_alloc(curp, pflags, &mancb))) warnx("memory exhausted"); diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index 6c00c53c852..cfa06a08604 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.4 2009/06/23 22:05:42 schwarze Exp $ */ +/* $Id: man.c,v 1.5 2009/06/23 22:31:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -182,6 +182,8 @@ man_node_append(struct man *man, struct man_node *p) abort(); /* NOTREACHED */ } + + p->parent->nchild++; man->last = p; @@ -250,6 +252,8 @@ man_node_free(struct man_node *p) if (p->string) free(p->string); + if (p->parent) + p->parent->nchild--; free(p); } @@ -263,6 +267,7 @@ man_node_freelist(struct man_node *p) if (p->next) man_node_freelist(p->next); + assert(0 == p->nchild); man_node_free(p); } diff --git a/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h index 8457a5fcc98..4b966542839 100644 --- a/usr.bin/mandoc/man.h +++ b/usr.bin/mandoc/man.h @@ -1,4 +1,4 @@ -/* $Id: man.h,v 1.3 2009/06/18 23:34:53 schwarze Exp $ */ +/* $Id: man.h,v 1.4 2009/06/23 22:31:26 schwarze Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -63,6 +63,7 @@ struct man_node { struct man_node *child; struct man_node *next; struct man_node *prev; + int nchild; int line; int pos; int tok; @@ -73,7 +74,8 @@ struct man_node { char *string; }; -#define MAN_IGN_MACRO (1 << 0) /* Ignore unknown macros. */ +#define MAN_IGN_MACRO (1 << 0) +#define MAN_IGN_CHARS (1 << 1) extern const char *const *man_macronames; diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 4f6b53f3fa3..08e2a1ca72e 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $Id: man_validate.c,v 1.3 2009/06/18 23:34:53 schwarze Exp $ */ +/* $Id: man_validate.c,v 1.4 2009/06/23 22:31:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -23,8 +23,6 @@ #include "libman.h" -/* FIXME: validate text. */ - #define POSTARGS struct man *m, const struct man_node *n typedef int (*v_post)(POSTARGS); @@ -33,13 +31,14 @@ struct man_valid { v_post *posts; }; -static int count(const struct man_node *); static int check_eq0(POSTARGS); static int check_ge1(POSTARGS); static int check_ge2(POSTARGS); static int check_le1(POSTARGS); static int check_le2(POSTARGS); static int check_le5(POSTARGS); +static int check_text(POSTARGS); +static int check_root(POSTARGS); static v_post posts_le1[] = { check_le1, NULL }; static v_post posts_le2[] = { check_le2, NULL }; @@ -85,9 +84,9 @@ man_valid_post(struct man *m) switch (m->last->type) { case (MAN_TEXT): - /* FALLTHROUGH */ + return(check_text(m, m->last)); case (MAN_ROOT): - return(1); + return(check_root(m, m->last)); default: break; } @@ -102,14 +101,37 @@ man_valid_post(struct man *m) } -static inline int -count(const struct man_node *n) -{ - int i; +static int +check_root(POSTARGS) +{ + + if (NULL == m->first->child) + return(man_nerr(m, n, WNODATA)); + if (NULL == m->meta.title) + return(man_nerr(m, n, WNOTITLE)); + + return(1); +} + + +static int +check_text(POSTARGS) +{ + const char *p; + int pos; + + assert(n->string); + + for (p = n->string, pos = n->pos + 1; *p; p++, pos++) { + if ('\t' == *p || isprint((u_char)*p)) + continue; - for (i = 0; n; n = n->next, i++) - /* Loop. */ ; - return(i); + if (MAN_IGN_CHARS & m->pflags) + return(man_pwarn(m, n->line, pos, WNPRINT)); + return(man_perr(m, n->line, pos, WNPRINT)); + } + + return(1); } @@ -117,12 +139,11 @@ count(const struct man_node *n) static int \ check_##name(POSTARGS) \ { \ - int c; \ - if ((c = count(n->child)) ineq (x)) \ + if (n->nchild ineq (x)) \ return(1); \ return(man_verr(m, n->line, n->pos, \ "expected line arguments %s %d, have %d", \ - #ineq, (x), c)); \ + #ineq, (x), n->nchild)); \ } INEQ_DEFINE(0, ==, eq0) |