From: schwarze Date: Sun, 11 Jun 2017 19:36:31 +0000 (+0000) Subject: Style message about legacy man(7) date format in mdoc(7) documents X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=3427e516dc4b7945a9b6bdac78d32baac2599fab;p=openbsd Style message about legacy man(7) date format in mdoc(7) documents and operating system dependent messages about missing or unexpected Mdocdate; inspired by mdoclint(1). --- diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h index 41d31723c88..4b42b61b544 100644 --- a/usr.bin/mandoc/libmandoc.h +++ b/usr.bin/mandoc/libmandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libmandoc.h,v 1.52 2017/04/29 12:43:55 schwarze Exp $ */ +/* $OpenBSD: libmandoc.h,v 1.53 2017/06/11 19:36:31 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -45,7 +45,7 @@ void mandoc_vmsg(enum mandocerr, struct mparse *, int, int, const char *, ...) __attribute__((__format__ (__printf__, 5, 6))); char *mandoc_getarg(struct mparse *, char **, int, int *); -char *mandoc_normdate(struct mparse *, char *, int, int); +char *mandoc_normdate(struct roff_man *, char *, int, int); int mandoc_eos(const char *, size_t); int mandoc_strntoi(const char *, size_t, int); const char *mandoc_a2msec(const char*); diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 38c9f6d3e4f..bf59a013f06 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.98 2017/05/05 15:16:25 schwarze Exp $ */ +/* $OpenBSD: man_validate.c,v 1.99 2017/06/11 19:36:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -165,7 +165,7 @@ check_root(CHKARGS) man->meta.title = mandoc_strdup(""); man->meta.msec = mandoc_strdup(""); man->meta.date = man->quick ? mandoc_strdup("") : - mandoc_normdate(man->parse, NULL, n->line, n->pos); + mandoc_normdate(man, NULL, n->line, n->pos); } } @@ -321,8 +321,7 @@ post_TH(CHKARGS) if (n && n->string && '\0' != n->string[0]) { man->meta.date = man->quick ? mandoc_strdup(n->string) : - mandoc_normdate(man->parse, n->string, - n->line, n->pos); + mandoc_normdate(man, n->string, n->line, n->pos); } else { man->meta.date = mandoc_strdup(""); mandoc_msg(MANDOCERR_DATE_MISSING, man->parse, diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c index f667c59fee0..8000e4ad664 100644 --- a/usr.bin/mandoc/mandoc.c +++ b/usr.bin/mandoc/mandoc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.c,v 1.68 2017/06/02 19:21:03 schwarze Exp $ */ +/* $OpenBSD: mandoc.c,v 1.69 2017/06/11 19:36:31 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2011-2015, 2017 Ingo Schwarze @@ -26,8 +26,9 @@ #include #include -#include "mandoc.h" #include "mandoc_aux.h" +#include "mandoc.h" +#include "roff.h" #include "libmandoc.h" static int a2time(time_t *, const char *, const char *); @@ -513,14 +514,14 @@ fail: } char * -mandoc_normdate(struct mparse *parse, char *in, int ln, int pos) +mandoc_normdate(struct roff_man *man, char *in, int ln, int pos) { time_t t; /* No date specified: use today's date. */ if (in == NULL || *in == '\0' || strcmp(in, "$" "Mdocdate$") == 0) { - mandoc_msg(MANDOCERR_DATE_MISSING, parse, ln, pos, NULL); + mandoc_msg(MANDOCERR_DATE_MISSING, man->parse, ln, pos, NULL); return time2a(time(NULL)); } @@ -530,10 +531,13 @@ mandoc_normdate(struct mparse *parse, char *in, int ln, int pos) a2time(&t, "%b %d, %Y", in)) return time2a(t); - /* Do not warn about the legacy man(7) format. */ + /* In man(7), do not warn about the legacy format. */ - if ( ! a2time(&t, "%Y-%m-%d", in)) - mandoc_msg(MANDOCERR_DATE_BAD, parse, ln, pos, in); + if (a2time(&t, "%Y-%m-%d", in) == 0) + mandoc_msg(MANDOCERR_DATE_BAD, man->parse, ln, pos, in); + else if (man->macroset == MACROSET_MDOC) + mandoc_vmsg(MANDOCERR_DATE_LEGACY, man->parse, + ln, pos, "Dd %s", in); /* Use any non-mdoc(7) date verbatim. */ diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index d659d20d873..6f14e23ec31 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.170 2017/06/11 17:16:36 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.171 2017/06/11 19:36:31 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -46,6 +46,9 @@ enum mandocerr { MANDOCERR_STYLE, /* ===== start of style suggestions ===== */ + MANDOCERR_MDOCDATE, /* Mdocdate found: Dd ... */ + MANDOCERR_MDOCDATE_MISSING, /* Mdocdate missing: Dd ... */ + MANDOCERR_DATE_LEGACY, /* legacy man(7) date format: Dd ... */ 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 b78256c501c..257e7204f6a 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.251 2017/06/11 17:16:36 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.252 2017/06/11 19:36:31 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -1775,9 +1775,8 @@ post_root(POST_ARGS) /* Add missing prologue data. */ if (mdoc->meta.date == NULL) - mdoc->meta.date = mdoc->quick ? - mandoc_strdup("") : - mandoc_normdate(mdoc->parse, NULL, 0, 0); + mdoc->meta.date = mdoc->quick ? mandoc_strdup("") : + mandoc_normdate(mdoc, NULL, 0, 0); if (mdoc->meta.title == NULL) { mandoc_msg(MANDOCERR_DT_NOTITLE, @@ -2333,7 +2332,7 @@ post_dd(POST_ARGS) if (n->child == NULL || n->child->string[0] == '\0') { mdoc->meta.date = mdoc->quick ? mandoc_strdup("") : - mandoc_normdate(mdoc->parse, NULL, n->line, n->pos); + mandoc_normdate(mdoc, NULL, n->line, n->pos); return; } @@ -2342,7 +2341,7 @@ post_dd(POST_ARGS) if (mdoc->quick) mdoc->meta.date = datestr; else { - mdoc->meta.date = mandoc_normdate(mdoc->parse, + mdoc->meta.date = mandoc_normdate(mdoc, datestr, n->line, n->pos); free(datestr); } @@ -2554,6 +2553,29 @@ post_os(POST_ARGS) 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; + + /* + * This is the earliest point where we can check + * Mdocdate conventions because we don't know + * the operating system earlier. + */ + + while (n->tok != MDOC_Dd) + if ((n = n->prev) == NULL) + return; + if ((n = n->child) == NULL) + return; + if (strcmp(n->string, "$" "Mdocdate")) { + if (mdoc->meta.os_e == MDOC_OS_OPENBSD) + mandoc_vmsg(MANDOCERR_MDOCDATE_MISSING, + mdoc->parse, n->line, n->pos, + "Dd %s", n->string); + } else { + if (mdoc->meta.os_e == MDOC_OS_NETBSD) + mandoc_vmsg(MANDOCERR_MDOCDATE, + mdoc->parse, n->line, n->pos, + "Dd %s", n->string); + } } enum roff_sec diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 4de20b114ac..2f794e23a53 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.147 2017/06/11 17:16:36 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.148 2017/06/11 19:36:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -84,6 +84,9 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "generic style suggestion", + "Mdocdate found", + "Mdocdate missing", + "legacy man(7) date format", "useless macro", "consider using OS macro", "errnos out of order",