From ce0ef8473022b7420e4d98edcbd2e884e90968cf Mon Sep 17 00:00:00 2001 From: schwarze Date: Wed, 7 Jun 2017 23:29:31 +0000 Subject: [PATCH] style checks related to .Er; inspired by mdoclint(1) --- usr.bin/mandoc/mandoc.1 | 34 +++++++++++++++++++++++++++-- usr.bin/mandoc/mandoc.h | 4 +++- usr.bin/mandoc/mdoc_validate.c | 40 +++++++++++++++++++++++++++++++--- usr.bin/mandoc/read.c | 4 +++- usr.bin/mandoc/roff.h | 9 +++++++- 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 2354ec21155..7a98442fb45 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.118 2017/06/06 15:00:56 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.119 2017/06/07 23:29:31 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" Copyright (c) 2012, 2014-2017 Ingo Schwarze @@ -15,7 +15,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 6 2017 $ +.Dd $Mdocdate: June 7 2017 $ .Dt MANDOC 1 .Os .Sh NAME @@ -75,6 +75,11 @@ and for the .Xr man 7 .Ic \&TH macro. +This can also be used to perform style checks according to the +conventions of one operating system while running on a different +operating system; see +.Sx Style messages +for details. .It Fl K Ar encoding Specify the input encoding. The supported @@ -743,6 +748,15 @@ option or .Fl T Cm lint output mode. .Ss Style messages +As indicated below, some style checks are only performed if a +specific operating system name occurs in the arguments of the +.Ic \&Os +macro, of the +.Fl Ios +command line option, or, if neither are present, in the return value +of the +.Xr uname 3 +function. .Bl -ohang .It Sy "useless macro" .Pq mdoc @@ -763,6 +777,22 @@ macro that could be represented using .Ic \&Fx , or .Ic \&Dx . +.It Sy "errnos out of order" +.Pq mdoc, Nx +The +.Ic \&Er +items in a +.Ic \&Bl +list are not in alphabetical order. +.It Sy "duplicate errno" +.Pq mdoc, Nx +A +.Ic \&Bl +list contains two consecutive +.Ic \&It +entries describing the same +.Ic \&Er +number. .It Sy "description line ends with a full stop" .Pq mdoc Do not use punctuation at the end of an diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index a0ddd429047..90910c5ca07 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.165 2017/06/06 15:00:56 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.166 2017/06/07 23:29:31 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -48,6 +48,8 @@ enum mandocerr { MANDOCERR_MACRO_USELESS, /* useless macro: macro */ MANDOCERR_BX, /* consider using OS macro: macro */ + MANDOCERR_ER_ORDER, /* errnos out of order: Er ... */ + MANDOCERR_ER_REP, /* duplicate errno: Er ... */ MANDOCERR_ND_DOT, /* description line ends with a full stop */ MANDOCERR_WARNING, /* ===== start of warnings ===== */ diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index aff0934fa67..fd3f38eddf5 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_validate.c,v 1.246 2017/06/01 15:24:41 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.247 2017/06/07 23:29:31 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -1467,6 +1467,8 @@ post_bl(POST_ARGS) struct roff_node *nparent, *nprev; /* of the Bl block */ struct roff_node *nblock, *nbody; /* of the Bl */ struct roff_node *nchild, *nnext; /* of the Bl body */ + const char *prev_Er; + int order; nbody = mdoc->last; switch (nbody->type) { @@ -1567,6 +1569,34 @@ post_bl(POST_ARGS) nchild = nnext; } + + if (mdoc->meta.os_e != MDOC_OS_NETBSD) + return; + + prev_Er = NULL; + for (nchild = nbody->child; nchild != NULL; nchild = nchild->next) { + if (nchild->tok != MDOC_It) + continue; + if ((nnext = nchild->head->child) == NULL) + continue; + if (nnext->type == ROFFT_BLOCK) + nnext = nnext->body->child; + if (nnext == NULL || nnext->tok != MDOC_Er) + continue; + nnext = nnext->child; + if (prev_Er != NULL) { + order = strcmp(prev_Er, nnext->string); + if (order > 0) + mandoc_vmsg(MANDOCERR_ER_ORDER, + mdoc->parse, nnext->line, nnext->pos, + "Er %s %s", prev_Er, nnext->string); + else if (order == 0) + mandoc_vmsg(MANDOCERR_ER_REP, + mdoc->parse, nnext->line, nnext->pos, + "Er %s", prev_Er); + } + prev_Er = nnext->string; + } } static void @@ -2373,11 +2403,11 @@ post_os(POST_ARGS) mdoc->meta.os = NULL; deroff(&mdoc->meta.os, n); if (mdoc->meta.os) - return; + goto out; if (mdoc->defos) { mdoc->meta.os = mandoc_strdup(mdoc->defos); - return; + goto out; } #ifdef OSNAME @@ -2394,6 +2424,10 @@ post_os(POST_ARGS) } mdoc->meta.os = mandoc_strdup(defbuf); #endif /*!OSNAME*/ + +out: mdoc->meta.os_e = strstr(mdoc->meta.os, "OpenBSD") != NULL ? + MDOC_OS_OPENBSD : strstr(mdoc->meta.os, "NetBSD") != NULL ? + MDOC_OS_NETBSD : MDOC_OS_OTHER; } enum roff_sec diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 7c6ccaed233..0d1089c71bf 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.143 2017/06/06 15:00:56 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.144 2017/06/07 23:29:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -86,6 +86,8 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "useless macro", "consider using OS macro", + "errnos out of order", + "duplicate errno", "description line ends with a full stop", "generic warning", diff --git a/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h index c1ce3b281a4..5f4df297751 100644 --- a/usr.bin/mandoc/roff.h +++ b/usr.bin/mandoc/roff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.h,v 1.33 2017/06/07 00:50:30 schwarze Exp $ */ +/* $OpenBSD: roff.h,v 1.34 2017/06/07 23:29:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze @@ -26,6 +26,12 @@ enum roff_macroset { MACROSET_MAN }; +enum mdoc_os { + MDOC_OS_OTHER = 0, + MDOC_OS_NETBSD, + MDOC_OS_OPENBSD +}; + enum roff_sec { SEC_NONE = 0, SEC_NAME, @@ -528,6 +534,7 @@ struct roff_meta { char *name; /* Leading manual name. */ char *date; /* Normalized date. */ int hasbody; /* Document is not empty. */ + enum mdoc_os os_e; /* Operating system. */ }; struct roff_man { -- 2.20.1