diff options
author | 2017-07-01 09:47:30 +0000 | |
---|---|---|
committer | 2017-07-01 09:47:30 +0000 | |
commit | c93f1e0f2d3891330860de19b5ec3e274971a300 (patch) | |
tree | 6aa6244559b5608dfb842dda23dbc7377e0ee1ba /main.c | |
parent | 3aad1243de81f4fa87d3d67a5c4c6f0385bd0ac7 (diff) | |
download | mandoc-c93f1e0f2d3891330860de19b5ec3e274971a300.tar.gz mandoc-c93f1e0f2d3891330860de19b5ec3e274971a300.tar.zst mandoc-c93f1e0f2d3891330860de19b5ec3e274971a300.zip |
Basic reporting of .Xrs to manual pages that don't exist
in the base system, inspired by mdoclint(1).
We are able to do this because (1) the -mdoc parser, the -Tlint validator,
and the man(1) manual page lookup code are all in the same program
and (2) the mandoc.db(5) database format allows fast lookup.
Feedback from, previous versions tested by, and OK jmc@.
A few features will be added to this in the tree, step by step.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.293 2017/06/24 14:38:32 schwarze Exp $ */ +/* $Id: main.c,v 1.294 2017/07/01 09:47:30 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org> @@ -43,6 +43,7 @@ #include "mandoc_aux.h" #include "mandoc.h" +#include "mandoc_xr.h" #include "roff.h" #include "mdoc.h" #include "man.h" @@ -86,6 +87,7 @@ struct curparse { int mandocdb(int, char *[]); +static void check_xr(const char *); static int fs_lookup(const struct manpaths *, size_t ipath, const char *, const char *, const char *, @@ -517,6 +519,7 @@ main(int argc, char *argv[]) break; } } + mandoc_xr_free(); mparse_free(curp.mp); mchars_free(); @@ -747,6 +750,8 @@ parse(struct curparse *curp, int fd, const char *file) if (man == NULL) return; + if (curp->mmin < MANDOCERR_STYLE) + mandoc_xr_reset(); if (man->macroset == MACROSET_MDOC) { if (curp->outtype != OUTT_TREE || !curp->outopts->noval) mdoc_validate(man); @@ -798,10 +803,38 @@ parse(struct curparse *curp, int fd, const char *file) break; } } + check_xr(file); mparse_updaterc(curp->mp, &rc); } static void +check_xr(const char *file) +{ + static struct manpaths paths; + struct mansearch search; + struct mandoc_xr *xr; + char *cp; + size_t sz; + + if (paths.sz == 0) + manpath_base(&paths); + + for (xr = mandoc_xr_get(); xr != NULL; xr = xr->next) { + search.arch = NULL; + search.sec = xr->sec; + search.outkey = NULL; + search.argmode = ARG_NAME; + search.firstmatch = 1; + if (mansearch(&search, &paths, 1, &xr->name, NULL, &sz)) + continue; + mandoc_asprintf(&cp, "Xr %s %s", xr->name, xr->sec); + mmsg(MANDOCERR_XR_BAD, MANDOCLEVEL_STYLE, + file, xr->line, xr->pos + 1, cp); + free(cp); + } +} + +static void outdata_alloc(struct curparse *curp) { switch (curp->outtype) { |