]> git.cameronkatri.com Git - mandoc.git/commitdiff
warn about botched .Xr ordering and punctuation below SEE ALSO;
authorIngo Schwarze <schwarze@openbsd.org>
Thu, 11 Sep 2014 23:53:30 +0000 (23:53 +0000)
committerIngo Schwarze <schwarze@openbsd.org>
Thu, 11 Sep 2014 23:53:30 +0000 (23:53 +0000)
inspired by mdoclint(1)

mandoc.h
mdoc_validate.c
read.c

index af8f4fc91ca10366533bcfca6b82978a17b197c5..15098a4cd2ba11f839587d0008725d3714797b90 100644 (file)
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/*     $Id: mandoc.h,v 1.154 2014/09/07 23:25:01 schwarze Exp $ */
+/*     $Id: mandoc.h,v 1.155 2014/09/11 23:53:30 schwarze Exp $ */
 /*
  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -72,6 +72,8 @@ enum  mandocerr {
        MANDOCERR_SEC_ORDER, /* sections out of conventional order: Sh title */
        MANDOCERR_SEC_REP, /* duplicate section title: Sh title */
        MANDOCERR_SEC_MSEC, /* unexpected section: Sh title for ... only */
+       MANDOCERR_XR_ORDER, /* unusual Xr order: ... after ... */
+       MANDOCERR_XR_PUNCT, /* unusual Xr punctuation: ... after ... */
        MANDOCERR_AN_MISSING, /* AUTHORS section without An macro */
 
        /* related to macros and nesting */
index c89de9c98fe2ab118138ea3a6e45aac19fae01f6..913168e51dfcb55e6f9fe6ff532a1590a5ba9a12 100644 (file)
@@ -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:
@@ -1904,6 +1907,68 @@ post_sh_name(POST_ARGS)
        return(1);
 }
 
+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)
 {
diff --git a/read.c b/read.c
index 97d09cdfad37cebaeb5ec500b61832310f6f3798..31645ecfb9a5cb4ac77e6a6fade393bb5056603b 100644 (file)
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-/*     $Id: read.c,v 1.86 2014/09/07 23:25:01 schwarze Exp $ */
+/*     $Id: read.c,v 1.87 2014/09/11 23:53:30 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -117,6 +117,8 @@ static      const char * const      mandocerrs[MANDOCERR_MAX] = {
        "sections out of conventional order",
        "duplicate section title",
        "unexpected section",
+       "unusual Xr order",
+       "unusual Xr punctuation",
        "AUTHORS section without An macro",
 
        /* related to macros and nesting */