source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: style checks related to .Er; inspired by mdoclint(1)
@ 2017-06-07 23:30 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-06-07 23:30 UTC (permalink / raw)
  To: source

Log Message:
-----------
style checks related to .Er; inspired by mdoclint(1)

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

Revision Data
-------------
Index: mandoc.1
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.1,v
retrieving revision 1.194
retrieving revision 1.195
diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.194 -r1.195
--- mandoc.1
+++ mandoc.1
@@ -75,6 +75,11 @@ and for the
 .Xr man 7
 .Ic \&TH
 macro.
+This can also be used to perform style checks according to the
+conventions of one operating system while running on a different
+operating system; see
+.Sx Style messages
+for details.
 .It Fl K Ar encoding
 Specify the input encoding.
 The supported
@@ -743,6 +748,15 @@ option or
 .Fl T Cm lint
 output mode.
 .Ss Style messages
+As indicated below, some style checks are only performed if a
+specific operating system name occurs in the arguments of the
+.Ic \&Os
+macro, of the
+.Fl Ios
+command line option, or, if neither are present, in the return value
+of the
+.Xr uname 3
+function.
 .Bl -ohang
 .It Sy "useless macro"
 .Pq mdoc
@@ -763,6 +777,22 @@ macro that could be represented using
 .Ic \&Fx ,
 or
 .Ic \&Dx .
+.It Sy "errnos out of order"
+.Pq mdoc, Nx
+The
+.Ic \&Er
+items in a
+.Ic \&Bl
+list are not in alphabetical order.
+.It Sy "duplicate errno"
+.Pq mdoc, Nx
+A
+.Ic \&Bl
+list contains two consecutive
+.Ic \&It
+entries describing the same
+.Ic \&Er
+number.
 .It Sy "description line ends with a full stop"
 .Pq mdoc
 Do not use punctuation at the end of an
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.h,v
retrieving revision 1.223
retrieving revision 1.224
diff -Lmandoc.h -Lmandoc.h -u -p -r1.223 -r1.224
--- mandoc.h
+++ mandoc.h
@@ -48,6 +48,8 @@ enum	mandocerr {
 
 	MANDOCERR_MACRO_USELESS, /* useless macro: macro */
 	MANDOCERR_BX, /* consider using OS macro: macro */
+	MANDOCERR_ER_ORDER, /* errnos out of order: Er ... */
+	MANDOCERR_ER_REP, /* duplicate errno: Er ... */
 	MANDOCERR_ND_DOT, /* description line ends with a full stop */
 
 	MANDOCERR_WARNING, /* ===== start of warnings ===== */
Index: read.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/read.c,v
retrieving revision 1.171
retrieving revision 1.172
diff -Lread.c -Lread.c -u -p -r1.171 -r1.172
--- read.c
+++ read.c
@@ -90,6 +90,8 @@ static	const char * const	mandocerrs[MAN
 
 	"useless macro",
 	"consider using OS macro",
+	"errnos out of order",
+	"duplicate errno",
 	"description line ends with a full stop",
 
 	"generic warning",
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_validate.c,v
retrieving revision 1.330
retrieving revision 1.331
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.330 -r1.331
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -1479,6 +1479,8 @@ post_bl(POST_ARGS)
 	struct roff_node	*nparent, *nprev; /* of the Bl block */
 	struct roff_node	*nblock, *nbody;  /* of the Bl */
 	struct roff_node	*nchild, *nnext;  /* of the Bl body */
+	const char		*prev_Er;
+	int			 order;
 
 	nbody = mdoc->last;
 	switch (nbody->type) {
@@ -1579,6 +1581,34 @@ post_bl(POST_ARGS)
 
 		nchild = nnext;
 	}
+
+	if (mdoc->meta.os_e != MDOC_OS_NETBSD)
+		return;
+
+	prev_Er = NULL;
+	for (nchild = nbody->child; nchild != NULL; nchild = nchild->next) {
+		if (nchild->tok != MDOC_It)
+			continue;
+		if ((nnext = nchild->head->child) == NULL)
+			continue;
+		if (nnext->type == ROFFT_BLOCK)
+			nnext = nnext->body->child;
+		if (nnext == NULL || nnext->tok != MDOC_Er)
+			continue;
+		nnext = nnext->child;
+		if (prev_Er != NULL) {
+			order = strcmp(prev_Er, nnext->string);
+			if (order > 0)
+				mandoc_vmsg(MANDOCERR_ER_ORDER,
+				    mdoc->parse, nnext->line, nnext->pos,
+				    "Er %s %s", prev_Er, nnext->string);
+			else if (order == 0)
+				mandoc_vmsg(MANDOCERR_ER_REP,
+				    mdoc->parse, nnext->line, nnext->pos,
+				    "Er %s", prev_Er);
+		}
+		prev_Er = nnext->string;
+	}
 }
 
 static void
@@ -2385,11 +2415,11 @@ post_os(POST_ARGS)
 	mdoc->meta.os = NULL;
 	deroff(&mdoc->meta.os, n);
 	if (mdoc->meta.os)
-		return;
+		goto out;
 
 	if (mdoc->defos) {
 		mdoc->meta.os = mandoc_strdup(mdoc->defos);
-		return;
+		goto out;
 	}
 
 #ifdef OSNAME
@@ -2406,6 +2436,10 @@ post_os(POST_ARGS)
 	}
 	mdoc->meta.os = mandoc_strdup(defbuf);
 #endif /*!OSNAME*/
+
+out:	mdoc->meta.os_e = strstr(mdoc->meta.os, "OpenBSD") != NULL ?
+	    MDOC_OS_OPENBSD : strstr(mdoc->meta.os, "NetBSD") != NULL ?
+	    MDOC_OS_NETBSD : MDOC_OS_OTHER;
 }
 
 enum roff_sec
Index: roff.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -Lroff.h -Lroff.h -u -p -r1.51 -r1.52
--- roff.h
+++ roff.h
@@ -26,6 +26,12 @@ enum	roff_macroset {
 	MACROSET_MAN
 };
 
+enum	mdoc_os {
+	MDOC_OS_OTHER = 0,
+	MDOC_OS_NETBSD,
+	MDOC_OS_OPENBSD
+};
+
 enum	roff_sec {
 	SEC_NONE = 0,
 	SEC_NAME,
@@ -528,6 +534,7 @@ struct	roff_meta {
 	char		 *name;    /* Leading manual name. */
 	char		 *date;    /* Normalized date. */
 	int		  hasbody; /* Document is not empty. */
+	enum mdoc_os	  os_e;    /* Operating system. */
 };
 
 struct	roff_man {
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-07 23:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-07 23:30 mdocml: style checks related to .Er; inspired by mdoclint(1) schwarze

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).