diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2020-04-24 12:02:33 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2020-04-24 12:02:33 +0000 |
commit | 1849b727a60f67043a27dc863e3f90e2dbb84dfe (patch) | |
tree | a125523ca4600295cc5a94e8ca0582a1d871427f | |
parent | d75c48416eef7eb48487f6dc9a1bafa2c262b81c (diff) | |
download | mandoc-1849b727a60f67043a27dc863e3f90e2dbb84dfe.tar.gz mandoc-1849b727a60f67043a27dc863e3f90e2dbb84dfe.tar.zst mandoc-1849b727a60f67043a27dc863e3f90e2dbb84dfe.zip |
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.c | 11 | ||||
-rw-r--r-- | mandoc.1 | 20 | ||||
-rw-r--r-- | mandoc.h | 3 | ||||
-rw-r--r-- | mandoc_msg.c | 7 | ||||
-rw-r--r-- | mdoc_validate.c | 10 | ||||
-rw-r--r-- | read.c | 12 | ||||
-rw-r--r-- | roff_int.h | 5 |
7 files changed, 52 insertions, 16 deletions
diff --git a/man_validate.c b/man_validate.c index 84fc4424..2069fadc 100644 --- a/man_validate.c +++ b/man_validate.c @@ -1,4 +1,4 @@ -/* $Id: man_validate.c,v 1.153 2020/04/18 20:40:10 schwarze Exp $ */ +/* $Id: man_validate.c,v 1.154 2020/04/24 12:02:33 schwarze Exp $ */ /* * Copyright (c) 2010, 2012-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> @@ -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); @@ -1,7 +1,7 @@ -.\" $Id: mandoc.1,v 1.242 2020/02/15 15:28:13 schwarze Exp $ +.\" $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 @@ -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: February 15 2020 $ +.Dd $Mdocdate: April 24 2020 $ .Dt MANDOC 1 .Os .Sh NAME @@ -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 @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.267 2020/04/03 11:35:01 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.268 2020/04/24 12:02:33 schwarze Exp $ */ /* * Copyright (c) 2012-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> @@ -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 4a3e5203..318a219e 100644 --- a/mandoc_msg.c +++ b/mandoc_msg.c @@ -1,7 +1,7 @@ -/* $Id: mandoc_msg.c,v 1.10 2020/01/19 18:02:00 schwarze Exp $ */ +/* $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 129e4730..39c66b1f 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.385 2020/04/18 20:40:10 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.386 2020/04/24 12:02:33 schwarze Exp $ */ /* * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> @@ -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. */ @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.218 2020/04/18 20:40:10 schwarze Exp $ */ +/* $Id: read.c,v 1.219 2020/04/24 12:02:33 schwarze Exp $ */ /* * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> @@ -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; @@ -1,7 +1,7 @@ -/* $Id: roff_int.h,v 1.16 2019/01/05 00:36:50 schwarze Exp $ */ +/* $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. */ }; |