diff options
28 files changed, 96 insertions, 75 deletions
diff --git a/libmandoc.h b/libmandoc.h index ad76f021..88d2f00e 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2013-2015,2017,2018,2020 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -47,8 +47,9 @@ struct buf { struct roff; struct roff_man; +struct roff_node; -char *mandoc_normdate(struct roff_man *, char *, int, int); +char *mandoc_normdate(struct roff_node *, struct roff_node *); int mandoc_eos(const char *, size_t); int mandoc_strntoi(const char *, size_t, int); const char *mandoc_a2msec(const char*); diff --git a/man_validate.c b/man_validate.c index 421a4843..1d3078a7 100644 --- a/man_validate.c +++ b/man_validate.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010, 2012-2020 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -185,7 +185,7 @@ check_root(CHKARGS) man->meta.title = mandoc_strdup(""); man->meta.msec = mandoc_strdup(""); - man->meta.date = mandoc_normdate(man, NULL, n->line, n->pos); + man->meta.date = mandoc_normdate(NULL, NULL); } if (man->meta.os_e && @@ -401,15 +401,10 @@ post_TH(CHKARGS) if (n != NULL) n = n->next; - if (n != NULL && n->string != NULL && n->string[0] != '\0') - man->meta.date = mandoc_normdate(man, - n->string, n->line, n->pos); - else { + if (man->quick && n != NULL) man->meta.date = mandoc_strdup(""); - mandoc_msg(MANDOCERR_DATE_MISSING, - n == NULL ? nb->line : n->line, - n == NULL ? nb->pos : n->pos, "TH"); - } + else + man->meta.date = mandoc_normdate(n, nb); /* TITLE MSEC DATE ->OS<- VOL */ @@ -1073,7 +1073,7 @@ macro lacks the mandatory section argument. The section number in a .Ic \&Dt line is invalid, but still used. -.It Sy "missing date, using today's date" +.It Sy "missing date, using \(dq\(dq" .Pq mdoc, man The document was parsed as .Xr mdoc 7 @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -536,45 +536,59 @@ fail: } char * -mandoc_normdate(struct roff_man *man, char *in, int ln, int pos) +mandoc_normdate(struct roff_node *nch, struct roff_node *nbl) { char *cp; time_t t; - if (man->quick) - return mandoc_strdup(in == NULL ? "" : in); + /* No date specified. */ - /* No date specified: use today's date. */ - - if (in == NULL || *in == '\0') - mandoc_msg(MANDOCERR_DATE_MISSING, ln, pos, NULL); - if (in == NULL || *in == '\0' || strcmp(in, "$" "Mdocdate$") == 0) + if (nch == NULL) { + if (nbl == NULL) + mandoc_msg(MANDOCERR_DATE_MISSING, 0, 0, NULL); + else + mandoc_msg(MANDOCERR_DATE_MISSING, nbl->line, + nbl->pos, "%s", roff_name[nbl->tok]); + return mandoc_strdup(""); + } + if (*nch->string == '\0') { + mandoc_msg(MANDOCERR_DATE_MISSING, nch->line, + nch->pos, "%s", roff_name[nbl->tok]); + return mandoc_strdup(""); + } + if (strcmp(nch->string, "$" "Mdocdate$") == 0) return time2a(time(NULL)); /* Valid mdoc(7) date format. */ - if (a2time(&t, "$" "Mdocdate: %b %d %Y $", in) || - a2time(&t, "%b %d, %Y", in)) { + if (a2time(&t, "$" "Mdocdate: %b %d %Y $", nch->string) || + a2time(&t, "%b %d, %Y", nch->string)) { cp = time2a(t); if (t > time(NULL) + 86400) - mandoc_msg(MANDOCERR_DATE_FUTURE, ln, pos, "%s", cp); - else if (*in != '$' && strcmp(in, cp) != 0) - mandoc_msg(MANDOCERR_DATE_NORM, ln, pos, "%s", cp); + mandoc_msg(MANDOCERR_DATE_FUTURE, nch->line, + nch->pos, "%s %s", roff_name[nbl->tok], cp); + else if (*nch->string != '$' && + strcmp(nch->string, cp) != 0) + mandoc_msg(MANDOCERR_DATE_NORM, nch->line, + nch->pos, "%s %s", roff_name[nbl->tok], 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, ln, pos, "%s", in); + if (a2time(&t, "%Y-%m-%d", nch->string) == 0) + mandoc_msg(MANDOCERR_DATE_BAD, nch->line, nch->pos, + "%s %s", roff_name[nbl->tok], nch->string); else if (t > time(NULL) + 86400) - mandoc_msg(MANDOCERR_DATE_FUTURE, ln, pos, "%s", in); - else if (man->meta.macroset == MACROSET_MDOC) - mandoc_msg(MANDOCERR_DATE_LEGACY, ln, pos, "Dd %s", in); + mandoc_msg(MANDOCERR_DATE_FUTURE, nch->line, nch->pos, + "%s %s", roff_name[nbl->tok], nch->string); + else if (nbl->tok == MDOC_Dd) + mandoc_msg(MANDOCERR_DATE_LEGACY, nch->line, nch->pos, + "Dd %s", nch->string); /* Use any non-mdoc(7) date verbatim. */ - return mandoc_strdup(in); + return mandoc_strdup(nch->string); } int @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2012-2019 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2012-2020 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -83,7 +83,7 @@ enum mandocerr { MANDOCERR_TH_NOTITLE, /* missing manual title, using "": [macro] */ MANDOCERR_MSEC_MISSING, /* missing manual section, using "": macro */ MANDOCERR_MSEC_BAD, /* unknown manual section: Dt ... section */ - MANDOCERR_DATE_MISSING, /* missing date, using today's date */ + MANDOCERR_DATE_MISSING, /* missing date, using "": [macro] */ 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 "" */ diff --git a/mandoc_msg.c b/mandoc_msg.c index 15e4de01..2be6b0a1 100644 --- a/mandoc_msg.c +++ b/mandoc_msg.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2014-2019 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2014-2020 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -83,7 +83,7 @@ static const char *const type_message[MANDOCERR_MAX] = { "missing manual title, using \"\"", "missing manual section, using \"\"", "unknown manual section", - "missing date, using today's date", + "missing date, using \"\"", "cannot parse date, using it verbatim", "date in the future, using it anyway", "missing Os macro, using \"\"", diff --git a/mdoc_macro.c b/mdoc_macro.c index 2e3772dc..628e8391 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -61,7 +61,7 @@ static void rew_pending(struct roff_man *, const struct roff_node *); static const struct mdoc_macro mdoc_macros[MDOC_MAX - MDOC_Dd] = { - { in_line_eoln, MDOC_PROLOGUE }, /* Dd */ + { in_line_eoln, MDOC_PROLOGUE | MDOC_JOIN }, /* Dd */ { in_line_eoln, MDOC_PROLOGUE }, /* Dt */ { in_line_eoln, MDOC_PROLOGUE }, /* Os */ { blk_full, MDOC_PARSED | MDOC_JOIN }, /* Sh */ diff --git a/mdoc_validate.c b/mdoc_validate.c index 390667d5..f5f37b9f 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -1909,7 +1909,7 @@ post_root(POST_ARGS) /* Add missing prologue data. */ if (mdoc->meta.date == NULL) - mdoc->meta.date = mandoc_normdate(mdoc, NULL, 0, 0); + mdoc->meta.date = mandoc_normdate(NULL, NULL); if (mdoc->meta.title == NULL) { mandoc_msg(MANDOCERR_DT_NOTITLE, 0, 0, "EOF"); @@ -2507,7 +2507,6 @@ static void post_dd(POST_ARGS) { struct roff_node *n; - char *datestr; n = mdoc->last; n->flags |= NODE_NOPRT; @@ -2524,10 +2523,10 @@ post_dd(POST_ARGS) mandoc_msg(MANDOCERR_PROLOG_ORDER, n->line, n->pos, "Dd after Os"); - datestr = NULL; - deroff(&datestr, n); - mdoc->meta.date = mandoc_normdate(mdoc, datestr, n->line, n->pos); - free(datestr); + if (mdoc->quick && n != NULL) + mdoc->meta.date = mandoc_strdup(""); + else + mdoc->meta.date = mandoc_normdate(n->child, n); } static void diff --git a/regress/man/TH/baddate.out_lint b/regress/man/TH/baddate.out_lint index 6785463d..eed40c28 100644 --- a/regress/man/TH/baddate.out_lint +++ b/regress/man/TH/baddate.out_lint @@ -1 +1 @@ -mandoc: baddate.in:2:18: WARNING: cannot parse date, using it verbatim: three bad words +mandoc: baddate.in:2:18: WARNING: cannot parse date, using it verbatim: TH three bad words diff --git a/regress/man/TH/emptydate.out_lint b/regress/man/TH/emptydate.out_lint index dba0e545..15f4f171 100644 --- a/regress/man/TH/emptydate.out_lint +++ b/regress/man/TH/emptydate.out_lint @@ -1 +1 @@ -mandoc: emptydate.in:2:20: WARNING: missing date, using today's date: TH +mandoc: emptydate.in:2:20: WARNING: missing date, using "": TH diff --git a/regress/man/TH/longdate.out_lint b/regress/man/TH/longdate.out_lint index 3006dad3..45d0ef0b 100644 --- a/regress/man/TH/longdate.out_lint +++ b/regress/man/TH/longdate.out_lint @@ -1 +1 @@ -mandoc: longdate.in:2:19: WARNING: cannot parse date, using it verbatim: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012 +mandoc: longdate.in:2:19: WARNING: cannot parse date, using it verbatim: TH 1234567890123456789012345678901234567890123456789012345678901234567890123456789012 diff --git a/regress/man/TH/noTH.out_lint b/regress/man/TH/noTH.out_lint index 01b7b045..407308cb 100644 --- a/regress/man/TH/noTH.out_lint +++ b/regress/man/TH/noTH.out_lint @@ -1,2 +1,2 @@ mandoc: noTH.in: WARNING: missing manual title, using "" -mandoc: noTH.in: WARNING: missing date, using today's date +mandoc: noTH.in: WARNING: missing date, using "" diff --git a/regress/man/TH/noarg.out_lint b/regress/man/TH/noarg.out_lint index f4273215..fb994099 100644 --- a/regress/man/TH/noarg.out_lint +++ b/regress/man/TH/noarg.out_lint @@ -1,3 +1,3 @@ mandoc: noarg.in:2:2: WARNING: missing manual title, using "": TH mandoc: noarg.in:2:2: WARNING: missing manual section, using "": TH -mandoc: noarg.in:2:2: WARNING: missing date, using today's date: TH +mandoc: noarg.in:2:2: WARNING: missing date, using "": TH diff --git a/regress/man/TH/onearg.out_lint b/regress/man/TH/onearg.out_lint index 65062684..e86ec4e2 100644 --- a/regress/man/TH/onearg.out_lint +++ b/regress/man/TH/onearg.out_lint @@ -1,2 +1,2 @@ mandoc: onearg.in:2:2: WARNING: missing manual section, using "": TH TH-ONEARG -mandoc: onearg.in:2:2: WARNING: missing date, using today's date: TH +mandoc: onearg.in:2:2: WARNING: missing date, using "": TH diff --git a/regress/man/TH/twoargs.out_lint b/regress/man/TH/twoargs.out_lint index 3cd469f5..0211ddfa 100644 --- a/regress/man/TH/twoargs.out_lint +++ b/regress/man/TH/twoargs.out_lint @@ -1,2 +1,2 @@ mandoc: twoargs.in:2:2: WARNING: missing manual section, using "": TH TH-TWOARGS -mandoc: twoargs.in:2:2: WARNING: missing date, using today's date: TH +mandoc: twoargs.in:2:2: WARNING: missing date, using "": TH diff --git a/regress/mdoc/Dd/Makefile b/regress/mdoc/Dd/Makefile index e31b2730..9c48fd4e 100644 --- a/regress/mdoc/Dd/Makefile +++ b/regress/mdoc/Dd/Makefile @@ -1,20 +1,12 @@ -# $OpenBSD: Makefile,v 1.5 2020/01/08 10:17:15 schwarze Exp $ +# $OpenBSD: Makefile,v 1.6 2020/01/19 16:16:33 schwarze Exp $ REGRESS_TARGETS = badarg dupe late long manarg noarg order LINT_TARGETS = badarg dupe late long manarg noarg order -# noarg output contains the date when the file is formatted +# groff-1.22.4 prints footer fields of excessive length on top of +# each other rather than breaking the output line. -SKIP_ASCII ?= noarg -SKIP_MARKDOWN ?= noarg - -# If groff finds exactly three arguments, it assumes they are month, -# day and year without further checking. If there are no arguments, -# groff uses the string "Epoch". Otherwise, it silently falls back -# to today's date. -# That is not at all sane behaviour, we are not going to imitate it. - -SKIP_GROFF = badarg long manarg noarg +SKIP_GROFF = long # Autodetection fails for late .Dd, so specify -mdoc explicitly. diff --git a/regress/mdoc/Dd/badarg.out_lint b/regress/mdoc/Dd/badarg.out_lint index f463d775..70b82a40 100644 --- a/regress/mdoc/Dd/badarg.out_lint +++ b/regress/mdoc/Dd/badarg.out_lint @@ -1,2 +1,2 @@ -mandoc: badarg.in:2:2: WARNING: cannot parse date, using it verbatim: bad date +mandoc: badarg.in:2:5: WARNING: cannot parse date, using it verbatim: Dd bad date mandoc: badarg.in:2:5: STYLE: Mdocdate missing: Dd bad date (OpenBSD) diff --git a/regress/mdoc/Dd/dupe.out_lint b/regress/mdoc/Dd/dupe.out_lint index 72ccde41..8cb4ba96 100644 --- a/regress/mdoc/Dd/dupe.out_lint +++ b/regress/mdoc/Dd/dupe.out_lint @@ -1,3 +1,3 @@ -mandoc: dupe.in:2:5: STYLE: Mdocdate missing: Dd August (OpenBSD) +mandoc: dupe.in:2:5: STYLE: Mdocdate missing: Dd August 1, 2014 (OpenBSD) mandoc: dupe.in:5:2: ERROR: duplicate prologue macro: Dd mandoc: dupe.in:11:2: ERROR: duplicate prologue macro: Dd diff --git a/regress/mdoc/Dd/long.out_lint b/regress/mdoc/Dd/long.out_lint index a189560d..11597144 100644 --- a/regress/mdoc/Dd/long.out_lint +++ b/regress/mdoc/Dd/long.out_lint @@ -1,2 +1,2 @@ -mandoc: long.in:2:2: WARNING: cannot parse date, using it verbatim: 1234567890123456789012345678901234567890123456789012345678901234567890123456789 +mandoc: long.in:2:5: WARNING: cannot parse date, using it verbatim: Dd 1234567890123456789012345678901234567890123456789012345678901234567890123456789 mandoc: long.in:2:5: STYLE: Mdocdate missing: Dd 1234567890123456789012345678901234567890123456789012345678901234567890123456789 (OpenBSD) diff --git a/regress/mdoc/Dd/manarg.out_lint b/regress/mdoc/Dd/manarg.out_lint index a8f48f44..9fe5e21e 100644 --- a/regress/mdoc/Dd/manarg.out_lint +++ b/regress/mdoc/Dd/manarg.out_lint @@ -1,2 +1,2 @@ -mandoc: manarg.in:2:2: STYLE: legacy man(7) date format: Dd 2014-08-07 +mandoc: manarg.in:2:5: STYLE: legacy man(7) date format: Dd 2014-08-07 mandoc: manarg.in:2:5: STYLE: Mdocdate missing: Dd 2014-08-07 (OpenBSD) diff --git a/regress/mdoc/Dd/noarg.out_ascii b/regress/mdoc/Dd/noarg.out_ascii new file mode 100644 index 00000000..e9206d09 --- /dev/null +++ b/regress/mdoc/Dd/noarg.out_ascii @@ -0,0 +1,9 @@ +DD-NOARG(1) General Commands Manual DD-NOARG(1) + +NNAAMMEE + DDdd--nnooaarrgg - date macro without an argument + +DDEESSCCRRIIPPTTIIOONN + some text + +OpenBSD OpenBSD diff --git a/regress/mdoc/Dd/noarg.out_lint b/regress/mdoc/Dd/noarg.out_lint index e6ccd352..7202e12d 100644 --- a/regress/mdoc/Dd/noarg.out_lint +++ b/regress/mdoc/Dd/noarg.out_lint @@ -1 +1 @@ -mandoc: noarg.in:2:2: WARNING: missing date, using today's date +mandoc: noarg.in:2:2: WARNING: missing date, using "": Dd diff --git a/regress/mdoc/Dd/noarg.out_markdown b/regress/mdoc/Dd/noarg.out_markdown new file mode 100644 index 00000000..b5af6385 --- /dev/null +++ b/regress/mdoc/Dd/noarg.out_markdown @@ -0,0 +1,11 @@ +DD-NOARG(1) - General Commands Manual + +# NAME + +**Dd-noarg** - date macro without an argument + +# DESCRIPTION + +some text + +OpenBSD - diff --git a/regress/mdoc/Dd/order.out_lint b/regress/mdoc/Dd/order.out_lint index 4eb9d3bd..6cecfa13 100644 --- a/regress/mdoc/Dd/order.out_lint +++ b/regress/mdoc/Dd/order.out_lint @@ -1,2 +1,2 @@ mandoc: order.in:3:2: WARNING: prologue macros out of order: Dd after Dt -mandoc: order.in:3:5: STYLE: Mdocdate missing: Dd August (OpenBSD) +mandoc: order.in:3:5: STYLE: Mdocdate missing: Dd August 5, 2014 (OpenBSD) diff --git a/regress/mdoc/Os/dupe.in b/regress/mdoc/Os/dupe.in index df38d04e..6608d63f 100644 --- a/regress/mdoc/Os/dupe.in +++ b/regress/mdoc/Os/dupe.in @@ -1,4 +1,4 @@ -.\" $OpenBSD: dupe.in,v 1.2 2017/07/04 14:53:26 schwarze Exp $ +.\" $OpenBSD: dupe.in,v 1.3 2020/01/19 16:36:47 schwarze Exp $ .Dd $Mdocdate$ .Os NetBSD .Dt OS-DUPE 1 diff --git a/regress/mdoc/Os/dupe.out_ascii b/regress/mdoc/Os/dupe.out_ascii index c120c4e1..c3dc72fa 100644 --- a/regress/mdoc/Os/dupe.out_ascii +++ b/regress/mdoc/Os/dupe.out_ascii @@ -6,4 +6,4 @@ NNAAMMEE DDEESSCCRRIIPPTTIIOONN initial text final text -OpenBSD July 4, 2017 OpenBSD +OpenBSD January 19, 2020 OpenBSD diff --git a/regress/mdoc/Os/dupe.out_lint b/regress/mdoc/Os/dupe.out_lint index 63b9dfd2..13ec7fe5 100644 --- a/regress/mdoc/Os/dupe.out_lint +++ b/regress/mdoc/Os/dupe.out_lint @@ -1,9 +1,9 @@ mandoc: dupe.in:3:5: STYLE: operating system explicitly specified: Os NetBSD (NetBSD) -mandoc: dupe.in:2:5: STYLE: Mdocdate found: Dd $Mdocdate: (NetBSD) +mandoc: dupe.in:2:5: STYLE: Mdocdate found: Dd $Mdocdate$ (NetBSD) mandoc: dupe.in:4:2: WARNING: prologue macros out of order: Dt after Os mandoc: dupe.in:5:2: ERROR: duplicate prologue macro: Os mandoc: dupe.in:5:5: STYLE: operating system explicitly specified: Os FreeBSD (NetBSD) -mandoc: dupe.in:2:5: STYLE: Mdocdate found: Dd $Mdocdate: (NetBSD) +mandoc: dupe.in:2:5: STYLE: Mdocdate found: Dd $Mdocdate$ (NetBSD) mandoc: dupe.in:11:2: ERROR: duplicate prologue macro: Os mandoc: dupe.in:11:5: STYLE: operating system explicitly specified: Os OpenBSD (NetBSD) mandoc: dupe.in: STYLE: RCS id missing: (NetBSD) diff --git a/regress/mdoc/Os/dupe.out_markdown b/regress/mdoc/Os/dupe.out_markdown index 8186cb3d..b5930051 100644 --- a/regress/mdoc/Os/dupe.out_markdown +++ b/regress/mdoc/Os/dupe.out_markdown @@ -9,4 +9,4 @@ OS-DUPE(1) - General Commands Manual initial text final text -OpenBSD - July 4, 2017 +OpenBSD - January 19, 2020 |