discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
* Use OSNAME/uname and msec.in for man(7) input
@ 2011-10-07 21:14 Yuri Pankov
  2011-10-07 22:12 ` Kristaps Dzonsons
  0 siblings, 1 reply; 5+ messages in thread
From: Yuri Pankov @ 2011-10-07 21:14 UTC (permalink / raw)
  To: discuss

[-- Attachment #1: Type: text/plain, Size: 384 bytes --]

Hi,

I want to propose the following change to man_validate.c - if we are
missing SOURCE and VOL in TH, do the same as for the mdoc manpages -
use OSNAME, if it's not defined, use uname output and get the VOL from
msec.in if VOL isn't defined in manpage. I've attached the diff that
seems to work for me (mostly just copy/paste from mdoc_validate.c), hope
the idea sounds ok..


Yuri

[-- Attachment #2: mandoc.diff --]
[-- Type: text/x-diff, Size: 3504 bytes --]

diff -r e29e4165c957 usr/src/cmd/mandoc/libmdoc.h
--- a/usr/src/cmd/mandoc/libmdoc.h	Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/libmdoc.h	Sat Oct 08 01:01:42 2011 +0400
@@ -124,7 +124,6 @@
 const char	 *mdoc_a2st(const char *);
 const char	 *mdoc_a2arch(const char *);
 const char	 *mdoc_a2vol(const char *);
-const char	 *mdoc_a2msec(const char *);
 int		  mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
 int		  mdoc_valid_post(struct mdoc *);
 enum margverr	  mdoc_argv(struct mdoc *, int, enum mdoct,
diff -r e29e4165c957 usr/src/cmd/mandoc/man_validate.c
--- a/usr/src/cmd/mandoc/man_validate.c	Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/man_validate.c	Sat Oct 08 01:01:42 2011 +0400
@@ -19,6 +19,10 @@
 #include "config.h"
 #endif
 
+#ifndef OSNAME
+#include <sys/utsname.h>
+#endif
+
 #include <sys/types.h>
 
 #include <assert.h>
@@ -357,8 +361,12 @@
 static int
 post_TH(CHKARGS)
 {
-	const char	*p;
+	char		buf[BUFSIZ];
+	const char	*cp, *p;
 	int		 line, pos;
+#ifndef OSNAME
+	struct utsname    utsname;
+#endif
 
 	if (m->meta.title)
 		free(m->meta.title);
@@ -412,13 +420,47 @@
 
 	/* TITLE MSEC DATE ->SOURCE<- VOL */
 
-	if (n && (n = n->next))
+	if (n && (n = n->next)) {
 		m->meta.source = mandoc_strdup(n->string);
+	} else {
+#ifdef OSNAME
+		if (strlcpy(buf, OSNAME, BUFSIZ) >= BUFSIZ) {
+			man_nmsg(m, n, MANDOCERR_MEM);
+			return(0);
+		}
+#else /*!OSNAME */
+		if (-1 == uname(&utsname)) {
+			man_nmsg(m, n, MANDOCERR_UNAME);
+			m->meta.source = mandoc_strdup("UNKNOWN");
+			return(0);
+		}
+
+		if (strlcpy(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) {
+			man_nmsg(m, n, MANDOCERR_MEM);
+			return(0);
+		}
+		if (strlcat(buf, " ", BUFSIZ) >= BUFSIZ) {
+			man_nmsg(m, n, MANDOCERR_MEM);
+			return(0);
+		}
+		if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) {
+			man_nmsg(m, n, MANDOCERR_MEM);
+			return(0);
+		}
+#endif /*!OSNAME*/
+		m->meta.source = mandoc_strdup(buf);
+	}
 
 	/* TITLE MSEC DATE SOURCE ->VOL<- */
 
-	if (n && (n = n->next))
+	if (n && (n = n->next)) {
 		m->meta.vol = mandoc_strdup(n->string);
+	} else {
+		if (NULL != (cp = mandoc_a2msec(m->meta.msec)))
+			m->meta.vol = mandoc_strdup(cp);
+		else
+			m->meta.vol = mandoc_strdup("UNKNOWN");
+	}
 
 	/*
 	 * Remove the `TH' node after we've processed it for our
diff -r e29e4165c957 usr/src/cmd/mandoc/mandoc.h
--- a/usr/src/cmd/mandoc/mandoc.h	Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/mandoc.h	Sat Oct 08 01:01:42 2011 +0400
@@ -409,6 +409,8 @@
 const char	 *mparse_strerror(enum mandocerr);
 const char	 *mparse_strlevel(enum mandoclevel);
 
+const char	 *mandoc_a2msec(const char *);
+
 void		 *mandoc_calloc(size_t, size_t);
 void		 *mandoc_malloc(size_t);
 void		 *mandoc_realloc(void *, size_t);
diff -r e29e4165c957 usr/src/cmd/mandoc/mdoc_validate.c
--- a/usr/src/cmd/mandoc/mdoc_validate.c	Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/mdoc_validate.c	Sat Oct 08 01:01:42 2011 +0400
@@ -2077,7 +2077,7 @@
 	 *       arch = NULL
 	 */
 
-	cp = mdoc_a2msec(nn->string);
+	cp = mandoc_a2msec(nn->string);
 	if (cp) {
 		mdoc->meta.vol = mandoc_strdup(cp);
 		mdoc->meta.msec = mandoc_strdup(nn->string);
diff -r e29e4165c957 usr/src/cmd/mandoc/msec.c
--- a/usr/src/cmd/mandoc/msec.c	Fri Oct 07 21:40:20 2011 +0400
+++ b/usr/src/cmd/mandoc/msec.c	Sat Oct 08 01:01:42 2011 +0400
@@ -29,7 +29,7 @@
 	if (0 == strcmp(p, x)) return(y);
 
 const char *
-mdoc_a2msec(const char *p)
+mandoc_a2msec(const char *p)
 {
 
 #include "msec.in"

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-10-10  2:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-07 21:14 Use OSNAME/uname and msec.in for man(7) input Yuri Pankov
2011-10-07 22:12 ` Kristaps Dzonsons
2011-10-07 22:21   ` Yuri Pankov
2011-10-09 22:33     ` Ingo Schwarze
2011-10-10  2:39       ` Yuri Pankov

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