Re: Minor incorrectness on 'man smtpd.conf'

Ingo Schwarze <[email protected]>
Newsgroups gmane.os.openbsd.www
Message-ID <[email protected]>
Hi Stefan,

Stefan Wollny wrote on Thu, May 24, 2012 at 01:54:31PM +0200:

> As OpenBSD 5.1 was released on May 1st, 2012, shouldn't any man page
> dated after this point-of-time also be referenced to "5.1"?

The manual sources themselves do *not* contain hardcoded release
numbers, or we would have to change each manual for each release,
which would cause lots of pointless churn.

If you install OpenBSD 5.1 or OpenBSD-current, man(1) will show
you the correct release numbers, because mandoc(1) does the right
thing, on the fly.

However, the man.cgi online web pages are generated on the fly
by mandoc(1) on the web server, and the web server is currently
running OpenBSD 5.0 stable, so you see 5.0 (known problem).

I proposed a solution to Bob (let mandoc support a command line
option to specify the default release for the .Os macro, and let
man.cgi use that option), but Bob didn't tell me yet whether he
likes that solution.

Thanks for the reminder.
  Ingo


P.S.

> Beside this: Excellent writing - Thank you!

That's kind of a compliment for jmc@ (and several other developers
who are probably not listening here :).

> Having read the summary of the fine work on OpenSMTPD on undeadly.org
> I try to steal some time and to tests on i386 and amd64.

I doubt that gilles@ is listening here, but thanks for testing
in any case.


 ----- 8< ----- schnipp ----- >8 ----- 8< ----- schnapp ----- >8 -----

Hi,

following up to my own promise:

Ingo Schwarze wrote on Sat, Apr 07, 2012 at 02:24:48PM +0200:

> So, you have one binary /usr/bin/mandoc on the server and it has
> to render the same macro ".Os" (without arguments) as "OpenBSD 5.0"
> or "OpenBSD 5.1" or "OpenBSD-current", depending on the manual
> directory.  Currently, it can't; it uses the .Os argument from
> inside the manual or uname(3) by default.
> 
> I dont't like adding options, but in this case i suggest adding
> 
>   -Oos='OpenBSD whatever'
> 
> as a command line option to mandoc(1), with the precedence
> 
>   1. .Os argument   or
>   2. -Oos option    or
>   3. uname(3)       by default

It turned out it is not an output option, but an input option:
It affects the contents of the parse tree.

So the patch is surprisingly complicated: There is no infrastucture
for input options yet.  Considering that i don't know whether we will
ever need to invent any other input options, i designed the interface
so that it can be easily extended, but kept the implementation minimal.

Still, it needs to be passed by the main program (mandoc.h, main.c,
mandoc.1, mandocdb.c) through the generic parser (libmandoc.h, read.c)
into the mdoc parser (libmdoc.h, mdoc.c, mdoc_validate.c).

Yours,
  Ingo

P.S.
Following what krw@ just said on ICB, here are some ausfluechte:
I'm glad it's kristaps@ fault that my patch is so complicated.


