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

* Re: Use OSNAME/uname and msec.in for man(7) input
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Kristaps Dzonsons @ 2011-10-07 22:12 UTC (permalink / raw)
  To: discuss; +Cc: Yuri Pankov

On 07/10/2011 23:14, Yuri Pankov wrote:
> 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..

Hi Yuri,

I don't see groff doing this on any machines I have handy... do you have 
a use-case in mind for this behaviour?

Take care,

Kristaps
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

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

* Re: Use OSNAME/uname and msec.in for man(7) input
  2011-10-07 22:12 ` Kristaps Dzonsons
@ 2011-10-07 22:21   ` Yuri Pankov
  2011-10-09 22:33     ` Ingo Schwarze
  0 siblings, 1 reply; 5+ messages in thread
From: Yuri Pankov @ 2011-10-07 22:21 UTC (permalink / raw)
  To: Kristaps Dzonsons; +Cc: discuss

On Sat, Oct 08, 2011 at 12:12:01AM +0200, Kristaps Dzonsons wrote:
> On 07/10/2011 23:14, Yuri Pankov wrote:
> > 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..
> 
> Hi Yuri,
> 
> I don't see groff doing this on any machines I have handy... do you have 
> a use-case in mind for this behaviour?

It depends on the contents of the macro file it's using - yes, by
default it doesn't do this, but given, e.g.,
http://src.illumos.org/source/xref/illumos-gate/usr/src/cmd/troff/troff.d/tmac.d/an
you will get the the output with "Illumos" and translated man section if
they are omitted in the manpage..

I don't think that it's something where groff compatibility is needed.


Yuri
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

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

* Re: Use OSNAME/uname and msec.in for man(7) input
  2011-10-07 22:21   ` Yuri Pankov
@ 2011-10-09 22:33     ` Ingo Schwarze
  2011-10-10  2:39       ` Yuri Pankov
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Schwarze @ 2011-10-09 22:33 UTC (permalink / raw)
  To: Yuri Pankov; +Cc: discuss

Hi Yuri,

Yuri Pankov wrote on Sat, Oct 08, 2011 at 02:21:47AM +0400:
> On Sat, Oct 08, 2011 at 12:12:01AM +0200, Kristaps Dzonsons wrote:
> > On 07/10/2011 23:14, Yuri Pankov wrote:

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

I like your idea in general; it provides additional useful information
and makes mdoc(7) and man(7) formatting more similar, both of which
is good.

Before commit to bsd.lv and openbsd.org, you patch would require
minor tweaking (missing BUFSIZ definition, move function to the
right file, ...) but we could take care of those points.

>> I don't see groff doing this on any machines I have handy... do you have 
>> a use-case in mind for this behaviour?

Well, most of the man(7) manuals in the OpenBSD tree profit from
this, look at cvs(1) and tic(1) for example.

> It depends on the contents of the macro file it's using - yes, by
> default it doesn't do this, but given, e.g.,
> http://src.illumos.org/source/xref/illumos-gate/usr/src/cmd/troff/troff.d/tmac.d/an
> you will get the the output with "Illumos" and translated man section if
> they are omitted in the manpage..
> 
> I don't think that it's something where groff compatibility is needed.

We *do* value compatibility very much and don't want to introduce
gratuitious output differences, even in such small matters, at least
not without very good reasons.

So i suggest that you contact the groff crowd and offer them a port
of your related an.tmac patch for their repository.  Feel free to
mention that i'm in favour of making mandoc(1) follow their lead if
they take the patch - or, Kristaps, if you disagree, just say so.

I'm reading the groff lists and will see the commit to the groff
codebase.

Thanks,
  Ingo
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

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

* Re: Use OSNAME/uname and msec.in for man(7) input
  2011-10-09 22:33     ` Ingo Schwarze
@ 2011-10-10  2:39       ` Yuri Pankov
  0 siblings, 0 replies; 5+ messages in thread
From: Yuri Pankov @ 2011-10-10  2:39 UTC (permalink / raw)
  To: Ingo Schwarze; +Cc: discuss

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

On Mon, Oct 10, 2011 at 12:33:32AM +0200, Ingo Schwarze wrote:
> Hi Yuri,
> 
> Yuri Pankov wrote on Sat, Oct 08, 2011 at 02:21:47AM +0400:
> > On Sat, Oct 08, 2011 at 12:12:01AM +0200, Kristaps Dzonsons wrote:
> > > On 07/10/2011 23:14, Yuri Pankov wrote:
> 
> >>> 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..
> 
> I like your idea in general; it provides additional useful information
> and makes mdoc(7) and man(7) formatting more similar, both of which
> is good.
> 
> Before commit to bsd.lv and openbsd.org, you patch would require
> minor tweaking (missing BUFSIZ definition, move function to the
> right file, ...) but we could take care of those points.
> 
> >> I don't see groff doing this on any machines I have handy... do you have 
> >> a use-case in mind for this behaviour?
> 
> Well, most of the man(7) manuals in the OpenBSD tree profit from
> this, look at cvs(1) and tic(1) for example.
> 
> > It depends on the contents of the macro file it's using - yes, by
> > default it doesn't do this, but given, e.g.,
> > http://src.illumos.org/source/xref/illumos-gate/usr/src/cmd/troff/troff.d/tmac.d/an
> > you will get the the output with "Illumos" and translated man section if
> > they are omitted in the manpage..
> > 
> > I don't think that it's something where groff compatibility is needed.
> 
> We *do* value compatibility very much and don't want to introduce
> gratuitious output differences, even in such small matters, at least
> not without very good reasons.

I don't see this change as introducing any incompatibility with groff
output, that's more like default groff macro used - I'm not going to
submit a request to change behaviour to groff lists, and if you see it
as not appropriate, please just drop it. :-)


> So i suggest that you contact the groff crowd and offer them a port
> of your related an.tmac patch for their repository.  Feel free to
> mention that i'm in favour of making mandoc(1) follow their lead if
> they take the patch - or, Kristaps, if you disagree, just say so.
> 
> I'm reading the groff lists and will see the commit to the groff
> codebase.


Thanks,
Yuri

[-- Attachment #2: Type: application/pgp-signature, Size: 834 bytes --]

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