From e41d5b43e124d26f83cd86b64dd41d5ab85b1ef4 Mon Sep 17 00:00:00 2001 From: schwarze Date: Mon, 3 Jul 2017 13:40:00 +0000 Subject: [PATCH] warn about time machines; suggested by Thomas Klausner --- usr.bin/mandoc/mandoc.1 | 12 ++++++++++-- usr.bin/mandoc/mandoc.c | 14 +++++++++++--- usr.bin/mandoc/mandoc.h | 3 ++- usr.bin/mandoc/read.c | 3 ++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 1304a3fae47..d73611dadba 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.135 2017/07/02 15:31:48 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.136 2017/07/03 13:40:00 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: July 2 2017 $ +.Dd $Mdocdate: July 3 2017 $ .Dt MANDOC 1 .Os .Sh NAME @@ -981,6 +981,14 @@ The date given in a or .Ic \&TH macro does not follow the conventional format. +.It Sy "date in the future, using it anyway" +.Pq mdoc , man +The date given in a +.Ic \&Dd +or +.Ic \&TH +macro is more than a day ahead of the current system +.Xr time 3 . .It Sy "missing Os macro, using \(dq\(dq" .Pq mdoc The default or current system is not shown in this case. diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c index 3aff3c5b77f..92637e41d93 100644 --- a/usr.bin/mandoc/mandoc.c +++ b/usr.bin/mandoc/mandoc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.c,v 1.70 2017/06/14 01:31:19 schwarze Exp $ */ +/* $OpenBSD: mandoc.c,v 1.71 2017/07/03 13:40:00 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2011-2015, 2017 Ingo Schwarze @@ -518,6 +518,7 @@ fail: char * mandoc_normdate(struct roff_man *man, char *in, int ln, int pos) { + char *cp; time_t t; /* No date specified: use today's date. */ @@ -530,13 +531,20 @@ mandoc_normdate(struct roff_man *man, char *in, int ln, int pos) /* Valid mdoc(7) date format. */ if (a2time(&t, "$" "Mdocdate: %b %d %Y $", in) || - a2time(&t, "%b %d, %Y", in)) - return time2a(t); + a2time(&t, "%b %d, %Y", in)) { + cp = time2a(t); + if (t > time(NULL) + 86400) + mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse, + ln, pos, cp); + return cp; + } /* In man(7), do not warn about the legacy format. */ if (a2time(&t, "%Y-%m-%d", in) == 0) mandoc_msg(MANDOCERR_DATE_BAD, man->parse, ln, pos, in); + else if (t > time(NULL) + 86400) + mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse, ln, pos, in); else if (man->macroset == MACROSET_MDOC) mandoc_vmsg(MANDOCERR_DATE_LEGACY, man->parse, ln, pos, "Dd %s", in); diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index a4443df99d9..4fa2e6241eb 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.181 2017/07/02 15:31:48 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.182 2017/07/03 13:40:00 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -76,6 +76,7 @@ enum mandocerr { MANDOCERR_MSEC_BAD, /* unknown manual section: Dt ... section */ MANDOCERR_DATE_MISSING, /* missing date, using today's date */ MANDOCERR_DATE_BAD, /* cannot parse date, using it verbatim: date */ + MANDOCERR_DATE_FUTURE, /* date in the future, using it anyway: date */ MANDOCERR_OS_MISSING, /* missing Os macro, using "" */ MANDOCERR_PROLOG_REP, /* duplicate prologue macro: macro */ MANDOCERR_PROLOG_LATE, /* late prologue macro: macro */ diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 5e341726f81..5c409947c49 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.157 2017/07/02 15:31:48 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.158 2017/07/03 13:40:00 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -114,6 +114,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "unknown manual section", "missing date, using today's date", "cannot parse date, using it verbatim", + "date in the future, using it anyway", "missing Os macro, using \"\"", "duplicate prologue macro", "late prologue macro", -- 2.20.1