aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-09-11 23:53:30 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-09-11 23:53:30 +0000
commitaa5a603865c1cffc40900d4d20fa22fe1a875691 (patch)
tree8dfed454e37c1bdd3fb019f6f71a3520e3d29b8d /mdoc_validate.c
parent324d681dc664dcafae58984dfa627d1330143efc (diff)
downloadmandoc-aa5a603865c1cffc40900d4d20fa22fe1a875691.tar.gz
mandoc-aa5a603865c1cffc40900d4d20fa22fe1a875691.tar.zst
mandoc-aa5a603865c1cffc40900d4d20fa22fe1a875691.zip
warn about botched .Xr ordering and punctuation below SEE ALSO;
inspired by mdoclint(1)
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index c89de9c9..913168e5 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.247 2014/09/07 23:25:01 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.248 2014/09/11 23:53:30 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -117,6 +117,7 @@ static int post_rs(POST_ARGS);
static int post_sh(POST_ARGS);
static int post_sh_head(POST_ARGS);
static int post_sh_name(POST_ARGS);
+static int post_sh_see_also(POST_ARGS);
static int post_sh_authors(POST_ARGS);
static int post_st(POST_ARGS);
static int post_vt(POST_ARGS);
@@ -1856,6 +1857,8 @@ post_sh(POST_ARGS)
switch (mdoc->lastsec) {
case SEC_NAME:
return(post_sh_name(mdoc));
+ case SEC_SEE_ALSO:
+ return(post_sh_see_also(mdoc));
case SEC_AUTHORS:
return(post_sh_authors(mdoc));
default:
@@ -1905,6 +1908,68 @@ post_sh_name(POST_ARGS)
}
static int
+post_sh_see_also(POST_ARGS)
+{
+ const struct mdoc_node *n;
+ const char *name, *sec;
+ const char *lastname, *lastsec, *lastpunct;
+ int cmp;
+
+ n = mdoc->last->child;
+ lastname = lastsec = lastpunct = NULL;
+ while (n != NULL) {
+ if (n->tok != MDOC_Xr || n->nchild < 2)
+ break;
+
+ /* Process one .Xr node. */
+
+ name = n->child->string;
+ sec = n->child->next->string;
+ if (lastsec != NULL) {
+ if (lastpunct[0] != ',' || lastpunct[1] != '\0')
+ mandoc_vmsg(MANDOCERR_XR_PUNCT,
+ mdoc->parse, n->line, n->pos,
+ "%s before %s(%s)", lastpunct,
+ name, sec);
+ cmp = strcmp(lastsec, sec);
+ if (cmp > 0)
+ mandoc_vmsg(MANDOCERR_XR_ORDER,
+ mdoc->parse, n->line, n->pos,
+ "%s(%s) after %s(%s)", name,
+ sec, lastname, lastsec);
+ else if (cmp == 0 && strcmp(lastname, name) > 0)
+ mandoc_vmsg(MANDOCERR_XR_ORDER,
+ mdoc->parse, n->line, n->pos,
+ "%s after %s", name, lastname);
+ }
+ lastname = name;
+ lastsec = sec;
+
+ /* Process the following node. */
+
+ n = n->next;
+ if (n == NULL)
+ break;
+ if (n->tok == MDOC_Xr) {
+ lastpunct = "none";
+ continue;
+ }
+ if (n->type != MDOC_TEXT)
+ break;
+ for (name = n->string; *name != '\0'; name++)
+ if (isalpha((const unsigned char)*name))
+ return(1);
+ lastpunct = n->string;
+ if (n->next == NULL)
+ mandoc_vmsg(MANDOCERR_XR_PUNCT, mdoc->parse,
+ n->line, n->pos, "%s after %s(%s)",
+ lastpunct, lastname, lastsec);
+ n = n->next;
+ }
+ return(1);
+}
+
+static int
child_an(const struct mdoc_node *n)
{