* mandoc: provide a STYLE message when mandoc knows the file name and the
@ 2020-04-24 12:03 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2020-04-24 12:03 UTC (permalink / raw)
To: source
Log Message:
-----------
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@
Modified Files:
--------------
mandoc:
man_validate.c
mandoc.1
mandoc.h
mandoc_msg.c
mdoc_validate.c
read.c
roff_int.h
Revision Data
-------------
Index: man_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_validate.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -Lman_validate.c -Lman_validate.c -u -p -r1.153 -r1.154
--- man_validate.c
+++ 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);
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_validate.c,v
retrieving revision 1.385
retrieving revision 1.386
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.385 -r1.386
--- mdoc_validate.c
+++ 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. */
Index: mandoc_msg.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc_msg.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lmandoc_msg.c -Lmandoc_msg.c -u -p -r1.10 -r1.11
--- mandoc_msg.c
+++ 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[MA
"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",
Index: mandoc.1
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.1,v
retrieving revision 1.242
retrieving revision 1.243
diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.242 -r1.243
--- mandoc.1
+++ 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 argume
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
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.h,v
retrieving revision 1.267
retrieving revision 1.268
diff -Lmandoc.h -Lmandoc.h -u -p -r1.267 -r1.268
--- mandoc.h
+++ 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 */
Index: roff_int.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff_int.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -Lroff_int.h -Lroff_int.h -u -p -r1.16 -r1.17
--- roff_int.h
+++ 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. */
};
Index: read.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/read.c,v
retrieving revision 1.218
retrieving revision 1.219
diff -Lread.c -Lread.c -u -p -r1.218 -r1.219
--- read.c
+++ read.c
@@ -554,7 +554,7 @@ mparse_readfd(struct mparse *curp, int f
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 f
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;
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-04-24 12:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24 12:03 mandoc: provide a STYLE message when mandoc knows the file name and the schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).