Index: libmandoc.h
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/libmandoc.h,v
retrieving revision 1.16
diff -u -p -r1.16 libmandoc.h
--- libmandoc.h	2 Dec 2011 01:45:43 -0000	1.16
+++ libmandoc.h	8 Apr 2012 15:07:07 -0000
@@ -52,7 +52,7 @@ int		 mandoc_strntoi(const char *, size_
 const char	*mandoc_a2msec(const char*);
 
 void	 	 mdoc_free(struct mdoc *);
-struct	mdoc	*mdoc_alloc(struct roff *, struct mparse *);
+struct	mdoc	*mdoc_alloc(struct roff *, struct mparse *, char *);
 void		 mdoc_reset(struct mdoc *);
 int	 	 mdoc_parseln(struct mdoc *, int, char *, int);
 int		 mdoc_endparse(struct mdoc *);
Index: libmdoc.h
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/libmdoc.h,v
retrieving revision 1.48
diff -u -p -r1.48 libmdoc.h
--- libmdoc.h	2 Dec 2011 01:45:43 -0000	1.48
+++ libmdoc.h	8 Apr 2012 15:07:07 -0000
@@ -24,6 +24,7 @@ enum	mdoc_next {
 
 struct	mdoc {
 	struct mparse	 *parse; /* parse pointer */
+	char		 *defos; /* default argument for .Os */
 	int		  flags; /* parse flags */
 #define	MDOC_HALT	 (1 << 0) /* error in parse: halt */
 #define	MDOC_LITERAL	 (1 << 1) /* in a literal scope */
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/main.c,v
retrieving revision 1.82
diff -u -p -r1.82 main.c
--- main.c	25 Dec 2011 17:34:57 -0000	1.82
+++ main.c	8 Apr 2012 15:07:07 -0000
@@ -1,7 +1,7 @@
 /*	$Id: main.c,v 1.82 2011/12/25 17:34:57 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <[email protected]>
- * Copyright (c) 2010, 2011 Ingo Schwarze <[email protected]>
+ * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <[email protected]>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -79,6 +79,7 @@ main(int argc, char *argv[])
 	struct curparse	 curp;
 	enum mparset	 type;
 	enum mandoclevel rc;
+	char		*defos;
 
 	progname = strrchr(argv[0], '/');
 	if (progname == NULL)
@@ -98,10 +99,24 @@ main(int argc, char *argv[])
 	type = MPARSE_AUTO;
 	curp.outtype = OUTT_ASCII;
 	curp.wlevel  = MANDOCLEVEL_FATAL;
+	defos = NULL;
 
 	/* LINTED */
-	while (-1 != (c = getopt(argc, argv, "m:O:T:VW:")))
+	while (-1 != (c = getopt(argc, argv, "I:m:O:T:VW:")))
 		switch (c) {
+		case ('I'):
+			if (strncmp(optarg, "os=", 3)) {
+				fprintf(stderr, "-I%s: Bad argument\n",
+						optarg);
+				return((int)MANDOCLEVEL_BADARG);
+			}
+			if (defos) {
+				fprintf(stderr, "-I%s: Duplicate argument\n",
+						optarg);
+				return((int)MANDOCLEVEL_BADARG);
+			}
+			defos = mandoc_strdup(optarg + 3);
+			break;
 		case ('m'):
 			if ( ! moptions(&type, optarg))
 				return((int)MANDOCLEVEL_BADARG);
@@ -126,7 +141,7 @@ main(int argc, char *argv[])
 			/* NOTREACHED */
 		}
 
-	curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp);
+	curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp, defos);
 
 	/*
 	 * Conditionally start up the lookaside buffer before parsing.
@@ -153,6 +168,7 @@ main(int argc, char *argv[])
 		(*curp.outfree)(curp.outdata);
 	if (curp.mp)
 		mparse_free(curp.mp);
+	free(defos);
 
 	return((int)rc);
 }
Index: mandoc.1
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mandoc.1,v
retrieving revision 1.53
diff -u -p -r1.53 mandoc.1
--- mandoc.1	25 Dec 2011 20:15:54 -0000	1.53
+++ mandoc.1	8 Apr 2012 15:07:07 -0000
@@ -23,6 +23,9 @@
 .Sh SYNOPSIS
 .Nm mandoc
 .Op Fl V
+.Sm off
+.Op Fl I Cm os Li = Ar name
+.Sm on
 .Op Fl m Ns Ar format
 .Op Fl O Ns Ar option
 .Op Fl T Ns Ar output
@@ -49,6 +52,15 @@ output.
 .Pp
 The arguments are as follows:
 .Bl -tag -width Ds
+.Sm off
+.It Fl I Cm os Li = Ar name
+.Sm on
+Override the default operating system
+.Ar name
+for the
+.Xr mdoc 7
+.Sq \&Os
+macro.
 .It Fl m Ns Ar format
 Input format.
 See
Index: mandoc.h
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mandoc.h,v
retrieving revision 1.43
diff -u -p -r1.43 mandoc.h
--- mandoc.h	12 Nov 2011 22:43:18 -0000	1.43
+++ mandoc.h	8 Apr 2012 15:07:07 -0000
@@ -413,8 +413,8 @@ int		  mchars_spec2cp(const struct mchar
 			const char *, size_t);
 const char	 *mchars_spec2str(const struct mchars *, 
 			const char *, size_t, size_t *);
-struct mparse	 *mparse_alloc(enum mparset, 
-			enum mandoclevel, mandocmsg, void *);
+struct mparse	 *mparse_alloc(enum mparset, enum mandoclevel,
+			mandocmsg, void *, char *);
 void		  mparse_free(struct mparse *);
 void		  mparse_keep(struct mparse *);
 enum mandoclevel  mparse_readfd(struct mparse *, int, const char *);
Index: mandocdb.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mandocdb.c,v
retrieving revision 1.38
diff -u -p -r1.38 mandocdb.c
--- mandocdb.c	15 Jan 2012 16:31:05 -0000	1.38
+++ mandocdb.c	8 Apr 2012 15:07:08 -0000
@@ -374,7 +374,7 @@ mandocdb(int argc, char *argv[])
 	info.lorder = 4321;
 	info.flags = R_DUP;
 
-	mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL);
+	mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, NULL);
 
 	memset(&buf, 0, sizeof(struct buf));
 	memset(&dbuf, 0, sizeof(struct buf));
Index: mdoc.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mdoc.c,v
retrieving revision 1.86
diff -u -p -r1.86 mdoc.c
--- mdoc.c	30 Sep 2011 00:13:21 -0000	1.86
+++ mdoc.c	8 Apr 2012 15:07:08 -0000
@@ -193,13 +193,14 @@ mdoc_free(struct mdoc *mdoc)
  * Allocate volatile and non-volatile parse resources.  
  */
 struct mdoc *
-mdoc_alloc(struct roff *roff, struct mparse *parse)
+mdoc_alloc(struct roff *roff, struct mparse *parse, char *defos)
 {
 	struct mdoc	*p;
 
 	p = mandoc_calloc(1, sizeof(struct mdoc));
 
 	p->parse = parse;
+	p->defos = defos;
 	p->roff = roff;
 
 	mdoc_hash_init();
Index: mdoc_validate.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mdoc_validate.c,v
retrieving revision 1.100
diff -u -p -r1.100 mdoc_validate.c
--- mdoc_validate.c	3 Dec 2011 22:47:27 -0000	1.100
+++ mdoc_validate.c	8 Apr 2012 15:07:08 -0000
@@ -1,7 +1,7 @@
 /*	$Id: mdoc_validate.c,v 1.100 2011/12/03 22:47:27 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <[email protected]>
- * Copyright (c) 2010, 2011 Ingo Schwarze <[email protected]>
+ * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <[email protected]>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -2183,14 +2183,15 @@ post_os(POST_ARGS)
 	n = mdoc->last;
 
 	/*
-	 * Set the operating system by way of the `Os' macro.  Note that
-	 * if an argument isn't provided and -DOSNAME="\"foo\"" is
-	 * provided during compilation, this value will be used instead
-	 * of filling in "sysname release" from uname().
+	 * Set the operating system by way of the `Os' macro.
+	 * The order of precedence is:
+	 * 1. the argument of the `Os' macro, unless empty
+	 * 2. the -Ios=foo command line argument, if provided
+	 * 3. -DOSNAME="\"foo\"", if provided during compilation
+	 * 4. "sysname release" from uname(3)
  	 */
 
-	if (mdoc->meta.os)
-		free(mdoc->meta.os);
+	free(mdoc->meta.os);
 
 	buf[0] = '\0';
 	if (-1 == (c = concat(buf, n->child, BUFSIZ))) {
@@ -2200,11 +2201,11 @@ post_os(POST_ARGS)
 
 	assert(c);
 
-	/* XXX: yes, these can all be dynamically-adjusted buffers, but
-	 * it's really not worth the extra hackery.
-	 */
-
 	if ('\0' == buf[0]) {
+		if (mdoc->defos) {
+			mdoc->meta.os = mandoc_strdup(mdoc->defos);
+			return(1);
+		}
 #ifdef OSNAME
 		if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) {
 			mdoc_nmsg(mdoc, n, MANDOCERR_MEM);
Index: read.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/read.c,v
retrieving revision 1.6
diff -u -p -r1.6 read.c
--- read.c	26 Feb 2012 21:01:43 -0000	1.6
+++ read.c	8 Apr 2012 15:07:08 -0000
@@ -54,6 +54,7 @@ struct	mparse {
 	void		 *arg; /* argument to mmsg */
 	const char	 *file; 
 	struct buf	 *secondary;
+	char		 *defos; /* default operating system */
 };
 
 static	void	  resize_buf(struct buf *, size_t);
@@ -236,7 +237,8 @@ pset(const char *buf, int pos, struct mp
 	switch (curp->inttype) {
 	case (MPARSE_MDOC):
 		if (NULL == curp->pmdoc) 
-			curp->pmdoc = mdoc_alloc(curp->roff, curp);
+			curp->pmdoc = mdoc_alloc(curp->roff, curp,
+					curp->defos);
 		assert(curp->pmdoc);
 		curp->mdoc = curp->pmdoc;
 		return;
@@ -252,7 +254,8 @@ pset(const char *buf, int pos, struct mp
 
 	if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3))  {
 		if (NULL == curp->pmdoc) 
-			curp->pmdoc = mdoc_alloc(curp->roff, curp);
+			curp->pmdoc = mdoc_alloc(curp->roff, curp,
+					curp->defos);
 		assert(curp->pmdoc);
 		curp->mdoc = curp->pmdoc;
 		return;
@@ -694,7 +697,8 @@ mparse_readfd(struct mparse *curp, int f
 }
 
 struct mparse *
-mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, mandocmsg mmsg, void *arg)
+mparse_alloc(enum mparset inttype, enum mandoclevel wlevel,
+		mandocmsg mmsg, void *arg, char *defos)
 {
 	struct mparse	*curp;
 
@@ -706,6 +710,7 @@ mparse_alloc(enum mparset inttype, enum 
 	curp->mmsg = mmsg;
 	curp->arg = arg;
 	curp->inttype = inttype;
+	curp->defos = defos;
 
 	curp->roff = roff_alloc(curp);
 	return(curp);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.