source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: warn about botched .Xr ordering and punctuation below SEE ALSO;
Date: Thu, 11 Sep 2014 19:53:30 -0400 (EDT)	[thread overview]
Message-ID: <201409112353.s8BNrU5Q000464@krisdoz.my.domain> (raw)

Log Message:
-----------
warn about botched .Xr ordering and punctuation below SEE ALSO;
inspired by mdoclint(1)

Modified Files:
--------------
    mdocml:
        mandoc.h
        mdoc_validate.c
        read.c

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.247
retrieving revision 1.248
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.247 -r1.248
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -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:
@@ -1901,6 +1904,68 @@ post_sh_name(POST_ARGS)
 
 	mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
 	    n->line, n->pos, mdoc_macronames[n->tok]);
+	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);
 }
 
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.154
retrieving revision 1.155
diff -Lmandoc.h -Lmandoc.h -u -p -r1.154 -r1.155
--- mandoc.h
+++ mandoc.h
@@ -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: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -Lread.c -Lread.c -u -p -r1.86 -r1.87
--- read.c
+++ read.c
@@ -117,6 +117,8 @@ static	const char * const	mandocerrs[MAN
 	"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 */
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-09-11 23:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201409112353.s8BNrU5Q000464@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).