summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2020-04-24 12:02:33 +0000
committerIngo Schwarze <schwarze@openbsd.org>2020-04-24 12:02:33 +0000
commit8cb870017a69040560be430c7f7978efa809acb3 (patch)
tree47f257f67a01e84b2f35c6e70b21c7c6bc3e9de8
parent2258889db3530de027ab40978bb09a8a824e9c5f (diff)
downloadmandoc-8cb870017a69040560be430c7f7978efa809acb3.tar.gz
provide a STYLE message when mandoc knows the file name and the extension
disagrees with the section number given in the .Dt or .TH macro; feature suggested and patch tested by jmc@
-rw-r--r--man_validate.c9
-rw-r--r--mandoc.118
-rw-r--r--mandoc.h1
-rw-r--r--mandoc_msg.c7
-rw-r--r--mdoc_validate.c8
-rw-r--r--read.c10
-rw-r--r--roff_int.h5
7 files changed, 47 insertions, 11 deletions
diff --git a/man_validate.c b/man_validate.c
index cb814217..da2f1ee7 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -510,9 +510,14 @@ post_TH(CHKARGS)
if (n != NULL)
n = n->next;
- if (n != NULL && n->string != NULL)
+ if (n != NULL && n->string != NULL) {
man->meta.msec = mandoc_strdup(n->string);
- else {
+ if (man->filesec != '\0' &&
+ man->filesec != *n->string &&
+ *n->string >= '1' && *n->string <= '9')
+ mandoc_msg(MANDOCERR_MSEC_FILE, n->line, n->pos,
+ "*.%c vs TH ... %c", man->filesec, *n->string);
+ } else {
man->meta.msec = mandoc_strdup("");
mandoc_msg(MANDOCERR_MSEC_MISSING,
nb->line, nb->pos, "TH %s", man->meta.title);
diff --git a/mandoc.1 b/mandoc.1
index 7497ec15..5f10320e 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1,7 +1,7 @@
-.\" $Id$
+.\" $OpenBSD: mandoc.1,v 1.166 2020/02/15 15:28:01 schwarze Exp $
.\"
-.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2012, 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
+.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -1078,6 +1078,20 @@ macro lacks the mandatory section argument.
The section number in a
.Ic \&Dt
line is invalid, but still used.
+.It Sy "filename/section mismatch"
+.Pq mdoc , man
+The name of the input file being processed is known and its file
+name extension starts with a non-zero digit, but the
+.Ic \&Dt
+or
+.Ic \&TH
+macro contains a
+.Ar section
+argument that starts with a different non-zero digit.
+The
+.Ar section
+argument is used as provided anyway.
+Consider checking whether the file name or the argument need a correction.
.It Sy "missing date, using \(dq\(dq"
.Pq mdoc, man
The document was parsed as
diff --git a/mandoc.h b/mandoc.h
index 12c0040a..0cacb4b5 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -84,6 +84,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_MSEC_FILE, /* filename/section mismatch: ... */
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 */
diff --git a/mandoc_msg.c b/mandoc_msg.c
index 8ce4ede9..318a219e 100644
--- a/mandoc_msg.c
+++ b/mandoc_msg.c
@@ -1,7 +1,7 @@
-/* $Id$ */
+/* $OpenBSD: mandoc_msg.c,v 1.8 2020/01/19 17:59:01 schwarze Exp $ */
/*
- * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -14,6 +14,8 @@
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Implementation of warning and error messages for mandoc(1).
*/
#include "config.h"
@@ -83,6 +85,7 @@ static const char *const type_message[MANDOCERR_MAX] = {
"missing manual title, using \"\"",
"missing manual section, using \"\"",
"unknown manual section",
+ "filename/section mismatch",
"missing date, using \"\"",
"cannot parse date, using it verbatim",
"date in the future, using it anyway",
diff --git a/mdoc_validate.c b/mdoc_validate.c
index fa0ada83..95db41cb 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -2765,8 +2765,14 @@ post_dt(POST_ARGS)
mandoc_msg(MANDOCERR_MSEC_BAD,
nn->line, nn->pos, "Dt ... %s", nn->string);
mdoc->meta.vol = mandoc_strdup(nn->string);
- } else
+ } else {
mdoc->meta.vol = mandoc_strdup(cp);
+ if (mdoc->filesec != '\0' &&
+ mdoc->filesec != *nn->string &&
+ *nn->string >= '1' && *nn->string <= '9')
+ mandoc_msg(MANDOCERR_MSEC_FILE, nn->line, nn->pos,
+ "*.%c vs Dt ... %c", mdoc->filesec, *nn->string);
+ }
/* Optional third argument: architecture. */
diff --git a/read.c b/read.c
index 587dfe2a..f2790de5 100644
--- a/read.c
+++ b/read.c
@@ -554,7 +554,7 @@ mparse_readfd(struct mparse *curp, int fd, const char *filename)
struct buf blk;
struct buf *save_primary;
- const char *save_filename;
+ const char *save_filename, *cp;
size_t offset;
int save_filenc, save_lineno;
int with_mmap;
@@ -562,7 +562,13 @@ mparse_readfd(struct mparse *curp, int fd, const char *filename)
if (recursion_depth > 64) {
mandoc_msg(MANDOCERR_ROFFLOOP, curp->line, 0, NULL);
return;
- }
+ } else if (recursion_depth == 0 &&
+ (cp = strrchr(filename, '.')) != NULL &&
+ cp[1] >= '1' && cp[1] <= '9')
+ curp->man->filesec = cp[1];
+ else
+ curp->man->filesec = '\0';
+
if (read_whole_file(curp, fd, &blk, &with_mmap) == -1)
return;
diff --git a/roff_int.h b/roff_int.h
index 63da38df..e0700a74 100644
--- a/roff_int.h
+++ b/roff_int.h
@@ -1,7 +1,7 @@
-/* $Id$ */
+/* $OpenBSD: roff_int.h,v 1.16 2019/01/05 00:36:46 schwarze Exp $ */
/*
+ * Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2013-2015, 2017-2019 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
@@ -59,6 +59,7 @@ struct roff_man {
enum roff_sec lastsec; /* Last section seen. */
enum roff_sec lastnamed; /* Last standard section seen. */
enum roff_next next; /* Where to put the next node. */
+ char filesec; /* Section digit in the file name. */
};