From: schwarze Date: Sat, 17 Jun 2017 22:40:27 +0000 (+0000) Subject: style message about missing RCS ids; inspired by mdoclint X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=172864f7d93ba0d8df37f4bdb67469680cf6c670;p=openbsd style message about missing RCS ids; inspired by mdoclint --- diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 8e85eba162a..3532ceb56c5 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_validate.c,v 1.100 2017/06/17 16:47:29 schwarze Exp $ */ +/* $OpenBSD: man_validate.c,v 1.101 2017/06/17 22:40:27 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -168,6 +168,10 @@ check_root(CHKARGS) man->meta.date = man->quick ? mandoc_strdup("") : mandoc_normdate(man, NULL, n->line, n->pos); } + + if (man->meta.os_e && + (man->meta.rcsids & (1 << man->meta.os_e)) == 0) + mandoc_msg(MANDOCERR_RCS_MISSING, man->parse, 0, 0, NULL); } static void @@ -336,6 +340,10 @@ post_TH(CHKARGS) man->meta.os = mandoc_strdup(n->string); else if (man->defos != NULL) man->meta.os = mandoc_strdup(man->defos); + man->meta.os_e = man->meta.os == NULL ? MDOC_OS_OTHER : + strstr(man->meta.os, "OpenBSD") != NULL ? MDOC_OS_OPENBSD : + strstr(man->meta.os, "NetBSD") != NULL ? MDOC_OS_NETBSD : + MDOC_OS_OTHER; /* TITLE MSEC DATE OS ->VOL<- */ /* If missing, use the default VOL name for MSEC. */ diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 19253b8219d..0e6d6b322cc 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.123 2017/06/13 15:05:22 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.124 2017/06/17 22:40:27 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 13 2017 $ +.Dd $Mdocdate: June 17 2017 $ .Dt MANDOC 1 .Os .Sh NAME @@ -757,6 +757,48 @@ of the .Xr uname 3 function. .Bl -ohang +.It Sy "Mdocdate found" +.Pq mdoc , Nx +The +.Ic \&Dd +macro uses CVS +.Ic Mdocdate +keyword substitution, which is not supported by the +.Nx +base system. +Consider using the conventional +.Dq "Month dd, yyyy" +format instead. +.It Sy "Mdocdate missing" +.Pq mdoc , Ox +The +.Ic \&Dd +macro does not use CVS +.Ic Mdocdate +keyword substitution, but using it is conventionally expected in the +.Ox +base system. +.It Sy "legacy man(7) date format" +.Pq mdoc +The +.Ic \&Dd +macro uses the legacy +.Xr man 7 +date format +.Dq yyyy-dd-mm . +Consider using the conventional +.Xr mdoc 7 +date format +.Dq "Month dd, yyyy" +instead. +.It Sy "RCS id missing" +.Pq Ox , Nx +The manual page lacks the comment line with the RCS identifier +generated by CVS +.Ic OpenBSD +or +.Ic NetBSD +keyword substitution as conventionally used in these operating systems. .It Sy "useless macro" .Pq mdoc A diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index ed4d1d7fc17..bb7b9c32ebd 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.172 2017/06/14 01:31:19 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.173 2017/06/17 22:40:27 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -49,6 +49,7 @@ enum mandocerr { MANDOCERR_MDOCDATE, /* Mdocdate found: Dd ... */ MANDOCERR_MDOCDATE_MISSING, /* Mdocdate missing: Dd ... */ MANDOCERR_DATE_LEGACY, /* legacy man(7) date format: Dd ... */ + MANDOCERR_RCS_MISSING, /* RCS id missing */ MANDOCERR_MACRO_USELESS, /* useless macro: macro */ MANDOCERR_BX, /* consider using OS macro: macro */ MANDOCERR_ER_ORDER, /* errnos out of order: Er ... */ diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 13ee30cc51c..1f56a980ea1 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.253 2017/06/11 20:02:48 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.254 2017/06/17 22:40:27 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -1791,7 +1791,10 @@ post_root(POST_ARGS) mandoc_msg(MANDOCERR_OS_MISSING, mdoc->parse, 0, 0, NULL); mdoc->meta.os = mandoc_strdup(""); - } + } else if (mdoc->meta.os_e && + (mdoc->meta.rcsids & (1 << mdoc->meta.os_e)) == 0) + mandoc_msg(MANDOCERR_RCS_MISSING, + mdoc->parse, 0, 0, NULL); /* Check that we begin with a proper `Sh'. */ diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 2f794e23a53..83422873abc 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.148 2017/06/11 19:36:31 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.149 2017/06/17 22:40:27 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -87,6 +87,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "Mdocdate found", "Mdocdate missing", "legacy man(7) date format", + "RCS id missing", "useless macro", "consider using OS macro", "errnos out of order", diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 7193bdba615..516c13217d1 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.184 2017/06/14 22:50:37 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.185 2017/06/17 22:40:27 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017 Ingo Schwarze @@ -1164,6 +1164,7 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos) size_t maxl; /* expected length of the escape name */ size_t naml; /* actual length of the escape name */ enum mandoc_esc esc; /* type of the escape sequence */ + enum mdoc_os os_e; /* kind of RCS id seen */ int inaml; /* length returned from mandoc_escape() */ int expand_count; /* to avoid infinite loops */ int npos; /* position in numeric expression */ @@ -1181,6 +1182,23 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos) stesc++; if (*stesc != '"' && *stesc != '#') continue; + + /* Comment found, look for RCS id. */ + + if ((cp = strstr(stesc, "$" "OpenBSD")) != NULL) { + os_e = MDOC_OS_OPENBSD; + cp += 8; + } else if ((cp = strstr(stesc, "$" "NetBSD")) != NULL) { + os_e = MDOC_OS_NETBSD; + cp += 7; + } + if (cp != NULL && + isalnum((unsigned char)*cp) == 0 && + strchr(cp, '$') != NULL) + r->man->meta.rcsids |= 1 << os_e; + + /* Handle trailing whitespace. */ + cp = strchr(stesc--, '\0') - 1; if (*cp == '\n') { done = 1; diff --git a/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h index ae8b99755e4..c68464693fd 100644 --- a/usr.bin/mandoc/roff.h +++ b/usr.bin/mandoc/roff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.h,v 1.36 2017/06/14 22:50:37 schwarze Exp $ */ +/* $OpenBSD: roff.h,v 1.37 2017/06/17 22:40:27 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze @@ -534,6 +534,7 @@ struct roff_meta { char *name; /* Leading manual name. */ char *date; /* Normalized date. */ int hasbody; /* Document is not empty. */ + int rcsids; /* Bits indexed by enum mdoc_os. */ enum mdoc_os os_e; /* Operating system. */ };