From 369129e10cecda27554b9987d819367bcfcf3353 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Mon, 22 Jun 2009 13:09:17 +0000 Subject: libman documents require `TH' and at least one node. libman requirements documented in man.7 STRUCTURE section. Added STRUCTURE section to mdoc.7, too. --- libman.h | 6 ++++-- man.7 | 21 +++++++++++++++++---- man.c | 8 +++++++- man_validate.c | 19 ++++++++++++++++--- mdoc.7 | 20 ++++++++++++++++++-- 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/libman.h b/libman.h index 8f1228d4..9509aa0d 100644 --- a/libman.h +++ b/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.10 2009/06/18 10:53:58 kristaps Exp $ */ +/* $Id: libman.h,v 1.11 2009/06/22 13:09:17 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -45,7 +45,9 @@ enum merr { WDATE, WLNSCOPE, WTSPACE, - WTQUOTE + WTQUOTE, + WNODATA, + WNOTITLE }; __BEGIN_DECLS diff --git a/man.7 b/man.7 index 42ab6e57..5cca8277 100644 --- a/man.7 +++ b/man.7 @@ -1,4 +1,4 @@ -.\" $Id: man.7,v 1.14 2009/06/18 10:32:00 kristaps Exp $ +.\" $Id: man.7,v 1.15 2009/06/22 13:09:17 kristaps Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 18 2009 $ +.Dd $Mdocdate: June 22 2009 $ .Dt MAN 7 .Os .\" SECTION @@ -97,7 +97,7 @@ Characters may alternatively be escaped by a slash-asterisk, .Sq \e* , with the same combinations as described above. This form is deprecated. .\" SECTION -.Sh STRUCTURE +.Sh SYNTAX Macros are one to three three characters in length and begin with a control character , .Sq \&. , @@ -155,7 +155,20 @@ The .Sq \&.TP macro is similar, but does not need an empty argument line to trigger the behaviour. -.\" PARAGRAPH +.\" SECTION +.Sh STRUCTURE +Each +.Nm +document must contain contains at least the +.Sq \&.TH +macro describing the document's section and title. It may occur +anywhere in the document, although conventionally, it appears as the +first macro. +.Pp +Beyond the +.Sq \&.TH , +at least one macro or text node must appear in the document. +.\" SECTION .Sh MACROS This section contains a complete list of all .Nm diff --git a/man.c b/man.c index 8067153c..bf53b87a 100644 --- a/man.c +++ b/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.24 2009/06/18 20:46:19 kristaps Exp $ */ +/* $Id: man.c,v 1.25 2009/06/22 13:09:17 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -466,6 +466,12 @@ man_err(struct man *m, int line, int pos, case (WTQUOTE): p = "unterminated quotation"; break; + case (WNODATA): + p = "document has no data"; + break; + case (WNOTITLE): + p = "document has no title/section"; + break; } assert(p); diff --git a/man_validate.c b/man_validate.c index 7c06e47d..7a573b76 100644 --- a/man_validate.c +++ b/man_validate.c @@ -1,4 +1,4 @@ -/* $Id: man_validate.c,v 1.13 2009/06/22 10:40:04 kristaps Exp $ */ +/* $Id: man_validate.c,v 1.14 2009/06/22 13:09:17 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -38,6 +38,7 @@ 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,8 +86,7 @@ man_valid_post(struct man *m) case (MAN_TEXT): return(check_text(m, m->last)); case (MAN_ROOT): - /* FIXME: validate that TH has been invoked! */ - return(1); + return(check_root(m, m->last)); default: break; } @@ -101,6 +101,19 @@ man_valid_post(struct man *m) } +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) { diff --git a/mdoc.7 b/mdoc.7 index 6228cc67..4b0914ac 100644 --- a/mdoc.7 +++ b/mdoc.7 @@ -1,4 +1,4 @@ -.\" $Id: mdoc.7,v 1.31 2009/06/22 12:22:35 kristaps Exp $ +.\" $Id: mdoc.7,v 1.32 2009/06/22 13:09:17 kristaps Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons .\" @@ -278,7 +278,23 @@ In-lines have \(>=0 scoped arguments. \&.Yy \(lB\-arg \(lBval...\(rB\(rB arg0 arg1 argN .Ed -.\" +.\" SECTION +.Sh STRUCTURE +Each +.Nm +document must begin with the document prologue, containing, in order, +.Sq \&.Dd , +.Sq \&.Dt , +and +.Sq \&.Os . +.Pp +Following these, the document body must begin with the NAME section +containing at least one +.Sq \&.Nm +followed by a +.Sq \&.Nd +macro. +.\" SECTION .Sh MACROS This section contains a complete list of all .Nm -- cgit v1.2.3-56-ge451